module

Alumna::SMTP::Header

Header values for the SMTP message (RFC 5322 and RFC 2047). All methods write to the IO. They do not build a String.

Mail.new (Alumna 0.10.1+) already rejects CR and LF in from, to, reply_to, and subject. So a value here cannot add a header line.

Constants

AT = 64_u8
FOLD_AT = 78

Recommended line length (RFC 5322 section 2.1.1). Folding aims for this.

LESS = 60_u8
LINE_LIMIT = 998

Hard line limit without CRLF (RFC 5322 section 2.1.1).

MORE = 62_u8
QUOTE = 34_u8
SPACE = 32_u8
TAB = 9_u8
WORD_BYTES = 39

UTF-8 bytes in one encoded word. 39 bytes = 52 base64 characters. "=?UTF-8?B?" + 52 + "?=" = 64, so "Subject: " + one word stays under 76.

Class methods

address(value : String) : Bytes

The bare address for the envelope and for the Message-ID domain. "Name a@b" gives "a@b". A value without "<...>" at the end is the address. The result is a view of the value bytes. It does not allocate.

Source
domain(value : String) : Bytes

The part after the last "@" of the bare address. Empty when there is no "@".

Source
write_address(io : IO, name : String, value : String) : Nil

Writes "Name: address" CRLF.

Source
write_addresses(io : IO, name : String, values : Array(String)) : Nil

Writes "Name: address, address" CRLF. Each address after the first is on its own folded line, so a long list does not make a long line.

Source
write_text(io : IO, name : String, value : String) : Nil

Writes "Name: value" CRLF for free text (Subject). Printable ASCII is folded at spaces. Other text uses RFC 2047 encoded words. A word too long to fold also uses encoded words, so no line passes LINE_LIMIT.

Source