Home / Section index
 www.icosaedro.it 

 Mailer Tutorial - E-mail EBNF Syntax

Last update: 2018-09-02

This page shows the EBNF syntax of an Internet e-mail as specified in the document Internet Message Format, RFC 5322. The syntax therein described has been converted to EBNF generating the text available here and then checked and formatted using the BNF_CHK program. Among all the defined rules, you may find of particular interest the following rules:

The rule specials (no. 22) is not used here but it is cited in the specification. Rules whose name starts with obs_ are referring to obsolete specifications.

See also:

BNF_CHK EBNF syntax short guide

"abc"   is the literal string composed of the ASCII characters a,b,c in the order.

"a".."z"   means a single ASCII character ranging from a up to z.

A B C   means rules A,B,C in the order. This "product" of rules has priority over the "sum" of rules below.

A | B   means rule A or rule B. This "sum" of rules has less priority than the product above.

A ( B | C )   means rule A followed by either rule B or rule C. Then, round parenthesis can be used to override product priority over sum.

[A]   means zero or one occurrences of the rule A, that is the rule is optional.

{A}   means zero or more occurrences of the rule A.

For more about the EBNF syntax, see the BNF_CHK program page.

E-mail EBNF (RFC 5322)

1. NUL = "ASCII code zero" ;
2. HTAB = "ASCII code 9" ;
3. LF = "ASCII code 10" ;
4. CR = "ASCII code 13" ;
5. CRLF = CR4 LF3 ;
6. SP = "ASCII code 32" ;
7. WSP = SP6 | HTAB2 ;
8. ALPHA = "A".."Z" | "a".."z" ;
9. DIGIT = "0".."9" ;
10. DQUOTE = "\"" ;
11. VCHAR = "!".."~" ;
12. quoted_pair = "\\" ( VCHAR11 | WSP7 ) | obs_qp96 ;
13. FWS = [ { WSP7 } CRLF5 ] WSP7 { WSP7 } | obs_FWS101 ;
14. ctext = "!".."'" | "*".."[" | "]".."~" | obs_ctext93 ;
15. ccontent = ctext14 | quoted_pair12 | comment16 ;
16. comment = "(" { [ FWS13 ] ccontent15 } [ FWS13 ] ")" ;
17. CFWS = [ FWS13 ] comment16 { [ FWS13 ] comment16 } [ FWS13 ] | FWS13 ;
18. atext = ALPHA8 | DIGIT9 | "!" | "#" | "$" | "%" | "&" | "'" | "*" | "+" | "-" | "/" | "=" | "?" | "^" | "_" | "`" | "{" | "|" | "}" | "~" ;
19. atom = [ CFWS17 ] atext18 { atext18 } [ CFWS17 ] ;
20. dot_atom_text = atext18 { atext18 } { "." atext18 { atext18 } } ;
21. dot_atom = [ CFWS17 ] dot_atom_text20 [ CFWS17 ] ;
22. specials = "(" | ")" | "<" | ">" | "[" | "]" | ":" | ";" | "@" | "\\" | "," | "." | DQUOTE10 ;
23. qtext = "!" | "#".."[" | "]".."~" | obs_qtext94 ;
24. qcontent = qtext23 | quoted_pair12 ;
25. quoted_string = [ CFWS17 ] DQUOTE10 { [ FWS13 ] qcontent24 } [ FWS13 ] DQUOTE10 [ CFWS17 ] ;
26. word = atom19 | quoted_string25 ;
27. phrase = word26 { word26 } | obs_phrase99 ;
28. unstructured = { [ FWS13 ] VCHAR11 } { WSP7 } | obs_unstruct98 ;
29. date_time = [ day_of_week30 "," ] date32 time36 [ CFWS17 ] ;
30. day_of_week = [ FWS13 ] day_name31 | obs_day_of_week102 ;
31. day_name = "Mon" | "Tue" | "Wed" | "Thu" | "Fri" | "Sat" | "Sun" ;
32. date = day33 month34 year35 ;
33. day = [ FWS13 ] DIGIT9 [ DIGIT9 ] FWS13 | obs_day103 ;
34. month = "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec" ;
35. year = FWS13 DIGIT9 DIGIT9 DIGIT9 DIGIT9 FWS13 | obs_year104 ;
36. time = time_of_day37 zone41 ;
37. time_of_day = hour38 ":" minute39 [ ":" second40 ] ;
38. hour = DIGIT9 DIGIT9 | obs_hour105 ;
39. minute = DIGIT9 DIGIT9 | obs_minute106 ;
40. second = DIGIT9 DIGIT9 | obs_second107 ;
41. zone = FWS13 ( "+" | "-" ) DIGIT9 DIGIT9 DIGIT9 DIGIT9 | obs_zone108 ;
42. address = mailbox43 | group46 ;
43. mailbox = name_addr44 | addr_spec51 ;
44. name_addr = [ display_name47 ] angle_addr45 ;
45. angle_addr = [ CFWS17 ] "<" addr_spec51 ">" [ CFWS17 ] | obs_angle_addr109 ;
46. group = display_name47 ":" [ group_list50 ] ";" [ CFWS17 ] ;
47. display_name = phrase27 ;
48. mailbox_list = mailbox43 { "," mailbox43 } | obs_mbox_list112 ;
49. address_list = address42 { "," address42 } | obs_addr_list113 ;
50. group_list = mailbox_list48 | CFWS17 | obs_group_list114 ;
51. addr_spec = local_part52 "@" domain53 ;
52. local_part = dot_atom21 | quoted_string25 | obs_local_part115 ;
53. domain = dot_atom21 | domain_literal54 | obs_domain116 ;
54. domain_literal = [ CFWS17 ] "[" { [ FWS13 ] dtext55 } [ FWS13 ] "]" [ CFWS17 ] ;
55. dtext = "!".."Z" | "^".."~" | obs_dtext117 ;
56. message = ( fields59 | obs_fields118 ) [ CRLF5 body57 ] ;
57. body = { { text58 } CRLF5 } { text58 } | obs_body97 ;
58. text = "ASCII codes: 1-9, 11, 12, 14-127" ;
59. fields = { trace84 { optional_field89 } | { resent_date77 | resent_from78 | resent_sender79 | resent_to80 | resent_cc81 | resent_bcc82 | resent_msg_id83 } } { orig_date60 | from61 | sender62 | reply_to63 | to64 | cc65 | bcc66 | message_id67 | in_reply_to68 | references69 | subject74 | comments75 | keywords76 | optional_field89 } ;
60. orig_date = "Date:" date_time29 CRLF5 ;
61. from = "From:" mailbox_list48 CRLF5 ;
62. sender = "Sender:" mailbox43 CRLF5 ;
63. reply_to = "Reply_To:" address_list49 CRLF5 ;
64. to = "To:" address_list49 CRLF5 ;
65. cc = "Cc:" address_list49 CRLF5 ;
66. bcc = "Bcc:" [ address_list49 | CFWS17 ] CRLF5 ;
67. message_id = "Message_ID:" msg_id70 CRLF5 ;
68. in_reply_to = "In_Reply_To:" msg_id70 { msg_id70 } CRLF5 ;
69. references = "References:" msg_id70 { msg_id70 } CRLF5 ;
70. msg_id = [ CFWS17 ] "<" id_left71 "@" id_right72 ">" [ CFWS17 ] ;
71. id_left = dot_atom_text20 | obs_id_left129 ;
72. id_right = dot_atom_text20 | no_fold_literal73 | obs_id_right130 ;
73. no_fold_literal = "[" { dtext55 } "]" ;
74. subject = "Subject:" unstructured28 CRLF5 ;
75. comments = "Comments:" unstructured28 CRLF5 ;
76. keywords = "Keywords:" phrase27 { "," phrase27 } CRLF5 ;
77. resent_date = "Resent_Date:" date_time29 CRLF5 ;
78. resent_from = "Resent_From:" mailbox_list48 CRLF5 ;
79. resent_sender = "Resent_Sender:" mailbox43 CRLF5 ;
80. resent_to = "Resent_To:" address_list49 CRLF5 ;
81. resent_cc = "Resent_Cc:" address_list49 CRLF5 ;
82. resent_bcc = "Resent_Bcc:" [ address_list49 | CFWS17 ] CRLF5 ;
83. resent_msg_id = "Resent_Message_ID:" msg_id70 CRLF5 ;
84. trace = [ return85 ] received87 { received87 } ;
85. return = "Return_Path:" path86 CRLF5 ;
86. path = angle_addr45 | [ CFWS17 ] "<" [ CFWS17 ] ">" [ CFWS17 ] ;
87. received = "Received:" { received_token88 } ";" date_time29 CRLF5 ;
88. received_token = word26 | angle_addr45 | addr_spec51 | domain53 ;
89. optional_field = field_name90 ":" unstructured28 CRLF5 ;
90. field_name = ftext91 { ftext91 } ;
91. ftext = "!".."9" | ";".."~" ;
92. obs_NO_WS_CTL = "ASCII codes 1-8, 11, 12, 14-31, 127" ;
93. obs_ctext = obs_NO_WS_CTL92 ;
94. obs_qtext = obs_NO_WS_CTL92 ;
95. obs_utext = NUL1 | obs_NO_WS_CTL92 | VCHAR11 ;
96. obs_qp = "\\" ( NUL1 | obs_NO_WS_CTL92 | LF3 | CR4 ) ;
97. obs_body = { { LF3 } { CR4 } { ( NUL1 | text58 ) { LF3 } { CR4 } } | CRLF5 } ;
98. obs_unstruct = { { LF3 } { CR4 } { obs_utext95 { LF3 } { CR4 } } | FWS13 } ;
99. obs_phrase = word26 { word26 | "." | CFWS17 } ;
100. obs_phrase_list = [ phrase27 | CFWS17 ] { "," [ phrase27 | CFWS17 ] } ;
101. obs_FWS = WSP7 { WSP7 } { CRLF5 WSP7 { WSP7 } } ;
102. obs_day_of_week = [ CFWS17 ] day_name31 [ CFWS17 ] ;
103. obs_day = [ CFWS17 ] DIGIT9 [ DIGIT9 ] [ CFWS17 ] ;
104. obs_year = [ CFWS17 ] DIGIT9 DIGIT9 { DIGIT9 } [ CFWS17 ] ;
105. obs_hour = [ CFWS17 ] DIGIT9 DIGIT9 [ CFWS17 ] ;
106. obs_minute = [ CFWS17 ] DIGIT9 DIGIT9 [ CFWS17 ] ;
107. obs_second = [ CFWS17 ] DIGIT9 DIGIT9 [ CFWS17 ] ;
108. obs_zone = "UT" | "GMT" | "EST" | "EDT" | "CST" | "CDT" | "MST" | "MDT" | "PST" | "PDT" | "A".."I" | "K".."Z" | "a".."i" | "k".."z" ;
109. obs_angle_addr = [ CFWS17 ] "<" obs_route110 addr_spec51 ">" [ CFWS17 ] ;
110. obs_route = obs_domain_list111 ":" ;
111. obs_domain_list = { CFWS17 | "," } "@" domain53 { "," [ CFWS17 ] [ "@" domain53 ] } ;
112. obs_mbox_list = { [ CFWS17 ] "," } mailbox43 { "," [ mailbox43 | CFWS17 ] } ;
113. obs_addr_list = { [ CFWS17 ] "," } address42 { "," [ address42 | CFWS17 ] } ;
114. obs_group_list = [ CFWS17 ] "," { [ CFWS17 ] "," } [ CFWS17 ] ;
115. obs_local_part = word26 { "." word26 } ;
116. obs_domain = atom19 { "." atom19 } ;
117. obs_dtext = obs_NO_WS_CTL92 | quoted_pair12 ;
118. obs_fields = { obs_return142 | obs_received143 | obs_orig_date119 | obs_from120 | obs_sender121 | obs_reply_to122 | obs_to123 | obs_cc124 | obs_bcc125 | obs_message_id126 | obs_in_reply_to127 | obs_references128 | obs_subject131 | obs_comments132 | obs_keywords133 | obs_resent_date136 | obs_resent_from134 | obs_resent_send135 | obs_resent_rply141 | obs_resent_to137 | obs_resent_cc138 | obs_resent_bcc139 | obs_resent_mid140 | obs_optional144 } ;
119. obs_orig_date = "Date" { WSP7 } ":" date_time29 CRLF5 ;
120. obs_from = "From" { WSP7 } ":" mailbox_list48 CRLF5 ;
121. obs_sender = "Sender" { WSP7 } ":" mailbox43 CRLF5 ;
122. obs_reply_to = "Reply_To" { WSP7 } ":" address_list49 CRLF5 ;
123. obs_to = "To" { WSP7 } ":" address_list49 CRLF5 ;
124. obs_cc = "Cc" { WSP7 } ":" address_list49 CRLF5 ;
125. obs_bcc = "Bcc" { WSP7 } ":" ( address_list49 | { [ CFWS17 ] "," } [ CFWS17 ] ) CRLF5 ;
126. obs_message_id = "Message_ID" { WSP7 } ":" msg_id70 CRLF5 ;
127. obs_in_reply_to = "In_Reply_To" { WSP7 } ":" { phrase27 | msg_id70 } CRLF5 ;
128. obs_references = "References" { WSP7 } ":" { phrase27 | msg_id70 } CRLF5 ;
129. obs_id_left = local_part52 ;
130. obs_id_right = domain53 ;
131. obs_subject = "Subject" { WSP7 } ":" unstructured28 CRLF5 ;
132. obs_comments = "Comments" { WSP7 } ":" unstructured28 CRLF5 ;
133. obs_keywords = "Keywords" { WSP7 } ":" obs_phrase_list100 CRLF5 ;
134. obs_resent_from = "Resent_From" { WSP7 } ":" mailbox_list48 CRLF5 ;
135. obs_resent_send = "Resent_Sender" { WSP7 } ":" mailbox43 CRLF5 ;
136. obs_resent_date = "Resent_Date" { WSP7 } ":" date_time29 CRLF5 ;
137. obs_resent_to = "Resent_To" { WSP7 } ":" address_list49 CRLF5 ;
138. obs_resent_cc = "Resent_Cc" { WSP7 } ":" address_list49 CRLF5 ;
139. obs_resent_bcc = "Resent_Bcc" { WSP7 } ":" ( address_list49 | { [ CFWS17 ] "," } [ CFWS17 ] ) CRLF5 ;
140. obs_resent_mid = "Resent_Message_ID" { WSP7 } ":" msg_id70 CRLF5 ;
141. obs_resent_rply = "Resent_Reply_To" { WSP7 } ":" address_list49 CRLF5 ;
142. obs_return = "Return_Path" { WSP7 } ":" path86 CRLF5 ;
143. obs_received = "Received" { WSP7 } ":" { received_token88 } CRLF5 ;
144. obs_optional = field_name90 { WSP7 } ":" unstructured28 CRLF5 ;

Umberto Salsi
Comments
Contact
Site map
Home / Section index
Still no comments to this page. Use the Comments link above to add your contribute.