Check / Display Name Format from Title

I need to know what are the rules for checking / format from the field ( name-addr ) in the letter. Rfc explains the name-addr format, but goes into detail about display-name .

Like this:

 From: John Q. Public < JQP@bar.com > 

I want to know the characters and length. How do I know that John Q. Public has valid characters? Should I only allow printable US-ASCII characters?

I turned to RFC 2822 and did not find the display name in the specific format

+7
rfc smtp rfc2822
source share
1 answer

This is all defined in rfc that you contacted in your question (by the way, a newer version of this RFC 5322 document):

 display-name = phrase phrase = 1*word / obs-phrase word = atom / quoted-string atom = [CFWS] 1*atext [CFWS] atext = ALPHA / DIGIT / ; Any character except controls, "!" / "#" / ; SP, and specials. "$" / "%" / ; Used for atoms "&" / "'" / "*" / "+" / "-" / "/" / "=" / "?" / "^" / "_" / "`" / "{" / "|" / "}" / "~" specials = "(" / ")" / ; Special characters used in "<" / ">" / ; other parts of the syntax "[" / "]" / ":" / ";" / "@" / "\" / "," / "." / DQUOTE 

You need to skip a bit in the document to find the definitions of each of these types of tokens, but they are all there.

Once you have the definitions, all you have to do is check your name string and see if it contains only valid characters.

By definition, a display-name is a phrase , a phrase is 1 or more word tectons (or obs-word , which I now ignore to simplify this explanation).

A word token can be either atom or quoted-string .

In your example, John Q. Public contains the character special , "." which cannot be displayed in the atom token. What about quoted-string token? Well, let's see ...

 quoted-string = [CFWS] DQUOTE *([FWS] qcontent) [FWS] DQUOTE [CFWS] qcontent = qtext / quoted-pair qtext = NO-WS-CTL / ; Non white space controls %d33 / ; The rest of the US-ASCII %d35-91 / ; characters not including "\" %d93-126 ; or the quote character 

Based on this, we can say that a "." Is allowed in the quotation mark string "." , therefore ... the correct formatting for your display-name can be any of the following:

 From: "John Q. Public" < JQB@bar.com > 

or

 From: John "Q." Public < JQB@bar.com > 

or

 From: "John Q." Public < JQB@bar.com > 

or

 From: John "Q. Public" < JQB@bar.com > 

Any of them will work.

+16
source share

All Articles