2017 © Pedro Peláez
 

library email

Faster MIME Mail Parser could be used to parse emails in MIME format.

image

bashkarev/email

Faster MIME Mail Parser could be used to parse emails in MIME format.

  • Monday, March 13, 2017
  • by bashkarev
  • Repository
  • 3 Watchers
  • 18 Stars
  • 2,657 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 7 Open issues
  • 2 Versions
  • 30 % Grown

The README.md

Faster MIME Mail Parser

Faster MIME Mail Parser could be used to parse emails in MIME format., (*1)

Build Status, (*2)

Usage

Basic usage is the following:, (*3)

$file = fopen('path/to/file.eml', 'r');
$message = \bashkarev\email\Parser::email($file);

$message->textHtml();

$message->getParts();
$message->getAttachments();

Settings

There are settings available., (*4)

  • charset - character set to use. Should be specified in uppercase only. Default is UTF-8., (*5)

    \bashkarev\email\Parser::$charset = "WINDOWS-1251";
    
  • buffer - read buffer size in bytes. Default is 500000., (*6)

    \bashkarev\email\Parser::$buffer = 4096;
    

Attachments

There is attachments parsing support., (*7)

Saving attachments to files

Saving to files could be done as follows:, (*8)

$file = fopen('path/to/file.eml', 'rb');
$message = \bashkarev\email\Parser::email($file);
foreach ($message->getAttachments() as $attachment) {
    $attachment->save('dir/' . $attachment->getFileName('undefined'));
}

Streaming attachment to output

In order to stream attachment to output directly you need to do the following:, (*9)

$file = fopen('path/to/file.eml', 'rb');
$message = \bashkarev\email\Parser::email($file);
$attachment = $message->getAttachments()[0];
header("Content-Type: {$attachment->getMimeType()};");
header("Content-Disposition: attachment; filename=\"{$attachment->getFileName('undefined')}\"");
$attachment->getStream()->copy(fopen('php://output', 'c'));

message/partial

$block = \bashkarev\email\Parser::email([
    fopen('path/to/part.1.eml', 'rb'),
    fopen('path/to/part.2.eml', 'rb'),
]);
$block->getMessage();

message/rfc822

$file = fopen('path/to/file.eml', 'rb');
$container = \bashkarev\email\Parser::email($file);
$message = $container->getAttachments()[0]->getMessage();

message/feedback-report

$file = fopen('path/to/file.eml', 'rb');
$container = \bashkarev\email\Parser::email($file);
foreach ($container->getAttachments() as $attachment) {
    if ($attachment->getMimeType() === 'message/feedback-report') {
        /**
         * @var \bashkarev\email\messages\Feedback $feedback
         */
        $feedback = $attachment->getMessage();
        $feedback->getType(); // Feedback::TYPE_ABUSE ...
    }
}

message/external-body

Supported types: url, local-file, ftp., (*10)

FTP auth

$file = fopen('path/to/file.eml', 'rb');
$container = \bashkarev\email\Parser::email($file);
foreach ($container->getAttachments() as $attachment) {
    if ($attachment->getStream() instanceof \bashkarev\email\transports\Ftp) {
        /**
         * @var \bashkarev\email\transports\Ftp $transport
         */
        $transport = $attachment->getStream();
        $transport->username = 'username';
        $transport->password = '******';
        $attachment->save('dir/' . $attachment->getFileName('undefined'));
    }
}

The Versions

13/03 2017

dev-master

9999999-dev

Faster MIME Mail Parser could be used to parse emails in MIME format.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Avatar bashkarev

mail mime mailparse email arf fbl mime-parser

13/03 2017

1.0

1.0.0.0

Faster MIME Mail Parser could be used to parse emails in MIME format.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-mbstring *

 

The Development Requires

by Avatar bashkarev

mail mime mailparse email arf fbl mime-parser