Provides a way to define a filter of MessagePart for use in various calls to add/remove MessagePart.

A PartFilter is defined as a set of properties in the class, set to either be 'included' or 'excluded'. The filter is simplistic in that a property defined as included must be set on a part for it to be passed, and an excluded filter must not be set for the part to be passed. There is no provision for creating logical conditions.

The only property set by default is $signedpart, which defaults to FILTER_EXCLUDE.

A PartFilter can be instantiated with an array of keys matching class properties, and values to set them for convenience.

$inlineParts = $message->getAllParts(new PartFilter([
    'multipart' => PartFilter::FILTER_INCLUDE,
    'headers' => [
        FILTER_EXCLUDE => [
            'Content-Disposition': 'attachment'
        ]
    ]
]));

$inlineTextPart = $message->getAllParts(PartFilter::fromInlineContentType('text/plain'));
author Zaahid Bateson
package MailMimeParser

 Methods

Constructs a PartFilter, optionally instantiating member variables with values in the passed array.

__construct(array $filter = array()

The passed array must use keys equal to member variable names, e.g. 'multipart', 'textpart', 'signedpart' and 'headers'.

Parameters

$filter

array

Returns the value of the member variable denoted by $name

__get(string $name) : mixed

Parameters

$name

string

Returns

mixed

Returns true if the variable denoted by $name is a member variable of PartFilter.

__isset(string $name) : boolean

Parameters

$name

string

Returns

boolean

Sets the member variable denoted by $name to the passed $value after validating it.

__set(string $name, integer|array $value) 

Parameters

$name

string

$value

integerarray

Exceptions

\InvalidArgumentException

Determines if the passed MessagePart should be filtered out or not.

filter(\ZBateson\MailMimeParser\Message\Part\MessagePart $part) : boolean

If the MessagePart passes all filter tests, true is returned. Otherwise false is returned.

Parameters

$part

\ZBateson\MailMimeParser\Message\Part\MessagePart

Returns

boolean

Convenience method to filter for a specific mime type.

fromContentType(string $mimeType) : \ZBateson\MailMimeParser\Message\PartFilter
Static

Parameters

$mimeType

string

Returns

\ZBateson\MailMimeParser\Message\PartFilter

Convenience method to search for parts with a specific Content-Disposition, optionally including multipart parts.

fromDisposition(string $disposition, integer $multipart = \ZBateson\MailMimeParser\Message\PartFilter::FILTER_OFF) : \ZBateson\MailMimeParser\Message\PartFilter
Static

Parameters

$disposition

string

$multipart

integer

Returns

\ZBateson\MailMimeParser\Message\PartFilter

Convenience method to look for parts of a specific mime-type, and that do not specifically have a Content-Disposition equal to 'attachment'.

fromInlineContentType(string $mimeType) : \ZBateson\MailMimeParser\Message\PartFilter
Static

Parameters

$mimeType

string

Returns

\ZBateson\MailMimeParser\Message\PartFilter

Sets the PartFilter's headers filter to the passed array after validating it.

setHeaders(array $headers) 

Parameters

$headers

array

Exceptions

\InvalidArgumentException

Returns true if the passed MessagePart fails the filter's hascontent filter settings.

failsHasContentFilter(\ZBateson\MailMimeParser\Message\Part\MessagePart $part) : boolean

Parameters

$part

\ZBateson\MailMimeParser\Message\Part\MessagePart

Returns

boolean

Tests a single header value against $part, and returns true if the test fails.

failsHeaderFor(\ZBateson\MailMimeParser\Message\Part\MessagePart $part, integer $type, string $name, string $header) : boolean
staticvar array $map

Parameters

$part

\ZBateson\MailMimeParser\Message\Part\MessagePart

$type

integer

$name

string

$header

string

Returns

boolean

Returns true if the passed MessagePart fails the filter's header filter settings.

failsHeaderPartFilter(\ZBateson\MailMimeParser\Message\Part\MessagePart $part) : boolean

Parameters

$part

\ZBateson\MailMimeParser\Message\Part\MessagePart

Returns

boolean

Returns true if the passed MessagePart fails the filter's multipart filter settings.

failsMultiPartFilter(\ZBateson\MailMimeParser\Message\Part\MessagePart $part) : boolean

Parameters

$part

\ZBateson\MailMimeParser\Message\Part\MessagePart

Returns

boolean

Returns true if the passed MessagePart fails the filter's signedpart filter settings.

failsSignedPartFilter(\ZBateson\MailMimeParser\Message\Part\MessagePart $part) : boolean

Parameters

$part

\ZBateson\MailMimeParser\Message\Part\MessagePart

Returns

boolean

Returns true if the passed MessagePart fails the filter's textpart filter settings.

failsTextPartFilter(\ZBateson\MailMimeParser\Message\Part\MessagePart $part) : boolean

Parameters

$part

\ZBateson\MailMimeParser\Message\Part\MessagePart

Returns

boolean

Validates an argument passed to __set to insure it's set to a value in $valid.

validateArgument(string $name, string $value, array $valid) 

Parameters

$name

string

Name of the member variable

$value

string

The value to test

$valid

array

an array of valid values

Exceptions

\InvalidArgumentException

 Properties

 

filters based on whether MessagePart::hasContent is true

$hascontent : integer

Default

\ZBateson\MailMimeParser\Message\PartFilter::FILTER_OFF
 

calculated hash of the filter

$hashCode : string

Default

 

array of header rules. The top-level contains keys of FILTER_INCLUDE and/or FILTER_EXCLUDE, which contain key => value mapping of header names => values to search for. Note that when searching MimePart::getHeaderValue is used (so additional parameters need not be matched) and strcasecmp is used.

$headers : array<mixed,string[]>

Default

array()
 

filters based on whether MimePart::isMultiPart is true

$multipart : integer

Default

\ZBateson\MailMimeParser\Message\PartFilter::FILTER_OFF
 

filters based on whether the parent of a part is a multipart/signed part and this part has a content-type equal to its parent's 'protocol' parameter in its content-type header

$signedpart : integer

Default

\ZBateson\MailMimeParser\Message\PartFilter::FILTER_EXCLUDE
 

filters based on whether MessagePart::isTextPart is true

$textpart : integer

Default

\ZBateson\MailMimeParser\Message\PartFilter::FILTER_OFF

 Constants

 

<p>an excluded filter must not be included in a part</p>

FILTER_EXCLUDE = 1 : integer
 

<p>an included filter must be included in a part</p>

FILTER_INCLUDE = 2 : integer
 

<p>indicates a filter is not in use</p>

FILTER_OFF = 0 : integer