You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:"Calibri",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.
The text was updated successfully, but these errors were encountered:
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
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.
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. Theswitch
operator in PHP uses the==
operator internally. Since0 == "string"
results totrue
, PHP jumps into thesender
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 thevalues
property contains an object of typestdClass
that is not string serializable.The resulting error is the following:
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:
Expected behavior
In case the key is
0
, the switch operation should not go into thesender
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.The text was updated successfully, but these errors were encountered: