zalazdi / laravel-imap

Laravel 5 IMAP client.
MIT License
48 stars 24 forks source link

Handling Disposition for parts with type text #4

Open msimonis-eco opened 8 years ago

msimonis-eco commented 8 years ago

Hi,

plain-text attachments are defined as type text in mails, which leads to the issue that in your lib I will only get the last item with type TEXT in bodies['text'].

In case of an txt-file you will see the return-parameters of imap_fetchstructure set like this:

  ["type"] => int(0)
  ["ifdisposition"] => int(1)
  ["disposition"] => string(10) "attachment"

That means, this part is an attachment not the text-body-part.

When your Message-Class runs through the parts you will only get the last part with type text in bodies['text'].

You should use the ifdisposition-flag.

I helped myself by changing the first if in fetchStructure of Message.php from

   if ($structure->type == self::TYPE_TEXT) {

to

    if ($structure->type == self::TYPE_TEXT && !$structure->ifdisposition) {

and than just added the TYPE_TEXT-Handling in your attachment-part:

       switch($structure->type) {
           case self::TYPE_TEXT:
               $type = "Text";
               break;

Only parts with not disposition and type text will go into bodies['text'] and the other parts will now end in the attachments. This is just my workaround and will not handle multiple non-attachment text-parts.

The right way would be to first test for the disposition flag and then handle dispositions of type "attachment" as attachment and dispositions of type "inline" or parts without disposition as bodies-parts.

To go deeper into this, there are more disposition-types: http://www.iana.org/assignments/cont-disp/cont-disp.xhtml

Cheers, Matthias

zalazdi commented 8 years ago

Hello,

can you send me example message? I'm colleting different message types to improve this lib.

It will be done for 3 weeks.

msimonis-eco commented 8 years ago

Hi,

I sent some examples to the address from your git-account.