compose

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 14 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 compose builds outgoing mail: the rules for replies and forwards (this file) and the message builder (docs/design/send.md).

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("invalid message")

ErrInvalid marks a message Build refuses to write: a header value with a line break, an address that does not parse, a bad message identifier.

Functions

func Attribution

func Attribution(date time.Time, name string, loc *time.Location) string

Attribution is the line above a quoted message: "On <date> at <time>, <name> wrote:", with name "someone" when empty, the date rendered in loc.

func Build

func Build(w io.Writer, m Message) error

Build writes m to w as an RFC 5322 message with CRLF line endings (docs/design/send.md, Building a message). The body is multipart/alternative with a text and an HTML part; the HTML part is inside multipart/related with the inline images when there are any, and the alternative is inside multipart/mixed with the attachments when there are any. Bodies are quoted-printable or base64 and non-ASCII header text is RFC 2047 or RFC 2231 encoded, so the message is 7-bit. Build checks m before writing anything and returns an error wrapping ErrInvalid for a value it will not write.

func ForwardHTML

func ForwardHTML(src Source, loc *time.Location) string

ForwardHTML is the body of a forward: a "Begin forwarded message" line above a cite blockquote holding the source's From, Subject, Date and To headers, then the quoted body. Every inserted value is HTML-escaped. Selected is ignored: forwards always quote the whole message.

func ForwardSubject

func ForwardSubject(s string) string

ForwardSubject is a forward's subject: trimmed, unchanged when it already starts (case-insensitively) with "fwd:" or "fw:", else prefixed with "Fwd: ".

func NewMessageID

func NewMessageID(from string) string

NewMessageID returns a random message identifier (without angle brackets) in the domain of the address from, or in frostmail.invalid when from has no usable domain. Content IDs use it too.

func QuoteHTML

func QuoteHTML(src Source, loc *time.Location) string

QuoteHTML is the body of a reply: the attribution line above the quoted source inside a cite blockquote. The attribution name is the source's From name, else its address. A non-blank Selected replaces the body with escaped plain text, after normalizing line endings and trimming whitespace.

func ReplyReferences

func ReplyReferences(src Source) []string

ReplyReferences is a reply's References: the source's References then its Message-ID, skipping empty strings and repeats; when longer than 20, the first entry and the last 19. Nil when empty.

func ReplySubject

func ReplySubject(s string) string

ReplySubject is a reply's subject: trimmed, unchanged when it already starts (case-insensitively) with "re:", "aw:" or "sv:", else prefixed with "Re: ".

func ValidAddress

func ValidAddress(a Address) bool

ValidAddress reports whether Build accepts a as a recipient.

Types

type Address

type Address struct {
	Name string
	Addr string
}

Address is one mailbox address.

func ReplyRecipients

func ReplyRecipients(src Source, self []string, all bool) (to, cc []Address)

ReplyRecipients returns a reply's To and Cc. To is the source's Reply-To, else its From, without the account's own addresses (self); if that leaves To empty (a reply to one's own message), To is the source's To without self. With all, Cc is the source's To followed by its Cc, without self, without addresses already in To and without repeats (the first occurrence wins, name included); without all, Cc is nil. Empty addresses are dropped, and empty results are nil. Address comparisons ignore case.

type Attachment

type Attachment struct {
	Filename    string
	ContentType string // "" or unparsable means application/octet-stream
	Open        func() (io.ReadCloser, error)
}

Attachment is one attached file. Open is called once, while Build writes the part.

type Calendar

type Calendar struct {
	Method string
	Data   []byte
}

Calendar is an iCalendar object with its iTIP method, such as REPLY.

type Inline

type Inline struct {
	CID         string // without angle brackets, in Message-ID syntax
	ContentType string // "" or unparsable means application/octet-stream
	Open        func() (io.ReadCloser, error)
}

Inline is an image the HTML shows from a cid:<CID> URL.

type Message

type Message struct {
	From       Address
	ReplyTo    []Address
	To         []Address
	Cc         []Address
	Bcc        []Address
	Subject    string
	MessageID  string   // without angle brackets
	InReplyTo  string   // without angle brackets; may be empty
	References []string // without angle brackets
	Date       time.Time
	// HTML is the body; the text alternative is made from it.
	HTML string
	// Inline holds the images HTML refers to as cid: URLs.
	Inline      []Inline
	Attachments []Attachment
	// WriteBcc writes the Bcc header field. Only the Drafts copy sets it, so
	// its recipients survive on the server; a sent message never does.
	WriteBcc bool
	// Calendar, when set, is an iTIP object sent as mail (RFC 6047): the
	// last part of the alternative.
	Calendar *Calendar
}

Message is what Build writes: a draft's content with its headers.

func (Message) Envelope

func (m Message) Envelope() []string

Envelope returns the SMTP recipients: the To, Cc and Bcc addresses in that order, each once (compared case-insensitively).

type Source

type Source struct {
	From       Address
	ReplyTo    []Address
	To         []Address
	Cc         []Address
	Subject    string
	MessageID  string   // without angle brackets
	References []string // without angle brackets
	Date       time.Time
	HTML       string // the sanitized rendering; "" for a text-only message
	Text       string
	Selected   string // plain text selected for a reply; blank quotes the whole message; forwards ignore it
}

Source is the message a reply or forward starts from.

Jump to

Keyboard shortcuts

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