MailMimeParser 1.3

PartFilter

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'));
Tags
author

Zaahid Bateson

Table of Contents

FILTER_EXCLUDE  = 1
FILTER_INCLUDE  = 2
FILTER_OFF  = 0
$hascontent  : int
$hashCode  : string
$headers  : array<string|int, array<string|int, string>>
$multipart  : int
$signedpart  : int
$textpart  : int
__construct()  : mixed
Constructs a PartFilter, optionally instantiating member variables with values in the passed array.
__get()  : mixed
Returns the value of the member variable denoted by $name
__isset()  : bool
Returns true if the variable denoted by $name is a member variable of PartFilter.
__set()  : mixed
Sets the member variable denoted by $name to the passed $value after validating it.
filter()  : bool
Determines if the passed MessagePart should be filtered out or not.
fromContentType()  : PartFilter
Convenience method to filter for a specific mime type.
fromDisposition()  : PartFilter
Convenience method to search for parts with a specific Content-Disposition, optionally including multipart parts.
fromInlineContentType()  : PartFilter
Convenience method to look for parts of a specific mime-type, and that do not specifically have a Content-Disposition equal to 'attachment'.
setHeaders()  : mixed
Sets the PartFilter's headers filter to the passed array after validating it.
failsHasContentFilter()  : bool
Returns true if the passed MessagePart fails the filter's hascontent filter settings.
failsHeaderFor()  : bool
Tests a single header value against $part, and returns true if the test fails.
failsHeaderPartFilter()  : bool
Returns true if the passed MessagePart fails the filter's header filter settings.
failsMultiPartFilter()  : bool
Returns true if the passed MessagePart fails the filter's multipart filter settings.
failsSignedPartFilter()  : bool
Returns true if the passed MessagePart fails the filter's signedpart filter settings.
failsTextPartFilter()  : bool
Returns true if the passed MessagePart fails the filter's textpart filter settings.
validateArgument()  : mixed
Validates an argument passed to __set to insure it's set to a value in $valid.

Constants

Properties

$hascontent

private int $hascontent = ZBatesonMailMimeParserMessagePartFilter::FILTER_OFF

$headers

private array<string|int, array<string|int, string>> $headers = []

$multipart

private int $multipart = ZBatesonMailMimeParserMessagePartFilter::FILTER_OFF

$signedpart

private int $signedpart = ZBatesonMailMimeParserMessagePartFilter::FILTER_EXCLUDE

$textpart

private int $textpart = ZBatesonMailMimeParserMessagePartFilter::FILTER_OFF

Methods

__construct()

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

public __construct([array<string|int, mixed> $filter = [] ]) : mixed

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

Parameters
$filter : array<string|int, mixed> = []
Return values
mixed

__get()

Returns the value of the member variable denoted by $name

public __get(string $name) : mixed
Parameters
$name : string
Return values
mixed

__isset()

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

public __isset(string $name) : bool
Parameters
$name : string
Return values
bool

__set()

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

public __set(string $name, int|array<string|int, mixed> $value) : mixed
Parameters
$name : string
$value : int|array<string|int, mixed>
Tags
throws
InvalidArgumentException
Return values
mixed

filter()

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

public filter(MessagePart $part) : bool

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

Parameters
$part : MessagePart
Return values
bool

fromContentType()

Convenience method to filter for a specific mime type.

public static fromContentType(string $mimeType) : PartFilter
Parameters
$mimeType : string
Return values
PartFilter

fromDisposition()

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

public static fromDisposition(string $disposition[, int $multipart = PartFilter::FILTER_OFF ]) : PartFilter
Parameters
$disposition : string
$multipart : int = PartFilter::FILTER_OFF
Return values
PartFilter

fromInlineContentType()

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

public static fromInlineContentType(string $mimeType) : PartFilter
Parameters
$mimeType : string
Return values
PartFilter

setHeaders()

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

public setHeaders(array<string|int, mixed> $headers) : mixed
Parameters
$headers : array<string|int, mixed>
Tags
throws
InvalidArgumentException
Return values
mixed

failsHasContentFilter()

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

private failsHasContentFilter(MessagePart $part) : bool
Parameters
$part : MessagePart
Return values
bool

failsHeaderFor()

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

private failsHeaderFor(MessagePart $part, int $type, string $name, string $header) : bool
Parameters
$part : MessagePart
$type : int
$name : string
$header : string
Tags
staticvar

array $map

Return values
bool

failsHeaderPartFilter()

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

private failsHeaderPartFilter(MessagePart $part) : bool
Parameters
$part : MessagePart
Return values
bool

failsMultiPartFilter()

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

private failsMultiPartFilter(MessagePart $part) : bool
Parameters
$part : MessagePart
Return values
bool

failsSignedPartFilter()

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

private failsSignedPartFilter(MessagePart $part) : bool
Parameters
$part : MessagePart
Return values
bool

failsTextPartFilter()

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

private failsTextPartFilter(MessagePart $part) : bool
Parameters
$part : MessagePart
Return values
bool

validateArgument()

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

private validateArgument(string $name, string $value, array<string|int, mixed> $valid) : mixed
Parameters
$name : string

Name of the member variable

$value : string

The value to test

$valid : array<string|int, mixed>

an array of valid values

Tags
throws
InvalidArgumentException
Return values
mixed

Search results