SSilence / php-imap-client

a easy solution for simple IMAP email access in php
MIT License
268 stars 138 forks source link

saveAttachments problem #238

Closed tolgacinar closed 2 years ago

tolgacinar commented 5 years ago

Save attachments with this function but cant open files. Files are breaking

YaWK commented 4 years ago

I've had the same issue. You need to base64_decode the attachment body. I've changed the line of file_put_contents[...] in ImapClient\SaveAttachments method to this:

This solved the problem for me: _file_put_contents($dir.DIRECTORY_SEPARATOR.$newFileName, base64decode($attachment->body));

ggiacomoo commented 4 years ago

thanks, why not pulled?!?!

tuptuptup commented 3 years ago

@YaWK @ggiacomoo It's a good solution, but not for each attachment. Some of attachments need quoted_printable_decode.

        if (base64_decode($attachment->body, true) == true){
            file_put_contents($dir.$newFileName, base64_decode($attachment->body););
        }else{
            file_put_contents($dir.$newFileName, quoted_printable_decode($attachment->body));
        }
tolgacinar commented 2 years ago

Solved.

https://github.com/SSilence/php-imap-client/issues/238#issuecomment-530195536