Documentation
¶
Overview ¶
Package msg reads and writes RFC 5322 messages: parsing what arrives (tolerant of the malformed mail spam and old clients produce), composing what lfr sends, and turning HTML into readable text.
Index ¶
- func Compose(d Draft) ([]byte, error)
- func Fold(raw []byte) []byte
- func FormatAddress(name, email string) string
- func HTMLToText(src string) string
- func NewMessageID(domain string) string
- func Rewrite(raw []byte, set [][2]string, drop []string) ([]byte, error)
- func Snippet(text string, n int) string
- type Address
- type Attachment
- type Draft
- type File
- type Header
- type Parsed
- type Part
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compose ¶
Compose renders d as a MIME message with CRLF line endings: text only, multipart/alternative when HTML is present, multipart/mixed with files.
func Fold ¶
Fold wraps header fields longer than 78 characters at whitespace, so lines with encoded words stay within RFC 2047's 76 characters and every line within RFC 5322 §2.1.1's 78 where a break is possible. Only the top header of raw changes; raw has CRLF line endings.
func FormatAddress ¶
FormatAddress renders "Name <email>".
func HTMLToText ¶
HTMLToText renders HTML as plain text: blocks become paragraphs, list items get dashes, links keep their target when it differs from their text, and scripts, styles and hidden preheaders disappear.
func NewMessageID ¶
NewMessageID makes a unique Message-ID on domain.
Types ¶
type Attachment ¶
type Attachment struct {
Index int `json:"index"`
Name string `json:"name"`
Type string `json:"type"`
Size int `json:"size"`
}
Attachment describes one attachment of a parsed message.
func AttachmentData ¶
func AttachmentData(raw []byte, i int) (Attachment, []byte, bool)
AttachmentData returns the content of attachment i of raw.
type Draft ¶
type Draft struct {
From Address
To, Cc []Address
ReplyTo []Address
Subject string
Date time.Time
MessageID string // without angle brackets; generated when empty
InReplyTo string
References []string
Header [][2]string // extra fields, in order (e.g. List-Unsubscribe)
Text string
HTML string
Files []File
}
Draft is a message to compose.
type Header ¶
type Header struct {
// contains filtered or unexported fields
}
Header is the top-level header, keys canonical.
type Parsed ¶
type Parsed struct {
From Address `json:"from"`
To []Address `json:"to,omitempty"`
Cc []Address `json:"cc,omitempty"`
ReplyTo []Address `json:"reply_to,omitempty"`
Subject string `json:"subject"`
Date time.Time `json:"date"`
MessageID string `json:"message_id,omitempty"`
InReplyTo string `json:"in_reply_to,omitempty"`
References []string `json:"references,omitempty"`
Text string `json:"text"`
HTML string `json:"html,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
Header Header `json:"-"`
Parts []Part `json:"-"` // every leaf part, for reports and bounces
}
Parsed is the readable content of a message.