View on GitHub

zbateson/mail-mime-parser

A PHP email parser

Home - Sponsors - API Documentation - Upgrading to 3.0 - Contributors

Upgrading to 1.0

The majority of changes won’t have an effect on simple implementations parsing emails to extract content/attachments. For simple uses, only a few changes will need to be made – most likely changing calls from Message::getTextStream and Message::getHtmlStream to Message::getTextResourceHandle and Message::getHtmlResourceHandle.

If you’re modifying messages after parsing them, MimePart::attachContentResourceHandle has been removed. Instead, MessagePart::setContent accepts a wider range of parameters. You can pass a resource handle, a string or a Psr7 StreamInterface.

In addition, if you’re signing or verifying messages, the method signature for that changed as well and would need to be updated (see below under the Message class).

The class structure of messages changed, more complicated use cases may require a more careful upgrade, and a further look at the new inheritance structure.

Message class

The most common change users will run into is the change from resource streams to Psr7 Streams. The following method signatures have changed:

$message = Message::from($handle);
echo $message->getTextStream()->getContents();
// equivalent shortcut
echo $message->getTextContent();
// or if your code is already using a resource handle, it may be easier to
// use getTextResourceHandle
$contentHandle = $message->getTextResourceHandle

The way a message is written out has been changed:

Methods related to signing and verification changed names:

Message part classes

MimePart used to be the base class for Message and other parts: NonMimePart and UUEncodedPart. Now, a new base class was created, and the structure has changed:

As mentioned in the introduction, MimePart::attachContentResourceHandle has been removed. Instead, MessagePart::setContent accepts a wider range of parameters. You can pass a resource handle, a string or a Psr7 StreamInterface.

MimePart::detachContentResourceHandle is now MessagePart::detachContentStream.