Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return value of Ddeboer\\Imap\\Message\\AbstractPart::getDecodedContent() must be of the type string, boolean returned #284

Closed
wujku opened this issue Jan 16, 2018 · 25 comments
Labels

Comments

@wujku
Copy link
Contributor

wujku commented Jan 16, 2018

No description provided.

@Slamdunk
Copy link
Collaborator

It happens only on malformed base64 contents, isn't it?
May you post the raw email please?

@Slamdunk Slamdunk added the bug label Jan 16, 2018
@ghost
Copy link

ghost commented Jan 17, 2018

I have same issue.

@Slamdunk
Copy link
Collaborator

@Bambiq may you share the raw mail that triggered the error?

@ghost
Copy link

ghost commented Jan 17, 2018

Resend email to u or what?

@Slamdunk
Copy link
Collaborator

  1. Save the email as a file
  2. Zip it
  3. Upload the zip here in Github

Of course take care to obfuscate sensitive datas.

@ghost
Copy link

ghost commented Jan 17, 2018

msg.zip

@ghost
Copy link

ghost commented Jan 17, 2018

Please give me answer as soon as possible, thank u.

@Slamdunk
Copy link
Collaborator

@Bambiq Are you able to save the message in EML format? Binary data can't be used to test the issue, we need raw plain-text data as it is sent through the internet.

@ghost
Copy link

ghost commented Jan 17, 2018

Ok. i send u in a few hours.

@Slamdunk
Copy link
Collaborator

Ping @wujku and @Bambiq for an example

@Slamdunk
Copy link
Collaborator

Ping 2 @wujku @Bambiq

@daivantrinh
Copy link

Hello! I get the same error message.
It seems that I get the error when i try and parse a mail with an attachment that also is a mail with another attachment.

Is there a solution to this yet?

@Slamdunk
Copy link
Collaborator

@daivantrinh The problem is still unknown, you can help us by providing the raw email that generated your error.

To do so you can call the $message->getRawMessage() and post here the result as a GitHub attachment.

@daivantrinh
Copy link

daivantrinh commented Mar 22, 2018

Here is the file from $message->getRawMessage()
The mail has an attachment that is a mail with a PDF attachment.

The mail is sent with Outlook 2016 and the receiver is office 365 basket.

mail.txt

Regards.

@Slamdunk
Copy link
Collaborator

I'm sorry @daivantrinh may you also post the full error stack please? I need it to recreate the exact error in the test suite

@daivantrinh
Copy link

Hello @Slamdunk, how do I generate the full stack error?

Sorry for my ignorance.

@Slamdunk
Copy link
Collaborator

Simply re-run your script or your application, and post the error message you see.

@daivantrinh
Copy link

I have made a quickfix to the problem by removing the expected return value in,
PartInterface.php - getDecodedContent()
and
AbstracatPart.php - getDecodedContent()
To not expect a returned string.
It seems that AbstracatPart.php - getDecodedContent() returns a false boolean and not a string.

Here is the error you asked for.
PHP Fatal error: Uncaught TypeError: Return value of Ddeboer\Imap\Message\AbstractPart::getDecodedContent() must be of the type string, boolean returned in /var/www/html/vendor/ddeboer/imap/src/Message/AbstractPart.php:348
Stack trace:
#0 /var/www/html/mailparser.php(124): Ddeboer\Imap\Message\AbstractPart->getDecodedContent()
#1 {main}
thrown in /var/www/html/vendor/ddeboer/imap/src/Message/AbstractPart.php on line 348

@Slamdunk
Copy link
Collaborator

Bug reproduced: present only in PHP 7.0

@daivantrinh
Copy link

I updated to 1.4.1 and run the script again with php 7.0.
This time i get this error.

PHP Fatal error: Uncaught Ddeboer\Imap\Exception\UnexpectedEncodingException: Cannot decode content
imap_alerts (0):
imap_errors (0): in /var/www/html/vendor/ddeboer/imap/src/Message/AbstractPart.php:340
Stack trace:
#0 /var/www/html//mailparser.php(124): Ddeboer\Imap\Message\AbstractPart->getDecodedContent()
#1 {main}
thrown in /var/www/html/vendor/ddeboer/imap/src/Message/AbstractPart.php on line 340

Its the same mail that is generating this new error.

@Slamdunk
Copy link
Collaborator

@daivantrinh the bug resides in PHP 7.0 and cannot be fixed.

What I've done in #324 is making this error manageable: now you can you a try/catch statement with a specific exception type catch on \Ddeboer\Imap\Exception\UnexpectedEncodingException, and if you get that specific exception you can try to use the getContent method to manually handle the encoded content.

The issue is fixed in PHP 7.1, we can't do much more. Remember that on November 2018 this library will drop PHP < 7.1 support, so the sooner you update your PHP version the better.

@daivantrinh
Copy link

@Slamdunk, thanks for the quick reply and solution.

I am looking to upgrading to PHP 7.1.
Will use try catch untill then.

Thanks again for the great repo, have a great day!

@billynoah
Copy link

billynoah commented May 1, 2018

Although this is now catchable I'm still having an issue as described above by daivantrinh where there is an "eml" attachment with attachments itself. When I output $content within getDecodedContent() I can see that the content is the wrong part. In other words, I have a jpg attachment and an eml attachment and the jpeg is base64 encoded. When $this->getContent() is called it's getting the content from the eml attachment - with is quoted-printable. Somehow the attachment within an attachment is causing the part boundaries to get skewed or mixed up.

So when it attempts to decode the base64 encoded jpg it calls $this->getContent() and gets content from a different attachment, thus causing base64_decode() to return false. I would be happy to provide the specific email I have where this came up - but would prefer it to be directly to one of the devs as this email contains sensitive data.

Should we re-open this issue or create a new one? Can someone contact me directly to collaborate on debugging this and finding a solution? Thanks.

@Slamdunk
Copy link
Collaborator

Slamdunk commented May 1, 2018

@billynoah sure: open a new issue with the error stack and email me the original raw email content, I'll dig into it and keep the sensitive data away from public

@billynoah
Copy link

thanks - my email is visible on my profile - can you email me directly so I have your address? also, can you explain what error stack means? It's the same error basically, the library wants to decode base64 but instead it's mixing up the mail parts so it tries to decode some quoted printable content as base64 and the result is false. I can email you an email that will allow you to reproduce the issue. hopefully that will suffice. in the meantime - I'll open a new issue. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants