MailMimeParser 2.4

ReceivedDomainPart extends ReceivedPart
in package

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

Tags
author

Zaahid Bateson

Table of Contents

MIME_PART_PATTERN  = '=\\?[^?=]+\\?[QBqb]\\?[^\\?]+\\?='
MIME_PART_PATTERN_NO_QUOTES  = '=\\?[^\\?=]+\\?[QBqb]\\?[^\\?"]+\\?='
$address  : string
$canIgnoreSpacesAfter  : bool
$canIgnoreSpacesBefore  : bool
$charsetConverter  : MbWrapper
$ehloName  : string
$hostname  : string
$language  : string
$languages  : array<string|int, mixed>
$name  : string
$value  : string
__construct()  : mixed
Constructor.
__toString()  : string
Returns the value of the part (which is a string).
getAddress()  : string|null
Returns the address of the server, or whatever string that looks like an address in the address position when parsing (but never a hostname).
getEhloName()  : string|null
Returns the name used to identify the server in the first part of the extended-domain line.
getHostname()  : string|null
Returns the hostname of the server, or whatever string in the hostname position when parsing (but never an address).
getLanguage()  : string
Returns the RFC-1766 (or subset) language tag, if the parameter is a split RFC-2231 part with a language tag set.
getLanguageArray()  : array<string|int, array<string|int, string>>
Returns an array of parts mapped to languages in the header value, for instance the string:
getName()  : string
Returns the name of the parameter.
getValue()  : string|null
Returns the part's value.
ignoreSpacesAfter()  : bool
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.
ignoreSpacesBefore()  : bool
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.
addToLanguage()  : self
Adds the passed part into the languages array with the given language.
convertEncoding()  : string
Ensures the encoding of the passed string is set to UTF-8.
decodeMime()  : string
Finds and replaces mime parts with their values.
decodeMatchedEntity()  : string
Decodes a matched mime entity part into a string and returns it, after adding the string into the languages array.
decodeSplitPart()  : string
Decodes a single mime-encoded entity.

Constants

MIME_PART_PATTERN

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

regex pattern matching a mime-encoded part

MIME_PART_PATTERN_NO_QUOTES

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

regex pattern used when parsing parameterized headers

Properties

$canIgnoreSpacesAfter

protected bool $canIgnoreSpacesAfter = false

set to true to ignore spaces after this part

$canIgnoreSpacesBefore

protected bool $canIgnoreSpacesBefore = false

set to true to ignore spaces before this part

$charsetConverter

protected MbWrapper $charsetConverter

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

$ehloName

protected string $ehloName

The name used to identify the server in the EHLO line.

$language

protected string $language

the RFC-1766 language tag if set.

$languages

protected array<string|int, mixed> $languages = []

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

Each array element is an array containing two elements, one with key 'lang', and another with key 'value'.

$value

protected string $value

the value of the part

Methods

__construct()

Constructor.

public __construct(MbWrapper $charsetConverter, string $name, string $value[, string $ehloName = null ][, string $hostname = null ][, string $address = null ]) : mixed
Parameters
$charsetConverter : MbWrapper
$name : string
$value : string
$ehloName : string = null
$hostname : string = null
$address : string = null
Return values
mixed

__toString()

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

public __toString() : string
Return values
string

the value

getAddress()

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

public getAddress() : string|null
Return values
string|null

getEhloName()

Returns the name used to identify the server in the first part of the extended-domain line.

public getEhloName() : string|null

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.

Return values
string|null

The name

getHostname()

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

public getHostname() : string|null
Return values
string|null

getLanguage()

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

public getLanguage() : string
Return values
string

the language

getLanguageArray()

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

public getLanguageArray() : array<string|int, array<string|int, 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' => ' Welcome!' ]
]
Return values
array<string|int, array<string|int, string>>

getName()

Returns the name of the parameter.

public getName() : string
Return values
string

The name.

getValue()

Returns the part's value.

public getValue() : string|null
Return values
string|null

the value of the part

ignoreSpacesAfter()

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.

public ignoreSpacesAfter() : bool
Return values
bool

ignoreSpacesBefore()

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.

public ignoreSpacesBefore() : bool
Return values
bool

addToLanguage()

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

protected addToLanguage(string $part[, string|null $language = null ]) : self
Parameters
$part : string
$language : string|null = null
Return values
self

convertEncoding()

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

protected convertEncoding(string $str[, string $from = 'ISO-8859-1' ][, bool $force = false ]) : string

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 = 'ISO-8859-1'
$force : bool = false
Return values
string

utf-8 string

decodeMime()

Finds and replaces mime parts with their values.

protected 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
Return values
string

decodeMatchedEntity()

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

private decodeMatchedEntity(array<string|int, string> $matches) : string
Parameters
$matches : array<string|int, string>
Return values
string

decodeSplitPart()

Decodes a single mime-encoded entity.

private 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
Return values
string

Search results