Provides various routines to manipulate and create multipart messages from an existing message (e.g. to make space for attachments in a message, or to change a simple message to a multipart/alternative one, etc.

..)

author Zaahid Bateson
package MailMimeParser
inherited_from \ZBateson\MailMimeParser\Message\Helper\AbstractHelper

 Methods

Constructor

__construct(\ZBateson\MailMimeParser\Message\Part\Factory\MimePartFactory $mimePartFactory, \ZBateson\MailMimeParser\Message\Part\Factory\UUEncodedPartFactory $uuEncodedPartFactory, \ZBateson\MailMimeParser\Message\Part\Factory\PartBuilderFactory $partBuilderFactory, \ZBateson\MailMimeParser\Message\Helper\GenericHelper $genericHelper) 
inherited_from \ZBateson\MailMimeParser\Message\Helper\AbstractHelper::__construct()

Parameters

$mimePartFactory

\ZBateson\MailMimeParser\Message\Part\Factory\MimePartFactory

$uuEncodedPartFactory

\ZBateson\MailMimeParser\Message\Part\Factory\UUEncodedPartFactory

$partBuilderFactory

\ZBateson\MailMimeParser\Message\Part\Factory\PartBuilderFactory

$genericHelper

\ZBateson\MailMimeParser\Message\Helper\GenericHelper

Constructor

__construct(\ZBateson\MailMimeParser\Message\Part\Factory\MimePartFactory $mimePartFactory, \ZBateson\MailMimeParser\Message\Part\Factory\UUEncodedPartFactory $uuEncodedPartFactory, \ZBateson\MailMimeParser\Message\Part\Factory\PartBuilderFactory $partBuilderFactory) 
Inherited

Parameters

$mimePartFactory

\ZBateson\MailMimeParser\Message\Part\Factory\MimePartFactory

$uuEncodedPartFactory

\ZBateson\MailMimeParser\Message\Part\Factory\UUEncodedPartFactory

$partBuilderFactory

\ZBateson\MailMimeParser\Message\Part\Factory\PartBuilderFactory

Creates a new mime part as a multipart/alternative and assigns the passed $contentPart as a part below it before returning it.

createAlternativeContentPart(\ZBateson\MailMimeParser\Message $message, \ZBateson\MailMimeParser\Message\Part\MessagePart $contentPart) : \ZBateson\MailMimeParser\Message\Part\MimePart

Parameters

$message

\ZBateson\MailMimeParser\Message

$contentPart

\ZBateson\MailMimeParser\Message\Part\MessagePart

Returns

\ZBateson\MailMimeParser\Message\Part\MimePartthe alternative part

Creates and adds a MimePart for the passed content and options as an attachment.

createAndAddPartForAttachment(\ZBateson\MailMimeParser\Message $message, string|resource|\ZBateson\MailMimeParser\Message\Helper\Psr\Http\Message\StreamInterface\StreamInterface $resource, string $mimeType, string $disposition, string $filename = null) : \ZBateson\MailMimeParser\Message\Part\MimePart

Parameters

$message

\ZBateson\MailMimeParser\Message

$resource

stringresource\ZBateson\MailMimeParser\Message\Helper\Psr\Http\Message\StreamInterface\StreamInterface

$mimeType

string

$disposition

string

$filename

string

Returns

\ZBateson\MailMimeParser\Message\Part\MimePart

Creates a new content part for the passed mimeType and charset, making space by creating a multipart/alternative if needed

createContentPartForMimeType(\ZBateson\MailMimeParser\Message $message, string $mimeType, string $charset) : \ZBateson\MailMimeParser\Message\Part\MimePart

Parameters

$message

\ZBateson\MailMimeParser\Message

$mimeType

string

$charset

string

Returns

\ZBateson\MailMimeParser\Message\Part\MimePart

Creates a multipart/related part out of 'inline' children of $parent and returns it.

createMultipartRelatedPartForInlineChildrenOf(\ZBateson\MailMimeParser\Message\Part\ParentHeaderPart $parent) : \ZBateson\MailMimeParser\Message\Part\MimePart

Parameters

$parent

\ZBateson\MailMimeParser\Message\Part\ParentHeaderPart

Returns

\ZBateson\MailMimeParser\Message\Part\MimePart

Enforces the message to be a mime message for a non-mime (e.g. uuencoded or unspecified) message. If the message has uuencoded attachments, sets up the message as a multipart/mixed message and creates a separate content part.

enforceMime(\ZBateson\MailMimeParser\Message $message) 

Parameters

$message

\ZBateson\MailMimeParser\Message

Finds an alternative inline part in the message and returns it if one exists.

findOtherContentPartFor(\ZBateson\MailMimeParser\Message $message, string $mimeType) : \ZBateson\MailMimeParser\Message\Part\MimeType

If the passed $mimeType is text/plain, searches for a text/html part. Otherwise searches for a text/plain part to return.

Parameters

$message

\ZBateson\MailMimeParser\Message

$mimeType

string

Returns

\ZBateson\MailMimeParser\Message\Part\MimeTypeor null if not found

Searches the passed $alternativePart for a part with the passed mime type and returns its parent.

getContentPartContainerFromAlternative(string $mimeType, \ZBateson\MailMimeParser\Message\Part\ParentHeaderPart $alternativePart) : boolean | \ZBateson\MailMimeParser\Message\Part\MimePart

Used for alternative mime types that have a multipart/mixed or multipart/related child containing a content part of $mimeType, where the whole mixed/related part should be removed.

Parameters

$mimeType

string

the content-type to find below $alternativePart

$alternativePart

\ZBateson\MailMimeParser\Message\Part\ParentHeaderPart

The multipart/alternative part to look under

Returns

boolean\ZBateson\MailMimeParser\Message\Part\MimePartfalse if a part is not found

Creates and returns a unique boundary.

getUniqueBoundary(string $mimeType) : string

Parameters

$mimeType

string

first 3 characters of a multipart type are used, e.g. REL for relative or ALT for alternative

Returns

string

Moves all parts under $from into this message except those with a content-type equal to $exceptMimeType. If the message is not a multipart/mixed message, it is set to multipart/mixed first.

moveAllPartsAsAttachmentsExcept(\ZBateson\MailMimeParser\Message $message, \ZBateson\MailMimeParser\Message\Part\ParentHeaderPart $from, string $exceptMimeType) 

Parameters

$message

\ZBateson\MailMimeParser\Message

$from

\ZBateson\MailMimeParser\Message\Part\ParentHeaderPart

$exceptMimeType

string

Removes the content part of the message with the passed mime type. If there is a remaining content part and it is an alternative part of the main message, the content part is moved to the message part.

removeAllContentPartsByMimeType(\ZBateson\MailMimeParser\Message $message, string $mimeType, boolean $keepOtherContent = false) : boolean

If the content part is part of an alternative part beneath the message, the alternative part is replaced by the remaining content part, optionally keeping other parts if $keepOtherContent is set to true.

Parameters

$message

\ZBateson\MailMimeParser\Message

$mimeType

string

$keepOtherContent

boolean

Returns

booleantrue on success

Removes all parts of $mimeType from $alternativePart.

removeAllContentPartsFromAlternative(\ZBateson\MailMimeParser\Message $message, string $mimeType, \ZBateson\MailMimeParser\Message\Part\ParentHeaderPart $alternativePart, boolean $keepOtherContent) : boolean

If $alternativePart contains a multipart/mixed or multipart/relative part with other parts of different content-types, the multipart part is removed, and parts of different content-types can optionally be moved to the main message part.

Parameters

$message

\ZBateson\MailMimeParser\Message

$mimeType

string

$alternativePart

\ZBateson\MailMimeParser\Message\Part\ParentHeaderPart

$keepOtherContent

boolean

Returns

boolean

Removes the 'inline' part with the passed contentType, at the given index defaulting to the first

removePartByMimeType(\ZBateson\MailMimeParser\Message $message, string $mimeType, integer $index = 0) : boolean

Parameters

$message

\ZBateson\MailMimeParser\Message

$mimeType

string

$index

integer

Returns

booleantrue on success

Either creates a mime part or sets the existing mime part with the passed mimeType to $strongOrHandle.

setContentPartForMimeType(\ZBateson\MailMimeParser\Message $message, string $mimeType, string|resource $stringOrHandle, string $charset) 

Parameters

$message

\ZBateson\MailMimeParser\Message

$mimeType

string

$stringOrHandle

stringresource

$charset

string

Sets the passed message as multipart/alternative.

setMessageAsAlternative(\ZBateson\MailMimeParser\Message $message) 

If the message has content, a new part is created and added as a child of the message. The message's content and content headers are moved to the new part.

Parameters

$message

\ZBateson\MailMimeParser\Message

Sets the passed message as multipart/mixed.

setMessageAsMixed(\ZBateson\MailMimeParser\Message $message) 

If the message has content, a new part is created and added as a child of the message. The message's content and content headers are moved to the new part.

Parameters

$message

\ZBateson\MailMimeParser\Message

Creates a unique mime boundary and assigns it to the passed part's Content-Type header with the passed mime type.

setMimeHeaderBoundaryOnPart(\ZBateson\MailMimeParser\Message\Part\ParentHeaderPart $part, string $mimeType) 

Parameters

$part

\ZBateson\MailMimeParser\Message\Part\ParentHeaderPart

$mimeType

string

 Properties

 

to create parts for attachments/content

$mimePartFactory : \ZBateson\MailMimeParser\Message\Part\Factory\MimePartFactory

Default

 

to create parts for attachments/content

$partBuilderFactory : \ZBateson\MailMimeParser\Message\Part\Factory\PartBuilderFactory

Default

 

to create parts for attachments

$uuEncodedPartFactory : \ZBateson\MailMimeParser\Message\Part\Factory\UUEncodedPartFactory

Default

 

a GenericHelper instance

$genericHelper : \ZBateson\MailMimeParser\Message\Helper\GenericHelper

Default