zalazdi / laravel-imap

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

Problem with attachments with no charset. #3

Closed msimonis-eco closed 8 years ago

msimonis-eco commented 8 years ago

Hi,

your mail-client is throwing an encoding exception when a Message-Part has no charset.

[Zalazdi\LaravelImap\Exceptions\GetMessagesFailedException]
mb_convert_encoding(): Illegal character encoding specified

For example Microsoft-Outlook and the web-client for exchange sends txt-attachments like this:

Content-Type: text/plain; name="test.txt" Content-Description: test.txt Content-Disposition: attachment; filename="test.txt"; size=6; creation-date="Mon, 09 Nov 2015 18:11:36 GMT"; modification-date="Mon, 09 Nov 2015 18:11:40 GMT" Content-Transfer-Encoding: base64

The charset is missing.

In this case the Exception is thrown in /var/www/codebase/eco/bss/tickets/api/vendor/zalazdi/laravel-imap/src/Message.php when trying to convert the encoding in

$content = $this->convertEncoding($content, $encoding);

You can fix this by trying to detect the charset with the php-function mb_detect_encoding.

$encoding = $this->getEncoding($structure); if (!$encoding) { $encoding = mb_detect_encoding($content); }

It will still fail if the function is also not able to detect the charset but for most text-attachments this should work.

Cheers, Matthias

urameshibr commented 8 years ago

@msimonis-eco I have the same problem, can you to solve this?