unsubscribe

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package unsubscribe unsubscribes a person from a mailing list with the one-click web link the list's mail carries (RFC 8058): a List-Unsubscribe header that names an https URL, and a List-Unsubscribe-Post header of "List-Unsubscribe=One-Click". It is the only package that calls an unsubscribe link. MailRules never sends email on the person's behalf, so a list that offers only a mailto: address cannot be unsubscribed from here.

The link comes from the email, so whoever sent it chose it. Client calls it only on the public internet (publicnet): a link that leads to the daemon's own machine or network is refused when it is dialed, on the address actually connected to. The fake for tests is in unsubscribe/unsubscribetest.

Index

Constants

View Source
const Timeout = 10 * time.Second

Timeout bounds one unsubscribe request, connection and answer included.

Variables

View Source
var ErrNotOneClick = errors.New("not a one-click unsubscribe link")

ErrNotOneClick means the link is not an RFC 8058 one-click link MailRules calls: not https, not on port 443, or not a URL at all. Nothing was sent.

Functions

func Host

func Host(link string) string

Host returns the host name of a link, for logs and messages: never the whole link.

func OneClick

func OneClick(headers map[string][]string) string

OneClick returns the https link of an RFC 8058 one-click unsubscribe that headers (canonical keys, as message.Summary.Headers has them) offer, or "" when they offer none: no List-Unsubscribe, one that names only mailto: or http: links, or no List-Unsubscribe-Post of "List-Unsubscribe=One-Click".

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the daemon's Unsubscriber: an HTTP client that connects only to public addresses, sends no cookies, follows no redirect and gives up after Timeout.

func New

func New(r publicnet.Resolver) *Client

New returns the daemon's client. r looks up a link's host; nil is the system's resolver.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(ctx context.Context, link string) error

Unsubscribe POSTs the one-click body to link. No cookie, authorization or other context goes with it (RFC 8058).

type RefusedError

type RefusedError struct {
	Host   string
	Status int
}

RefusedError is the answer of a site that did not take the unsubscribe: any status but 2xx, a redirect included (RFC 8058 has the site answer the POST itself).

func (*RefusedError) Error

func (e *RefusedError) Error() string

type Unsubscriber

type Unsubscriber interface {
	// Unsubscribe POSTs "List-Unsubscribe=One-Click" to link and returns nil when the site
	// answered 2xx. An error never contains the link, which often carries a token that
	// names the person; at most its host.
	Unsubscribe(ctx context.Context, link string) error
}

Unsubscriber calls a one-click unsubscribe link. The daemon's is Client; tests use unsubscribetest.Fake.

Directories

Path Synopsis
Package unsubscribetest is an in-memory unsubscribe.Unsubscriber for tests of the packages that unsubscribe.
Package unsubscribetest is an in-memory unsubscribe.Unsubscriber for tests of the packages that unsubscribe.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL