Skip to main content

Module encode

Module encode 

Source
Expand description

The encodings a message has to speak.

Base64, quoted-printable, RFC 2047 encoded-words, header folding, RFC 5322 dates, and SMTP dot-stuffing. None of it is interesting, and all of it is where mail actually breaks: a header that is one byte too long, a body line that starts with a dot, an accented name that arrives as mojibake.

Functions§

base64_body
Base64 wrapped at 76 characters with CRLF, which is what a MIME body part must look like — an unwrapped 2 MB single line is not a legal message.
base64_decode
base64_encode
dot_stuff
Prefix any line that starts with . with a second one.
encode_word
Encode a header value as RFC 2047 encoded-words when it is not plain ASCII.
header_line
Write Name: value, folded so no line runs past [HEADER_WIDTH].
normalize_crlf
Every line ending becomes CRLF, which is the only line ending a message on the wire is allowed to have.
percent_encode
Percent-encode a filename for an RFC 2231 filename* parameter.
quoted_printable
Encode a body part as quoted-printable (RFC 2045).
rfc5322_date
Format a Date: header, RFC 5322 style, in UTC.
sanitize_header_text
Strip anything that would let a value break out of its header.
unique_token
A value unique within this process, for boundaries and message ids.