mox

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package mox adapts the mox admin API (Sherpa JSON-RPC) to mail.Engine.

Index

Constants

View Source
const (
	TimeoutEnv  = "APP_MAIL_API_TIMEOUT"
	MaxBytesEnv = "APP_MAIL_API_MAX_BYTES"
	// AdminPortEnv overrides the mox admin listener port inside the container.
	AdminPortEnv = "APP_MAIL_ADMIN_PORT"

	// DefaultAdminPort is the hardened template's admin listener, never
	// published on the host.
	DefaultAdminPort = 8080
)

Env knobs for the admin API client.

Variables

This section is empty.

Functions

func AdminBaseURL

func AdminBaseURL(host string) string

AdminBaseURL builds the adapter address from the service's container address on the app network. The control plane resolves host; the admin port is never reachable from outside that network.

func AdminReachable

func AdminReachable(ctx context.Context, base string) bool

AdminReachable reports whether the admin listener at base answers HTTP. It sends no credentials: any non-5xx reply (a login prompt included) proves the listener is up. Private-target rules match New.

func ExtractDKIM

func ExtractDKIM(recs []mail.DNSRecord) []mail.DKIMKey

ExtractDKIM finds DKIM TXT records and returns the selector and bare public key of each, in selector order, so the DNS engine can build the record.

func ParseRecords

func ParseRecords(lines []string) []mail.DNSRecord

ParseRecords turns zone-file lines into records, skipping blanks and comments. A line that does not parse is skipped rather than failing the set.

Types

type Client

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

Client talks to one mox admin API.

func New

func New(cfg Config) (*Client, error)

New validates the configured address and builds a client. Only http(s) is accepted and link-local or metadata hosts are refused up front; the dial guard repeats the check on the resolved address.

func (*Client) AccountDetail

func (c *Client) AccountDetail(ctx context.Context, name string) (mail.AccountDetail, error)

AccountDetail reads the account config and its disk usage; mox returns both as a two element result.

func (*Client) Accounts

func (c *Client) Accounts(ctx context.Context) ([]mail.Account, error)

Accounts lists accounts. mox returns two lists: every account, then the ones with login disabled (verified against v0.0.17).

func (*Client) AddAccount

func (c *Client) AddAccount(ctx context.Context, a mail.AccountSpec) error

AddAccount creates the account, turns off self-chosen passwords so only generated ones are used (ADR 059 section 2.4), and sets the password. A failure after the add removes the half-made account again.

func (*Client) AddAddress

func (c *Client) AddAddress(ctx context.Context, address, account string) error

AddAddress attaches another address to an existing account.

func (*Client) AddAlias

func (c *Client) AddAlias(ctx context.Context, a mail.Alias) error

AddAlias forwards the alias address to its targets.

func (*Client) AddDomain

func (c *Client) AddDomain(ctx context.Context, d mail.DomainSpec) error

AddDomain creates the domain. With an existing account the localpart must be empty.

func (*Client) Aliases

func (c *Client) Aliases(ctx context.Context, domain string) ([]mail.Alias, error)

Aliases lists a domain's aliases from DomainLocalparts, whose second result maps alias localparts to their config.

func (*Client) DKIMKeys

func (c *Client) DKIMKeys(ctx context.Context, domain string) ([]mail.DKIMKey, error)

DKIMKeys returns the selectors and public keys from the domain records.

func (*Client) DNSRecords

func (c *Client) DNSRecords(ctx context.Context, domain string) ([]mail.DNSRecord, error)

DNSRecords returns the engine's zone-file lines for the domain, parsed.

func (*Client) Domains

func (c *Client) Domains(ctx context.Context) ([]mail.Domain, error)

Domains lists served domains. mox returns either plain names or objects with an ASCII form; both decode here.

func (*Client) Health

func (c *Client) Health(ctx context.Context) error

Health checks login and a cheap read.

func (*Client) HoldMessages

func (c *Client) HoldMessages(ctx context.Context, ids []int64, hold bool) (int, error)

HoldMessages sets hold on the listed ids only. An empty list is refused because an empty mox filter matches the whole queue.

func (*Client) HoldQueue

func (c *Client) HoldQueue(ctx context.Context) error

HoldQueue pauses delivery of every queued message (mox QueueHoldSet).

func (*Client) QueueList

func (c *Client) QueueList(ctx context.Context, limit int) ([]mail.QueueEntry, error)

QueueList lists up to limit queued messages, oldest first.

func (*Client) QueueStats

func (c *Client) QueueStats(ctx context.Context) (mail.QueueStats, error)

QueueStats counts queued messages and those whose last attempt failed.

func (*Client) ReleaseQueue

func (c *Client) ReleaseQueue(ctx context.Context) error

ReleaseQueue resumes delivery of held messages.

func (*Client) RemoveAccount

func (c *Client) RemoveAccount(ctx context.Context, name string) error

RemoveAccount deletes the account by name.

func (*Client) RemoveAlias

func (c *Client) RemoveAlias(ctx context.Context, address string) error

RemoveAlias deletes the alias.

func (*Client) RemoveDomain

func (c *Client) RemoveDomain(ctx context.Context, name string) error

RemoveDomain deletes the domain.

func (*Client) SetLoginDisabled

func (c *Client) SetLoginDisabled(ctx context.Context, account, message string) error

SetLoginDisabled saves the account's LoginDisabled message; "" re-enables.

func (*Client) SetPassword

func (c *Client) SetPassword(ctx context.Context, account, password string) error

SetPassword sets the mailbox password; the value is scrubbed from errors.

func (*Client) SetQuota

func (c *Client) SetQuota(context.Context, string, mail.Quota) error

SetQuota is unsupported: mox keeps quota in its config file, not the API.

type Config

type Config struct {
	BaseURL     string
	Credentials mail.CredentialSource
	HTTPClient  *http.Client
}

Config configures the adapter. BaseURL is the engine's admin origin on the app network (see AdminBaseURL), for example http://10.0.0.5:8080. HTTPClient is for tests only.

Jump to

Keyboard shortcuts

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