Documentation
¶
Overview ¶
Package mime encodes electronic mail parts for delivery.
One way to encode the message is as either mixed or related, depending on the presence of inline attachments:
multipart/related |- multipart/alternative | |- text/plain | `- text/html |- attachments... `- inline_attachments...
This approach may not work in older clients, like Apple Mail.
A better way to structure the multipart MIME message is by subordinating the inline attachments to the alternative related part. The packages uses this approach to ensure compatibility with older clients:
multipart/mixed |- multipart/alternative | |- text/plain | `- multipart/related | |- text/html | `- inline_attachments... `- attachments...
Inline images can be encoded into the HTML image tag as base64 encoded data. However, Outlook completely blocks such images. Therefore, this package always encodes inline images as attachments and references them via a content ID in the HTML image source attribute.
All output of this package is wrapped to LineLengthLimit, not just the headers. RFC 5321 requires that electronic mail text lines must not exceed 1,000 characters. This requirement is full satisfied. The content of plain text and HTML sections are wrapped by `mime/quotedprintable` encoding of the stardard library.
Index ¶
- Constants
- func FileContentDisposition(fieldname, filename string) string
- func NewBoundary(r *rand.Rand) string
- func NewEncoderBase64(w io.Writer) io.WriteCloser
- func SplitAttachments(s string, attachments []cachedAttachment) (normal []cachedAttachment, inline []inlineAttachment)
- func WriteAddressHeader(w io.Writer, name string, addresses ...mail.Address) (err error)
- func WriteHeader(w io.Writer, name, value string) (n int, err error)
- func WriteTimeHeader(w io.Writer, name string, t time.Time) (int, error)
- type AttachmentRepository
- type Writer
Constants ¶
const ( // LineLengthLimit is the maximum length of a line // for MIME encoding. // // RFC 5322 2.1.1 limits to 78, excluding CRLF. // `mime/quotedprintable` sets this to 76. LineLengthLimit = 76 // BoundaryLengthLimit is the maximum length of a boundary string // for MIME encoding according to RFC 1341 set to 70 characters. Boundary can never // wrap to the next line, as space characters are not allowed in boundaries. // Therefore, the maximum length must be reduced by the length of the parameter name. BoundaryLengthLimit = 70 - len(`boundary`) + 2 // Mime package BEncoder refers to RFC 2047, section 2 to set // maximum word length to 75 characters. from which the length // of the prefix and suffix are subtracted to get the limit. // One less is to prevent line wrapping in the middle of a multi-byte // UTF character rune. WordLengthLimit = LineLengthLimit - 1 - len("=?UTF-8?b?") - len("?=") BEncodingPrefix = "=?UTF-8?b?" BEncodingSuffix = "?=" CRNL = "\r\n" ContentTypeOctetStream = "application/octet-stream" ContentTypeTextPlain = "text/plain" ContentTypeTextHTML = "text/html" ContentTypeImageJPEG = "image/jpeg" ContentTypeImageBMP = "image/bmp" ContentTypeImagePNG = "image/png" ContentTypeImageGIF = "image/gif" ContentTypeImageWEBP = "image/webp" ContentTypeZip = "application/zip" )
Variables ¶
This section is empty.
Functions ¶
func FileContentDisposition ¶
FileContentDisposition returns the value of a Content-Disposition header with the provided field name and file name.
func NewBoundary ¶
func NewEncoderBase64 ¶
func NewEncoderBase64(w io.Writer) io.WriteCloser
NewEncoderBase64 encodes data to standard Base64 encoding while keeping each line under LineLengthLimit. Encoder must be closed to work correctly.
func SplitAttachments ¶
func SplitAttachments(s string, attachments []cachedAttachment) (normal []cachedAttachment, inline []inlineAttachment)
func WriteAddressHeader ¶
WriteAddressHeader writes a list of MIME-mail encoded address header to the given writer. It respects LineLengthLimit by wrapping long lines. If no addresses are provided, it does nothing.
TODO: if the name is too long, it will not be wrapped. TODO: if the email address is too long, it will not be wrapped.
func WriteHeader ¶
TODO: remove <n int> from WriteHeader signature