I need to know what are the rules for validation/format from(name-addr
) field in the email.
In rfc explained the format of name-addr
, but goes into detail about the display-name
.
Like this:
From: John Q. Public <[email protected]>
I want to know the characters and length allowed.
How do I know that John Q. Public
has valid characters?
Should I allow only printable US-ASCII characters ?
I consulted the RFC 2822 and not found on the specific format of a display name
This is all defined in the rfc you linked to in your question (btw, the newer version of this document is RFC 5322):
You have to jump around in the document a bit to find the definitions of each of these token types, but they are all there.
Once you have the definitions, all you need to do is scan over your name string and see if it consists only of the valid characters.
According to the definitions, a
display-name
is aphrase
and aphrase
is 1-or-moreword
tokens (or anobs-word
which I'll ignore for now to make this explanation simpler).A
word
token can be either anatom
or aquoted-string
.In your example,
John Q. Public
contains aspecial
character,"."
, which cannot appear within anatom
token. What about aquoted-string
token? Well, let's see...Based on this, we can tell that a
"."
is allowed within a quoted-string, so... the correct formatting for yourdisplay-name
can be any of the following:or
or
or
Any one of those will work.