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-nameis aphraseand aphraseis 1-or-morewordtokens (or anobs-wordwhich I'll ignore for now to make this explanation simpler).A
wordtoken can be either anatomor aquoted-string.In your example,
John Q. Publiccontains aspecialcharacter,".", which cannot appear within anatomtoken. What about aquoted-stringtoken? Well, let's see...Based on this, we can tell that a
"."is allowed within a quoted-string, so... the correct formatting for yourdisplay-namecan be any of the following:or
or
or
Any one of those will work.