Coder Social home page Coder Social logo

fetch's Introduction

Fetch Build Status

License Latest Stable Version Coverage Status Total Downloads

Fetch is a library for reading email and attachments, primarily using the POP and IMAP protocols.

Installing

N.b. A note on Ubuntu 14.04 (probably other Debian-based / Apt managed systems), the install of php5-imap does not enable the extension for CLI (possibly others as well), which can cause composer to report fetch requires ext-imap

sudo ln -s /etc/php5/mods-available/imap.ini /etc/php5/cli/conf.d/30-imap.ini

Composer

Installing Fetch can be done through a variety of methods, although Composer is recommended.

Until Fetch reaches a stable API with version 1.0 it is recommended that you review changes before even Minor updates, although bug fixes will always be backwards compatible.

"require": {
  "tedivm/fetch": "0.7.*"
}

Pear

Fetch is also available through Pear.

$ pear channel-discover pear.tedivm.com
$ pear install tedivm/Fetch

Github

Releases of Fetch are available on Github.

Sample Usage

This is just a simple code to show how to access messages by using Fetch. It uses Fetch own autoload, but it can (and should be, if applicable) replaced with the one generated by composer.

use Fetch\Server;
use Fetch\Message;

$server = new Server('imap.example.com', 993);
$server->setAuthentication('username', 'password');

/** @var Message[] $message */
$messages = $server->getMessages();

foreach ($messages as $message) {
    echo "Subject: {$message->getSubject()}", PHP_EOL;
    echo "Body: {$message->getMessageBody()}", PHP_EOL;
}

License

Fetch is licensed under the BSD License. See the LICENSE file for details.

fetch's People

Contributors

arabcoders avatar bbcvasseur avatar benr77 avatar bjornpost avatar dangerous avatar dharyk avatar gpilla avatar gries avatar guillaume-ro-fr avatar gwarnants avatar kevinsmith avatar lewiscowles1986 avatar linniksa avatar littleslicebigcity avatar lumbendil avatar luxifer avatar orzilca avatar prestaspirit avatar quingkhaos avatar rejinka avatar sergeyklay avatar sgrodzicki avatar sgsabbage avatar sherblot avatar skl avatar tedivm avatar tomsommer avatar vasulief avatar vsychov avatar xethron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fetch's Issues

test fails

  1. Fetch\Test\MessageTest::testMoveToMailbox
    Server returned Message.
    Failed asserting that false is an instance of class "\Fetch\Message".

Support for moving messages to subfolders

I can see that there is a method to move a message from one mailbox to another, but is there any support for moving a message to a subdirectory of the current IMAP mailbox?
Thanks.

imap_savebody issue on Windows

Method \Fetch\Attachment\saveAs, this line (about 221, latest pull):

$result = imap_savebody($this->imapStream, $filePointer, $this->messageId, $this->partId ?: 1, FT_UID);

...on Windows (PHP 5.4.30 with XDebug, Apache 2.2.18) makes PHP crash. When the code reaches this line, the execution suddenly stops. No, errors, no lines in error.log, no HTTP status returned.

This is obviously not related to Fetch code, but I could bypass this problem by inserting a line like this (before the one with imap_savebody):

$temp = imap_fetchbody($this->imapStream, $this->messageId, $this->partId ?: 1, FT_UID);

Would it be possible to put something like this in the next pull?

Calling imap_fetchbody before imap_savebody seems to solve this strange issue. Here I read something about imap_fetchbody and Apache that crashes: http://www.tek-tips.com/viewthread.cfm?qid=1574115

Thank you for your attention.

windows-1255 encoding fails

Messages with windows-1255 encoding trigger an error:

Warning: mb_convert_encoding(): Illegal character encoding specified in ... /vendor/tedivm/fetch/src/Fetch/Message.php on line 485

Clean Email Body

How can I clean the message body being returned by Fetch? I am using gmail as email provider and every email contains unnecessary texts and base64 encoded objects. Is it possible to get emails without attachments? Thanks

Basic Usage

Could you throw some "Basic Usage" into your README.md to point folks in the right direction?

Make server immutable

Server is currently a mutable object being able to authenticate, set the current mailbox, etc. By making immutable I mean increasing immutability to be able to:

  • authenticate to a server with different credentials, so that it does not get overwritten (maybe a connection object or something)
  • get mailboxes (as an object) from the server/connection and operate on them directly instead of doing it on the server object

What do you think?

Release 0.5.4

Can you tag version 0.5.4 so that the getOrdered() method is available?

Undefined property: stdClass::$bytes

Hi there,

I'm getting the following error when an email has an attachment of 0 bytes Undefined property: stdClass::$bytes

Attachment.php:101

$this->size = $structure->bytes;

I've wrapped it in an isset, which to gets rid of the error, but not sure if this size is required elsewhere?

Undisclosed recipients will throw error

error thrown if the email was sent to Undisclosed recipients,

 Undefined property: stdClass::$host

 $currentAddress['address'] = $address->mailbox . '@' . $address->host;

phpunit test suite cannot be run repeatedly

Something I noticed as I was working on #121: with a fresh Vagrant environment, you can run the phpunit test suite once and everything passes. Run it again immediately, and you're hit with several failures because the test suite makes changes to the environment without resetting those changes when it's done.

Here are the errors:

There were 7 failures:

1) Fetch\Test\MessageTest::testMoveToMailbox
Server returned Message.
Failed asserting that false is an instance of class "\Fetch\Message".

/Users/username/repos/Fetch/tests/Fetch/Test/MessageTest.php:241

2) Fetch\Test\ServerTest::testNumMessages
Failed asserting that 11 matches expected 12.

/Users/username/repos/Fetch/tests/Fetch/Test/ServerTest.php:102

3) Fetch\Test\ServerTest::testSetMailBox
Failed asserting that true is false.

/Users/username/repos/Fetch/tests/Fetch/Test/ServerTest.php:152

4) Fetch\Test\ServerTest::testHasMailBox
Does not have mailbox "Cheese"
Failed asserting that true is false.

/Users/username/repos/Fetch/tests/Fetch/Test/ServerTest.php:164

5) Fetch\Test\ServerTest::testListMailBoxes
Does not have mailbox "Cheese"
Failed asserting that an array does not contain '{172.31.1.2:143/novalidate-cert}Cheese'.

/Users/username/repos/Fetch/tests/Fetch/Test/ServerTest.php:174

6) Fetch\Test\ServerTest::testCreateMailbox
Does not have mailbox "Cheese"
Failed asserting that true is false.

/Users/username/repos/Fetch/tests/Fetch/Test/ServerTest.php:181

7) Fetch\Test\ServerTest::testExpunge
Message exists
Failed asserting that false is an instance of class "\Fetch\Message".

/Users/username/repos/Fetch/tests/Fetch/Test/ServerTest.php:207

Obviously it makes adding tests difficult if you can only run the suite once each time the entire Vagrant environment is set up. Initially, I looked at fixing these issues by reversing environment changes in the tests themselves, but the changes are all over the place. I thought I'd check before doing anything huge here.

Would it be possible to modify runTests.sh to setup the vagrant environment if it doesn't exist, and to otherwise just reset the environment?

Message Body Decoding / Multipart base64

I'm using this library to get my exchange journaling mails from gmail into my MySQL database. It works like a charm, except the message body decoding of Multipart base64 mails. How can I solve this problem and get a readable message from it ?

For example, such a message body is saved in my database table:

Sender: [email protected]
Subject: Jobanfrage
Message-Id: F03EB7C5ACB6624CB754CC1D8D3371EC5C989C80@AMSPRD0610MB373.eurprd06.prod.outlook.com
To: [email protected]

--000_F03EB7C5ACB6624CB754CC1D8D3371EC5C989C80AMSPRD0610MB373
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64

SGFsbG8gTGluZSwNCg0KSW0gQW5oYW5nIGRpZXNlciBFbWFpbCBzZW5kZSBpY2ggZGlyIGRlaW5l...cutted base64...
--000_F03EB7C5ACB6624CB754CC1D8D3371EC5C989C80AMSPRD0610MB373
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64

PGh0bWwgeG1sbnM6dj0idXJuOnNjaGVtYXMtbWljcm9zb2Z0LWNvbTp2bWwiIHhtbG5zOm89InVy
bjpzY2hlbWFzLW1pY3Jvc29mdC1jb206b2ZmaWNlOm9mZmljZSIgeG1sbnM6dz0idXJuOnNjaGVt...cutted base64....

--000_F03EB7C5ACB6624CB754CC1D8D3371EC5C989C80AMSPRD0610MB373--

--009_F03EB7C5ACB6624CB754CC1D8D3371EC5C989C80AMSPRD0610MB373
Content-Type: image/jpeg; name="image001.jpg"
Content-Description: image001.jpg
Content-Disposition: inline; filename="image001.jpg"; size�53;
creation-date="Thu, 22 Aug 2013 08:17:17 GMT";
modification-date="Thu, 22 Aug 2013 08:17:17 GMT"
Content-ID: [email protected]
Content-Transfer-Encoding: base64

/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABQAAD/7QAsUGhvdG9z
aG9wIDMuMAA4QklNBCUAAAAAABAAAAAAAAAAAAAAAAAAAAAA/+4ADkFkb2JlAGTAAAAAAf/bAIQA...cutted base64...
--009_F03EB7C5ACB6624CB754CC1D8D3371EC5C989C80AMSPRD0610MB373
Content-Type: image/png; name="image002.png"
Content-Description: image002.png
Content-Disposition: inline; filename="image002.png"; size52;
creation-date="Thu, 22 Aug 2013 08:17:17 GMT";
modification-date="Thu, 22 Aug 2013 08:17:17 GMT"
Content-ID: [email protected]
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAhFBMVEUAAAAAFVAAGFIAG1UDHlcH
IVoKJFwNKF8PKFwRKV0RK2ETK18ULmQVLWAXMWYbNGkeN2tDXppGYp1KZqBLZJpOaaJSbaVWcKhX
cKJYcqRadKtddqled65heq1he61he7BifLBifLFlf7NphbdqgLFsgrNwhrJxjrxzibl6lsLQ2Ovi
6PZj+2o5AAAAEXRSTlMAv7+/v7+/v7+/v7+/v7+/v/mxPx0AAAB6SURBVBgZBcHRSkJhEAbA+Y8b
hgQFBdr7v5xQFyFBHXL3a2Z5AQBf9fwOAFKZP2D2OD2k5t7A8bR8r6mZBmrR21TvgKVv9q40aHw6
SCXgjLMPqQQAkcqAq4srUgmAIJUACFJPbwF4Zd1r9gaOfjhMTTbgZiOzPAKA33+ZjUAYiPBBrwAA
AABJRU5ErkJggg=
--009_F03EB7C5ACB6624CB754CC1D8D3371EC5C989C80AMSPRD0610MB373
Content-Type: image/png; name="image003.png"
Content-Description: image003.png
Content-Disposition: inline; filename="image003.png"; sizeY4;
creation-date="Thu, 22 Aug 2013 08:17:17 GMT";
modification-date="Thu, 22 Aug 2013 08:17:17 GMT"
Content-ID: [email protected]
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACGUlEQVR42p2RXUhTYRjH34iIbrot
y4bTaVku11GyIX1LMMIiuml9XBZ002U3MaQ0xGoJmh7GEqHIEcaRiMyM9UaWs0RQm2W4tpHbWjCI..cutted base64...

--009_F03EB7C5ACB6624CB754CC1D8D3371EC5C989C80AMSPRD0610MB373
Content-Type: image/jpeg; name="image004.jpg"
Content-Description: image004.jpg
Content-Disposition: inline; filename="image004.jpg"; sizeY24;
creation-date="Thu, 22 Aug 2013 08:17:17 GMT";
modification-date="Thu, 22 Aug 2013 08:17:17 GMT"
Content-ID: [email protected]
Content-Transfer-Encoding: base64

/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABQAAD/7gAOQWRvYmUA
ZMAAAAAB/9sAhAACAgICAgICAgICAwICAgMEAwICAwQFBAQEBAQFBgUFBQUFBQYGBwcIBwcGCQkK...cutted base64...

--009_F03EB7C5ACB6624CB754CC1D8D3371EC5C989C80AMSPRD0610MB373--

--000_F03EB7C5ACB6624CB754CC1D8D3371EC5C989C80AMSPRD0610MB373
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64

SGFsbG8gTGluZSwNCg0KSW0gQW5oYW5nIGRpZXNlciBFbWFpbCBzZW5kZSBpY2ggZGlyIGRlaW5l
IEVpbnNhdHp2ZXJlaW5iYXJ1bmcgbWl0IGFsbGVuIHdpY2h0aWdlbiBJbmZvcm1hdGlvbmVuIHp1...cutted base64...

--000_F03EB7C5ACB6624CB754CC1D8D3371EC5C989C80AMSPRD0610MB373
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64

PGh0bWwgeG1sbnM6dj0idXJuOnNjaGVtYXMtbWljcm9zb2Z0LWNvbTp2bWwiIHhtbG5zOm89InVy
bjpzY2hlbWFzLW1pY3Jvc29mdC1jb206b2ZmaWNlOm9mZmljZSIgeG1sbnM6dz0idX...cutted base64...

"ext-imap" requirement for composer doesn't work properly

I tried installing Fetch via composer on my localhost machine running Linux Mint 15 (based off Ubunt) with PHP 5.5, with IMAP installed, but composer fails the update with the following:

  Problem 1
    - Installation request for tedivm/fetch dev-master -> satisfiable by tedivm/fetch[dev-master].
    - tedivm/fetch dev-master requires ext-imap * -> the requested PHP extension imap is missing from your system.

I tried installing and using the library manually and it works just fine.

Why return only the first FROM address?

I noticed that the sender and from addresses are treated differently than the rest of the addresses by the getAddresses method in that only the first address listed for each is actually returned. For the sender address, this makes sense. Though extremely rare, however, it is possible for an email to have multiple addresses listed in the FROM header.

It's also worth noting that if you set $asString to true on the getAddresses method, all addresses listed for sender and from are returned, not just the first ones.

imap_fetchbody marks all my mails in a mailbox as "read" whereas they should remain "unread"

It seems that:

imap_fetchbody($this->imapStream, $this->uid, $partIdentifier, FT_UID)

This particular line of code is stored in Message.php around 470.
This particular line of code is marking all the mails in my mailbox as read. I cannot figure out why this happens. I wish I had a solution, but I can`t find out what the reason for this behaviour is.

In any case, I tested using Roundcube on one tab, my code on the second. I`m marking them as unread in Roundcube, make sure they are marked as unread, then run the code and eventually reached this line of code. If I comment out this line of code, none of my mails are changed and remain unread ( which is what should be the case ).

I dont have any code to quickly reproduce this problem, but I figure im not alone in this?

On returning HTML and plain text message bodies

I notice Fetch will always return an HTML or plain text body when requested, even if the original message doesn't actually contain an HTML or plain text version. I have a need where I actually want to only return the HTML and/or plain text if the original message included it. Of course, I can extend Fetch for my needs, but it feels like this might be a general enough use that others would benefit. I'm happy to fork it, code it up (backwards-compatible, of course), and issue a pull request if you like, but I wanted to see if that's even something you want Fetch to do before I did anything.

Use secondary interface when making requests to the IMAP

I want to use a secondary interface with a different IP when making requests to the IMAP server. How do I accomplish that?

With curl is as easy as setting up a flag:

curl_setopt($curlh, CURLOPT_INTERFACE, "xxx.xxx.xxx.xxx");

For imap the only remaining option is to bind php to a different interface, which is also a pain ...

Wrapper for imap_subscribe and imap_unsubscribe

Hi,

I'm missing the functionality to (un)subscribe mailboxes:

public function subscribeToMailBox($mailbox) {
 return imap_subscribe($this->getImapStream(), $this->getServerSpecification() . $mailbox);
}

public function unsubscribeFromMailBox($mailbox) {
 return imap_unsubscribe($this->getImapStream(), $this->getServerSpecification() . $mailbox);
}

As workaround I extend the class Fetch\Server to add this functionality, since getServerSpecification() is protected.

Thanks!

SSL/TLS handshake with the IMAP server

It looks like SSL/TLS handshake is handled at a different (PHP) layer. Are there methods for adjusting these options, built into this library? I can see some options here https://github.com/tedious/Fetch/blob/master/src/Fetch/Server.php :

    /**
     * These are the flags that depend on ssl support being compiled into imap.
     *
     * @var array
     */
    public static $sslFlags = array('ssl', 'validate-cert', 'novalidate-cert', 'tls', 'notls');
    /**
     * This is used to prevent the class from putting up conflicting tags. Both directions- key to value, value to key-
     * are checked, so if "novalidate-cert" is passed then "validate-cert" is removed, and vice-versa.
     *
     * @var array
     */
    public static $exclusiveFlags = array('validate-cert' => 'novalidate-cert', 'tls' => 'notls');

Do you have a practical example on how to use different certs for a particular IMAP service, or do we have to use same valid root certificate that comes installed on a machine, in my case Linux machine?

Thanks.

Do not change read status

Dear Tedious,

How can I use the class and not change the read status of the emails.
The only thing I want to do is to read the emails into a database, without changing the status of the messages.

iconv(): Detected an illegal character in input string

Hello, on some messages I get this notice:

ErrorException [ Notice ]: iconv(): Detected an illegal character in input string
APPPATH/vendor/tedivm/fetch/src/Fetch/Message.php @ line 421:

I debuged thesemessages, I see that the values during error are:
$parameters['charset'] = utf-8;
self::$charset = UTF-8//TRANSLIT;

Any idea on how to fix it?

Please add a new Tag

Since there are 18 commits after the last tag, can you please add a new tag like 0.6.2?

Thanks!

Dependency requirement (ext-imap) breaks Composer udpate

Hi,

Commit 9334952 introduced the requirement for the PHP imap extension.

Unfortunately, this makes composer update fail (I do have php5-imap installed on my Ubuntu):

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - tedivm/fetch dev-master requires ext-imap * -> the requested PHP extension imap is missing from your system.
    - tedivm/fetch dev-master requires ext-imap * -> the requested PHP extension imap is missing from your system.
    - Installation request for tedivm/fetch dev-master -> satisfiable by tedivm/fetch[dev-master].

Apparently, the same problem (where a commit enforces this dependency and breaks compsoer update) appeared in the past: #28

Thanks!

Encoding Issue

I have an email from Netflix that sets off this exception:

iconv(): Detected an illegal character in input string

From this code on line 441 of Message.php:

 if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset)
                $messageBody = iconv($parameters['charset'], self::$charset, $messageBody);

Seems like an encoding issue. The email seems to be encoded 7bit UTF-8. What can be done to help prevent this?

Here is the email in question:

http://pastie.org/private/4b7pdeox56crvmfdk31dw

->getMessages($limit) is SLOW if $limit > 5

The following code takes ages to run and it crashes my server:
$messages = $server->getMessages(100);

Looks like it loads all the possible details about every message, but how am I supposed to display a listing (load only message's subject) with, lets say, 50 newest messages FAST (so that user does not notice it). In source I cannot find a function that loads only the subject of messages. I dont need the content at that moment..

Exception when email subject is null

An exception occurs when you try to fetch an email with no subject set. This has been tested using Gmail's IMAP access.

Dev Note
Maybe this is a good place to check if the $messageOverview has a subject attribute:

src/Fetch/Message.php:193: $this->subject = $messageOverview->subject;

Issue with multi-dimensional structure->parts

Whilst parsing a message which contains an embedded image for someone's signature I came across an issue which caused the entire message including plain, html and base64 image parts to be stored in the $plaintextMessage property. A dump of the full $this->structures object is shown below.

I have managed to solve it by adding a new method loadMessageParts() which recursively supplies structures to the processStructure() method. It also chains the $partIdentifier value which works correctly with imap_fetchbody(). See my multipart-fix branch

It might be that I've misunderstood use of the system and this fix isn't needed, as nobody else seems to be reporting a similar issue. Please post if this is the case or more information is needed on my issue or fix. If it seems the issue is valid I can ensure the code is formatted properly and submit a pull request.

The structure is as follows:

stdClass Object
(
    [type] => 1
    [encoding] => 0
    [ifsubtype] => 1
    [subtype] => ALTERNATIVE
    [ifdescription] => 0
    [ifid] => 0
    [ifdisposition] => 0
    [ifdparameters] => 0
    [ifparameters] => 1
    [parameters] => Array
        (
            [0] => stdClass Object
                (
                    [attribute] => BOUNDARY
                    [value] => ------------040407080008060204020006
                )
        )
    [parts] => Array
        (
            [0] => stdClass Object
                (
                    [type] => 0
                    [encoding] => 0
                    [ifsubtype] => 1
                    [subtype] => PLAIN
                    [ifdescription] => 0
                    [ifid] => 0
                    [lines] => 23
                    [bytes] => 400
                    [ifdisposition] => 0
                    [ifdparameters] => 0
                    [ifparameters] => 1
                    [parameters] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [attribute] => CHARSET
                                    [value] => UTF-8
                                )
                            [1] => stdClass Object
                                (
                                    [attribute] => FORMAT
                                    [value] => flowed
                                )
                        )
                )
            [1] => stdClass Object
                (
                    [type] => 1
                    [encoding] => 0
                    [ifsubtype] => 1
                    [subtype] => RELATED
                    [ifdescription] => 0
                    [ifid] => 0
                    [ifdisposition] => 0
                    [ifdparameters] => 0
                    [ifparameters] => 1
                    [parameters] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [attribute] => BOUNDARY
                                    [value] => ------------070800070803000004020103
                                )
                        )
                    [parts] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [type] => 0
                                    [encoding] => 0
                                    [ifsubtype] => 1
                                    [subtype] => HTML
                                    [ifdescription] => 0
                                    [ifid] => 0
                                    [lines] => 43
                                    [bytes] => 1594
                                    [ifdisposition] => 0
                                    [ifdparameters] => 0
                                    [ifparameters] => 1
                                    [parameters] => Array
                                        (
                                            [0] => stdClass Object
                                                (
                                                    [attribute] => CHARSET
                                                    [value] => UTF-8
                                                )
                                        )
                                )
                            [1] => stdClass Object
                                (
                                    [type] => 5
                                    [encoding] => 3
                                    [ifsubtype] => 1
                                    [subtype] => PNG
                                    [ifdescription] => 0
                                    [ifid] => 1
                                    [id] => <part2.08030200.00000802@REDACTED>
                                    [bytes] => 63816
                                    [ifdisposition] => 0
                                    [ifdparameters] => 0
                                    [ifparameters] => 0
                                    [parameters] => stdClass Object
                                        (
                                        )
                                )
                        )
                )
        )
)

New tag

Is it possible for you to tag a new version, because I use this project in production and I don't want to rely on a dev dependency. Thanks

Tag request

Since with PR #17 a important method was fixed and we rely on stable versions, we need a new tag please.

Alternative subtype not properly handled

Hi.

I've been wondering why an email with plain text and html was not correctly read. It seems to happen only when the html part contains an inline image. In this case, subtype is "alternative" and is handled by line from 451 to 459 in Message.php file.

What should be done then is parse the part which contains both plain text and html. Instead, the whole part (including boundaries, encoding, etc.) is assigned to html body.

Here are some information about this email :

  • mail source read in Roundcube
  • result of imap_fetchstructure()
  • result of imap_bodystruct()
  • result of imap_fetchbody()

https://gist.github.com/OlivierCecillon/511c2dd97fb94f4e462d

I can try to work on this problem, but I'm not completely ready with unit tests and vagrant yet...

In a multipart email messageBody() keeps headers

First of all; thanks for a ton for this library! This really saves us a lot of work. I think I've found an issue, but I'm not really sure if it's a bug in Fetch, php's imap_fetchbody or the email source:

After some investigation, I've found that imap_fetchbody() in https://github.com/tedivm/Fetch/blob/master/src/Fetch/Message.php#L436-L438 is called with $partIdentifier = 1, which causes imap_fetchbody() to return the entire message part (including headers) instead of just the message part's body.

To fix this, we can:

But I'm not really sure which solution to go for. Thoughts?

Obtaining the IMAP directory separator character

Is there any way to get the IMAP directory separator character? Usually it can be '.' or '/' but it varies from mailserver to mailserver.

I am writing an app that needs to create mailboxes on a variety of different mailservers so I need to programmatically extract this separator character so I can correctly construct the path to the new mailbox etc.

Undefined variable: currentAddress

I'm seeing the following notice when processing a message with BCC recipients only (and the primary recipient set to 'undisclosed-recipients'.

Notice: Undefined variable: currentAddress in vendor/tedivm/fetch/src/Fetch/Message.php line 633

Looking at the code it's simply due to the $currentAddress variable being defined inside an if statement whose condition is never fulfilled.

Gmail Issue - Undefined property: stdClass::$subject

I get the following Notice while connecting to a gmail server using the Sample Usage code in the readme section -

PHP Notice:  Undefined property: stdClass::$subject in /home/int3rlop3r/Programs/php/git_projects/Fetch/src/Fetch/Message.php on line 193
PHP Stack trace:
PHP   1. {main}() /home/int3rlop3r/Programs/php/git_projects/Fetch/test.php:0
PHP   2. Fetch\Server->getMessages() /home/int3rlop3r/Programs/php/git_projects/Fetch/test.php:8
PHP   3. Fetch\Message->__construct() /home/int3rlop3r/Programs/php/git_projects/Fetch/src/Fetch/Server.php:362
PHP   4. Fetch\Message->loadMessage() /home/int3rlop3r/Programs/php/git_projects/Fetch/src/Fetch/Message.php:178

imap_close

Shouldn't imap_close be called after each operation?

Unsupported encoding in mb_convert_encoding results in fatal error

Per 38dd385, calls to mb_convert_encoding are encapsulated in try…catch statements, however, mb_convert_encoding does not appear to yield exceptions — instead, unsupported character sets result in a fatal error:

2: mb_convert_encoding(): Illegal character encoding specified

A solution to this would be to check what conversions are supported with mb_list_encodings, but I'll leave that up to you to decide, seeing as you may want to do away with the apparently unnecessary try…catch statement, too.

On a sidenote, the issue I was having had to do with mails being encoded with 'unicode-1-1-utf-7', which is not supported by mbstring. I worked around it using the following ugly hack:

diff a/Fetch/Message.php b/Fetch/Message.php
--- a/Fetch/Message.php
+++ b/Fetch/Message.php
@@ -479,7 +479,7 @@ class Message

             if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) {
                 $mb_converted = false;
-                if (function_exists('mb_convert_encoding')) {
+                if (function_exists('mb_convert_encoding') && $parameters['charset'] != 'unicode-1-1-utf-7') {
                     try {
                         $messageBody = mb_convert_encoding($messageBody, self::$charset, $parameters['charset']);
                         $mb_converted = true;

Closing connection manually

I see, that code is missing explicit closeImapStream (or similar) method - sometimes you may want to close connection and open it once again in one script, while creating new object is tricky (for example, Fetch is your class dependency already configured and injected from outside).

I can provide PR if you want for that, or just close this issue if you think it's not needed:)

PS. Yes, I found those: #59, #62, #69 - but it was about destructor.

option to specify FT_PEEK

currently, fetching messages automatically marks them as read. this is not always desirable behavior and there's currently no way to change this.

it would be helpful to either add the option (FT_PEEK) flag to getMessages() or something similar.

i think it makes sense to actually have it on by default.

thanks!

Undefined property: stdClass::$host

Undefined property: stdClass::$host

... /vendor/tedivm/fetch/src/Fetch/Message.php:573

It can be reproduced when the To header is not an email.

Example:
To: undisclosed-recipients:;

It happened when i received a email from a Redmine app.

I fast fixed adding this:

$currentAddress['address'] = $address->mailbox . '@' . $address->host;
if (isset($address->personal))
    $currentAddress['name'] = $address->personal;
$outputAddresses[] = $currentAddress;

Changing with this...

if (property_exists($address, 'mailbox') && $address->mailbox != 'undisclosed-recipients') {
     $currentAddress['address'] = $address->mailbox . '@' . $address->host;
     if (isset($address->personal))
        $currentAddress['name'] = $address->personal;
        $outputAddresses[] = $currentAddress;
}

I know that is a fast and quite dirty solution.

Sorry for my english.

Proposal : setMessageClass method

Hi,

Currently it is not possible to extend the Fetch\Message class since it is used harcoded in Fetch\Server (in methods search(), getMessages() for instance).
I like the idea to set the name of the class to use to instanciate messages, like SplFileInfo::setFileClass or SplFileInfo::setInfoClass
It allows developper to extend Fetch\Message and use his own class easily.

X-UNKNOWN Charset causing message to be blank

Headers on the email as shown in Gmail:

To: [email protected]
Subject: Subject here...
X-PHP-Originating-Script: 1000:emailTest.php
From: [email protected]
Content-Type: text/html
Content-Transfer-Encoding: base64
Message-Id: <[email protected]>
Date: Wed,  2 Jul 2014 14:42:28 +0000 (UTC)

CiAgPHA+QmxhIEJsYSBCbGEuIFRoaXMgPGI+Yml0IHNob3VsZDwvYj4gYmUgaWdub3JlZDwvcD4K
CiAgJFNUQVJUJAogIFRlc3QgbWVzc2FnZSBnb2VzIGhlcmUuLi4gVGVzdCBtZWVzc2FnZSBnb2Vz
IGhlcmUuLi4KICAkRU5EJAoKCiAg

The $message->structure has a encoding of 3 and parameters has one element of CHARSET = X-UNKNOWN.

In Message.php, the following call to iconv returns false, so $messageBody gets lost.

                $messageBody = iconv($parameters['charset'], self::$charset, $messageBody);

Issue with POP3/IMAP on Exchange 2010

Hi

There is an issue with the code when connecting to Exchange 2010. It gives the following error:

Unknown: Kerberos error: Credentials cache file '/tmp/krb5cc_33' not found (try running kinit) for exch1.rainbow.local (errflg=1)

This can be resolved by adding a final parameter to the imap_open function call, as follows

$mbox = imap_open("{w2010ExchangeServer:993/imap/ssl}", $user, $password, NULL, 1, array('DISABLE_AUTHENTICATOR' => 'GSSAPI'));

Perhaps one way to add this into the code, is simple add a $parameter attribute to the class, which can be set as required. 👍

Mailbox list

Would be nice to have a nice clean way of listing all the mailboxes an email account has, for example, Inbox, Drafts, Sent, Archive, Trash, etc.

Proposal - Middleware

Hey! What would you think of adopting a "middleware" approach that would allow developers to add in middleware to messaging parsing.

For example, it would be nice to have a middleware which handled the UTF-8 encoding of the subject, html and plaintext email. Another middleware might be to attempt to clean HTML emails, which often come with a lot of useless cruft which makes displaying an html email in the browser difficult.

This helps in situations where more encoding or extra parsing is required by business logic. (You can likely wrap your business logic over/around this class, but the middleware approach makes for some interesting abilities).

Some middleware ("core middleware"?) could be created by extracting current functionalities such as encoding and other things which aren't strictly email related functionalities (potentially allowing you to clear that code out from being "hard coded" into the email classes).

Let me know what you think! (I can take constructive criticism :D )

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.