API / Minn\Mail / TextWrap

TextWrap final class

Minn\Mail\TextWrap · public/minn/src/Minn/Mail/TextWrap.php · 118 lines

Word wrapping for mail text. Lines break at spaces once they would pass the length; existing line breaks stay; a word longer than the line stays whole in plain text, and in quoted-printable text is cut into pieces ending in a soft break ("="), never inside an =XX escape or (for UTF-8) inside an encoded character. A line broken at a space keeps the space and, in quoted-printable text, a soft break after it.

Uses 1
Used by 1

Public

staticplain(string $text, int $length, string $eol): string#

Plain text wrapped to the length, every line ending in $eol.

staticquotedPrintable(string $text, int $length, string $charset, string $eol): string#

Quoted-printable text wrapped to the length with soft breaks, every line ending in $eol.

staticutf8Boundary(string $encoded, int $max): int#

Where to cut quoted-printable UTF-8 text at or before $max without splitting an encoded character.

Internals 5

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

privatewrapWith(string $text, int $length, string $softBreak, string $charset, string $eol): string#
privateline(string $line, int $length, string $softBreak, string $charset, string $eol): string#
privatecloseLine(string $word, string $out, string $buffer, int $length, string $softBreak, string $charset, string $eol): array#

Ends the line before a long word: with as much of the word as fits when more than twenty characters are left, else with a soft break.

@return array{0: string, 1: string} the output and what is left of the word
privatepieces(string $word, string $out, int $length, string $charset, string $eol): array#

A long word in line-length pieces, each but the last ending in a soft break.

@return array{0: string, 1: string} the output and the last piece, which starts the next line
privatecut(string $word, int $max, string $charset): int#

How much of the word to take: at most $max, never inside an escape.