2017 © Pedro Peláez
 

library mail-mime-parser

MIME email message parser

image

rsaccani/mail-mime-parser

MIME email message parser

  • Thursday, March 22, 2018
  • by rsaccani
  • Repository
  • 1 Watchers
  • 0 Stars
  • 42 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 20 Forks
  • 0 Open issues
  • 24 Versions
  • 200 % Grown

The README.md

zbateson/mail-mime-parser

Testable and PSR-compliant mail mime parser alternative to PHP's imap* functions and Pear libraries for reading messages in Internet Message Format RFC 822 (and later revisions RFC 2822, RFC 5322)., (*1)

Build Status Code Coverage Scrutinizer Code Quality Total Downloads Latest Stable Version, (*2)

The goals of this project are to be:, (*3)

  • Well written
  • Standards-compliant but forgiving
  • Tested where possible

To include it for use in your project, install it via composer:, (*4)

composer require zbateson/mail-mime-parser

Sponsors

SecuMailer, (*5)

A huge thank you to all my sponsors. <3, (*6)

If this project's helped you, please consider sponsoring me., (*7)

Php 5.4-7.0 Support Dropped

As of mail-mime-parser 2.3.0, support for php 5.4, 5.5, 5.6 and 7.0 has been dropped., (*8)

Removal Notice (since 2.0.0)

getContentResourceHandle, getTextResourceHandle, and getHtmlResourceHandle have all been deprecated in 1.2.1 and removed in 2.0.0. fread() will only return a single byte of a multibyte char, and so will cause potentially unexpected results/warnings in some cases, and psr7 streams should be used instead. Note that getBinaryContentResourceHandle and getResourceHandle are still available., (*9)

Change in 2.0

Upgrade to 2.0 to take advantage of the new on-demand parser which parses parts of a message as they're requested. This means reading only the headers from a larger message is as fast as a smaller message because the whole message is no longer parsed (similarly reading just the content and not a message's large attachments is also much faster.), (*10)

Because of the on-demand parsing, starting in 2.0, the passed resource handle or stream must remain open while the returned message object is still in use., (*11)

Old code:, (*12)

$handle = fopen('file.mime', 'r');
$message = $mailParser->parse($handle);         // returned `Message`
fclose($handle);

New code:, (*13)

// attaches the resource handle to the returned `IMessage` if the second parameter
// is true.  The resource handle is closed when the IMessage is destroyed.
$message = $mailParser->parse(fopen('file.mime', 'r'), true);

For a more complete list of changes, please visit the 2.0 Upgrade Guide., (*14)

Requirements

MailMimeParser requires PHP 7.1 or newer. Tested on PHP 7.1, 7.2, 7.3, 7.4, 8.0, 8.1 and 8.2., (*15)

Usage

use ZBateson\MailMimeParser\MailMimeParser;
use ZBateson\MailMimeParser\Message;
use ZBateson\MailMimeParser\Header\HeaderConsts;

// use an instance of MailMimeParser as a class dependency
$mailParser = new MailMimeParser();

// parse() accepts a string, resource or Psr7 StreamInterface
// pass `true` as the second argument to attach the passed $handle and close
// it when the returned IMessage is destroyed.
$handle = fopen('file.mime', 'r');
$message = $mailParser->parse($handle, false);         // returns `IMessage`

// OR: use this procedurally (Message::from also accepts a string,
// resource or Psr7 StreamInterface
// true or false as second parameter doesn't matter if passing a string.
$string = "Content-Type: text/plain\r\nSubject: Test\r\n\r\nMessage";
$message = Message::from($string, false);

echo $message->getHeaderValue(HeaderConsts::FROM);     // user@example.com
echo $message
    ->getHeader(HeaderConsts::FROM)                    // AddressHeader
    ->getPersonName();                                 // Person Name
echo $message->getHeaderValue(HeaderConsts::SUBJECT);  // The email's subject
echo $message
    ->getHeader(HeaderConsts::TO)                      // also AddressHeader
    ->getAddresses()[0]                                // AddressPart
    ->getPersonName();                                 // Person Name
echo $message
    ->getHeader(HeaderConsts::CC)                      // also AddressHeader
    ->getAddresses()[0]                                // AddressPart
    ->getEmail();                                      // user@example.com

echo $message->getTextContent();                       // or getHtmlContent()

echo $message->getHeader('X-Foo');                     // for custom or undocumented headers

$att = $message->getAttachmentPart(0);                 // first attachment
echo $att->getHeaderValue(HeaderConsts::CONTENT_TYPE); // e.g. "text/plain"
echo $att->getHeaderParameter(                         // value of "charset" part
    'content-type',
    'charset'
);
echo $att->getContent();                               // get the attached file's contents
$stream = $att->getContentStream();                    // the file is decoded automatically
$dest = \GuzzleHttp\Psr7\stream_for(
    fopen('my-file.ext')
);
\GuzzleHttp\Psr7\copy_to_stream(
    $stream, $dest
);
// OR: more simply if saving or copying to another stream
$att->saveContent('my-file.ext');               // writes to my-file.ext
$att->saveContent($stream);                     // copies to the stream

// close only when $message is no longer being used.
fclose($handle);

Documentation

Upgrading to 1.x or 2.x

License

BSD licensed - please see license agreement., (*16)

The Versions

22/03 2018

dev-master

9999999-dev https://github.com/zbateson/MailMimeParser

MIME email message parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser email php-imap

20/02 2018

1.0.0.x-dev

1.0.0.9999999-dev https://github.com/zbateson/MailMimeParser

MIME email message parser

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Zaahid Bateson

mail mime parser email php-imap

07/02 2018

0.4.8

0.4.8.0 https://github.com/zbateson/MailMimeParser

MIME email message parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser email php-imap

05/01 2018

0.4.7

0.4.7.0 https://github.com/zbateson/MailMimeParser

MIME email message parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser email php-imap

16/11 2017

0.4.6

0.4.6.0 https://github.com/zbateson/MailMimeParser

MIME email message parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser email php-imap

11/10 2017

0.4.5

0.4.5.0 https://github.com/zbateson/MailMimeParser

MIME email message parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser email php-imap

10/07 2017

0.4.4

0.4.4.0 https://github.com/zbateson/MailMimeParser

MIME email message parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser email php-imap

09/07 2017

dev-hhvm-tests

dev-hhvm-tests https://github.com/zbateson/MailMimeParser

MIME email message parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser email php-imap

05/04 2017

0.4.3

0.4.3.0 https://github.com/zbateson/MailMimeParser

MIME email message parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser email php-imap

02/04 2017

0.4.2

0.4.2.0 https://github.com/zbateson/MailMimeParser

MIME email message parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser email php-imap

05/03 2017

0.4.1

0.4.1.0 https://github.com/zbateson/MailMimeParser

MIME email message parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser email php-imap

02/02 2017

0.4.0

0.4.0.0 https://github.com/zbateson/MailMimeParser

PSR-2 compliant mime mail parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser

22/12 2016

0.3.3

0.3.3.0 https://github.com/zbateson/MailMimeParser

PSR-2 compliant mime mail parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser

16/12 2016

0.3.2

0.3.2.0 https://github.com/zbateson/MailMimeParser

PSR-2 compliant mime mail parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser

08/11 2016

0.3.1

0.3.1.0 https://github.com/zbateson/MailMimeParser

PSR-2 compliant mime mail parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser

26/09 2016

0.3.0

0.3.0.0 https://github.com/zbateson/MailMimeParser

PSR-2 compliant mime mail parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser

11/07 2016

0.2.5

0.2.5.0 https://github.com/zbateson/MailMimeParser

PSR-2 compliant mime mail parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser

15/04 2016

0.2.4

0.2.4.0 https://github.com/zbateson/MailMimeParser

PSR-2 compliant mime mail parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Zaahid Bateson

mail mime parser

05/03 2016

0.2.3

0.2.3.0 https://github.com/zbateson/MailMimeParser

PSR-2 compliant mime mail parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4

 

The Development Requires

by Zaahid Bateson

mail mime parser

05/03 2016

0.2.2

0.2.2.0 https://github.com/zbateson/MailMimeParser

PSR-2 compliant mime mail parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4

 

The Development Requires

by Zaahid Bateson

mail mime parser

29/02 2016

0.2.1

0.2.1.0 https://github.com/zbateson/MailMimeParser

PSR-2 compliant mime mail parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4

 

The Development Requires

by Zaahid Bateson

mail mime parser

28/02 2016

0.2.0

0.2.0.0 https://github.com/zbateson/MailMimeParser

PSR-2 compliant mime mail parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4

 

The Development Requires

by Zaahid Bateson

mail mime parser

24/11 2015

0.1.1

0.1.1.0 https://github.com/zbateson/MailMimeParser

PSR-2 compliant mime mail parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4

 

The Development Requires

by Zaahid Bateson

mail mime parser

23/11 2015

0.1.0

0.1.0.0 https://github.com/zbateson/MailMimeParser

PSR-2 compliant mime mail parser

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.5.0

 

The Development Requires

by Zaahid Bateson

mail mime parser