Represents a single mime header part token, with the possibility of it being MIME-Encoded as per RFC-2047.

MimeLiteralPart automatically decodes the value if it's encoded.

author Zaahid Bateson
package MailMimeParser
inherited_from \ZBateson\MailMimeParser\Header\Part\LiteralPart

 Methods

Decoding the passed token value if it's mime-encoded and assigns the decoded value to a member variable. Sets canIgnoreSpacesBefore and canIgnoreSpacesAfter.

__construct(\ZBateson\MbWrapper\MbWrapper $charsetConverter, string $token) 
inherited_from \ZBateson\MailMimeParser\Header\Part\LiteralPart::__construct()

Parameters

$charsetConverter

\ZBateson\MbWrapper\MbWrapper

$token

string

Sets up dependencies.

__construct(\ZBateson\MbWrapper\MbWrapper $charsetConverter) 
Inherited

Parameters

$charsetConverter

\ZBateson\MbWrapper\MbWrapper

Returns the value of the part (which is a string).

__toString() : string
Inherited

Returns

stringthe value

Returns an array of parts mapped to languages in the header value, for instance the string:

getLanguageArray() : array<mixed,string[]>

'Hello and =?UTF-8fr-be?Q?bonjour_?= =?UTF-8it?Q?mi amici?=. Welcome!'

Would be mapped in the returned array as follows:

[
    0 => [ 'lang' => null, 'value' => 'Hello and ' ],
    1 => [ 'lang' => 'fr-be', 'value' => 'bonjour ' ],
    3 => [ 'lang' => 'it', 'value' => 'mi amici' ],
    4 => [ 'lang' => null, 'value' => ' Weolcome!' ]
]

Returns

array<mixed,string[]>

Returns the part's value.

getValue() : string
Inherited

Returns

stringthe value of the part

Returns true if spaces before this part should be ignored.

ignoreSpacesAfter() : boolean

Overridden to return $this->canIgnoreSpacesAfter which is setup in the constructor.

Returns

boolean

Returns true if spaces after this part should be ignored. True is only returned for MimeLiterals if the part ends with a mime-encoded string Tokens if the Token's value is a single space, and for CommentParts.

ignoreSpacesAfter() : boolean
Inherited

Returns

boolean

Returns true if spaces before this part should be ignored.

ignoreSpacesBefore() : boolean

Overridden to return $this->canIgnoreSpacesBefore which is setup in the constructor.

Returns

boolean

Returns true if spaces before this part should be ignored. True is only returned for MimeLiterals if the part begins with a mime-encoded string, Tokens if the Token's value is a single space, and for CommentParts.

ignoreSpacesBefore() : boolean
Inherited

Returns

boolean

Adds the passed part into the languages array with the given language.

addToLanguage(string $part, string|null $language = null

Parameters

$part

string

$language

stringnull

Ensures the encoding of the passed string is set to UTF-8.

convertEncoding(string $str, string $from = 'ISO-8859-1', boolean $force = false) : string
Inherited

The method does nothing if the passed $from charset is UTF-8 already, or if $force is set to false and mb_check_encoding for $str returns true for 'UTF-8'.

Parameters

$str

string

$from

string

$force

boolean

Returns

stringutf-8 string

Finds and replaces mime parts with their values.

decodeMime(string $value) : string

The method splits the token value into an array on mime-part-patterns, either replacing a mime part with its value by calling iconv_mime_decode or converts the encoding on the text part by calling convertEncoding.

Parameters

$value

string

Returns

string

Decodes a matched mime entity part into a string and returns it, after adding the string into the languages array.

decodeMatchedEntity(array<mixed,string> $matches) : string

Parameters

$matches

array<mixed,string>

Returns

string

Decodes a single mime-encoded entity.

decodeSplitPart(string $entity) : string

Unfortunately, mb_decode_header fails for many charsets on PHP 5.4 and PHP 5.5 (even if they're listed as supported). iconv_mime_decode doesn't support all charsets.

Parsing out the charset and body of the encoded entity seems to be the way to go to support the most charsets.

Parameters

$entity

string

Returns

string

 Properties

 

set to true to ignore spaces after this part

$canIgnoreSpacesAfter : boolean

Default

false
 

set to true to ignore spaces before this part

$canIgnoreSpacesBefore : boolean

Default

false
 

the charset converter used for converting strings in HeaderPart::convertEncoding

$charsetConverter : \ZBateson\MbWrapper\MbWrapper

Default

 

maintains an array mapping rfc1766 language tags to parts of text in the value.

$languages : array

Default

array()
 

the value of the part

$value : string

Default

 Constants

 

<p>regex pattern matching a mime-encoded part</p>

MIME_PART_PATTERN = '=\?[^?=]+\?[QBqb]\?[^\?]+\?=' : string
 

<p>regex pattern used when parsing parameterized headers</p>

MIME_PART_PATTERN_NO_QUOTES = '=\?[^\?=]+\?[QBqb]\?[^\?"]+\?=' : string