Skip to content
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

Display name with '|' character not parsed #19

Open
postme opened this issue Feb 13, 2020 · 5 comments
Open

Display name with '|' character not parsed #19

postme opened this issue Feb 13, 2020 · 5 comments

Comments

@postme
Copy link

postme commented Feb 13, 2020

$sendingAddress = "Example | Example <example@example.com>";
$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.

@mmucklo
Copy link
Owner

mmucklo commented Feb 14, 2020

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.

@postme
Copy link
Author

postme commented Feb 14, 2020

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.

@mmucklo
Copy link
Owner

mmucklo commented Feb 14, 2020

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
Copy link
Owner

mmucklo commented Feb 19, 2020

@postme did you find anything in your searches?

@postme
Copy link
Author

postme commented Mar 2, 2020

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] 1
atext [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 <example@example.com> is a valid RFC 5322 email address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants