-
Notifications
You must be signed in to change notification settings - Fork 193
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
Parser::getRawHeader() may returns array #418
Conversation
Thanks, could you add a test? |
came looking for this as well. |
Hello, I tested it, but I couldn't reproduce the issue: $parser = new Parser();
$parser->setText(<<<MIME
From: expéditeur@example.com
To: destinataire@example.com
Subject: Exemple d'e-mail MIME avec en-tête Received
Received: from mail.example.com (mail.example.com [192.168.1.1])
by mx.example.net (Postfix) with ESMTPS id ABC12345
for <destinataire@example.com>; Mon, 20 Sep 2023 10:00:00 -0400 (EDT)
(envelope-from expéditeur@example.com)
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by mail.example.com (Postfix) with ESMTPSA id DEF67890
for <destinataire@example.com>; Mon, 20 Sep 2023 09:59:59 -0400 (EDT)
(envelope-from expéditeur@example.com)
Content-Type: multipart/mixed; boundary="frontière123"
--frontière123
Content-Type: text/plain
Bonjour,
Ceci est un exemple d'e-mail MIME avec un en-tête "Received" comprenant plusieurs lignes.
Cordialement,
Expéditeur
--frontière123
Content-Type: application/pdf; name="document.pdf"
Content-Disposition: attachment; filename="document.pdf"
[Contenu du fichier PDF ici]
--frontière123--
MIME
);
$subject = $parser->getHeader('Subject');
$this->assertEquals("Exemple d'e-mail MIME avec en-tête Received", $subject);
$received = $parser->getHeader('Received');
$this->assertEquals("from mail.example.com (mail.example.com [192.168.1.1]) by mx.example.net (Postfix) with ESMTPS id ABC12345 for <destinataire@example.com>; Mon, 20 Sep 2023 10:00:00 -0400 (EDT) (envelope-from expéditeur@example.com) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.example.com (Postfix) with ESMTPSA id DEF67890 for <destinataire@example.com>; Mon, 20 Sep 2023 09:59:59 -0400 (EDT) (envelope-from expéditeur@example.com)", $received);
$received_raw = $parser->getRawHeader('Received');
$this->assertEquals("from mail.example.com (mail.example.com [192.168.1.1]) by mx.example.net (Postfix) with ESMTPS id ABC12345 for <destinataire@example.com>; Mon, 20 Sep 2023 10:00:00 -0400 (EDT) (envelope-from expéditeur@example.com) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.example.com (Postfix) with ESMTPSA id DEF67890 for <destinataire@example.com>; Mon, 20 Sep 2023 09:59:59 -0400 (EDT) (envelope-from expéditeur@example.com)", $received_raw);
$headers = $parser->getHeaders();
$this->assertEquals([
'from' => 'expéditeur@example.com',
'to' => 'destinataire@example.com',
'subject' => "Exemple d'e-mail MIME avec en-tête Received",
'received' => 'from mail.example.com (mail.example.com [192.168.1.1]) by mx.example.net (Postfix) with ESMTPS id ABC12345 for <destinataire@example.com>; Mon, 20 Sep 2023 10:00:00 -0400 (EDT) (envelope-from expéditeur@example.com) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.example.com (Postfix) with ESMTPSA id DEF67890 for <destinataire@example.com>; Mon, 20 Sep 2023 09:59:59 -0400 (EDT) (envelope-from expéditeur@example.com)',
], $headers); This test passed, which means that |
I was able to reproduce it with 2 headers, but it's an edge case that I'm not quite sure how to handle because in 99% of the cases, we just want to have a string and not an array. $parser = new Parser();
$parser->setText(<<<MIME
From: expéditeur@example.com
To: destinataire@example.com
Subject: Exemple d'e-mail MIME avec en-tête Received
Received: from first line
Received: from second line
Content-Type: text/plain
hello world!
MIME
);
$subject = $parser->getHeader('Subject');
$this->assertEquals("Exemple d'e-mail MIME avec en-tête Received", $subject);
$received = $parser->getHeader('Received');
$this->assertEquals("from first line", $received);
$received_raw = $parser->getRawHeader('Received');
$this->assertEquals(["from first line", "from second line"], $received_raw);
$headers = $parser->getHeaders();
$this->assertEquals([
'from' => 'expéditeur@example.com',
'to' => 'destinataire@example.com',
'subject' => "Exemple d'e-mail MIME avec en-tête Received",
'received' => ["from first line", "from second line"],
], $headers); I agree that it's not ideal because |
@eXorus I see the pull request is still open for this, can we please push this mainstream? A lot of ESPs using mail-channels are relay are returning multiple received headers, and mail-channels is a major relay. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #418 +/- ##
=========================================
Coverage 97.00% 97.00%
Complexity 177 177
=========================================
Files 6 6
Lines 468 468
=========================================
Hits 454 454
Misses 14 14 ☔ View full report in Codecov by Sentry. |
I added the test and it's merged. |
getRawHeader may return array, if the mail has multiple header lines, like a Received