Quoted strings in email addresses are incorrectly parsed by lookup->normaliseHeaders #910
Replies: 3 comments
-
Can you please clarify which cases of address strings do you consider a "must have" to be supported? I ask so we can get a good understanding of what is required to normalise fields in MIME headers. As is so often the case, we only aim to support a useful subset of features, we don't want to support everything that is technically possible in RFC2822. |
Beta Was this translation helpful? Give feedback.
-
I agree, RFC2822 is a monstrosity!
In my experience I have seen only three common cases:
(These are also the only forms used as examples in the Annexes of RFC2822.) The first two are presently supported by Instead, I do not consider "addresses groups" a "must have": never seen in the wild (I added them to my function only because I realised that they required only one line more 😊). |
Beta Was this translation helpful? Give feedback.
-
I'm very sorry it took so long to fix the bug. We talked a few months ago about a suitable software design, thank you Giovanni for your feedback and your ideas. Here's what we came up with. The mail handling in the core extension has been updated. The new API for developers offers a couple of normalisation methods. To make a developer's life easier, but also to make the source code less error-prone. You don't have to use them... but I would say it's highly recommended... unless you have your own normalisation methods.
Should be fixed now, please let me know if this solution works for you. |
Beta Was this translation helpful? Give feedback.
-
If I understand well, there is a little problem in the method
lookup->normaliseHeaders
incore.php
. By looking at the code and at the way this method is used intoolbox->mail
, I understand that the purpose of this function is to format an almost-RFC2822 headers list as a MIME-compliant headers list (with non-ASCII characters properly encoded, and folded). If this is so,lookup->normaliseHeaders
fails to decode properly in email addresses quoted strings (and also, less important, address groups). I know that RFC2822 describes a thousand forms 😱 that never occur in the wild and that can be safely ignored, but quoted strings are indeed common enough: for example"Salmeri, Giovanni" <g.salmeri@example.org>
. This string is presentely translated bylookup->normaliseHeaders
in<"Salmeri>, Giovanni" <g.salmeri@example.org>
.After studying this issue, I found that there are two PHP functions with the aim of parsing address lists:
https://www.php.net/manual/en/function.imap-rfc822-parse-adrlist.php
https://www.php.net/manual/en/function.mailparse-rfc822-parse-addresses.php
Unfortunately neither is in the standard installation.
There are also PHP functions:
symfony/symfony#40205
Unfortunately, they intend to follow fully RFC2822 and are huge.
In order to adapt Mailer to the new API, I have written a very light alternative
parseAddresses
(lines 240-292) which recognises quoted strings (and flattens addresses groups). After some tests it seems to work well with all the common cases. Perhaps it can be useful? (In the original Mailer I did not face the problem, because following the steps of PHPmailer and the like, the function that builds the headers receives the single components of addresses [display name and address for each mailbox]: so no parsing was ever needed.)Beta Was this translation helpful? Give feedback.
All reactions