MailMimeParser 0.4

PartFilter

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

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
$defaultHeaderValues  : array<string|int, 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.
failsHeaderPartFilter()  : bool
Returns true if the passed MimePart fails the filter's header filter settings.
filter()  : bool
Determines if the passed MimePart should be filtered out or not. If the MimePart passes all filter tests, true is returned. Otherwise false is returned.
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.
failsMultiPartFilter()  : bool
Returns true if the passed MimePart fails the filter's multipart filter settings.
failsSignedPartFilter()  : bool
Returns true if the passed MimePart fails the filter's signedpart filter settings.
failsTextPartFilter()  : bool
Returns true if the passed MimePart 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

$defaultHeaderValues

private array<string|int, string> $defaultHeaderValues = ['Content-Type' => 'text/plain', 'Content-Disposition' => 'inline']

$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

failsHeaderPartFilter()

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

public failsHeaderPartFilter(MimePart $part) : bool
Parameters
$part : MimePart
Return values
bool

filter()

Determines if the passed MimePart should be filtered out or not. If the MimePart passes all filter tests, true is returned. Otherwise false is returned.

public filter(MimePart $part) : bool
Parameters
$part : MimePart
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

failsMultiPartFilter()

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

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

failsSignedPartFilter()

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

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

failsTextPartFilter()

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

private failsTextPartFilter(MimePart $part) : bool
Parameters
$part : MimePart
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