Copied!

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.

CloneableInstantiable
Constants
public ZBateson\MailMimeParser\Header\Part\MimeLiteralPart::MIME_PART_PATTERN = '=\?[^?=]+\?[QBqb]\?[^\?]+\?='
 
  • var string regex pattern matching a mime-encoded part
public ZBateson\MailMimeParser\Header\Part\MimeLiteralPart::MIME_PART_PATTERN_NO_QUOTES = '=\?[^\?=]+\?[QBqb]\?[^\?"]+\?='
 
  • var string regex pattern used when parsing parameterized headers
Methods
public __construct(ZBateson\MbWrapper\MbWrapper $charsetConverter, $token)
 

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

  • param string $token
public ZBateson\MailMimeParser\Header\Part\HeaderPart::__toString() : string
 

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

  • return string the value
public getLanguageArray()
 

Returns an array of parts mapped to languages in the header value, for instance the 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 string[][]
public ZBateson\MailMimeParser\Header\Part\HeaderPart::getValue() : ?string
 

Returns the part's value.

  • return ?string the value of the part
public ignoreSpacesAfter() : bool
 

Returns true if spaces before this part should be ignored.

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

public ignoreSpacesBefore() : bool
 

Returns true if spaces before this part should be ignored.

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

Properties
protected $canIgnoreSpacesAfter = false
 
  • var bool set to true to ignore spaces after this part
protected $canIgnoreSpacesBefore = false
 
  • var bool set to true to ignore spaces before this part
protected ZBateson\MailMimeParser\Header\Part\HeaderPart::$charsetConverter = NULL
 
  • var \MbWrapper $charsetConverter the charset converter used for converting strings in HeaderPart::convertEncoding
protected $languages = []
 
  • var array 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'.
protected ZBateson\MailMimeParser\Header\Part\HeaderPart::$value = NULL
 
  • var string the value of the part
Methods
protected addToLanguage(string $part, ?string $language = NULL) : self
 

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

protected ZBateson\MailMimeParser\Header\Part\HeaderPart::convertEncoding(string $str, string $from = 'ISO-8859-1', bool $force = false) : string
 

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

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

  • return string utf-8 string
protected decodeMime(string $value) : string
 

Finds and replaces mime parts with their values.

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.

Methods
private decodeMatchedEntity(array $matches) : string
 

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

  • param string[] $matches
private decodeSplitPart(string $entity) : string
 

Decodes a single mime-encoded entity.

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.

© 2024 Bruce Wells
Search Namespaces \ Classes
Configuration