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

Object of class stdClass could not be converted to string -> unsafe usage of switch case. #354

Closed
lionflence opened this issue Jan 5, 2023 · 2 comments
Labels
bug Something isn't working validating

Comments

@lionflence
Copy link

lionflence commented Jan 5, 2023

Describe the bug
Version 4.1.2
When parsing an email with this library I sometimes get the following message for parsing emails that are probably not formatted correctly.
Basically a part of the email is used for header parsing. Internally, php-imap splits the content into rows, checks if it contains the ":" symbol and uses the left part as the key, as far as I can see.
However there is one line in an email example I have, that looks like this: 0:30):.

This causes $key in the Header::rfc822_parse_headers to be 0. The switch operator in PHP uses the == operator internally. Since 0 == "string" results to true, PHP jumps into the sender case (breaks are missing for the previous cases). This causes an incorrect sender to be set for the mail.

This again then causes the application to crash when calling $attribute->__toString as the values property contains an object of type stdClass that is not string serializable.

The resulting error is the following:

In Attribute.php line 53:
                                                             
  Object of class stdClass could not be converted to string

Used config
I dont this this is required.

Code to Reproduce
Unfortunately I have to black out most of the email. I hope the following mail part is sufficient for reproducing the issue. You can see line 18 starting with the problematic string:

------=_NextPart_001_0273_01D69722.AE8639E0
Content-Type: text/html;
	type="multipart/alternative";
	boundary="_005_MN2PR19MB3343AA1352A16FB60C76F8E7FD320MN2PR19MB3343namp_";
	charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
</head>
<body lang=3D"DE" link=3D"#0563C1" vlink=3D"#954F72">
<ul style=3D"margin-top:0cm" type=3D"disc">
<li class=3D"MsoListParagraphCxSpLast" =
style=3D"margin-left:0cm;mso-add-space:auto;mso-list:l0 level1 lfo3">
<span style=3D"font-family:&quot;Calibri&quot;,sans-serif">K=C3=B6nntet =
ihr bitte noch folgendes XXXXX Wordmark direkt am Anfang des Videos =
einbauen, wenn xxxx die xxxx mit xxxx ank=C3=BCndigt (ca. Minute =
0:30):
</li></ul>
</body>
</html>

Expected behavior
In case the key is 0, the switch operation should not go into the sender case.

I think the easiest solution here is to use the if operation with triple equals to check for identity, instead of using the unsafe switch case.

@Webklex Webklex added bug Something isn't working validating labels Jan 5, 2023
@Webklex
Copy link
Owner

Webklex commented Jan 5, 2023

Hi @lionflence ,
many thanks for your detailed report. I would like to write a test in order to replicate this behavior. Would you mind sharing an anonymized version of this email?

Best regards & thanks again,

shuergab added a commit to shuergab/php-imap that referenced this issue Jan 24, 2023
Fixed the issue Webklex#354 by casting the key to string in the switch. Tested on over 100000 emails and over 100 accounts without any problem.
@shuergab
Copy link
Contributor

Hi @Webklex
I had the same issue, but managed to solve by casting the key to string. Did a pull request that solves the issue. Unluckily I have no copy of the email that caused the issue, but have an anonimized version of the raw headers if it's of any help.

Webklex pushed a commit that referenced this issue Mar 1, 2023
Fixed the issue #354 by casting the key to string in the switch. Tested on over 100000 emails and over 100 accounts without any problem.
@Webklex Webklex closed this as completed Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working validating
Projects
None yet
Development

No branches or pull requests

3 participants