2017 © Pedro Peláez
 

symfony-bundle mail-parser-bundle

Parse mails using the Zend framework libraries

image

lasso/mail-parser-bundle

Parse mails using the Zend framework libraries

  • Friday, March 18, 2016
  • by zodeus
  • Repository
  • 13 Watchers
  • 4 Stars
  • 6,088 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 25 Versions
  • 0 % Grown

The README.md

Lasso Mail Parser Build Status

For when you want easy access to an email's content. The Zend Framework has classes to parse emails, but they can be a bit clunky to use. For example, emails are split into parts, and you have to loop over all the parts in an email (which itself is treated as a part) to access the content., (*1)

What it does

The Lasso Mail Parser offers a simple way to get either html or text content from an email, discarding file attachments. Should both html and text parts be given, html is preferred., (*2)

How it works

An email is parsed with the Zend mail parser. It's parts are then recursively grouped by content type, such as 'text/plain' or 'text/html'. If any html or text parts are found, they are concatenated and the result returned. If no such parts are found, null is returned., (*3)

The concatenation string is determined by a call to a user-defined function, which makes flexible concatenation possible., (*4)

Usage

As this is a symfony bundle, you can add this repository to your composer.json file:, (*5)

https://packagist.org/packages/lasso/mail-parser-bundle, (*6)

Then request the parser like this:, (*7)

$parser = $container->get('lasso_mail_parser.parser');

Of course, it can be used with dependency injection too by adding it to your services.xml as a parameter., (*8)

Once you have a parser instance, parse the raw email source like this:, (*9)

$parser->parse(YOUR-EMAIL-BODY);

You can then use, (*10)

$emailAddresses = $parser->getAllEmailAddresses();

to extract email address from the email. You can restrict the fields used for extraction by passing in an array with the field names you wish to use:, (*11)

// Only retrieve recipients
$receiverEmailAddresses = $parser->getAllEmailAddress(['to', 'cc', 'bcc']);

Use, (*12)

$content = $parser->getPrimaryContent();

to get the main content. This will be html if html is present, else it will be plain text. You can pass in a custom glue function:, (*13)

$glue = function($contentType) {
    switch ($contentType) {
        case 'text/plain':
            return "\n====\n";

        case 'text/html':
            return '<hr />';
    }

    return '';
}

$content = $parser->getPrimaryContent($glue);

Now all html parts will be concatenated with hr-tags, and all text parts will be concatenated with newlines and '===='., (*14)

If you are processing emails send via envelope journaling (e.g. from Office365), you can access the enveloped email via, (*15)

$parser->getEnvelopedEmail();

This will return a normal part, and you can access content/headers on it. To check if an email has an enveloped email as an attachment, you can use, (*16)

$parser->hasEnvelopedEmail();

The Versions

18/03 2016

dev-master

9999999-dev https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

11/09 2015

v1.1.2

1.1.2.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

25/06 2015

v1.1.1

1.1.1.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

23/06 2015

v1.1.0

1.1.0.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

23/06 2015

v1.0.9

1.0.9.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

23/06 2015

v1.0.9-alpha

1.0.9.0-alpha https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

20/05 2015

v1.0.8

1.0.8.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

09/07 2014

v1.0.7

1.0.7.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

11/02 2014

1.0.6

1.0.6.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

07/11 2013

v1.0.5

1.0.5.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

22/10 2013

v1.0.4

1.0.4.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

19/10 2013

v1.0.3

1.0.3.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

18/10 2013

v1.0.2

1.0.2.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

02/10 2013

v1.0.1

1.0.1.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

01/10 2013

v1.0.0

1.0.0.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

25/09 2013

v0.9.9

0.9.9.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

17/09 2013

v0.9.8

0.9.8.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

17/09 2013

v0.9.7

0.9.7.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

13/09 2013

v0.9.6

0.9.6.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

22/08 2013

v0.9.5

0.9.5.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

16/08 2013

v0.9.4

0.9.4.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

15/08 2013

v0.9.3

0.9.3.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

09/08 2013

v0.9.2

0.9.2.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

09/08 2013

v0.9.1

0.9.1.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing

07/08 2013

v0.9.0

0.9.0.0 https://github.com/lassodatasystems

Parse mails using the Zend framework libraries

  Sources   Download

BSD-3-Clause

The Requires

 

mail email symfony2 zend parsing