Documentation ¶
Overview ¶
Package mailx implements precise syntactic RFC 822 message manipulation.
Package-wide plans: + TODO NEVER return io.EOF, change to io.ErrUnexpectedEOF + TODO change mailx.EOH to io.EOF
Index ¶
- Constants
- Variables
- func CopyMIMEHeader(header textproto.MIMEHeader) textproto.MIMEHeader
- func Fields2Mimeheader(fields []Field) textproto.MIMEHeader
- func JoinFields(fn string, fields []Field) string
- func SplitHeaderPartial(r io.Reader, fieldNames ...string) (textproto.MIMEHeader, error)
- type Field
- type Part
- type RawField
- type Splitter
Constants ¶
const ( MaxLineLength = 80 // including CRLF MaxAtomLength = 75 MaxLineOverlength = 1000 // including CRLF )
const CRLF = "\r\n"
const MessageIdEntropy = 24
This is one of the many formats mail.ParseDate attempts to parse; it also appears to be the most accurate date format specified for mail. time.RFC1123Z == "Mon, 02 Jan 2006 15:04:05 -0700"
Variables ¶
Functions ¶
func CopyMIMEHeader ¶
func CopyMIMEHeader(header textproto.MIMEHeader) textproto.MIMEHeader
func Fields2Mimeheader ¶
func Fields2Mimeheader(fields []Field) textproto.MIMEHeader
Types ¶
type Field ¶
type Field struct {
Name, Body string
}
Field.Name MAY NOT be in textproto.CanonicalMIMEHeaderKey form. It may also not be RFC-822-valid. See Field.CanonicalName() for both.
func Mimeheader2Fields ¶
func Mimeheader2Fields(h textproto.MIMEHeader) []Field
func Split ¶
Split is a convenience wrapper around NewSplitter. r must read a syntactically valid RFC 822 message (NOTE: some field body encodings may not be supported). Split MUST see a CRLF line after the header. No byte is lost except the CRLF separating header from body.
func (Field) CanonicalName ¶
Field.CanonicalName returns the canoncialised fixed name.
func (Field) Encode ¶
Encode encodes a Field in a way to maximise both decodability of the exact (including neighbouring whitespace) Field.Body by most mail agents as well as maximise MUA passthrough.
For a valid fieldname (nonempty, consisting of c>' '&&c!=':'&&c<='~') and a valid fieldbody (properly UTF-8-encoded), Encode is injective.
Encoded field may be folded. Encoded field includes a trailing CRLF.
The empty fieldname is encoded as "-". Invalid fieldname characters are replaced by '-'. Invalid fieldbody bytes are encoded as utf8.RuneError (there is no non-character-semantics IANA charset so encoding true data in mail field bodies is not possible in any context).
Overlong atoms (> 76 octets) or overlong lines (> 80 octets, including CRLF) may get emitted for whitespace-enclosed (counting left and right ends of string as implicit whitespace) strings of the form /<[!-~]*@[!-~]*>/ to aid in non-q-atom-compliant mail transfer agent's understanding of the message.
Guaranteed to not emit lines longer than 1000 bytes (including CRLF) if len(field.Name) <= 972 (equivalently, len(field.Name) + len(": ") + + len("=?UTF-8?Q?=FF=FF=FF=FF?=") + len("\r\n") <= 1000).
NOTE: When decoding mixed qatom/atom streams, whitespace is discarded iff it is present between two qatoms. [2023-11-13, jfrech] NOTE: An empty Q-encoded atom (e.g. "=?UTF-8?Q??=")
is invalid by RFC specifications.
[2023-11-22, jfrech] NOTE: Whitespace is kept between two atoms iff they
are not both q-atoms: decode("a b") = "a b", decode("a =?UTF-8?Q?b?=") = "a b", decode("=?UTF-8?Q?a?= b") = "a b", decode("=?UTF-8?Q?a?= =?UTF-8?Q?b?=") = "ab"
func (Field) Equal ¶
Equality in the /Field.CanonicalName coset.
type Part ¶
type RawField ¶
type RawField []byte
func (RawField) CanonicalName ¶
XXX this performs no checking if the rawfield is syntactically valid
func (RawField) Decode ¶
Field.Name == textproto.CanonicalMIMEHeaderKey(Field.Name)
type Splitter ¶
type Splitter struct {
// contains filtered or unexported fields
}