mailio_mime_decode (mailio v0.2.0)

Low-level MIME decoders (pure, total).

Transfer decodings (quoted-printable, base64), RFC 2047 encoded-words, and charset conversion to UTF-8. Every function is total: malformed input is decoded best-effort rather than raising, matching the parser's "never throw on bad mail" policy.

Summary

Functions

Lenient base64 decode: ignores whitespace/newlines and tolerates missing padding. Never raises.

Body-mode quoted-printable decode. Underscores are literal here (only RFC 2047 Q-encoding maps _ to space).

Decode a leaf body according to its Content-Transfer-Encoding.

Decode all RFC 2047 encoded-words in a header value to a UTF-8 binary, leaving non-encoded runs intact. Adjacent encoded-words separated only by whitespace have that whitespace removed (RFC 2047 s6.2).

Map a charset label to a canonical atom understood by to_utf8/2.

Convert bytes in the named charset to a UTF-8 binary. Unknown or unconvertible charsets fall back to latin1 so text is never lost.

Functions

decode_base64(Bin)

-spec decode_base64(binary()) -> binary().

Lenient base64 decode: ignores whitespace/newlines and tolerates missing padding. Never raises.

decode_quoted_printable(Bin)

-spec decode_quoted_printable(binary()) -> binary().

Body-mode quoted-printable decode. Underscores are literal here (only RFC 2047 Q-encoding maps _ to space).

decode_transfer(Body, Encoding)

-spec decode_transfer(binary(), binary() | undefined) -> binary().

Decode a leaf body according to its Content-Transfer-Encoding.

decode_words(Bin)

-spec decode_words(binary()) -> binary().

Decode all RFC 2047 encoded-words in a header value to a UTF-8 binary, leaving non-encoded runs intact. Adjacent encoded-words separated only by whitespace have that whitespace removed (RFC 2047 s6.2).

normalize_charset(Bin)

-spec normalize_charset(binary() | undefined) -> atom().

Map a charset label to a canonical atom understood by to_utf8/2.

to_utf8(Bin, Charset)

-spec to_utf8(binary(), binary() | undefined) -> binary().

Convert bytes in the named charset to a UTF-8 binary. Unknown or unconvertible charsets fall back to latin1 so text is never lost.