Documentation
¶
Overview ¶
Package compose builds outgoing mail: the rules for replies and forwards (this file) and the message builder (docs/design/send.md).
Index ¶
- Variables
- func Attribution(date time.Time, name string, loc *time.Location) string
- func Build(w io.Writer, m Message) error
- func ForwardHTML(src Source, loc *time.Location) string
- func ForwardSubject(s string) string
- func NewMessageID(from string) string
- func QuoteHTML(src Source, loc *time.Location) string
- func ReplyReferences(src Source) []string
- func ReplySubject(s string) string
- func ValidAddress(a Address) bool
- type Address
- type Attachment
- type Calendar
- type Inline
- type Message
- type Source
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
ForwardSubject is a forward's subject: trimmed, unchanged when it already starts (case-insensitively) with "fwd:" or "fw:", else prefixed with "Fwd: ".
func NewMessageID ¶
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 ¶
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 ¶
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 ¶
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 ¶
ValidAddress reports whether Build accepts a as a recipient.
Types ¶
type Address ¶
Address is one mailbox address.
func ReplyRecipients ¶
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 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.
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.