Holds extra information about a parsed Received header part, for FROM and BY parts, namely: ehlo name, hostname, and address.

The parsed parts would be mapped as follows:

FROM ehlo name (hostname [address]), for example: FROM computer (domain.com [1.2.3.4]) would contain "computer" for getEhloName(), domain.com for getHostname and 1.2.3.4 for getAddress().

This doesn't change if the ehlo name is an address, it is still returned in getEhloName(), and not in getAddress(). Additionally square brackets are not stripped from getEhloName() if its an address. For example: "FROM [1.2.3.4]" would return "[1.2.3.4]" in a call to getEhloName().

For further information on how the header's parsed, check the documentation for \ZBateson\MailMimeParser\Header\Consumer\Received\DomainConsumer.

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

 Methods

Constructor.

__construct(\ZBateson\MbWrapper\MbWrapper $charsetConverter, string $name, string $value, string $ehloName = null, string $hostname = null, string $address = null

If $language is provided, $name and $value are not mime-decoded. Instead, they're taken as literals as part of a SplitParameterToken.

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

Parameters

$charsetConverter

\ZBateson\MbWrapper\MbWrapper

$name

string

$value

string

$ehloName

string

$hostname

string

$address

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 address of the server, or whatever string that looks like an address in the address position when parsing (but never a hostname).

getAddress() : string

Returns

string

Returns the name used to identify the server in the first part of the extended-domain line. Note that this is not necessarily the name used in the EHLO line to an SMTP server, since implementations differ so much, not much can be guaranteed except the position it was parsed in.

getEhloName() : string

Returns

string

Returns the hostname of the server, or whatever string in the hostname position when parsing (but never an address).

getHostname() : 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

 

The address.

$address : string

Default

 

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 name used to identify the server in the EHLO line.

$ehloName : string

Default

 

The hostname.

$hostname : string

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