mx

package
v0.97.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 48 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mx implements mail exchange processing.

Index

Constants

View Source
const (
	DraftHeaderBcc     = "X-TeaNode-Draft-Bcc"
	DraftHeaderReplyTo = "X-TeaNode-Draft-Reply-To-Item"
	DraftHeaderForward = "X-TeaNode-Draft-Forward-Item"

	// DraftHeaderKey names the draft itself, across saves.
	//
	// Saving a draft writes a new message and removes the old one, which is
	// what IMAP means by editing one: a stored message never changes, so a
	// changed draft is a different message with a different item. That makes
	// an item id a name for one save rather than for the draft, and anything
	// holding an item id -- an agent that wrote a draft and is waiting to be
	// told to send it, a held reply -- is left pointing at a message that is
	// gone the moment the person opens the draft and the composer saves it.
	// This key is written on the first save and carried by every save after
	// it, so there is a name for the draft that outlives them.
	DraftHeaderKey = "X-TeaNode-Draft-Key"
)

The headers a draft carries for the composer: what it answers or forwards, by item, and the Bcc the sent message will not show.

Variables

This section is empty.

Functions

func AttachmentCount

func AttachmentCount(mail *models.Mail) int

AttachmentCount is how many attachments a message carries, for the index.

func FindSentCopy

func FindSentCopy(tx db.Transaction, folder *models.MailboxFolder, messageId string) (*models.MailboxItem, error)

FindSentCopy is the item a Sent folder already holds for a message, by Message-ID, or nil.

A message a person sends reaches their Sent folder twice: this server files it there when it accepts the submission, and the mail program then uploads its own copy over IMAP, because a program cannot know that the server has filed it. The two arrive tens of milliseconds apart, in either order, and are the same message under one Message-ID. Whichever comes second finds the first here and leaves it at that. Only Sent: a program uploads a draft again on purpose, and there the newer copy is the one wanted.

func RuleMatches

func RuleMatches(rule models.MailboxRule, mail *models.Mail, senderKnown bool, insight *models.MailInsight) bool

RuleMatches is the dry run the settings page offers: which of the last messages would this rule match.

func SearchDocument

func SearchDocument(mail *models.Mail) string

SearchDocument is the text a folder search runs over: subject, sender, recipients, the readable body and the attachments' names.

func ThreadIDFor

func ThreadIDFor(tx db.Transaction, headers []string) (string, error)

ThreadIDFor is the conversation a message belongs to: the thread of whatever it answers, by In-Reply-To or References, or nothing when it answers nothing and so begins one of its own.

Exported because the exchange is not the only thing that stores a message. A draft saved from the dashboard and a message a mail program appends over IMAP are stored too, and one stored without a conversation reads as a conversation of its own — which for a draft reply, or a program's own copy of what it sent, is wrong in the one place it shows.

Types

type AgentHook

type AgentHook interface {
	OnMailboxDelivery(tx db.Transaction, mailbox *models.Mailbox, item *models.MailboxItem, mail *models.Mail)
}

AgentHook is told, inside the delivery transaction, that a message has been placed in a mailbox. It queues work in that transaction and never calls a model: a model outage must never bounce mail. Errors are its own to log; delivery does not wait on it.

type CalendarHook

type CalendarHook interface {
	// recipient is the address this was delivered to. An invitation has to
	// name the person whose calendar it enters, and the address the sender
	// wrote to is the only place that is reliably known: a mailbox reached
	// by a catch-all advertises no address of its own.
	OnMailboxDelivery(tx db.Transaction, mailbox *models.Mailbox, recipient string, item *models.MailboxItem, mail *models.Mail)
}

CalendarHook is told the same thing, and for the same reason: a message may carry an invitation, and working out whether it does means reading the message from storage. It notes the message in the delivery transaction and reads it afterwards.

Separate from AgentHook because an invitation is not the agent's business: a person who has never turned an agent on still wants their meetings.

type Exchange

type Exchange interface {
	Close() error

	// handle received mail
	HandleEnvelope(ctx context.Context, envelope *mailparse.Envelope) error

	// AcceptSubmission prepares mailbox mail, storage and queued deliveries in
	// the supplied transaction. The caller's commit makes acceptance durable;
	// no external delivery starts here. Errors roll back this command's writes.
	AcceptSubmission(ctx context.Context, transaction db.Transaction, envelope *mailparse.Envelope) (*models.Mail, error)

	// SetAgentHook installs what is told about a message placed in a
	// mailbox, inside the delivery transaction. Nil means nobody is told,
	// which is the case while the agent is off.
	SetAgentHook(hook AgentHook)

	// SetCalendarHook installs what is told about a message that may carry
	// an invitation.
	SetCalendarHook(hook CalendarHook)

	// RunInsightRules runs the rules that read the agent's insight — the
	// second phase, once the insight exists — against a message in the
	// Inbox. The first phase ran at delivery for the other rules.
	RunInsightRules(tx db.Transaction, mailbox *models.Mailbox, item *models.MailboxItem, mail *models.Mail, insight *models.MailInsight) error

	// AutoReplyRefusal is why a message in a mailbox must not be answered
	// automatically, or empty when it may be: the out-of-office reply's
	// ladder, with the given quiet period per sender (zero for the
	// out-of-office default).
	AutoReplyRefusal(tx db.Transaction, mailbox *models.Mailbox, recipient string, item *models.MailboxItem, mail *models.Mail, now time.Time) (string, error)
}

func Open

func Open(database db.Database, configuration config.Store, storage storage.Storage, resolver resolver.Resolver, spamFilter spamfilter.Filter, clamav clamav.Client, locator geoip.Locator, settings *Settings) (Exchange, error)

type RelaySettings

type RelaySettings struct {
	Host string
	Port uint16

	// TLS is how the connection is encrypted, and whether the certificate is
	// checked. See smtpc.TLSMode.
	TLS smtpc.TLSMode

	Username string
	Password string
}

RelaySettings describes the one server outgoing mail is handed to.

func (*RelaySettings) Address

func (self *RelaySettings) Address() string

Address is the relay as a dialable host:port.

type Settings

type Settings struct {
	// server identity
	Server  string
	Service string

	// MailServers are the names mail arrives at for this server — what every
	// configured domain's MX records point at. Used to notice that a domain
	// being delivered to is served by this same server, which would loop.
	//
	// This was one name, filled from server.name, and that is not what an MX
	// record points at: the panel tells an operator to publish MX records
	// naming server.mailServers, so on any deployment where the two differ
	// the check compared against a name no MX record carries and never fired.
	MailServers []string

	// secret for signing addresses
	Secret []byte

	// socks5 proxy for outbound smtp connections (optional)
	SOCKS5Proxy string

	// Relay hands outgoing mail to one server rather than delivering it by
	// MX lookup. Nil when mail is delivered directly.
	Relay *RelaySettings

	// whether to disable sending mail over smtp
	DisableSendMail bool
}

Jump to

Keyboard shortcuts

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