API / Minn\Mail / HeaderWords

HeaderWords final class

Minn\Mail\HeaderWords · public/minn/src/Minn/Mail/HeaderWords.php · 112 lines

Header text as mail carries it (RFC 2047): left alone when it is plain and short enough, quoted when a phrase needs it, otherwise encoded words in Q (mostly ASCII) or B (mostly not), folded to the line length the transport allows: 63 for PHP's mail(), 998 otherwise. Plain text only becomes an encoded word to be folded when it is too long for one line.

Used by 1

Constants and properties

constMAIL_LINE = 63
constSMTP_LINE = 998
privateATEXT_PHRASE = '/[^A-Za-z0-9!#$%&\'*+\\/=?^_`{|}~ -]/'

Public

staticencode(string $text, string $position, string $charset, int $lineLength, string $eol): string#

The header text encoded for its position ("text", "phrase" or "comment").

$lineLengthintthe transport's limit (MAIL_LINE or SMTP_LINE)
staticq(string $text, string $position = 'text'): string#

RFC 2047 "Q" encoding for a position: spaces as "_", and the characters the position cannot carry as =XX.

staticbase64Lines(string $text, string $charset): array#

Base64 lines of at most 63 characters cut at whole characters, so a multibyte character is never split across encoded words.

@return list<string>
staticdecode(string $value, string $charset): string#

Encoded words decoded (adjacent ones joined) and converted into $charset; other text passes through.

Internals 3

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatespecials(string $text, string $position): int#

How many characters the position counts as needing encoding.

privatebLines(string $text, string $charset, int $width): array#
@return list<string>
privateqLines(string $text, string $position, string $charset, int $width, string $eol): array#
@return list<string>