MailMimeParser 0.4

MimeLiteralPart extends LiteralPart

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.

Tags
author

Zaahid Bateson

Table of Contents

MIME_PART_PATTERN  = '=\?[A-Za-z\-_0-9]+\?[QBqb]\?[^\?]+\?='
$canIgnoreSpacesAfter  : bool
$canIgnoreSpacesBefore  : bool
$value  : string
__construct()  : mixed
Decoding the passed token value if it's mime-encoded and assigns the decoded value to a member variable. Sets canIgnoreSpacesBefore and canIgnoreSpacesAfter.
__toString()  : string
Returns the value of the part (which is a string).
getValue()  : string
Returns the part's value.
ignoreSpacesAfter()  : bool
Returns true if spaces before this part should be ignored.
ignoreSpacesBefore()  : bool
Returns true if spaces before this part should be ignored.
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 single mime-encoded entity.

Constants

MIME_PART_PATTERN

public string MIME_PART_PATTERN = '=\?[A-Za-z\-_0-9]+\?[QBqb]\?[^\?]+\?='

Properties

$canIgnoreSpacesBefore

protected bool $canIgnoreSpacesBefore = false

Methods

__construct()

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

public __construct(string $token) : mixed
Parameters
$token : string
Return values
mixed

__toString()

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

public __toString() : string
Return values
string

the value

getValue()

Returns the part's value.

public getValue() : string
Return values
string

the value of the part

ignoreSpacesAfter()

Returns true if spaces before this part should be ignored.

public ignoreSpacesAfter() : bool

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

Return values
bool

ignoreSpacesBefore()

Returns true if spaces before this part should be ignored.

public ignoreSpacesBefore() : bool

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

Return values
bool

convertEncoding()

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

protected convertEncoding(string $str) : string
Parameters
$str : string
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 single mime-encoded entity.

private decodeMatchedEntity(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