Giter Club home page Giter Club logo

email's Introduction

Faster MIME Mail Parser

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

Build Status

Usage

Basic usage is the following:

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

$message->textHtml();

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

Settings

There are settings available.

  • charset - character set to use. Should be specified in uppercase only. Default is UTF-8.

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

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

Attachments

There is attachments parsing support.

Saving attachments to files

Saving to files could be done as follows:

$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:

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

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'));
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.