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...)

public __construct(ZBateson\MailMimeParser\Message\Factory\IMimePartFactory $mimePartFactory, ZBateson\MailMimeParser\Message\Factory\IUUEncodedPartFactory $uuEncodedPartFactory, ZBateson\MailMimeParser\Message\Helper\GenericHelper $genericHelper)
public createAlternativeContentPart(ZBateson\MailMimeParser\IMessage $message, ZBateson\MailMimeParser\Message\IMessagePart $contentPart)

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

  • return \IMimePart the alternative part
public createAndAddPartForAttachment(ZBateson\MailMimeParser\IMessage $message, $resource, string $mimeType, string $disposition, ?string $filename = NULL, string $encoding = 'base64')

Creates and adds a IMimePart for the passed content and options as an

  • param string|resource|\Psr\Http\Message\StreamInterface $resource
public createContentPartForMimeType(ZBateson\MailMimeParser\IMessage $message, string $mimeType, string $charset)

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

  • return \ZBateson\MailMimeParser\Message\IMimePart
public createMultipartRelatedPartForInlineChildrenOf(ZBateson\MailMimeParser\Message\IMimePart $parent)

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

  • return \IMimePart
public enforceMime(ZBateson\MailMimeParser\IMessage $message)

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.

public findOtherContentPartFor(ZBateson\MailMimeParser\IMessage $message, string $mimeType)

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

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

  • return \IMimePart or null if not found
public getContentPartContainerFromAlternative( $mimeType, ZBateson\MailMimeParser\Message\IMimePart $alternativePart)

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

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.

  • param string $mimeType the content-type to find below $alternativePart
  • param \IMimePart $alternativePart The multipart/alternative part to look
  • return bool|\IMimePart false if a part is not found
public getUniqueBoundary(string $mimeType) : string

Creates and returns a unique boundary.

  • param string $mimeType first 3 characters of a multipart type are used,
    e.g. REL for relative or ALT for alternative
public moveAllNonMultiPartsToMessageExcept(ZBateson\MailMimeParser\IMessage $message, ZBateson\MailMimeParser\Message\IMimePart $from, string $exceptMimeType) : self

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.

public removeAllContentPartsByMimeType(ZBateson\MailMimeParser\IMessage $message, string $mimeType, bool $keepOtherContent = false) : bool

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.

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.

  • return bool true on success
public removeAllContentPartsFromAlternative(ZBateson\MailMimeParser\IMessage $message, string $mimeType, ZBateson\MailMimeParser\Message\IMimePart $alternativePart, bool $keepOtherContent) : bool

Removes all parts of $mimeType from $alternativePart.

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.

public removePartByMimeType(ZBateson\MailMimeParser\IMessage $message, string $mimeType, int $index = 0) : bool

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

  • return bool true on success
public setContentPartForMimeType(ZBateson\MailMimeParser\IMessage $message, string $mimeType, $stringOrHandle, string $charset) : self

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

  • param string|resource $stringOrHandle
public setMessageAsAlternative(ZBateson\MailMimeParser\IMessage $message) : self

Sets the passed message as multipart/alternative.

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.

public setMessageAsMixed(ZBateson\MailMimeParser\IMessage $message) : self

Sets the passed message as multipart/mixed.

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.

public setMimeHeaderBoundaryOnPart(ZBateson\MailMimeParser\Message\IMimePart $part, string $mimeType) : self

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

protected ZBateson\MailMimeParser\Message\Helper\AbstractHelper::$mimePartFactory = NULL
  • var \IMimePartFactory to create parts for attachments/content
protected ZBateson\MailMimeParser\Message\Helper\AbstractHelper::$uuEncodedPartFactory = NULL
  • var \IUUEncodedPartFactory to create parts for attachments
private $genericHelper = NULL
  • var \GenericHelper a GenericHelper instance
© 2023 Bruce Wells
Search Namespaces \ Classes