suppressionv1
import suppressionv1 "pocketone.dev/ext/contracts/mail/suppression/v1"
Package suppressionv1 is the mail.suppression/v1 contract: addresses an app must not send bulk mail to (unsubscribed, bounced, complained), and the unsubscribe link every bulk message carries. Anything that sends to many people checks it; whatever provides it keeps the list.
A wire contract at /api/_c/mail.suppression/v1. The unsubscribe operations are public: the link in a message is signed by the provider, and mail providers POST to it for one-click unsubscribes (RFC 8058).
Source: ext/contracts/mail/suppression/v1.
Constants
const (
Unsubscribed = "unsubscribed"
Bounced = "bounced"
Complained = "complained"
Manual = "manual"
)
Reasons an address is suppressed.
Variables
var Contract = extkit.NewContract[List]("mail.suppression/v1", extkit.One).JS(extkit.JSHooks, nil).JSTypes(jsTypes)
Contract is mail.suppression/v1.
var W = extkit.NewWire(Contract, "suppression", func(inner List, g *extkit.Guard[List]) List {
return &guardList{inner, g}
},
extkit.Op[List]{
Name: "check",
Desc: "Says whether an address is suppressed, and why.",
Method: "GET",
Path: "check",
Scope: "suppression:read",
In: reflect.TypeOf(Address{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl List, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in Address
if err := extkit.DecodeQuery(req.Query, &in); err != nil {
return nil, err
}
return impl.Check(ctx, a, in)
},
},
extkit.Op[List]{
Name: "suppress",
Desc: "Adds an address (or changes its reason).",
Method: "POST",
Path: "suppress",
In: reflect.TypeOf(SuppressInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl List, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in SuppressInput
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Suppress(ctx, a, in)
},
},
extkit.Op[List]{
Name: "unsuppress",
Desc: "Removes an address, so it receives bulk mail again.",
Method: "POST",
Path: "unsuppress",
In: reflect.TypeOf(Address{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl List, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in Address
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Unsuppress(ctx, a, in)
},
},
extkit.Op[List]{
Name: "unsubscribe_page",
Desc: "Is the page an unsubscribe link opens (?t=<signed token>). It never unsubscribes by itself: link scanners open every URL in a message.",
Method: "GET",
Path: "unsubscribe",
Scope: "public",
In: reflect.TypeOf(Link{}),
Out: extkit.OutRaw,
Invoke: func(ctx context.Context, impl List, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in Link
if err := extkit.DecodeQuery(req.Query, &in); err != nil {
return nil, err
}
return impl.UnsubscribePage(ctx, a, in)
},
},
extkit.Op[List]{
Name: "unsubscribe",
Desc: "Confirms the page's form, or a mail provider's one-click POST (List-Unsubscribe=One-Click).",
Method: "POST",
Path: "unsubscribe",
Scope: "public",
RawIn: true,
Out: extkit.OutRaw,
Invoke: func(ctx context.Context, impl List, a extkit.Auth, req extkit.OpRequest) (any, error) {
in := extkit.RawIn{Query: req.Query, Body: req.Body, ContentType: req.ContentType, Header: req.Header}
return impl.Unsubscribe(ctx, a, in)
},
},
)
W is mail.suppression/v1's wire side: routes at /api/_c/mail.suppression/v1/<op>, action hooks, MCP tools and the client.
Functions
OnCheck
func OnCheck(owner any, fn func(e *extkit.CallEvent, in *Address) error)
OnCheck binds fn to check calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnSuppress
func OnSuppress(owner any, fn func(e *extkit.CallEvent, in *SuppressInput) error)
OnSuppress binds fn to suppress calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnUnsubscribe
func OnUnsubscribe(owner any, fn func(e *extkit.CallEvent, in *extkit.RawIn) error)
OnUnsubscribe binds fn to unsubscribe calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnUnsubscribePage
func OnUnsubscribePage(owner any, fn func(e *extkit.CallEvent, in *Link) error)
OnUnsubscribePage binds fn to unsubscribe_page calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnUnsuppress
func OnUnsuppress(owner any, fn func(e *extkit.CallEvent, in *Address) error)
OnUnsuppress binds fn to unsuppress calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
Types
Address
type Address struct {
Email string `json:"email"`
}
Address is one email address.
Client
type Client struct {
// contains filtered or unexported fields
}
Client is mail.suppression/v1 over HTTP, for the CLI and other apps. It implements List; the token it was made with is the credential, so the extkit.Auth argument is ignored.
NewClient
func NewClient(baseURL, token string, hc *http.Client) *Client
NewClient calls mail.suppression/v1 on the app at baseURL with token (a PocketBase auth token or an API token).
Client.Check
func (c *Client) Check(ctx context.Context, _ extkit.Auth, in Address) (Status, error)
Client.Suppress
func (c *Client) Suppress(ctx context.Context, _ extkit.Auth, in SuppressInput) (Status, error)
Client.Unsubscribe
func (c *Client) Unsubscribe(ctx context.Context, _ extkit.Auth, in extkit.RawIn) (extkit.RawOut, error)
Client.UnsubscribePage
func (c *Client) UnsubscribePage(ctx context.Context, _ extkit.Auth, in Link) (extkit.RawOut, error)
Client.Unsuppress
func (c *Client) Unsuppress(ctx context.Context, _ extkit.Auth, in Address) (Status, error)
Link
type Link struct {
T string `json:"t"`
}
Link is an unsubscribe link's signed token (?t=).
List
type List interface {
// Check says whether an address is suppressed, and why.
//
//op: GET check scope=suppression:read
Check(ctx context.Context, a extkit.Auth, in Address) (Status, error)
// Suppress adds an address (or changes its reason).
//
//op: POST suppress
Suppress(ctx context.Context, a extkit.Auth, in SuppressInput) (Status, error)
// Unsuppress removes an address, so it receives bulk mail again.
//
//op: POST unsuppress
Unsuppress(ctx context.Context, a extkit.Auth, in Address) (Status, error)
// UnsubscribePage is the page an unsubscribe link opens (?t=<signed token>). It never unsubscribes by itself: link
// scanners open every URL in a message.
//
//op: GET unsubscribe scope=public
UnsubscribePage(ctx context.Context, a extkit.Auth, in Link) (extkit.RawOut, error)
// Unsubscribe confirms the page's form, or a mail provider's one-click POST (List-Unsubscribe=One-Click).
//
//op: POST unsubscribe scope=public
Unsubscribe(ctx context.Context, a extkit.Auth, in extkit.RawIn) (extkit.RawOut, error)
}
List is an app's suppression list.
Status
type Status struct {
Email string `json:"email"`
Suppressed bool `json:"suppressed"`
Reason string `json:"reason,omitempty"`
Since *time.Time `json:"since,omitempty"`
}
Status is an address's place on the list.
SuppressInput
type SuppressInput struct {
Email string `json:"email"`
Reason string `json:"reason"` // Unsubscribed, Bounced, Complained or Manual
Source string `json:"source,omitempty"` // where it came from: link, one-click, ses, webhook, ...
Campaign string `json:"campaign,omitempty"` // the campaign that caused it, if any
}
SuppressInput suppresses an address.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.