encoding
ModuleBody encodings, chosen for the caller: quoted-printable for text and base64 for attachments.
Contents
Functions
base64Base64 in lines of 76 characters, each ended by CRLF (the last one too, so a part always ends on its own line).boundaryA fresh multipart boundary: `=_` and 32 random hex digits. It needs no quoting and cannot appear in a base64 body.is_asciiWhether every byte is ASCII (the empty string included).line_endingsEvery line ending, whatever it started as (CRLF, CR or LF), becomes CRLF.quoted_printableQuoted-printable (RFC 2045 section 6.7) after `line_endings`, with lines of at most 76 characters.use utopia_smtp::mime::encoding::base64;Rust
pub fn base64(value: &[u8]) -> Vec<u8>Base64 in lines of 76 characters, each ended by CRLF (the last one too, so a part always ends on its own line).
Rust
use utopia_smtp::mime::encoding;
assert_eq!(encoding::base64(b"hello"), b"aGVsbG8=\r\n");use utopia_smtp::mime::encoding::boundary;Rust
pub fn boundary() -> StringA fresh multipart boundary: =_ and 32 random hex digits. It needs no
quoting and cannot appear in a base64 body.
use utopia_smtp::mime::encoding::is_ascii;Rust
pub fn is_ascii(value: &[u8]) -> boolWhether every byte is ASCII (the empty string included).
Rust
use utopia_smtp::mime::encoding;
assert!(encoding::is_ascii(b"plain text"));
assert!(!encoding::is_ascii("héllo".as_bytes()));use utopia_smtp::mime::encoding::line_endings;Rust
pub fn line_endings(value: &[u8]) -> Cow<'_, [u8]>Every line ending, whatever it started as (CRLF, CR or LF), becomes CRLF.
Rust
use utopia_smtp::mime::encoding;
assert_eq!(&*encoding::line_endings(b"a\n\rb"), b"a\r\n\r\nb");use utopia_smtp::mime::encoding::quoted_printable;Rust
pub fn quoted_printable(value: &[u8]) -> Vec<u8>Quoted-printable (RFC 2045 section 6.7) after line_endings, with
lines of at most 76 characters.
Rust
use utopia_smtp::mime::encoding;
assert_eq!(encoding::quoted_printable("1 = 1\nhé".as_bytes()), b"1 =3D 1\r\nh=C3=A9");Rust
pub const CHUNK: usize = 57Base64 wraps at 76 characters, which is 57 bytes of input.