Documentation

EncodedWord
in package

FinalYes

RFC 2047 encoded-word encoder/decoder - has no dependency on ext-imap.

Decoding handles both B (base64) and Q (quoted-printable-style) encoded-words, since real-world mail uses both; encoding only ever produces B, which is simpler and unconditionally correct for any content shape.

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
3.0.0

Table of Contents

Methods

decode()  : string
Decode all RFC 2047 encoded-words found in a string. Never throws - malformed or unrecognized encoded-word-shaped text is left as literal output.
encode()  : string
Encode a string into one or more RFC 2047 encoded-words, if it contains anything outside printable US-ASCII. Returns the input unchanged otherwise.
findRanges()  : array<string|int, mixed>
Find the byte ranges of every individual RFC 2047 encoded-word in a string - used by Header::fold() to treat an encoded-word as an atomic, unbreakable unit when choosing fold points. Folding between two adjacent encoded-words, at their separating whitespace, is still fine - only folding INSIDE one is not.
convertToUtf8()  : string
Convert decoded bytes to UTF-8, gracefully degrading if the charset can't be converted (no mbstring, or an unrecognized charset name)
decodeRun()  : string
Decode a run of one or more whitespace-separated encoded-words, dropping the whitespace between them per RFC 2047 §6.2
decodeWord()  : string
Decode a single encoded-word's charset/encoding/text into UTF-8
needsEncoding()  : bool
Determine if a string contains anything outside printable US-ASCII and therefore needs RFC 2047 encoding
splitIntoChunks()  : array<string|int, mixed>
Split a UTF-8 string into byte-boundary-safe chunks, each short enough that base64-encoding it stays within $maxEncodedLength chars.

Methods

decode()

Decode all RFC 2047 encoded-words found in a string. Never throws - malformed or unrecognized encoded-word-shaped text is left as literal output.

public static decode(string $text) : string
Parameters
$text : string
Return values
string

encode()

Encode a string into one or more RFC 2047 encoded-words, if it contains anything outside printable US-ASCII. Returns the input unchanged otherwise.

public static encode(string $text[, string $charset = 'UTF-8' ]) : string
Parameters
$text : string
$charset : string = 'UTF-8'
Return values
string

findRanges()

Find the byte ranges of every individual RFC 2047 encoded-word in a string - used by Header::fold() to treat an encoded-word as an atomic, unbreakable unit when choosing fold points. Folding between two adjacent encoded-words, at their separating whitespace, is still fine - only folding INSIDE one is not.

public static findRanges(string $text) : array<string|int, mixed>
Parameters
$text : string
Return values
array<string|int, mixed>

convertToUtf8()

Convert decoded bytes to UTF-8, gracefully degrading if the charset can't be converted (no mbstring, or an unrecognized charset name)

protected static convertToUtf8(string $bytes, string $charset) : string
Parameters
$bytes : string
$charset : string
Return values
string

decodeRun()

Decode a run of one or more whitespace-separated encoded-words, dropping the whitespace between them per RFC 2047 §6.2

protected static decodeRun(string $run) : string
Parameters
$run : string
Return values
string

decodeWord()

Decode a single encoded-word's charset/encoding/text into UTF-8

protected static decodeWord(string $charset, string $encoding, string $encodedText) : string
Parameters
$charset : string
$encoding : string
$encodedText : string
Return values
string

needsEncoding()

Determine if a string contains anything outside printable US-ASCII and therefore needs RFC 2047 encoding

protected static needsEncoding(string $text) : bool
Parameters
$text : string
Return values
bool

splitIntoChunks()

Split a UTF-8 string into byte-boundary-safe chunks, each short enough that base64-encoding it stays within $maxEncodedLength chars.

protected static splitIntoChunks(string $text, int $maxEncodedLength) : array<string|int, mixed>

Scans UTF-8 lead-byte patterns manually - no mbstring dependency needed for this direction.

Parameters
$text : string
$maxEncodedLength : int
Return values
array<string|int, mixed>

        
On this page

Search results