Holds a single address or name/address pair.

The name part of the address may be mime-encoded, but the email address part can't be mime-encoded. Any whitespace in the email address part is stripped out.

A convenience method, getEmail, is provided for clarity -- but getValue returns the email address as well.

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

 Methods

Performs mime-decoding and initializes the address' name and email.

__construct(\ZBateson\MbWrapper\MbWrapper $charsetConverter, string $name, string $email) 

The passed $name may be mime-encoded. $email is stripped of any whitespace.

inherited_from \ZBateson\MailMimeParser\Header\Part\ParameterPart::__construct()

Parameters

$charsetConverter

\ZBateson\MbWrapper\MbWrapper

$name

string

$email

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 the email address.

getEmail() : string

Returns

string

Returns the RFC-1766 (or subset) language tag, if the parameter is a split RFC-2231 part with a language tag set.

getLanguage() : string
Inherited

Returns

string

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

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

'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 name of the parameter.

getName() : string
Inherited

Returns

string

Returns the part's value.

getValue() : string
Inherited

Returns

stringthe value of the part

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. 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
Inherited

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
Inherited

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
Inherited

Parameters

$matches

array<mixed,string>

Returns

string

Decodes a single mime-encoded entity.

decodeSplitPart(string $entity) : string
Inherited

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

 

the RFC-1766 language tag if set.

$language : string

Default

 

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

$languages : array

Default

array()
 

the name of the parameter

$name : string

Default

 

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