rfc2045.txt 71KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740
  1. Network Working Group N. Freed
  2. Request for Comments: 2045 Innosoft
  3. Obsoletes: 1521, 1522, 1590 N. Borenstein
  4. Category: Standards Track First Virtual
  5. November 1996
  6. Multipurpose Internet Mail Extensions
  7. (MIME) Part One:
  8. Format of Internet Message Bodies
  9. Status of this Memo
  10. This document specifies an Internet standards track protocol for the
  11. Internet community, and requests discussion and suggestions for
  12. improvements. Please refer to the current edition of the "Internet
  13. Official Protocol Standards" (STD 1) for the standardization state
  14. and status of this protocol. Distribution of this memo is unlimited.
  15. Abstract
  16. STD 11, RFC 822, defines a message representation protocol specifying
  17. considerable detail about US-ASCII message headers, and leaves the
  18. message content, or message body, as flat US-ASCII text. This set of
  19. documents, collectively called the Multipurpose Internet Mail
  20. Extensions, or MIME, redefines the format of messages to allow for
  21. (1) textual message bodies in character sets other than
  22. US-ASCII,
  23. (2) an extensible set of different formats for non-textual
  24. message bodies,
  25. (3) multi-part message bodies, and
  26. (4) textual header information in character sets other than
  27. US-ASCII.
  28. These documents are based on earlier work documented in RFC 934, STD
  29. 11, and RFC 1049, but extends and revises them. Because RFC 822 said
  30. so little about message bodies, these documents are largely
  31. orthogonal to (rather than a revision of) RFC 822.
  32. This initial document specifies the various headers used to describe
  33. the structure of MIME messages. The second document, RFC 2046,
  34. defines the general structure of the MIME media typing system and
  35. defines an initial set of media types. The third document, RFC 2047,
  36. describes extensions to RFC 822 to allow non-US-ASCII text data in
  37. Freed & Borenstein Standards Track [Page 1]
  38. RFC 2045 Internet Message Bodies November 1996
  39. Internet mail header fields. The fourth document, RFC 2048, specifies
  40. various IANA registration procedures for MIME-related facilities. The
  41. fifth and final document, RFC 2049, describes MIME conformance
  42. criteria as well as providing some illustrative examples of MIME
  43. message formats, acknowledgements, and the bibliography.
  44. These documents are revisions of RFCs 1521, 1522, and 1590, which
  45. themselves were revisions of RFCs 1341 and 1342. An appendix in RFC
  46. 2049 describes differences and changes from previous versions.
  47. Table of Contents
  48. 1. Introduction ......................................... 3
  49. 2. Definitions, Conventions, and Generic BNF Grammar .... 5
  50. 2.1 CRLF ................................................ 5
  51. 2.2 Character Set ....................................... 6
  52. 2.3 Message ............................................. 6
  53. 2.4 Entity .............................................. 6
  54. 2.5 Body Part ........................................... 7
  55. 2.6 Body ................................................ 7
  56. 2.7 7bit Data ........................................... 7
  57. 2.8 8bit Data ........................................... 7
  58. 2.9 Binary Data ......................................... 7
  59. 2.10 Lines .............................................. 7
  60. 3. MIME Header Fields ................................... 8
  61. 4. MIME-Version Header Field ............................ 8
  62. 5. Content-Type Header Field ............................ 10
  63. 5.1 Syntax of the Content-Type Header Field ............. 12
  64. 5.2 Content-Type Defaults ............................... 14
  65. 6. Content-Transfer-Encoding Header Field ............... 14
  66. 6.1 Content-Transfer-Encoding Syntax .................... 14
  67. 6.2 Content-Transfer-Encodings Semantics ................ 15
  68. 6.3 New Content-Transfer-Encodings ...................... 16
  69. 6.4 Interpretation and Use .............................. 16
  70. 6.5 Translating Encodings ............................... 18
  71. 6.6 Canonical Encoding Model ............................ 19
  72. 6.7 Quoted-Printable Content-Transfer-Encoding .......... 19
  73. 6.8 Base64 Content-Transfer-Encoding .................... 24
  74. 7. Content-ID Header Field .............................. 26
  75. 8. Content-Description Header Field ..................... 27
  76. 9. Additional MIME Header Fields ........................ 27
  77. 10. Summary ............................................. 27
  78. 11. Security Considerations ............................. 27
  79. 12. Authors' Addresses .................................. 28
  80. A. Collected Grammar .................................... 29
  81. Freed & Borenstein Standards Track [Page 2]
  82. RFC 2045 Internet Message Bodies November 1996
  83. 1. Introduction
  84. Since its publication in 1982, RFC 822 has defined the standard
  85. format of textual mail messages on the Internet. Its success has
  86. been such that the RFC 822 format has been adopted, wholly or
  87. partially, well beyond the confines of the Internet and the Internet
  88. SMTP transport defined by RFC 821. As the format has seen wider use,
  89. a number of limitations have proven increasingly restrictive for the
  90. user community.
  91. RFC 822 was intended to specify a format for text messages. As such,
  92. non-text messages, such as multimedia messages that might include
  93. audio or images, are simply not mentioned. Even in the case of text,
  94. however, RFC 822 is inadequate for the needs of mail users whose
  95. languages require the use of character sets richer than US-ASCII.
  96. Since RFC 822 does not specify mechanisms for mail containing audio,
  97. video, Asian language text, or even text in most European languages,
  98. additional specifications are needed.
  99. One of the notable limitations of RFC 821/822 based mail systems is
  100. the fact that they limit the contents of electronic mail messages to
  101. relatively short lines (e.g. 1000 characters or less [RFC-821]) of
  102. 7bit US-ASCII. This forces users to convert any non-textual data
  103. that they may wish to send into seven-bit bytes representable as
  104. printable US-ASCII characters before invoking a local mail UA (User
  105. Agent, a program with which human users send and receive mail).
  106. Examples of such encodings currently used in the Internet include
  107. pure hexadecimal, uuencode, the 3-in-4 base 64 scheme specified in
  108. RFC 1421, the Andrew Toolkit Representation [ATK], and many others.
  109. The limitations of RFC 822 mail become even more apparent as gateways
  110. are designed to allow for the exchange of mail messages between RFC
  111. 822 hosts and X.400 hosts. X.400 [X400] specifies mechanisms for the
  112. inclusion of non-textual material within electronic mail messages.
  113. The current standards for the mapping of X.400 messages to RFC 822
  114. messages specify either that X.400 non-textual material must be
  115. converted to (not encoded in) IA5Text format, or that they must be
  116. discarded, notifying the RFC 822 user that discarding has occurred.
  117. This is clearly undesirable, as information that a user may wish to
  118. receive is lost. Even though a user agent may not have the
  119. capability of dealing with the non-textual material, the user might
  120. have some mechanism external to the UA that can extract useful
  121. information from the material. Moreover, it does not allow for the
  122. fact that the message may eventually be gatewayed back into an X.400
  123. message handling system (i.e., the X.400 message is "tunneled"
  124. through Internet mail), where the non-textual information would
  125. definitely become useful again.
  126. Freed & Borenstein Standards Track [Page 3]
  127. RFC 2045 Internet Message Bodies November 1996
  128. This document describes several mechanisms that combine to solve most
  129. of these problems without introducing any serious incompatibilities
  130. with the existing world of RFC 822 mail. In particular, it
  131. describes:
  132. (1) A MIME-Version header field, which uses a version
  133. number to declare a message to be conformant with MIME
  134. and allows mail processing agents to distinguish
  135. between such messages and those generated by older or
  136. non-conformant software, which are presumed to lack
  137. such a field.
  138. (2) A Content-Type header field, generalized from RFC 1049,
  139. which can be used to specify the media type and subtype
  140. of data in the body of a message and to fully specify
  141. the native representation (canonical form) of such
  142. data.
  143. (3) A Content-Transfer-Encoding header field, which can be
  144. used to specify both the encoding transformation that
  145. was applied to the body and the domain of the result.
  146. Encoding transformations other than the identity
  147. transformation are usually applied to data in order to
  148. allow it to pass through mail transport mechanisms
  149. which may have data or character set limitations.
  150. (4) Two additional header fields that can be used to
  151. further describe the data in a body, the Content-ID and
  152. Content-Description header fields.
  153. All of the header fields defined in this document are subject to the
  154. general syntactic rules for header fields specified in RFC 822. In
  155. particular, all of these header fields except for Content-Disposition
  156. can include RFC 822 comments, which have no semantic content and
  157. should be ignored during MIME processing.
  158. Finally, to specify and promote interoperability, RFC 2049 provides a
  159. basic applicability statement for a subset of the above mechanisms
  160. that defines a minimal level of "conformance" with this document.
  161. HISTORICAL NOTE: Several of the mechanisms described in this set of
  162. documents may seem somewhat strange or even baroque at first reading.
  163. It is important to note that compatibility with existing standards
  164. AND robustness across existing practice were two of the highest
  165. priorities of the working group that developed this set of documents.
  166. In particular, compatibility was always favored over elegance.
  167. Freed & Borenstein Standards Track [Page 4]
  168. RFC 2045 Internet Message Bodies November 1996
  169. Please refer to the current edition of the "Internet Official
  170. Protocol Standards" for the standardization state and status of this
  171. protocol. RFC 822 and STD 3, RFC 1123 also provide essential
  172. background for MIME since no conforming implementation of MIME can
  173. violate them. In addition, several other informational RFC documents
  174. will be of interest to the MIME implementor, in particular RFC 1344,
  175. RFC 1345, and RFC 1524.
  176. 2. Definitions, Conventions, and Generic BNF Grammar
  177. Although the mechanisms specified in this set of documents are all
  178. described in prose, most are also described formally in the augmented
  179. BNF notation of RFC 822. Implementors will need to be familiar with
  180. this notation in order to understand this set of documents, and are
  181. referred to RFC 822 for a complete explanation of the augmented BNF
  182. notation.
  183. Some of the augmented BNF in this set of documents makes named
  184. references to syntax rules defined in RFC 822. A complete formal
  185. grammar, then, is obtained by combining the collected grammar
  186. appendices in each document in this set with the BNF of RFC 822 plus
  187. the modifications to RFC 822 defined in RFC 1123 (which specifically
  188. changes the syntax for `return', `date' and `mailbox').
  189. All numeric and octet values are given in decimal notation in this
  190. set of documents. All media type values, subtype values, and
  191. parameter names as defined are case-insensitive. However, parameter
  192. values are case-sensitive unless otherwise specified for the specific
  193. parameter.
  194. FORMATTING NOTE: Notes, such at this one, provide additional
  195. nonessential information which may be skipped by the reader without
  196. missing anything essential. The primary purpose of these non-
  197. essential notes is to convey information about the rationale of this
  198. set of documents, or to place these documents in the proper
  199. historical or evolutionary context. Such information may in
  200. particular be skipped by those who are focused entirely on building a
  201. conformant implementation, but may be of use to those who wish to
  202. understand why certain design choices were made.
  203. 2.1. CRLF
  204. The term CRLF, in this set of documents, refers to the sequence of
  205. octets corresponding to the two US-ASCII characters CR (decimal value
  206. 13) and LF (decimal value 10) which, taken together, in this order,
  207. denote a line break in RFC 822 mail.
  208. Freed & Borenstein Standards Track [Page 5]
  209. RFC 2045 Internet Message Bodies November 1996
  210. 2.2. Character Set
  211. The term "character set" is used in MIME to refer to a method of
  212. converting a sequence of octets into a sequence of characters. Note
  213. that unconditional and unambiguous conversion in the other direction
  214. is not required, in that not all characters may be representable by a
  215. given character set and a character set may provide more than one
  216. sequence of octets to represent a particular sequence of characters.
  217. This definition is intended to allow various kinds of character
  218. encodings, from simple single-table mappings such as US-ASCII to
  219. complex table switching methods such as those that use ISO 2022's
  220. techniques, to be used as character sets. However, the definition
  221. associated with a MIME character set name must fully specify the
  222. mapping to be performed. In particular, use of external profiling
  223. information to determine the exact mapping is not permitted.
  224. NOTE: The term "character set" was originally to describe such
  225. straightforward schemes as US-ASCII and ISO-8859-1 which have a
  226. simple one-to-one mapping from single octets to single characters.
  227. Multi-octet coded character sets and switching techniques make the
  228. situation more complex. For example, some communities use the term
  229. "character encoding" for what MIME calls a "character set", while
  230. using the phrase "coded character set" to denote an abstract mapping
  231. from integers (not octets) to characters.
  232. 2.3. Message
  233. The term "message", when not further qualified, means either a
  234. (complete or "top-level") RFC 822 message being transferred on a
  235. network, or a message encapsulated in a body of type "message/rfc822"
  236. or "message/partial".
  237. 2.4. Entity
  238. The term "entity", refers specifically to the MIME-defined header
  239. fields and contents of either a message or one of the parts in the
  240. body of a multipart entity. The specification of such entities is
  241. the essence of MIME. Since the contents of an entity are often
  242. called the "body", it makes sense to speak about the body of an
  243. entity. Any sort of field may be present in the header of an entity,
  244. but only those fields whose names begin with "content-" actually have
  245. any MIME-related meaning. Note that this does NOT imply thay they
  246. have no meaning at all -- an entity that is also a message has non-
  247. MIME header fields whose meanings are defined by RFC 822.
  248. Freed & Borenstein Standards Track [Page 6]
  249. RFC 2045 Internet Message Bodies November 1996
  250. 2.5. Body Part
  251. The term "body part" refers to an entity inside of a multipart
  252. entity.
  253. 2.6. Body
  254. The term "body", when not further qualified, means the body of an
  255. entity, that is, the body of either a message or of a body part.
  256. NOTE: The previous four definitions are clearly circular. This is
  257. unavoidable, since the overall structure of a MIME message is indeed
  258. recursive.
  259. 2.7. 7bit Data
  260. "7bit data" refers to data that is all represented as relatively
  261. short lines with 998 octets or less between CRLF line separation
  262. sequences [RFC-821]. No octets with decimal values greater than 127
  263. are allowed and neither are NULs (octets with decimal value 0). CR
  264. (decimal value 13) and LF (decimal value 10) octets only occur as
  265. part of CRLF line separation sequences.
  266. 2.8. 8bit Data
  267. "8bit data" refers to data that is all represented as relatively
  268. short lines with 998 octets or less between CRLF line separation
  269. sequences [RFC-821]), but octets with decimal values greater than 127
  270. may be used. As with "7bit data" CR and LF octets only occur as part
  271. of CRLF line separation sequences and no NULs are allowed.
  272. 2.9. Binary Data
  273. "Binary data" refers to data where any sequence of octets whatsoever
  274. is allowed.
  275. 2.10. Lines
  276. "Lines" are defined as sequences of octets separated by a CRLF
  277. sequences. This is consistent with both RFC 821 and RFC 822.
  278. "Lines" only refers to a unit of data in a message, which may or may
  279. not correspond to something that is actually displayed by a user
  280. agent.
  281. Freed & Borenstein Standards Track [Page 7]
  282. RFC 2045 Internet Message Bodies November 1996
  283. 3. MIME Header Fields
  284. MIME defines a number of new RFC 822 header fields that are used to
  285. describe the content of a MIME entity. These header fields occur in
  286. at least two contexts:
  287. (1) As part of a regular RFC 822 message header.
  288. (2) In a MIME body part header within a multipart
  289. construct.
  290. The formal definition of these header fields is as follows:
  291. entity-headers := [ content CRLF ]
  292. [ encoding CRLF ]
  293. [ id CRLF ]
  294. [ description CRLF ]
  295. *( MIME-extension-field CRLF )
  296. MIME-message-headers := entity-headers
  297. fields
  298. version CRLF
  299. ; The ordering of the header
  300. ; fields implied by this BNF
  301. ; definition should be ignored.
  302. MIME-part-headers := entity-headers
  303. [ fields ]
  304. ; Any field not beginning with
  305. ; "content-" can have no defined
  306. ; meaning and may be ignored.
  307. ; The ordering of the header
  308. ; fields implied by this BNF
  309. ; definition should be ignored.
  310. The syntax of the various specific MIME header fields will be
  311. described in the following sections.
  312. 4. MIME-Version Header Field
  313. Since RFC 822 was published in 1982, there has really been only one
  314. format standard for Internet messages, and there has been little
  315. perceived need to declare the format standard in use. This document
  316. is an independent specification that complements RFC 822. Although
  317. the extensions in this document have been defined in such a way as to
  318. be compatible with RFC 822, there are still circumstances in which it
  319. might be desirable for a mail-processing agent to know whether a
  320. message was composed with the new standard in mind.
  321. Freed & Borenstein Standards Track [Page 8]
  322. RFC 2045 Internet Message Bodies November 1996
  323. Therefore, this document defines a new header field, "MIME-Version",
  324. which is to be used to declare the version of the Internet message
  325. body format standard in use.
  326. Messages composed in accordance with this document MUST include such
  327. a header field, with the following verbatim text:
  328. MIME-Version: 1.0
  329. The presence of this header field is an assertion that the message
  330. has been composed in compliance with this document.
  331. Since it is possible that a future document might extend the message
  332. format standard again, a formal BNF is given for the content of the
  333. MIME-Version field:
  334. version := "MIME-Version" ":" 1*DIGIT "." 1*DIGIT
  335. Thus, future format specifiers, which might replace or extend "1.0",
  336. are constrained to be two integer fields, separated by a period. If
  337. a message is received with a MIME-version value other than "1.0", it
  338. cannot be assumed to conform with this document.
  339. Note that the MIME-Version header field is required at the top level
  340. of a message. It is not required for each body part of a multipart
  341. entity. It is required for the embedded headers of a body of type
  342. "message/rfc822" or "message/partial" if and only if the embedded
  343. message is itself claimed to be MIME-conformant.
  344. It is not possible to fully specify how a mail reader that conforms
  345. with MIME as defined in this document should treat a message that
  346. might arrive in the future with some value of MIME-Version other than
  347. "1.0".
  348. It is also worth noting that version control for specific media types
  349. is not accomplished using the MIME-Version mechanism. In particular,
  350. some formats (such as application/postscript) have version numbering
  351. conventions that are internal to the media format. Where such
  352. conventions exist, MIME does nothing to supersede them. Where no
  353. such conventions exist, a MIME media type might use a "version"
  354. parameter in the content-type field if necessary.
  355. Freed & Borenstein Standards Track [Page 9]
  356. RFC 2045 Internet Message Bodies November 1996
  357. NOTE TO IMPLEMENTORS: When checking MIME-Version values any RFC 822
  358. comment strings that are present must be ignored. In particular, the
  359. following four MIME-Version fields are equivalent:
  360. MIME-Version: 1.0
  361. MIME-Version: 1.0 (produced by MetaSend Vx.x)
  362. MIME-Version: (produced by MetaSend Vx.x) 1.0
  363. MIME-Version: 1.(produced by MetaSend Vx.x)0
  364. In the absence of a MIME-Version field, a receiving mail user agent
  365. (whether conforming to MIME requirements or not) may optionally
  366. choose to interpret the body of the message according to local
  367. conventions. Many such conventions are currently in use and it
  368. should be noted that in practice non-MIME messages can contain just
  369. about anything.
  370. It is impossible to be certain that a non-MIME mail message is
  371. actually plain text in the US-ASCII character set since it might well
  372. be a message that, using some set of nonstandard local conventions
  373. that predate MIME, includes text in another character set or non-
  374. textual data presented in a manner that cannot be automatically
  375. recognized (e.g., a uuencoded compressed UNIX tar file).
  376. 5. Content-Type Header Field
  377. The purpose of the Content-Type field is to describe the data
  378. contained in the body fully enough that the receiving user agent can
  379. pick an appropriate agent or mechanism to present the data to the
  380. user, or otherwise deal with the data in an appropriate manner. The
  381. value in this field is called a media type.
  382. HISTORICAL NOTE: The Content-Type header field was first defined in
  383. RFC 1049. RFC 1049 used a simpler and less powerful syntax, but one
  384. that is largely compatible with the mechanism given here.
  385. The Content-Type header field specifies the nature of the data in the
  386. body of an entity by giving media type and subtype identifiers, and
  387. by providing auxiliary information that may be required for certain
  388. media types. After the media type and subtype names, the remainder
  389. of the header field is simply a set of parameters, specified in an
  390. attribute=value notation. The ordering of parameters is not
  391. significant.
  392. Freed & Borenstein Standards Track [Page 10]
  393. RFC 2045 Internet Message Bodies November 1996
  394. In general, the top-level media type is used to declare the general
  395. type of data, while the subtype specifies a specific format for that
  396. type of data. Thus, a media type of "image/xyz" is enough to tell a
  397. user agent that the data is an image, even if the user agent has no
  398. knowledge of the specific image format "xyz". Such information can
  399. be used, for example, to decide whether or not to show a user the raw
  400. data from an unrecognized subtype -- such an action might be
  401. reasonable for unrecognized subtypes of text, but not for
  402. unrecognized subtypes of image or audio. For this reason, registered
  403. subtypes of text, image, audio, and video should not contain embedded
  404. information that is really of a different type. Such compound
  405. formats should be represented using the "multipart" or "application"
  406. types.
  407. Parameters are modifiers of the media subtype, and as such do not
  408. fundamentally affect the nature of the content. The set of
  409. meaningful parameters depends on the media type and subtype. Most
  410. parameters are associated with a single specific subtype. However, a
  411. given top-level media type may define parameters which are applicable
  412. to any subtype of that type. Parameters may be required by their
  413. defining content type or subtype or they may be optional. MIME
  414. implementations must ignore any parameters whose names they do not
  415. recognize.
  416. For example, the "charset" parameter is applicable to any subtype of
  417. "text", while the "boundary" parameter is required for any subtype of
  418. the "multipart" media type.
  419. There are NO globally-meaningful parameters that apply to all media
  420. types. Truly global mechanisms are best addressed, in the MIME
  421. model, by the definition of additional Content-* header fields.
  422. An initial set of seven top-level media types is defined in RFC 2046.
  423. Five of these are discrete types whose content is essentially opaque
  424. as far as MIME processing is concerned. The remaining two are
  425. composite types whose contents require additional handling by MIME
  426. processors.
  427. This set of top-level media types is intended to be substantially
  428. complete. It is expected that additions to the larger set of
  429. supported types can generally be accomplished by the creation of new
  430. subtypes of these initial types. In the future, more top-level types
  431. may be defined only by a standards-track extension to this standard.
  432. If another top-level type is to be used for any reason, it must be
  433. given a name starting with "X-" to indicate its non-standard status
  434. and to avoid a potential conflict with a future official name.
  435. Freed & Borenstein Standards Track [Page 11]
  436. RFC 2045 Internet Message Bodies November 1996
  437. 5.1. Syntax of the Content-Type Header Field
  438. In the Augmented BNF notation of RFC 822, a Content-Type header field
  439. value is defined as follows:
  440. content := "Content-Type" ":" type "/" subtype
  441. *(";" parameter)
  442. ; Matching of media type and subtype
  443. ; is ALWAYS case-insensitive.
  444. type := discrete-type / composite-type
  445. discrete-type := "text" / "image" / "audio" / "video" /
  446. "application" / extension-token
  447. composite-type := "message" / "multipart" / extension-token
  448. extension-token := ietf-token / x-token
  449. ietf-token := <An extension token defined by a
  450. standards-track RFC and registered
  451. with IANA.>
  452. x-token := <The two characters "X-" or "x-" followed, with
  453. no intervening white space, by any token>
  454. subtype := extension-token / iana-token
  455. iana-token := <A publicly-defined extension token. Tokens
  456. of this form must be registered with IANA
  457. as specified in RFC 2048.>
  458. parameter := attribute "=" value
  459. attribute := token
  460. ; Matching of attributes
  461. ; is ALWAYS case-insensitive.
  462. value := token / quoted-string
  463. token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
  464. or tspecials>
  465. tspecials := "(" / ")" / "<" / ">" / "@" /
  466. "," / ";" / ":" / "\" / <">
  467. "/" / "[" / "]" / "?" / "="
  468. ; Must be in quoted-string,
  469. ; to use within parameter values
  470. Freed & Borenstein Standards Track [Page 12]
  471. RFC 2045 Internet Message Bodies November 1996
  472. Note that the definition of "tspecials" is the same as the RFC 822
  473. definition of "specials" with the addition of the three characters
  474. "/", "?", and "=", and the removal of ".".
  475. Note also that a subtype specification is MANDATORY -- it may not be
  476. omitted from a Content-Type header field. As such, there are no
  477. default subtypes.
  478. The type, subtype, and parameter names are not case sensitive. For
  479. example, TEXT, Text, and TeXt are all equivalent top-level media
  480. types. Parameter values are normally case sensitive, but sometimes
  481. are interpreted in a case-insensitive fashion, depending on the
  482. intended use. (For example, multipart boundaries are case-sensitive,
  483. but the "access-type" parameter for message/External-body is not
  484. case-sensitive.)
  485. Note that the value of a quoted string parameter does not include the
  486. quotes. That is, the quotation marks in a quoted-string are not a
  487. part of the value of the parameter, but are merely used to delimit
  488. that parameter value. In addition, comments are allowed in
  489. accordance with RFC 822 rules for structured header fields. Thus the
  490. following two forms
  491. Content-type: text/plain; charset=us-ascii (Plain text)
  492. Content-type: text/plain; charset="us-ascii"
  493. are completely equivalent.
  494. Beyond this syntax, the only syntactic constraint on the definition
  495. of subtype names is the desire that their uses must not conflict.
  496. That is, it would be undesirable to have two different communities
  497. using "Content-Type: application/foobar" to mean two different
  498. things. The process of defining new media subtypes, then, is not
  499. intended to be a mechanism for imposing restrictions, but simply a
  500. mechanism for publicizing their definition and usage. There are,
  501. therefore, two acceptable mechanisms for defining new media subtypes:
  502. (1) Private values (starting with "X-") may be defined
  503. bilaterally between two cooperating agents without
  504. outside registration or standardization. Such values
  505. cannot be registered or standardized.
  506. (2) New standard values should be registered with IANA as
  507. described in RFC 2048.
  508. The second document in this set, RFC 2046, defines the initial set of
  509. media types for MIME.
  510. Freed & Borenstein Standards Track [Page 13]
  511. RFC 2045 Internet Message Bodies November 1996
  512. 5.2. Content-Type Defaults
  513. Default RFC 822 messages without a MIME Content-Type header are taken
  514. by this protocol to be plain text in the US-ASCII character set,
  515. which can be explicitly specified as:
  516. Content-type: text/plain; charset=us-ascii
  517. This default is assumed if no Content-Type header field is specified.
  518. It is also recommend that this default be assumed when a
  519. syntactically invalid Content-Type header field is encountered. In
  520. the presence of a MIME-Version header field and the absence of any
  521. Content-Type header field, a receiving User Agent can also assume
  522. that plain US-ASCII text was the sender's intent. Plain US-ASCII
  523. text may still be assumed in the absence of a MIME-Version or the
  524. presence of an syntactically invalid Content-Type header field, but
  525. the sender's intent might have been otherwise.
  526. 6. Content-Transfer-Encoding Header Field
  527. Many media types which could be usefully transported via email are
  528. represented, in their "natural" format, as 8bit character or binary
  529. data. Such data cannot be transmitted over some transfer protocols.
  530. For example, RFC 821 (SMTP) restricts mail messages to 7bit US-ASCII
  531. data with lines no longer than 1000 characters including any trailing
  532. CRLF line separator.
  533. It is necessary, therefore, to define a standard mechanism for
  534. encoding such data into a 7bit short line format. Proper labelling
  535. of unencoded material in less restrictive formats for direct use over
  536. less restrictive transports is also desireable. This document
  537. specifies that such encodings will be indicated by a new "Content-
  538. Transfer-Encoding" header field. This field has not been defined by
  539. any previous standard.
  540. 6.1. Content-Transfer-Encoding Syntax
  541. The Content-Transfer-Encoding field's value is a single token
  542. specifying the type of encoding, as enumerated below. Formally:
  543. encoding := "Content-Transfer-Encoding" ":" mechanism
  544. mechanism := "7bit" / "8bit" / "binary" /
  545. "quoted-printable" / "base64" /
  546. ietf-token / x-token
  547. These values are not case sensitive -- Base64 and BASE64 and bAsE64
  548. are all equivalent. An encoding type of 7BIT requires that the body
  549. Freed & Borenstein Standards Track [Page 14]
  550. RFC 2045 Internet Message Bodies November 1996
  551. is already in a 7bit mail-ready representation. This is the default
  552. value -- that is, "Content-Transfer-Encoding: 7BIT" is assumed if the
  553. Content-Transfer-Encoding header field is not present.
  554. 6.2. Content-Transfer-Encodings Semantics
  555. This single Content-Transfer-Encoding token actually provides two
  556. pieces of information. It specifies what sort of encoding
  557. transformation the body was subjected to and hence what decoding
  558. operation must be used to restore it to its original form, and it
  559. specifies what the domain of the result is.
  560. The transformation part of any Content-Transfer-Encodings specifies,
  561. either explicitly or implicitly, a single, well-defined decoding
  562. algorithm, which for any sequence of encoded octets either transforms
  563. it to the original sequence of octets which was encoded, or shows
  564. that it is illegal as an encoded sequence. Content-Transfer-
  565. Encodings transformations never depend on any additional external
  566. profile information for proper operation. Note that while decoders
  567. must produce a single, well-defined output for a valid encoding no
  568. such restrictions exist for encoders: Encoding a given sequence of
  569. octets to different, equivalent encoded sequences is perfectly legal.
  570. Three transformations are currently defined: identity, the "quoted-
  571. printable" encoding, and the "base64" encoding. The domains are
  572. "binary", "8bit" and "7bit".
  573. The Content-Transfer-Encoding values "7bit", "8bit", and "binary" all
  574. mean that the identity (i.e. NO) encoding transformation has been
  575. performed. As such, they serve simply as indicators of the domain of
  576. the body data, and provide useful information about the sort of
  577. encoding that might be needed for transmission in a given transport
  578. system. The terms "7bit data", "8bit data", and "binary data" are
  579. all defined in Section 2.
  580. The quoted-printable and base64 encodings transform their input from
  581. an arbitrary domain into material in the "7bit" range, thus making it
  582. safe to carry over restricted transports. The specific definition of
  583. the transformations are given below.
  584. The proper Content-Transfer-Encoding label must always be used.
  585. Labelling unencoded data containing 8bit characters as "7bit" is not
  586. allowed, nor is labelling unencoded non-line-oriented data as
  587. anything other than "binary" allowed.
  588. Unlike media subtypes, a proliferation of Content-Transfer-Encoding
  589. values is both undesirable and unnecessary. However, establishing
  590. only a single transformation into the "7bit" domain does not seem
  591. Freed & Borenstein Standards Track [Page 15]
  592. RFC 2045 Internet Message Bodies November 1996
  593. possible. There is a tradeoff between the desire for a compact and
  594. efficient encoding of largely- binary data and the desire for a
  595. somewhat readable encoding of data that is mostly, but not entirely,
  596. 7bit. For this reason, at least two encoding mechanisms are
  597. necessary: a more or less readable encoding (quoted-printable) and a
  598. "dense" or "uniform" encoding (base64).
  599. Mail transport for unencoded 8bit data is defined in RFC 1652. As of
  600. the initial publication of this document, there are no standardized
  601. Internet mail transports for which it is legitimate to include
  602. unencoded binary data in mail bodies. Thus there are no
  603. circumstances in which the "binary" Content-Transfer-Encoding is
  604. actually valid in Internet mail. However, in the event that binary
  605. mail transport becomes a reality in Internet mail, or when MIME is
  606. used in conjunction with any other binary-capable mail transport
  607. mechanism, binary bodies must be labelled as such using this
  608. mechanism.
  609. NOTE: The five values defined for the Content-Transfer-Encoding field
  610. imply nothing about the media type other than the algorithm by which
  611. it was encoded or the transport system requirements if unencoded.
  612. 6.3. New Content-Transfer-Encodings
  613. Implementors may, if necessary, define private Content-Transfer-
  614. Encoding values, but must use an x-token, which is a name prefixed by
  615. "X-", to indicate its non-standard status, e.g., "Content-Transfer-
  616. Encoding: x-my-new-encoding". Additional standardized Content-
  617. Transfer-Encoding values must be specified by a standards-track RFC.
  618. The requirements such specifications must meet are given in RFC 2048.
  619. As such, all content-transfer-encoding namespace except that
  620. beginning with "X-" is explicitly reserved to the IETF for future
  621. use.
  622. Unlike media types and subtypes, the creation of new Content-
  623. Transfer-Encoding values is STRONGLY discouraged, as it seems likely
  624. to hinder interoperability with little potential benefit
  625. 6.4. Interpretation and Use
  626. If a Content-Transfer-Encoding header field appears as part of a
  627. message header, it applies to the entire body of that message. If a
  628. Content-Transfer-Encoding header field appears as part of an entity's
  629. headers, it applies only to the body of that entity. If an entity is
  630. of type "multipart" the Content-Transfer-Encoding is not permitted to
  631. have any value other than "7bit", "8bit" or "binary". Even more
  632. severe restrictions apply to some subtypes of the "message" type.
  633. Freed & Borenstein Standards Track [Page 16]
  634. RFC 2045 Internet Message Bodies November 1996
  635. It should be noted that most media types are defined in terms of
  636. octets rather than bits, so that the mechanisms described here are
  637. mechanisms for encoding arbitrary octet streams, not bit streams. If
  638. a bit stream is to be encoded via one of these mechanisms, it must
  639. first be converted to an 8bit byte stream using the network standard
  640. bit order ("big-endian"), in which the earlier bits in a stream
  641. become the higher-order bits in a 8bit byte. A bit stream not ending
  642. at an 8bit boundary must be padded with zeroes. RFC 2046 provides a
  643. mechanism for noting the addition of such padding in the case of the
  644. application/octet-stream media type, which has a "padding" parameter.
  645. The encoding mechanisms defined here explicitly encode all data in
  646. US-ASCII. Thus, for example, suppose an entity has header fields
  647. such as:
  648. Content-Type: text/plain; charset=ISO-8859-1
  649. Content-transfer-encoding: base64
  650. This must be interpreted to mean that the body is a base64 US-ASCII
  651. encoding of data that was originally in ISO-8859-1, and will be in
  652. that character set again after decoding.
  653. Certain Content-Transfer-Encoding values may only be used on certain
  654. media types. In particular, it is EXPRESSLY FORBIDDEN to use any
  655. encodings other than "7bit", "8bit", or "binary" with any composite
  656. media type, i.e. one that recursively includes other Content-Type
  657. fields. Currently the only composite media types are "multipart" and
  658. "message". All encodings that are desired for bodies of type
  659. multipart or message must be done at the innermost level, by encoding
  660. the actual body that needs to be encoded.
  661. It should also be noted that, by definition, if a composite entity
  662. has a transfer-encoding value such as "7bit", but one of the enclosed
  663. entities has a less restrictive value such as "8bit", then either the
  664. outer "7bit" labelling is in error, because 8bit data are included,
  665. or the inner "8bit" labelling placed an unnecessarily high demand on
  666. the transport system because the actual included data were actually
  667. 7bit-safe.
  668. NOTE ON ENCODING RESTRICTIONS: Though the prohibition against using
  669. content-transfer-encodings on composite body data may seem overly
  670. restrictive, it is necessary to prevent nested encodings, in which
  671. data are passed through an encoding algorithm multiple times, and
  672. must be decoded multiple times in order to be properly viewed.
  673. Nested encodings add considerable complexity to user agents: Aside
  674. from the obvious efficiency problems with such multiple encodings,
  675. they can obscure the basic structure of a message. In particular,
  676. they can imply that several decoding operations are necessary simply
  677. Freed & Borenstein Standards Track [Page 17]
  678. RFC 2045 Internet Message Bodies November 1996
  679. to find out what types of bodies a message contains. Banning nested
  680. encodings may complicate the job of certain mail gateways, but this
  681. seems less of a problem than the effect of nested encodings on user
  682. agents.
  683. Any entity with an unrecognized Content-Transfer-Encoding must be
  684. treated as if it has a Content-Type of "application/octet-stream",
  685. regardless of what the Content-Type header field actually says.
  686. NOTE ON THE RELATIONSHIP BETWEEN CONTENT-TYPE AND CONTENT-TRANSFER-
  687. ENCODING: It may seem that the Content-Transfer-Encoding could be
  688. inferred from the characteristics of the media that is to be encoded,
  689. or, at the very least, that certain Content-Transfer-Encodings could
  690. be mandated for use with specific media types. There are several
  691. reasons why this is not the case. First, given the varying types of
  692. transports used for mail, some encodings may be appropriate for some
  693. combinations of media types and transports but not for others. (For
  694. example, in an 8bit transport, no encoding would be required for text
  695. in certain character sets, while such encodings are clearly required
  696. for 7bit SMTP.)
  697. Second, certain media types may require different types of transfer
  698. encoding under different circumstances. For example, many PostScript
  699. bodies might consist entirely of short lines of 7bit data and hence
  700. require no encoding at all. Other PostScript bodies (especially
  701. those using Level 2 PostScript's binary encoding mechanism) may only
  702. be reasonably represented using a binary transport encoding.
  703. Finally, since the Content-Type field is intended to be an open-ended
  704. specification mechanism, strict specification of an association
  705. between media types and encodings effectively couples the
  706. specification of an application protocol with a specific lower-level
  707. transport. This is not desirable since the developers of a media
  708. type should not have to be aware of all the transports in use and
  709. what their limitations are.
  710. 6.5. Translating Encodings
  711. The quoted-printable and base64 encodings are designed so that
  712. conversion between them is possible. The only issue that arises in
  713. such a conversion is the handling of hard line breaks in quoted-
  714. printable encoding output. When converting from quoted-printable to
  715. base64 a hard line break in the quoted-printable form represents a
  716. CRLF sequence in the canonical form of the data. It must therefore be
  717. converted to a corresponding encoded CRLF in the base64 form of the
  718. data. Similarly, a CRLF sequence in the canonical form of the data
  719. obtained after base64 decoding must be converted to a quoted-
  720. printable hard line break, but ONLY when converting text data.
  721. Freed & Borenstein Standards Track [Page 18]
  722. RFC 2045 Internet Message Bodies November 1996
  723. 6.6. Canonical Encoding Model
  724. There was some confusion, in the previous versions of this RFC,
  725. regarding the model for when email data was to be converted to
  726. canonical form and encoded, and in particular how this process would
  727. affect the treatment of CRLFs, given that the representation of
  728. newlines varies greatly from system to system, and the relationship
  729. between content-transfer-encodings and character sets. A canonical
  730. model for encoding is presented in RFC 2049 for this reason.
  731. 6.7. Quoted-Printable Content-Transfer-Encoding
  732. The Quoted-Printable encoding is intended to represent data that
  733. largely consists of octets that correspond to printable characters in
  734. the US-ASCII character set. It encodes the data in such a way that
  735. the resulting octets are unlikely to be modified by mail transport.
  736. If the data being encoded are mostly US-ASCII text, the encoded form
  737. of the data remains largely recognizable by humans. A body which is
  738. entirely US-ASCII may also be encoded in Quoted-Printable to ensure
  739. the integrity of the data should the message pass through a
  740. character-translating, and/or line-wrapping gateway.
  741. In this encoding, octets are to be represented as determined by the
  742. following rules:
  743. (1) (General 8bit representation) Any octet, except a CR or
  744. LF that is part of a CRLF line break of the canonical
  745. (standard) form of the data being encoded, may be
  746. represented by an "=" followed by a two digit
  747. hexadecimal representation of the octet's value. The
  748. digits of the hexadecimal alphabet, for this purpose,
  749. are "0123456789ABCDEF". Uppercase letters must be
  750. used; lowercase letters are not allowed. Thus, for
  751. example, the decimal value 12 (US-ASCII form feed) can
  752. be represented by "=0C", and the decimal value 61 (US-
  753. ASCII EQUAL SIGN) can be represented by "=3D". This
  754. rule must be followed except when the following rules
  755. allow an alternative encoding.
  756. (2) (Literal representation) Octets with decimal values of
  757. 33 through 60 inclusive, and 62 through 126, inclusive,
  758. MAY be represented as the US-ASCII characters which
  759. correspond to those octets (EXCLAMATION POINT through
  760. LESS THAN, and GREATER THAN through TILDE,
  761. respectively).
  762. (3) (White Space) Octets with values of 9 and 32 MAY be
  763. represented as US-ASCII TAB (HT) and SPACE characters,
  764. Freed & Borenstein Standards Track [Page 19]
  765. RFC 2045 Internet Message Bodies November 1996
  766. respectively, but MUST NOT be so represented at the end
  767. of an encoded line. Any TAB (HT) or SPACE characters
  768. on an encoded line MUST thus be followed on that line
  769. by a printable character. In particular, an "=" at the
  770. end of an encoded line, indicating a soft line break
  771. (see rule #5) may follow one or more TAB (HT) or SPACE
  772. characters. It follows that an octet with decimal
  773. value 9 or 32 appearing at the end of an encoded line
  774. must be represented according to Rule #1. This rule is
  775. necessary because some MTAs (Message Transport Agents,
  776. programs which transport messages from one user to
  777. another, or perform a portion of such transfers) are
  778. known to pad lines of text with SPACEs, and others are
  779. known to remove "white space" characters from the end
  780. of a line. Therefore, when decoding a Quoted-Printable
  781. body, any trailing white space on a line must be
  782. deleted, as it will necessarily have been added by
  783. intermediate transport agents.
  784. (4) (Line Breaks) A line break in a text body, represented
  785. as a CRLF sequence in the text canonical form, must be
  786. represented by a (RFC 822) line break, which is also a
  787. CRLF sequence, in the Quoted-Printable encoding. Since
  788. the canonical representation of media types other than
  789. text do not generally include the representation of
  790. line breaks as CRLF sequences, no hard line breaks
  791. (i.e. line breaks that are intended to be meaningful
  792. and to be displayed to the user) can occur in the
  793. quoted-printable encoding of such types. Sequences
  794. like "=0D", "=0A", "=0A=0D" and "=0D=0A" will routinely
  795. appear in non-text data represented in quoted-
  796. printable, of course.
  797. Note that many implementations may elect to encode the
  798. local representation of various content types directly
  799. rather than converting to canonical form first,
  800. encoding, and then converting back to local
  801. representation. In particular, this may apply to plain
  802. text material on systems that use newline conventions
  803. other than a CRLF terminator sequence. Such an
  804. implementation optimization is permissible, but only
  805. when the combined canonicalization-encoding step is
  806. equivalent to performing the three steps separately.
  807. (5) (Soft Line Breaks) The Quoted-Printable encoding
  808. REQUIRES that encoded lines be no more than 76
  809. characters long. If longer lines are to be encoded
  810. with the Quoted-Printable encoding, "soft" line breaks
  811. Freed & Borenstein Standards Track [Page 20]
  812. RFC 2045 Internet Message Bodies November 1996
  813. must be used. An equal sign as the last character on a
  814. encoded line indicates such a non-significant ("soft")
  815. line break in the encoded text.
  816. Thus if the "raw" form of the line is a single unencoded line that
  817. says:
  818. Now's the time for all folk to come to the aid of their country.
  819. This can be represented, in the Quoted-Printable encoding, as:
  820. Now's the time =
  821. for all folk to come=
  822. to the aid of their country.
  823. This provides a mechanism with which long lines are encoded in such a
  824. way as to be restored by the user agent. The 76 character limit does
  825. not count the trailing CRLF, but counts all other characters,
  826. including any equal signs.
  827. Since the hyphen character ("-") may be represented as itself in the
  828. Quoted-Printable encoding, care must be taken, when encapsulating a
  829. quoted-printable encoded body inside one or more multipart entities,
  830. to ensure that the boundary delimiter does not appear anywhere in the
  831. encoded body. (A good strategy is to choose a boundary that includes
  832. a character sequence such as "=_" which can never appear in a
  833. quoted-printable body. See the definition of multipart messages in
  834. RFC 2046.)
  835. NOTE: The quoted-printable encoding represents something of a
  836. compromise between readability and reliability in transport. Bodies
  837. encoded with the quoted-printable encoding will work reliably over
  838. most mail gateways, but may not work perfectly over a few gateways,
  839. notably those involving translation into EBCDIC. A higher level of
  840. confidence is offered by the base64 Content-Transfer-Encoding. A way
  841. to get reasonably reliable transport through EBCDIC gateways is to
  842. also quote the US-ASCII characters
  843. !"#$@[\]^`{|}~
  844. according to rule #1.
  845. Because quoted-printable data is generally assumed to be line-
  846. oriented, it is to be expected that the representation of the breaks
  847. between the lines of quoted-printable data may be altered in
  848. transport, in the same manner that plain text mail has always been
  849. altered in Internet mail when passing between systems with differing
  850. newline conventions. If such alterations are likely to constitute a
  851. Freed & Borenstein Standards Track [Page 21]
  852. RFC 2045 Internet Message Bodies November 1996
  853. corruption of the data, it is probably more sensible to use the
  854. base64 encoding rather than the quoted-printable encoding.
  855. NOTE: Several kinds of substrings cannot be generated according to
  856. the encoding rules for the quoted-printable content-transfer-
  857. encoding, and hence are formally illegal if they appear in the output
  858. of a quoted-printable encoder. This note enumerates these cases and
  859. suggests ways to handle such illegal substrings if any are
  860. encountered in quoted-printable data that is to be decoded.
  861. (1) An "=" followed by two hexadecimal digits, one or both
  862. of which are lowercase letters in "abcdef", is formally
  863. illegal. A robust implementation might choose to
  864. recognize them as the corresponding uppercase letters.
  865. (2) An "=" followed by a character that is neither a
  866. hexadecimal digit (including "abcdef") nor the CR
  867. character of a CRLF pair is illegal. This case can be
  868. the result of US-ASCII text having been included in a
  869. quoted-printable part of a message without itself
  870. having been subjected to quoted-printable encoding. A
  871. reasonable approach by a robust implementation might be
  872. to include the "=" character and the following
  873. character in the decoded data without any
  874. transformation and, if possible, indicate to the user
  875. that proper decoding was not possible at this point in
  876. the data.
  877. (3) An "=" cannot be the ultimate or penultimate character
  878. in an encoded object. This could be handled as in case
  879. (2) above.
  880. (4) Control characters other than TAB, or CR and LF as
  881. parts of CRLF pairs, must not appear. The same is true
  882. for octets with decimal values greater than 126. If
  883. found in incoming quoted-printable data by a decoder, a
  884. robust implementation might exclude them from the
  885. decoded data and warn the user that illegal characters
  886. were discovered.
  887. (5) Encoded lines must not be longer than 76 characters,
  888. not counting the trailing CRLF. If longer lines are
  889. found in incoming, encoded data, a robust
  890. implementation might nevertheless decode the lines, and
  891. might report the erroneous encoding to the user.
  892. Freed & Borenstein Standards Track [Page 22]
  893. RFC 2045 Internet Message Bodies November 1996
  894. WARNING TO IMPLEMENTORS: If binary data is encoded in quoted-
  895. printable, care must be taken to encode CR and LF characters as "=0D"
  896. and "=0A", respectively. In particular, a CRLF sequence in binary
  897. data should be encoded as "=0D=0A". Otherwise, if CRLF were
  898. represented as a hard line break, it might be incorrectly decoded on
  899. platforms with different line break conventions.
  900. For formalists, the syntax of quoted-printable data is described by
  901. the following grammar:
  902. quoted-printable := qp-line *(CRLF qp-line)
  903. qp-line := *(qp-segment transport-padding CRLF)
  904. qp-part transport-padding
  905. qp-part := qp-section
  906. ; Maximum length of 76 characters
  907. qp-segment := qp-section *(SPACE / TAB) "="
  908. ; Maximum length of 76 characters
  909. qp-section := [*(ptext / SPACE / TAB) ptext]
  910. ptext := hex-octet / safe-char
  911. safe-char := <any octet with decimal value of 33 through
  912. 60 inclusive, and 62 through 126>
  913. ; Characters not listed as "mail-safe" in
  914. ; RFC 2049 are also not recommended.
  915. hex-octet := "=" 2(DIGIT / "A" / "B" / "C" / "D" / "E" / "F")
  916. ; Octet must be used for characters > 127, =,
  917. ; SPACEs or TABs at the ends of lines, and is
  918. ; recommended for any character not listed in
  919. ; RFC 2049 as "mail-safe".
  920. transport-padding := *LWSP-char
  921. ; Composers MUST NOT generate
  922. ; non-zero length transport
  923. ; padding, but receivers MUST
  924. ; be able to handle padding
  925. ; added by message transports.
  926. IMPORTANT: The addition of LWSP between the elements shown in this
  927. BNF is NOT allowed since this BNF does not specify a structured
  928. header field.
  929. Freed & Borenstein Standards Track [Page 23]
  930. RFC 2045 Internet Message Bodies November 1996
  931. 6.8. Base64 Content-Transfer-Encoding
  932. The Base64 Content-Transfer-Encoding is designed to represent
  933. arbitrary sequences of octets in a form that need not be humanly
  934. readable. The encoding and decoding algorithms are simple, but the
  935. encoded data are consistently only about 33 percent larger than the
  936. unencoded data. This encoding is virtually identical to the one used
  937. in Privacy Enhanced Mail (PEM) applications, as defined in RFC 1421.
  938. A 65-character subset of US-ASCII is used, enabling 6 bits to be
  939. represented per printable character. (The extra 65th character, "=",
  940. is used to signify a special processing function.)
  941. NOTE: This subset has the important property that it is represented
  942. identically in all versions of ISO 646, including US-ASCII, and all
  943. characters in the subset are also represented identically in all
  944. versions of EBCDIC. Other popular encodings, such as the encoding
  945. used by the uuencode utility, Macintosh binhex 4.0 [RFC-1741], and
  946. the base85 encoding specified as part of Level 2 PostScript, do not
  947. share these properties, and thus do not fulfill the portability
  948. requirements a binary transport encoding for mail must meet.
  949. The encoding process represents 24-bit groups of input bits as output
  950. strings of 4 encoded characters. Proceeding from left to right, a
  951. 24-bit input group is formed by concatenating 3 8bit input groups.
  952. These 24 bits are then treated as 4 concatenated 6-bit groups, each
  953. of which is translated into a single digit in the base64 alphabet.
  954. When encoding a bit stream via the base64 encoding, the bit stream
  955. must be presumed to be ordered with the most-significant-bit first.
  956. That is, the first bit in the stream will be the high-order bit in
  957. the first 8bit byte, and the eighth bit will be the low-order bit in
  958. the first 8bit byte, and so on.
  959. Each 6-bit group is used as an index into an array of 64 printable
  960. characters. The character referenced by the index is placed in the
  961. output string. These characters, identified in Table 1, below, are
  962. selected so as to be universally representable, and the set excludes
  963. characters with particular significance to SMTP (e.g., ".", CR, LF)
  964. and to the multipart boundary delimiters defined in RFC 2046 (e.g.,
  965. "-").
  966. Freed & Borenstein Standards Track [Page 24]
  967. RFC 2045 Internet Message Bodies November 1996
  968. Table 1: The Base64 Alphabet
  969. Value Encoding Value Encoding Value Encoding Value Encoding
  970. 0 A 17 R 34 i 51 z
  971. 1 B 18 S 35 j 52 0
  972. 2 C 19 T 36 k 53 1
  973. 3 D 20 U 37 l 54 2
  974. 4 E 21 V 38 m 55 3
  975. 5 F 22 W 39 n 56 4
  976. 6 G 23 X 40 o 57 5
  977. 7 H 24 Y 41 p 58 6
  978. 8 I 25 Z 42 q 59 7
  979. 9 J 26 a 43 r 60 8
  980. 10 K 27 b 44 s 61 9
  981. 11 L 28 c 45 t 62 +
  982. 12 M 29 d 46 u 63 /
  983. 13 N 30 e 47 v
  984. 14 O 31 f 48 w (pad) =
  985. 15 P 32 g 49 x
  986. 16 Q 33 h 50 y
  987. The encoded output stream must be represented in lines of no more
  988. than 76 characters each. All line breaks or other characters not
  989. found in Table 1 must be ignored by decoding software. In base64
  990. data, characters other than those in Table 1, line breaks, and other
  991. white space probably indicate a transmission error, about which a
  992. warning message or even a message rejection might be appropriate
  993. under some circumstances.
  994. Special processing is performed if fewer than 24 bits are available
  995. at the end of the data being encoded. A full encoding quantum is
  996. always completed at the end of a body. When fewer than 24 input bits
  997. are available in an input group, zero bits are added (on the right)
  998. to form an integral number of 6-bit groups. Padding at the end of
  999. the data is performed using the "=" character. Since all base64
  1000. input is an integral number of octets, only the following cases can
  1001. arise: (1) the final quantum of encoding input is an integral
  1002. multiple of 24 bits; here, the final unit of encoded output will be
  1003. an integral multiple of 4 characters with no "=" padding, (2) the
  1004. final quantum of encoding input is exactly 8 bits; here, the final
  1005. unit of encoded output will be two characters followed by two "="
  1006. padding characters, or (3) the final quantum of encoding input is
  1007. exactly 16 bits; here, the final unit of encoded output will be three
  1008. characters followed by one "=" padding character.
  1009. Because it is used only for padding at the end of the data, the
  1010. occurrence of any "=" characters may be taken as evidence that the
  1011. end of the data has been reached (without truncation in transit). No
  1012. Freed & Borenstein Standards Track [Page 25]
  1013. RFC 2045 Internet Message Bodies November 1996
  1014. such assurance is possible, however, when the number of octets
  1015. transmitted was a multiple of three and no "=" characters are
  1016. present.
  1017. Any characters outside of the base64 alphabet are to be ignored in
  1018. base64-encoded data.
  1019. Care must be taken to use the proper octets for line breaks if base64
  1020. encoding is applied directly to text material that has not been
  1021. converted to canonical form. In particular, text line breaks must be
  1022. converted into CRLF sequences prior to base64 encoding. The
  1023. important thing to note is that this may be done directly by the
  1024. encoder rather than in a prior canonicalization step in some
  1025. implementations.
  1026. NOTE: There is no need to worry about quoting potential boundary
  1027. delimiters within base64-encoded bodies within multipart entities
  1028. because no hyphen characters are used in the base64 encoding.
  1029. 7. Content-ID Header Field
  1030. In constructing a high-level user agent, it may be desirable to allow
  1031. one body to make reference to another. Accordingly, bodies may be
  1032. labelled using the "Content-ID" header field, which is syntactically
  1033. identical to the "Message-ID" header field:
  1034. id := "Content-ID" ":" msg-id
  1035. Like the Message-ID values, Content-ID values must be generated to be
  1036. world-unique.
  1037. The Content-ID value may be used for uniquely identifying MIME
  1038. entities in several contexts, particularly for caching data
  1039. referenced by the message/external-body mechanism. Although the
  1040. Content-ID header is generally optional, its use is MANDATORY in
  1041. implementations which generate data of the optional MIME media type
  1042. "message/external-body". That is, each message/external-body entity
  1043. must have a Content-ID field to permit caching of such data.
  1044. It is also worth noting that the Content-ID value has special
  1045. semantics in the case of the multipart/alternative media type. This
  1046. is explained in the section of RFC 2046 dealing with
  1047. multipart/alternative.
  1048. Freed & Borenstein Standards Track [Page 26]
  1049. RFC 2045 Internet Message Bodies November 1996
  1050. 8. Content-Description Header Field
  1051. The ability to associate some descriptive information with a given
  1052. body is often desirable. For example, it may be useful to mark an
  1053. "image" body as "a picture of the Space Shuttle Endeavor." Such text
  1054. may be placed in the Content-Description header field. This header
  1055. field is always optional.
  1056. description := "Content-Description" ":" *text
  1057. The description is presumed to be given in the US-ASCII character
  1058. set, although the mechanism specified in RFC 2047 may be used for
  1059. non-US-ASCII Content-Description values.
  1060. 9. Additional MIME Header Fields
  1061. Future documents may elect to define additional MIME header fields
  1062. for various purposes. Any new header field that further describes
  1063. the content of a message should begin with the string "Content-" to
  1064. allow such fields which appear in a message header to be
  1065. distinguished from ordinary RFC 822 message header fields.
  1066. MIME-extension-field := <Any RFC 822 header field which
  1067. begins with the string
  1068. "Content-">
  1069. 10. Summary
  1070. Using the MIME-Version, Content-Type, and Content-Transfer-Encoding
  1071. header fields, it is possible to include, in a standardized way,
  1072. arbitrary types of data with RFC 822 conformant mail messages. No
  1073. restrictions imposed by either RFC 821 or RFC 822 are violated, and
  1074. care has been taken to avoid problems caused by additional
  1075. restrictions imposed by the characteristics of some Internet mail
  1076. transport mechanisms (see RFC 2049).
  1077. The next document in this set, RFC 2046, specifies the initial set of
  1078. media types that can be labelled and transported using these headers.
  1079. 11. Security Considerations
  1080. Security issues are discussed in the second document in this set, RFC
  1081. 2046.
  1082. Freed & Borenstein Standards Track [Page 27]
  1083. RFC 2045 Internet Message Bodies November 1996
  1084. 12. Authors' Addresses
  1085. For more information, the authors of this document are best contacted
  1086. via Internet mail:
  1087. Ned Freed
  1088. Innosoft International, Inc.
  1089. 1050 East Garvey Avenue South
  1090. West Covina, CA 91790
  1091. USA
  1092. Phone: +1 818 919 3600
  1093. Fax: +1 818 919 3614
  1094. EMail: ned@innosoft.com
  1095. Nathaniel S. Borenstein
  1096. First Virtual Holdings
  1097. 25 Washington Avenue
  1098. Morristown, NJ 07960
  1099. USA
  1100. Phone: +1 201 540 8967
  1101. Fax: +1 201 993 3032
  1102. EMail: nsb@nsb.fv.com
  1103. MIME is a result of the work of the Internet Engineering Task Force
  1104. Working Group on RFC 822 Extensions. The chairman of that group,
  1105. Greg Vaudreuil, may be reached at:
  1106. Gregory M. Vaudreuil
  1107. Octel Network Services
  1108. 17080 Dallas Parkway
  1109. Dallas, TX 75248-1905
  1110. USA
  1111. EMail: Greg.Vaudreuil@Octel.Com
  1112. Freed & Borenstein Standards Track [Page 28]
  1113. RFC 2045 Internet Message Bodies November 1996
  1114. Appendix A -- Collected Grammar
  1115. This appendix contains the complete BNF grammar for all the syntax
  1116. specified by this document.
  1117. By itself, however, this grammar is incomplete. It refers by name to
  1118. several syntax rules that are defined by RFC 822. Rather than
  1119. reproduce those definitions here, and risk unintentional differences
  1120. between the two, this document simply refers the reader to RFC 822
  1121. for the remaining definitions. Wherever a term is undefined, it
  1122. refers to the RFC 822 definition.
  1123. attribute := token
  1124. ; Matching of attributes
  1125. ; is ALWAYS case-insensitive.
  1126. composite-type := "message" / "multipart" / extension-token
  1127. content := "Content-Type" ":" type "/" subtype
  1128. *(";" parameter)
  1129. ; Matching of media type and subtype
  1130. ; is ALWAYS case-insensitive.
  1131. description := "Content-Description" ":" *text
  1132. discrete-type := "text" / "image" / "audio" / "video" /
  1133. "application" / extension-token
  1134. encoding := "Content-Transfer-Encoding" ":" mechanism
  1135. entity-headers := [ content CRLF ]
  1136. [ encoding CRLF ]
  1137. [ id CRLF ]
  1138. [ description CRLF ]
  1139. *( MIME-extension-field CRLF )
  1140. extension-token := ietf-token / x-token
  1141. hex-octet := "=" 2(DIGIT / "A" / "B" / "C" / "D" / "E" / "F")
  1142. ; Octet must be used for characters > 127, =,
  1143. ; SPACEs or TABs at the ends of lines, and is
  1144. ; recommended for any character not listed in
  1145. ; RFC 2049 as "mail-safe".
  1146. iana-token := <A publicly-defined extension token. Tokens
  1147. of this form must be registered with IANA
  1148. as specified in RFC 2048.>
  1149. Freed & Borenstein Standards Track [Page 29]
  1150. RFC 2045 Internet Message Bodies November 1996
  1151. ietf-token := <An extension token defined by a
  1152. standards-track RFC and registered
  1153. with IANA.>
  1154. id := "Content-ID" ":" msg-id
  1155. mechanism := "7bit" / "8bit" / "binary" /
  1156. "quoted-printable" / "base64" /
  1157. ietf-token / x-token
  1158. MIME-extension-field := <Any RFC 822 header field which
  1159. begins with the string
  1160. "Content-">
  1161. MIME-message-headers := entity-headers
  1162. fields
  1163. version CRLF
  1164. ; The ordering of the header
  1165. ; fields implied by this BNF
  1166. ; definition should be ignored.
  1167. MIME-part-headers := entity-headers
  1168. [fields]
  1169. ; Any field not beginning with
  1170. ; "content-" can have no defined
  1171. ; meaning and may be ignored.
  1172. ; The ordering of the header
  1173. ; fields implied by this BNF
  1174. ; definition should be ignored.
  1175. parameter := attribute "=" value
  1176. ptext := hex-octet / safe-char
  1177. qp-line := *(qp-segment transport-padding CRLF)
  1178. qp-part transport-padding
  1179. qp-part := qp-section
  1180. ; Maximum length of 76 characters
  1181. qp-section := [*(ptext / SPACE / TAB) ptext]
  1182. qp-segment := qp-section *(SPACE / TAB) "="
  1183. ; Maximum length of 76 characters
  1184. quoted-printable := qp-line *(CRLF qp-line)
  1185. Freed & Borenstein Standards Track [Page 30]
  1186. RFC 2045 Internet Message Bodies November 1996
  1187. safe-char := <any octet with decimal value of 33 through
  1188. 60 inclusive, and 62 through 126>
  1189. ; Characters not listed as "mail-safe" in
  1190. ; RFC 2049 are also not recommended.
  1191. subtype := extension-token / iana-token
  1192. token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
  1193. or tspecials>
  1194. transport-padding := *LWSP-char
  1195. ; Composers MUST NOT generate
  1196. ; non-zero length transport
  1197. ; padding, but receivers MUST
  1198. ; be able to handle padding
  1199. ; added by message transports.
  1200. tspecials := "(" / ")" / "<" / ">" / "@" /
  1201. "," / ";" / ":" / "\" / <">
  1202. "/" / "[" / "]" / "?" / "="
  1203. ; Must be in quoted-string,
  1204. ; to use within parameter values
  1205. type := discrete-type / composite-type
  1206. value := token / quoted-string
  1207. version := "MIME-Version" ":" 1*DIGIT "." 1*DIGIT
  1208. x-token := <The two characters "X-" or "x-" followed, with
  1209. no intervening white space, by any token>
  1210. Freed & Borenstein Standards Track [Page 31]