email-parse icon indicating copy to clipboard operation
email-parse copied to clipboard

Display name with '|' character not parsed

Open postme opened this issue 5 years ago • 5 comments

$sendingAddress = "Example | Example <[email protected]>";
$result = \Email\Parse::getInstance()->parse($sendingAddress, false);
$sendingDomain = strtolower($result['domain']);
print '$sendingDomain = ' . $sendingDomain;
$sendingAddress = strtolower($result['local_part']) . '@' . $sendingDomain;
print ': $sendingAddress = ' . $sendingAddress;

$sendingDomain = $sendingAddress = @

Stripping out the '|' character before parsing resolves the issue.

postme avatar Feb 13 '20 20:02 postme

Is that a valid RFC2822 email even? Can you point to a test case where this is parsable? I suppose the rules could be relaxed a bit, I think the Example | Example part technically needs to be in double quotes "Example | Example", although I may be wrong.

mmucklo avatar Feb 14 '20 07:02 mmucklo

Putting it in quotes does make it parseable, I'm trailing through RFC 5322 to check whether putting the display name in quotes is mandatory, it's not the most approachable of documents though.

postme avatar Feb 14 '20 07:02 postme

So as far as I can tell the "|" is valid according to RFC 5322, but according to wikipedia it's not:

https://en.wikipedia.org/wiki/Email_address

space and special characters "(),:;<>@[\] are allowed with restrictions (they are only allowed inside a quoted string, as described in the paragraph below, and in addition, a backslash or double-quote must be preceded by a backslash);

I need to dig a bit more.

mmucklo avatar Feb 14 '20 08:02 mmucklo

@postme did you find anything in your searches?

mmucklo avatar Feb 19 '20 07:02 mmucklo

I would venture that the authorative source is RFC 5322. This states the following in paragraph 3.4:

name-addr = [display-name] angle-addr display-name = phrase phrase = 1word word = atom / quoted-string atom = [CFWS] 1atext [CFWS] atext = ALPHA / DIGIT / ; Printable US-ASCII "!" / "#" / ; characters not including "$" / "%" / ; specials. Used for atoms. "&" / "'" / "*" / "+" / "-" / "/" / "=" / "?" / "^" / "_" / "`" / "{" / "|" / "}" / "~" specials = "(" / ")" / ; Special characters that do "<" / ">" / ; not appear in atext "[" / "]" / ":" / ";" / "@" / "" / "," / "." / DQUOTE

So deriving from this chain of definitions the "|" character is explicitly allowed in display name. Next question is whether the display name needs to be quoted to be valid.

3.2.4 states "Strings of characters that include characters other than those allowed in atoms can be represented in a quoted string format"

It follows from this that characters that are allowed in atoms dont need to be quoted. It could even be argued that special characters dont need to be quoted either as conveyed via the word "CAN" rather than "MUST".

Based on this reasoning I would posit that Example | Example <[email protected]> is a valid RFC 5322 email address.

postme avatar Mar 02 '20 20:03 postme