-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
SMTP Conversation Broken - MAIL FROM invalid #317
Comments
it should work when you put the receivers in quotes: |
On Tue, Feb 11, 2020 at 12:10 AM Phillip Smith ***@***.***> wrote:
When using the SMTP lib, if the 'From' header is set to *an RFC 5322
formatted address* with a display name (eg, Phillip Smith - Example<
***@***.***>), the SMTP conversation breaks because the MAIL FROM:
command is invalid
local-part = dot-atom / *quoted-string* / obs-local-part
Strings of characters that *include characters other than those allowed
in atoms* can be represented in a quoted string format, where the
characters are surrounded by quote (DQUOTE, ASCII value 34) characters.
Spaces aren't in the set of characters allowed in atoms.
Example code:
$smtp = new \SMTP('localhost', 25);
$smtp->set('From', 'Phillip Smith - ***@***.***>');
You're missing quotes - that isn't an RFC5322 formatted address without
them.
|
@pauljherring That is talking about the addr-spec part of the format. See section 3.4:
Spaces are perfectly valid in the "display name", as long as the addr-spec (ie, "[email protected]") is wrapped in @ikkez That is another workaround I didn't realize, but the quotes are not required in the RFC, so F3 should not require them (IMHO). |
Thanks for the quick responses by the way :) |
According to what @pauljherring linked, the rfc clearly states that quotes are required as long as the sender cannot be represented as dot-atom.
and as per Section 3.2.5, phrase is defined as
A word is either an atom or a quoted string. |
I think you're mixing up the "localpart" component of the email address, with the "display name" component of the address format. These are all valid RFC5322 addresses:
As real-world examples, the notification emails from GitHub to myself regarding updates on this issue contain the following headers (unquoted display-name):
Another sample from Google in my inbox has this unquoted display-name header:
One more sample from Hotmail also shows no quoting around the display-name:
So quoting the 'display-name' is optional (ie, not required) by the RFC, and not using quotes is valid and common, regardless of the presence of spaces within the display-name. |
In the absence of unambiguously being able to determine whether a separator character is part of a display name, or genuinely separating two email addresses, how would you suggest changing the following function call, modified slightly, from @ikkez's earlier post?
Presuming, of course that there are two email addresses in the string, and not just one with a display name containing something that looks like an email address. Or perhaps there's three with one being a local address. The
.. and we're back to atoms and quoted-strings. https://tools.ietf.org/html/rfc5322#section-3.2.3
I'm honestly not trying to be difficult here; it just sometimes comes across that way :) |
I enjoy collaborative problem solving, so all good! :) The
Results:
F3 doesn't necessarily need a new dependency though. There is also mail-mime-parser might be an option to avoid reinventing the wheel. Composer installs it without any additional PHP module requirements from what I can tell. Perhaps F3 could abstract some of this email handling functionality off to this? Email is deceivingly complex for such a 'simple' protocol, and it isn't the primary purpose of F3. mail-mime-parser is BSD 2-clause licensed, which is compatible with the GPLv3 that F3 is using.
Results:
|
Ok, introducing a comma into the first display name - I'm presuming you're not proposing banning commas from display names? ;) :
Quoting that first display name:
Quotes needed. I think it's merely an accident of php's implementation that - as long as you aren't using commas anywhere except as a separator, then it "seems to work." Rather than "working as intended." I'm minded of C's "undefined behaviour," when said undefined behaviour happens to match the expected behaviour by accident. See also: |
Yes, I see your point. But we're also slightly off-topic; the original bug is with how F3 is handling the |
Of course most servers probably can handle unquoted addresses, but as discussed: For a comprehensive solution you could add a lib, also this php-function (for me this is a perfect case of "know your api") is nice. Using a different parser for one field is not very reasonable and far from "fatfree". As there _is_ an easy workaround, I'd flag this with "wontfix". NB: the RFC really states to quote the displayname if it does not consist of atoms 😉 |
I appreciate the "wontfix" suggestion - it would be nice to handle it gracefully is some way, even if it throws an error. As I mentioned in my original post, currently F3 just silently ignores the corresponding error-condition (the 554 status code from the SMTP server), so perhaps the 'solution' to this problem is for F3 to properly handle the SMTP conversation error (instead of silently continuing and ignoring the error). At least future people like me will find the problem a lot sooner ;) |
Ah yes, I totally agree with that. if (preg_match('/^(4|5)\d{2}\s.*$/', $reply)) {
throw new SMTPException($cmd, $reply);
} But I've seen there is no errorhandling yet. |
When using the SMTP lib, if the 'From' header is set to an RFC 5322 formatted address with a display name (eg,
Phillip Smith - Example<[email protected]>
), the SMTP conversation breaks because theMAIL FROM:
command is invalidExample code:
Results in this
MAIL FROM:
value in the SMTP transaction:It is being caused by the "stringify headers" loop: https://github.com/bcosca/fatfree/blob/master/lib/smtp.php#L253
Appears to have been introduced in 3.6.0 by this change: https://github.com/bcosca/fatfree/blame/495a97c9957a9edfbaea362927be6f3faa96fc52/lib/smtp.php#L267
Workaround is to specify a plain email address in the "Sender" header:
Also,
send()
does NOT return an error in response to this failure, so it goes quietly undetected until someone notices they haven't received the expected emails for several months ;)I suggest either the "Sender" header is made mandatory, and valided/massaged into a plain email address without display name, or the stringify headers loop is adjusted (I'm not 100% understanding the purpose of this loop though)
The text was updated successfully, but these errors were encountered: