emacs-mime.texi 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900
  1. \input texinfo
  2. @include gnus-overrides.texi
  3. @setfilename ../../info/emacs-mime.info
  4. @settitle Emacs MIME Manual
  5. @include docstyle.texi
  6. @synindex fn cp
  7. @synindex vr cp
  8. @synindex pg cp
  9. @copying
  10. This file documents the Emacs MIME interface functionality.
  11. Copyright @copyright{} 1998--2015 Free Software Foundation, Inc.
  12. @quotation
  13. Permission is granted to copy, distribute and/or modify this document
  14. under the terms of the GNU Free Documentation License, Version 1.3 or
  15. any later version published by the Free Software Foundation; with no
  16. Invariant Sections, with the Front-Cover Texts being ``A GNU Manual'',
  17. and with the Back-Cover Texts as in (a) below. A copy of the license
  18. is included in the section entitled ``GNU Free Documentation License''.
  19. (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
  20. modify this GNU manual.''
  21. @end quotation
  22. @end copying
  23. @c Node ``Interface Functions'' uses non-ASCII characters
  24. @dircategory Emacs lisp libraries
  25. @direntry
  26. * Emacs MIME: (emacs-mime). Emacs MIME de/composition library.
  27. @end direntry
  28. @iftex
  29. @finalout
  30. @end iftex
  31. @setchapternewpage odd
  32. @titlepage
  33. @ifset WEBHACKDEVEL
  34. @title Emacs MIME Manual (DEVELOPMENT VERSION)
  35. @end ifset
  36. @ifclear WEBHACKDEVEL
  37. @title Emacs MIME Manual
  38. @end ifclear
  39. @author by Lars Magne Ingebrigtsen
  40. @page
  41. @vskip 0pt plus 1filll
  42. @insertcopying
  43. @end titlepage
  44. @contents
  45. @node Top
  46. @top Emacs MIME
  47. This manual documents the libraries used to compose and display
  48. @acronym{MIME} messages.
  49. This manual is directed at users who want to modify the behavior of
  50. the @acronym{MIME} encoding/decoding process or want a more detailed
  51. picture of how the Emacs @acronym{MIME} library works, and people who want
  52. to write functions and commands that manipulate @acronym{MIME} elements.
  53. @acronym{MIME} is short for @dfn{Multipurpose Internet Mail Extensions}.
  54. This standard is documented in a number of RFCs; mainly RFC2045 (Format
  55. of Internet Message Bodies), RFC2046 (Media Types), RFC2047 (Message
  56. Header Extensions for Non-@acronym{ASCII} Text), RFC2048 (Registration
  57. Procedures), RFC2049 (Conformance Criteria and Examples). It is highly
  58. recommended that anyone who intends writing @acronym{MIME}-compliant software
  59. read at least RFC2045 and RFC2047.
  60. @ifnottex
  61. @insertcopying
  62. @end ifnottex
  63. @menu
  64. * Decoding and Viewing:: A framework for decoding and viewing.
  65. * Composing:: @acronym{MML}; a language for describing @acronym{MIME} parts.
  66. * Interface Functions:: An abstraction over the basic functions.
  67. * Basic Functions:: Utility and basic parsing functions.
  68. * Standards:: A summary of RFCs and working documents used.
  69. * GNU Free Documentation License:: The license for this documentation.
  70. * Index:: Function and variable index.
  71. @end menu
  72. @node Decoding and Viewing
  73. @chapter Decoding and Viewing
  74. This chapter deals with decoding and viewing @acronym{MIME} messages on a
  75. higher level.
  76. The main idea is to first analyze a @acronym{MIME} article, and then allow
  77. other programs to do things based on the list of @dfn{handles} that are
  78. returned as a result of this analysis.
  79. @menu
  80. * Dissection:: Analyzing a @acronym{MIME} message.
  81. * Non-MIME:: Analyzing a non-@acronym{MIME} message.
  82. * Handles:: Handle manipulations.
  83. * Display:: Displaying handles.
  84. * Display Customization:: Variables that affect display.
  85. * Files and Directories:: Saving and naming attachments.
  86. * New Viewers:: How to write your own viewers.
  87. @end menu
  88. @node Dissection
  89. @section Dissection
  90. The @code{mm-dissect-buffer} is the function responsible for dissecting
  91. a @acronym{MIME} article. If given a multipart message, it will recursively
  92. descend the message, following the structure, and return a tree of
  93. @acronym{MIME} handles that describes the structure of the message.
  94. @node Non-MIME
  95. @section Non-MIME
  96. @vindex mm-uu-configure-list
  97. Gnus also understands some non-@acronym{MIME} attachments, such as
  98. postscript, uuencode, binhex, yenc, shar, forward, gnatsweb, pgp,
  99. diff. Each of these features can be disabled by add an item into
  100. @code{mm-uu-configure-list}. For example,
  101. @lisp
  102. (require 'mm-uu)
  103. (add-to-list 'mm-uu-configure-list '(pgp-signed . disabled))
  104. @end lisp
  105. @table @code
  106. @item postscript
  107. @findex postscript
  108. PostScript file.
  109. @item uu
  110. @findex uu
  111. Uuencoded file.
  112. @item binhex
  113. @findex binhex
  114. Binhex encoded file.
  115. @item yenc
  116. @findex yenc
  117. Yenc encoded file.
  118. @item shar
  119. @findex shar
  120. Shar archive file.
  121. @item forward
  122. @findex forward
  123. Non-@acronym{MIME} forwarded message.
  124. @item gnatsweb
  125. @findex gnatsweb
  126. Gnatsweb attachment.
  127. @item pgp-signed
  128. @findex pgp-signed
  129. @acronym{PGP} signed clear text.
  130. @item pgp-encrypted
  131. @findex pgp-encrypted
  132. @acronym{PGP} encrypted clear text.
  133. @item pgp-key
  134. @findex pgp-key
  135. @acronym{PGP} public keys.
  136. @item emacs-sources
  137. @findex emacs-sources
  138. @vindex mm-uu-emacs-sources-regexp
  139. Emacs source code. This item works only in the groups matching
  140. @code{mm-uu-emacs-sources-regexp}.
  141. @item diff
  142. @vindex diff
  143. @vindex mm-uu-diff-groups-regexp
  144. Patches. This is intended for groups where diffs of committed files
  145. are automatically sent to. It only works in groups matching
  146. @code{mm-uu-diff-groups-regexp}.
  147. @item verbatim-marks
  148. @cindex verbatim-marks
  149. Slrn-style verbatim marks.
  150. @item LaTeX
  151. @cindex LaTeX
  152. LaTeX documents. It only works in groups matching
  153. @code{mm-uu-tex-groups-regexp}.
  154. @end table
  155. @cindex text/x-verbatim
  156. @c Is @vindex suitable for a face?
  157. @vindex mm-uu-extract
  158. Some inlined non-@acronym{MIME} attachments are displayed using the face
  159. @code{mm-uu-extract}. By default, no @acronym{MIME} button for these
  160. parts is displayed. You can force displaying a button using @kbd{K b}
  161. (@code{gnus-summary-display-buttonized}) or add @code{text/x-verbatim}
  162. to @code{gnus-buttonized-mime-types}, @xref{MIME Commands, ,MIME
  163. Commands, gnus, Gnus Manual}.
  164. @node Handles
  165. @section Handles
  166. A @acronym{MIME} handle is a list that fully describes a @acronym{MIME}
  167. component.
  168. The following macros can be used to access elements in a handle:
  169. @table @code
  170. @item mm-handle-buffer
  171. @findex mm-handle-buffer
  172. Return the buffer that holds the contents of the undecoded @acronym{MIME}
  173. part.
  174. @item mm-handle-type
  175. @findex mm-handle-type
  176. Return the parsed @code{Content-Type} of the part.
  177. @item mm-handle-encoding
  178. @findex mm-handle-encoding
  179. Return the @code{Content-Transfer-Encoding} of the part.
  180. @item mm-handle-undisplayer
  181. @findex mm-handle-undisplayer
  182. Return the object that can be used to remove the displayed part (if it
  183. has been displayed).
  184. @item mm-handle-set-undisplayer
  185. @findex mm-handle-set-undisplayer
  186. Set the undisplayer object.
  187. @item mm-handle-disposition
  188. @findex mm-handle-disposition
  189. Return the parsed @code{Content-Disposition} of the part.
  190. @item mm-get-content-id
  191. Returns the handle(s) referred to by @code{Content-ID}.
  192. @end table
  193. @node Display
  194. @section Display
  195. Functions for displaying, removing and saving.
  196. @table @code
  197. @item mm-display-part
  198. @findex mm-display-part
  199. Display the part.
  200. @item mm-remove-part
  201. @findex mm-remove-part
  202. Remove the part (if it has been displayed).
  203. @item mm-inlinable-p
  204. @findex mm-inlinable-p
  205. Say whether a @acronym{MIME} type can be displayed inline.
  206. @item mm-automatic-display-p
  207. @findex mm-automatic-display-p
  208. Say whether a @acronym{MIME} type should be displayed automatically.
  209. @item mm-destroy-part
  210. @findex mm-destroy-part
  211. Free all resources occupied by a part.
  212. @item mm-save-part
  213. @findex mm-save-part
  214. Offer to save the part in a file.
  215. @item mm-pipe-part
  216. @findex mm-pipe-part
  217. Offer to pipe the part to some process.
  218. @item mm-interactively-view-part
  219. @findex mm-interactively-view-part
  220. Prompt for a mailcap method to use to view the part.
  221. @end table
  222. @node Display Customization
  223. @section Display Customization
  224. @table @code
  225. @item mm-inline-media-tests
  226. @vindex mm-inline-media-tests
  227. This is an alist where the key is a @acronym{MIME} type, the second element
  228. is a function to display the part @dfn{inline} (i.e., inside Emacs), and
  229. the third element is a form to be @code{eval}ed to say whether the part
  230. can be displayed inline.
  231. This variable specifies whether a part @emph{can} be displayed inline,
  232. and, if so, how to do it. It does not say whether parts are
  233. @emph{actually} displayed inline.
  234. @item mm-inlined-types
  235. @vindex mm-inlined-types
  236. This, on the other hand, says what types are to be displayed inline, if
  237. they satisfy the conditions set by the variable above. It's a list of
  238. @acronym{MIME} media types.
  239. @item mm-automatic-display
  240. @vindex mm-automatic-display
  241. This is a list of types that are to be displayed ``automatically'', but
  242. only if the above variable allows it. That is, only inlinable parts can
  243. be displayed automatically.
  244. @item mm-automatic-external-display
  245. @vindex mm-automatic-external-display
  246. This is a list of types that will be displayed automatically in an
  247. external viewer.
  248. @item mm-keep-viewer-alive-types
  249. @vindex mm-keep-viewer-alive-types
  250. This is a list of media types for which the external viewer will not
  251. be killed when selecting a different article.
  252. @item mm-attachment-override-types
  253. @vindex mm-attachment-override-types
  254. Some @acronym{MIME} agents create parts that have a content-disposition of
  255. @samp{attachment}. This variable allows overriding that disposition and
  256. displaying the part inline. (Note that the disposition is only
  257. overridden if we are able to, and want to, display the part inline.)
  258. @item mm-discouraged-alternatives
  259. @vindex mm-discouraged-alternatives
  260. List of @acronym{MIME} types that are discouraged when viewing
  261. @samp{multipart/alternative}. Viewing agents are supposed to view the
  262. last possible part of a message, as that is supposed to be the richest.
  263. However, users may prefer other types instead, and this list says what
  264. types are most unwanted. If, for instance, @samp{text/html} parts are
  265. very unwanted, and @samp{text/richtext} parts are somewhat unwanted,
  266. you could say something like:
  267. @lisp
  268. (setq mm-discouraged-alternatives
  269. '("text/html" "text/richtext")
  270. mm-automatic-display
  271. (remove "text/html" mm-automatic-display))
  272. @end lisp
  273. Adding @code{"image/.*"} might also be useful. Spammers use images as
  274. the preferred part of @samp{multipart/alternative} messages, so you might
  275. not notice there are other parts. See also
  276. @code{gnus-buttonized-mime-types}, @ref{MIME Commands, ,MIME Commands,
  277. gnus, Gnus Manual}. After adding @code{"multipart/alternative"} to
  278. @code{gnus-buttonized-mime-types} you can choose manually which
  279. alternative you'd like to view. For example, you can set those
  280. variables like:
  281. @lisp
  282. (setq gnus-buttonized-mime-types
  283. '("multipart/alternative" "multipart/signed")
  284. mm-discouraged-alternatives
  285. '("text/html" "image/.*"))
  286. @end lisp
  287. In this case, Gnus will display radio buttons for such a kind of spam
  288. message as follows:
  289. @example
  290. 1. (*) multipart/alternative ( ) image/gif
  291. 2. (*) text/plain ( ) text/html
  292. @end example
  293. @item mm-inline-large-images
  294. @vindex mm-inline-large-images
  295. When displaying inline images that are larger than the window, Emacs
  296. does not enable scrolling, which means that you cannot see the whole
  297. image. To prevent this, the library tries to determine the image size
  298. before displaying it inline, and if it doesn't fit the window, the
  299. library will display it externally (e.g., with @samp{ImageMagick} or
  300. @samp{xv}). Setting this variable to @code{t} disables this check and
  301. makes the library display all inline images as inline, regardless of
  302. their size. If you set this variable to @code{resize}, the image will
  303. be displayed resized to fit in the window, if Emacs has the ability to
  304. resize images.
  305. @item mm-inline-large-images-proportion
  306. @vindex mm-inline-images-max-proportion
  307. The proportion used when resizing large images.
  308. @item mm-inline-override-types
  309. @vindex mm-inline-override-types
  310. @code{mm-inlined-types} may include regular expressions, for example to
  311. specify that all @samp{text/.*} parts be displayed inline. If a user
  312. prefers to have a type that matches such a regular expression be treated
  313. as an attachment, that can be accomplished by setting this variable to a
  314. list containing that type. For example assuming @code{mm-inlined-types}
  315. includes @samp{text/.*}, then including @samp{text/html} in this
  316. variable will cause @samp{text/html} parts to be treated as attachments.
  317. @item mm-text-html-renderer
  318. @vindex mm-text-html-renderer
  319. This selects the function used to render @acronym{HTML}. The predefined
  320. renderers are selected by the symbols @code{gnus-article-html},
  321. @code{w3m}@footnote{See @uref{http://emacs-w3m.namazu.org/} for more
  322. information about emacs-w3m}, @code{links}, @code{lynx},
  323. @code{w3m-standalone} or @code{html2text}. If @code{nil} use an
  324. external viewer. You can also specify a function, which will be
  325. called with a @acronym{MIME} handle as the argument.
  326. @item mm-inline-text-html-with-images
  327. @vindex mm-inline-text-html-with-images
  328. Some @acronym{HTML} mails might have the trick of spammers using
  329. @samp{<img>} tags. It is likely to be intended to verify whether you
  330. have read the mail. You can prevent your personal information from
  331. leaking by setting this option to @code{nil} (which is the default).
  332. For emacs-w3m, you may use the command @kbd{t} on the image anchor to
  333. show an image even if it is @code{nil}.@footnote{The command @kbd{T}
  334. will load all images. If you have set the option
  335. @code{w3m-key-binding} to @code{info}, use @kbd{i} or @kbd{I}
  336. instead.}
  337. @item mm-w3m-safe-url-regexp
  338. @vindex mm-w3m-safe-url-regexp
  339. A regular expression that matches safe URL names, i.e., URLs that are
  340. unlikely to leak personal information when rendering @acronym{HTML}
  341. email (the default value is @samp{\\`cid:}). If @code{nil} consider
  342. all URLs safe. In Gnus, this will be overridden according to the value
  343. of the variable @code{gnus-safe-html-newsgroups}, @xref{Various
  344. Various, ,Various Various, gnus, Gnus Manual}.
  345. @item mm-inline-text-html-with-w3m-keymap
  346. @vindex mm-inline-text-html-with-w3m-keymap
  347. You can use emacs-w3m command keys in the inlined text/html part by
  348. setting this option to non-@code{nil}. The default value is @code{t}.
  349. @item mm-external-terminal-program
  350. @vindex mm-external-terminal-program
  351. The program used to start an external terminal.
  352. @item mm-enable-external
  353. @vindex mm-enable-external
  354. Indicate whether external @acronym{MIME} handlers should be used.
  355. If @code{t}, all defined external @acronym{MIME} handlers are used. If
  356. @code{nil}, files are saved to disk (@code{mailcap-save-binary-file}).
  357. If it is the symbol @code{ask}, you are prompted before the external
  358. @acronym{MIME} handler is invoked.
  359. When you launch an attachment through mailcap (@pxref{mailcap}) an
  360. attempt is made to use a safe viewer with the safest options---this isn't
  361. the case if you save it to disk and launch it in a different way
  362. (command line or double-clicking). Anyhow, if you want to be sure not
  363. to launch any external programs, set this variable to @code{nil} or
  364. @code{ask}.
  365. @end table
  366. @node Files and Directories
  367. @section Files and Directories
  368. @table @code
  369. @item mm-default-directory
  370. @vindex mm-default-directory
  371. The default directory for saving attachments. If @code{nil} use
  372. @code{default-directory}.
  373. @item mm-tmp-directory
  374. @vindex mm-tmp-directory
  375. Directory for storing temporary files.
  376. @item mm-file-name-rewrite-functions
  377. @vindex mm-file-name-rewrite-functions
  378. A list of functions used for rewriting file names of @acronym{MIME}
  379. parts. Each function is applied successively to the file name.
  380. Ready-made functions include
  381. @table @code
  382. @item mm-file-name-delete-control
  383. @findex mm-file-name-delete-control
  384. Delete all control characters.
  385. @item mm-file-name-delete-gotchas
  386. @findex mm-file-name-delete-gotchas
  387. Delete characters that could have unintended consequences when used
  388. with flawed shell scripts, i.e., @samp{|}, @samp{>} and @samp{<}; and
  389. @samp{-}, @samp{.} as the first character.
  390. @item mm-file-name-delete-whitespace
  391. @findex mm-file-name-delete-whitespace
  392. Remove all whitespace.
  393. @item mm-file-name-trim-whitespace
  394. @findex mm-file-name-trim-whitespace
  395. Remove leading and trailing whitespace.
  396. @item mm-file-name-collapse-whitespace
  397. @findex mm-file-name-collapse-whitespace
  398. Collapse multiple whitespace characters.
  399. @item mm-file-name-replace-whitespace
  400. @findex mm-file-name-replace-whitespace
  401. @vindex mm-file-name-replace-whitespace
  402. Replace whitespace with underscores. Set the variable
  403. @code{mm-file-name-replace-whitespace} to any other string if you do
  404. not like underscores.
  405. @end table
  406. The standard Emacs functions @code{capitalize}, @code{downcase},
  407. @code{upcase} and @code{upcase-initials} might also prove useful.
  408. @item mm-path-name-rewrite-functions
  409. @vindex mm-path-name-rewrite-functions
  410. List of functions used for rewriting the full file names of @acronym{MIME}
  411. parts. This is used when viewing parts externally, and is meant for
  412. transforming the absolute name so that non-compliant programs can find
  413. the file where it's saved.
  414. @end table
  415. @node New Viewers
  416. @section New Viewers
  417. Here's an example viewer for displaying @code{text/enriched} inline:
  418. @lisp
  419. (defun mm-display-enriched-inline (handle)
  420. (let (text)
  421. (with-temp-buffer
  422. (mm-insert-part handle)
  423. (save-window-excursion
  424. (enriched-decode (point-min) (point-max))
  425. (setq text (buffer-string))))
  426. (mm-insert-inline handle text)))
  427. @end lisp
  428. We see that the function takes a @acronym{MIME} handle as its parameter. It
  429. then goes to a temporary buffer, inserts the text of the part, does some
  430. work on the text, stores the result, goes back to the buffer it was
  431. called from and inserts the result.
  432. The two important helper functions here are @code{mm-insert-part} and
  433. @code{mm-insert-inline}. The first function inserts the text of the
  434. handle in the current buffer. It handles charset and/or content
  435. transfer decoding. The second function just inserts whatever text you
  436. tell it to insert, but it also sets things up so that the text can be
  437. ``undisplayed'' in a convenient manner.
  438. @node Composing
  439. @chapter Composing
  440. @cindex Composing
  441. @cindex MIME Composing
  442. @cindex MML
  443. @cindex MIME Meta Language
  444. Creating a @acronym{MIME} message is boring and non-trivial. Therefore,
  445. a library called @code{mml} has been defined that parses a language
  446. called @acronym{MML} (@acronym{MIME} Meta Language) and generates
  447. @acronym{MIME} messages.
  448. @findex mml-generate-mime
  449. The main interface function is @code{mml-generate-mime}. It will
  450. examine the contents of the current (narrowed-to) buffer and return a
  451. string containing the @acronym{MIME} message.
  452. @menu
  453. * Simple MML Example:: An example @acronym{MML} document.
  454. * MML Definition:: All valid @acronym{MML} elements.
  455. * Advanced MML Example:: Another example @acronym{MML} document.
  456. * Encoding Customization:: Variables that affect encoding.
  457. * Charset Translation:: How charsets are mapped from @sc{mule} to @acronym{MIME}.
  458. * Conversion:: Going from @acronym{MIME} to @acronym{MML} and vice versa.
  459. * Flowed text:: Soft and hard newlines.
  460. @end menu
  461. @node Simple MML Example
  462. @section Simple MML Example
  463. Here's a simple @samp{multipart/alternative}:
  464. @example
  465. <#multipart type=alternative>
  466. This is a plain text part.
  467. <#part type=text/enriched>
  468. <center>This is a centered enriched part</center>
  469. <#/multipart>
  470. @end example
  471. After running this through @code{mml-generate-mime}, we get this:
  472. @example
  473. Content-Type: multipart/alternative; boundary="=-=-="
  474. --=-=-=
  475. This is a plain text part.
  476. --=-=-=
  477. Content-Type: text/enriched
  478. <center>This is a centered enriched part</center>
  479. --=-=-=--
  480. @end example
  481. @node MML Definition
  482. @section MML Definition
  483. The @acronym{MML} language is very simple. It looks a bit like an SGML
  484. application, but it's not.
  485. The main concept of @acronym{MML} is the @dfn{part}. Each part can be of a
  486. different type or use a different charset. The way to delineate a part
  487. is with a @samp{<#part ...>} tag. Multipart parts can be introduced
  488. with the @samp{<#multipart ...>} tag. Parts are ended by the
  489. @samp{<#/part>} or @samp{<#/multipart>} tags. Parts started with the
  490. @samp{<#part ...>} tags are also closed by the next open tag.
  491. There's also the @samp{<#external ...>} tag. These introduce
  492. @samp{external/message-body} parts.
  493. Each tag can contain zero or more parameters on the form
  494. @samp{parameter=value}. The values may be enclosed in quotation marks,
  495. but that's not necessary unless the value contains white space. So
  496. @samp{filename=/home/user/#hello$^yes} is perfectly valid.
  497. The following parameters have meaning in @acronym{MML}; parameters that have no
  498. meaning are ignored. The @acronym{MML} parameter names are the same as the
  499. @acronym{MIME} parameter names; the things in the parentheses say which
  500. header it will be used in.
  501. @table @samp
  502. @item type
  503. The @acronym{MIME} type of the part (@code{Content-Type}).
  504. @item filename
  505. Use the contents of the file in the body of the part
  506. (@code{Content-Disposition}).
  507. @item recipient-filename
  508. Use this as the file name in the generated @acronym{MIME} message for
  509. the recipient. That is, even if the file is called @file{foo.txt}
  510. locally, use this name instead in the @code{Content-Disposition} in
  511. the sent message.
  512. @item charset
  513. The contents of the body of the part are to be encoded in the character
  514. set specified (@code{Content-Type}). @xref{Charset Translation}.
  515. @item name
  516. Might be used to suggest a file name if the part is to be saved
  517. to a file (@code{Content-Type}).
  518. @item disposition
  519. Valid values are @samp{inline} and @samp{attachment}
  520. (@code{Content-Disposition}).
  521. @item encoding
  522. Valid values are @samp{7bit}, @samp{8bit}, @samp{quoted-printable} and
  523. @samp{base64} (@code{Content-Transfer-Encoding}). @xref{Charset
  524. Translation}.
  525. @item description
  526. A description of the part (@code{Content-Description}).
  527. @item creation-date
  528. RFC822 date when the part was created (@code{Content-Disposition}).
  529. @item modification-date
  530. RFC822 date when the part was modified (@code{Content-Disposition}).
  531. @item read-date
  532. RFC822 date when the part was read (@code{Content-Disposition}).
  533. @item recipients
  534. Who to encrypt/sign the part to. This field is used to override any
  535. auto-detection based on the To/CC headers.
  536. @item sender
  537. Identity used to sign the part. This field is used to override the
  538. default key used.
  539. @item size
  540. The size (in octets) of the part (@code{Content-Disposition}).
  541. @item sign
  542. What technology to sign this @acronym{MML} part with (@code{smime}, @code{pgp}
  543. or @code{pgpmime})
  544. @item encrypt
  545. What technology to encrypt this @acronym{MML} part with (@code{smime},
  546. @code{pgp} or @code{pgpmime})
  547. @end table
  548. Parameters for @samp{text/plain}:
  549. @table @samp
  550. @item format
  551. Formatting parameter for the text, valid values include @samp{fixed}
  552. (the default) and @samp{flowed}. Normally you do not specify this
  553. manually, since it requires the textual body to be formatted in a
  554. special way described in RFC 2646. @xref{Flowed text}.
  555. @end table
  556. Parameters for @samp{application/octet-stream}:
  557. @table @samp
  558. @item type
  559. Type of the part; informal---meant for human readers
  560. (@code{Content-Type}).
  561. @end table
  562. Parameters for @samp{message/external-body}:
  563. @table @samp
  564. @item access-type
  565. A word indicating the supported access mechanism by which the file may
  566. be obtained. Values include @samp{ftp}, @samp{anon-ftp}, @samp{tftp},
  567. @samp{localfile}, and @samp{mailserver}. (@code{Content-Type}.)
  568. @item expiration
  569. The RFC822 date after which the file may no longer be fetched.
  570. (@code{Content-Type}.)
  571. @item size
  572. The size (in octets) of the file. (@code{Content-Type}.)
  573. @item permission
  574. Valid values are @samp{read} and @samp{read-write}
  575. (@code{Content-Type}).
  576. @end table
  577. Parameters for @samp{sign=smime}:
  578. @table @samp
  579. @item keyfile
  580. File containing key and certificate for signer.
  581. @end table
  582. Parameters for @samp{encrypt=smime}:
  583. @table @samp
  584. @item certfile
  585. File containing certificate for recipient.
  586. @end table
  587. @node Advanced MML Example
  588. @section Advanced MML Example
  589. Here's a complex multipart message. It's a @samp{multipart/mixed} that
  590. contains many parts, one of which is a @samp{multipart/alternative}.
  591. @example
  592. <#multipart type=mixed>
  593. <#part type=image/jpeg filename=~/rms.jpg disposition=inline>
  594. <#multipart type=alternative>
  595. This is a plain text part.
  596. <#part type=text/enriched name=enriched.txt>
  597. <center>This is a centered enriched part</center>
  598. <#/multipart>
  599. This is a new plain text part.
  600. <#part disposition=attachment>
  601. This plain text part is an attachment.
  602. <#/multipart>
  603. @end example
  604. And this is the resulting @acronym{MIME} message:
  605. @example
  606. Content-Type: multipart/mixed; boundary="=-=-="
  607. --=-=-=
  608. --=-=-=
  609. Content-Type: image/jpeg;
  610. filename="~/rms.jpg"
  611. Content-Disposition: inline;
  612. filename="~/rms.jpg"
  613. Content-Transfer-Encoding: base64
  614. /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRof
  615. Hh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/wAALCAAwADABAREA/8QAHwAA
  616. AQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQR
  617. BRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RF
  618. RkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ip
  619. qrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/9oACAEB
  620. AAA/AO/rifFHjldNuGsrDa0qcSSHkA+gHrXKw+LtWLrMb+RgTyhbr+HSug07xNqV9fQtZrNI
  621. AyiaE/NuBPOOOP0rvRNE880KOC8TbXXGCv1FPqjrF4LDR7u5L7SkTFT/ALWOP1xXgTuXfc7E
  622. sx6nua6rwp4IvvEM8chCxWxOdzn7wz6V9AaB4S07w9p5itow0rDLSY5Pt9K43xO66P4xs71m
  623. 2QXiGCbA4yOVJ9+1aYORkdK434lyNH4ahCnG66VT9Nj15JFbPdX0MS43M4VQf5/yr2vSpLnw
  624. 5ZW8dlCZ8KFXjOPX0/mK6rSPEGt3Angu44fNEReHYNvIH3TzXDeKNO8RX+kSX2ouZkicTIOc
  625. L+g7E810ulFjpVtv3bwgB3HJyK5L4quY/C9sVxk3ij/xx6850u7t1mtp/wDlpEw3An3Jr3Dw
  626. 34gsbWza4nBlhC5LDsaW6+IFgupQyCF3iHH7gA7c9R9ay7zx6t7aX9jHC4smhfBkGCvHGfrm
  627. tLQ7hbnRrV1GPkAP1x1/Hr+Ncr8Vzjwrbf8AX6v/AKA9eQRyYlQk8Yx9K6XTNbkgia2ciSIn
  628. 7p5Ga9Atte0LTLKO6it4i7dVRFJDcZ4PvXN+JvEMF9bILVGXJLSZ4zkjivRPDaeX4b08HOTC
  629. pOffmua+KkbS+GLVUGT9tT/0B68eeIpIFYjB70+OOVXyoOM9+M1eaWeCLzHPyHGO/NVWvJJm
  630. jQ8KGH1NfQWhXSXmh2c8eArRLwO3HSv/2Q==
  631. --=-=-=
  632. Content-Type: multipart/alternative; boundary="==-=-="
  633. --==-=-=
  634. This is a plain text part.
  635. --==-=-=
  636. Content-Type: text/enriched;
  637. name="enriched.txt"
  638. <center>This is a centered enriched part</center>
  639. --==-=-=--
  640. --=-=-=
  641. This is a new plain text part.
  642. --=-=-=
  643. Content-Disposition: attachment
  644. This plain text part is an attachment.
  645. --=-=-=--
  646. @end example
  647. @node Encoding Customization
  648. @section Encoding Customization
  649. @table @code
  650. @item mm-body-charset-encoding-alist
  651. @vindex mm-body-charset-encoding-alist
  652. Mapping from @acronym{MIME} charset to encoding to use. This variable is
  653. usually used except, e.g., when other requirements force a specific
  654. encoding (digitally signed messages require 7bit encodings). The
  655. default is
  656. @lisp
  657. ((iso-2022-jp . 7bit)
  658. (iso-2022-jp-2 . 7bit)
  659. (utf-16 . base64)
  660. (utf-16be . base64)
  661. (utf-16le . base64))
  662. @end lisp
  663. As an example, if you do not want to have ISO-8859-1 characters
  664. quoted-printable encoded, you may add @code{(iso-8859-1 . 8bit)} to
  665. this variable. You can override this setting on a per-message basis
  666. by using the @code{encoding} @acronym{MML} tag (@pxref{MML Definition}).
  667. @item mm-coding-system-priorities
  668. @vindex mm-coding-system-priorities
  669. Prioritize coding systems to use for outgoing messages. The default
  670. is @code{nil}, which means to use the defaults in Emacs, but is
  671. @code{(iso-8859-1 iso-2022-jp utf-8)} when running Emacs in the Japanese
  672. language environment. It is a list of coding system symbols (aliases of
  673. coding systems are also allowed, use @kbd{M-x describe-coding-system} to
  674. make sure you are specifying correct coding system names). For example,
  675. if you have configured Emacs to prefer UTF-8, but wish that outgoing
  676. messages should be sent in ISO-8859-1 if possible, you can set this
  677. variable to @code{(iso-8859-1)}. You can override this setting on a
  678. per-message basis by using the @code{charset} @acronym{MML} tag
  679. (@pxref{MML Definition}).
  680. As different hierarchies prefer different charsets, you may want to set
  681. @code{mm-coding-system-priorities} according to the hierarchy in Gnus.
  682. Here's an example:
  683. @c Corrections about preferred charsets are welcome. de, fr and fj
  684. @c should be correct, I don't know about the rest (so these are only
  685. @c examples):
  686. @lisp
  687. (add-to-list 'gnus-newsgroup-variables 'mm-coding-system-priorities)
  688. (setq gnus-parameters
  689. (nconc
  690. ;; Some charsets are just examples!
  691. '(("^cn\\." ;; Chinese
  692. (mm-coding-system-priorities
  693. '(iso-8859-1 cn-big5 chinese-iso-7bit utf-8)))
  694. ("^cz\\.\\|^pl\\." ;; Central and Eastern European
  695. (mm-coding-system-priorities '(iso-8859-2 utf-8)))
  696. ("^de\\." ;; German language
  697. (mm-coding-system-priorities '(iso-8859-1 iso-8859-15 utf-8)))
  698. ("^fr\\." ;; French
  699. (mm-coding-system-priorities '(iso-8859-15 iso-8859-1 utf-8)))
  700. ("^fj\\." ;; Japanese
  701. (mm-coding-system-priorities
  702. '(iso-8859-1 iso-2022-jp utf-8)))
  703. ("^ru\\." ;; Cyrillic
  704. (mm-coding-system-priorities
  705. '(koi8-r iso-8859-5 iso-8859-1 utf-8))))
  706. gnus-parameters))
  707. @end lisp
  708. @item mm-content-transfer-encoding-defaults
  709. @vindex mm-content-transfer-encoding-defaults
  710. Mapping from @acronym{MIME} types to encoding to use. This variable is usually
  711. used except, e.g., when other requirements force a safer encoding
  712. (digitally signed messages require 7bit encoding). Besides the normal
  713. @acronym{MIME} encodings, @code{qp-or-base64} may be used to indicate that for
  714. each case the most efficient of quoted-printable and base64 should be
  715. used.
  716. @code{qp-or-base64} has another effect. It will fold long lines so that
  717. MIME parts may not be broken by MTA@. So do @code{quoted-printable} and
  718. @code{base64}.
  719. Note that it affects body encoding only when a part is a raw forwarded
  720. message (which will be made by @code{gnus-summary-mail-forward} with the
  721. arg 2 for example) or is neither the @samp{text/*} type nor the
  722. @samp{message/*} type. Even though in those cases, you can override
  723. this setting on a per-message basis by using the @code{encoding}
  724. @acronym{MML} tag (@pxref{MML Definition}).
  725. @item mm-use-ultra-safe-encoding
  726. @vindex mm-use-ultra-safe-encoding
  727. When this is non-@code{nil}, it means that textual parts are encoded as
  728. quoted-printable if they contain lines longer than 76 characters or
  729. starting with "From " in the body. Non-7bit encodings (8bit, binary)
  730. are generally disallowed. This reduce the probability that a non-8bit
  731. clean MTA or MDA changes the message. This should never be set
  732. directly, but bound by other functions when necessary (e.g., when
  733. encoding messages that are to be digitally signed).
  734. @end table
  735. @node Charset Translation
  736. @section Charset Translation
  737. @cindex charsets
  738. During translation from @acronym{MML} to @acronym{MIME}, for each
  739. @acronym{MIME} part which has been composed inside Emacs, an appropriate
  740. charset has to be chosen.
  741. @vindex mail-parse-charset
  742. If you are running a non-@sc{mule} Emacs, this process is simple: If the
  743. part contains any non-@acronym{ASCII} (8-bit) characters, the @acronym{MIME} charset
  744. given by @code{mail-parse-charset} (a symbol) is used. (Never set this
  745. variable directly, though. If you want to change the default charset,
  746. please consult the documentation of the package which you use to process
  747. @acronym{MIME} messages.
  748. @xref{Various Message Variables, , Various Message Variables, message,
  749. Message Manual}, for example.)
  750. If there are only @acronym{ASCII} characters, the @acronym{MIME} charset US-ASCII is
  751. used, of course.
  752. @cindex MULE
  753. @cindex UTF-8
  754. @cindex Unicode
  755. @vindex mm-mime-mule-charset-alist
  756. Things are slightly more complicated when running Emacs with @sc{mule}
  757. support. In this case, a list of the @sc{mule} charsets used in the
  758. part is obtained, and the @sc{mule} charsets are translated to
  759. @acronym{MIME} charsets by consulting the table provided by Emacs itself
  760. or the variable @code{mm-mime-mule-charset-alist} for XEmacs.
  761. If this results in a single @acronym{MIME} charset, this is used to encode
  762. the part. But if the resulting list of @acronym{MIME} charsets contains more
  763. than one element, two things can happen: If it is possible to encode the
  764. part via UTF-8, this charset is used. (For this, Emacs must support
  765. the @code{utf-8} coding system, and the part must consist entirely of
  766. characters which have Unicode counterparts.) If UTF-8 is not available
  767. for some reason, the part is split into several ones, so that each one
  768. can be encoded with a single @acronym{MIME} charset. The part can only be
  769. split at line boundaries, though---if more than one @acronym{MIME} charset is
  770. required to encode a single line, it is not possible to encode the part.
  771. When running Emacs with @sc{mule} support, the preferences for which
  772. coding system to use is inherited from Emacs itself. This means that
  773. if Emacs is set up to prefer UTF-8, it will be used when encoding
  774. messages. You can modify this by altering the
  775. @code{mm-coding-system-priorities} variable though (@pxref{Encoding
  776. Customization}).
  777. The charset to be used can be overridden by setting the @code{charset}
  778. @acronym{MML} tag (@pxref{MML Definition}) when composing the message.
  779. The encoding of characters (quoted-printable, 8bit, etc.)@: is orthogonal
  780. to the discussion here, and is controlled by the variables
  781. @code{mm-body-charset-encoding-alist} and
  782. @code{mm-content-transfer-encoding-defaults} (@pxref{Encoding
  783. Customization}).
  784. @node Conversion
  785. @section Conversion
  786. @findex mime-to-mml
  787. A (multipart) @acronym{MIME} message can be converted to @acronym{MML}
  788. with the @code{mime-to-mml} function. It works on the message in the
  789. current buffer, and substitutes @acronym{MML} markup for @acronym{MIME}
  790. boundaries. Non-textual parts do not have their contents in the buffer,
  791. but instead have the contents in separate buffers that are referred to
  792. from the @acronym{MML} tags.
  793. @findex mml-to-mime
  794. An @acronym{MML} message can be converted back to @acronym{MIME} by the
  795. @code{mml-to-mime} function.
  796. These functions are in certain senses ``lossy''---you will not get back
  797. an identical message if you run @code{mime-to-mml} and then
  798. @code{mml-to-mime}. Not only will trivial things like the order of the
  799. headers differ, but the contents of the headers may also be different.
  800. For instance, the original message may use base64 encoding on text,
  801. while @code{mml-to-mime} may decide to use quoted-printable encoding, and
  802. so on.
  803. In essence, however, these two functions should be the inverse of each
  804. other. The resulting contents of the message should remain equivalent,
  805. if not identical.
  806. @node Flowed text
  807. @section Flowed text
  808. @cindex format=flowed
  809. The Emacs @acronym{MIME} library will respect the @code{use-hard-newlines}
  810. variable (@pxref{Hard and Soft Newlines, ,Hard and Soft Newlines,
  811. emacs, Emacs Manual}) when encoding a message, and the
  812. ``format=flowed'' Content-Type parameter when decoding a message.
  813. On encoding text, regardless of @code{use-hard-newlines}, lines
  814. terminated by soft newline characters are filled together and wrapped
  815. after the column decided by @code{fill-flowed-encode-column}.
  816. Quotation marks (matching @samp{^>* ?}) are respected. The variable
  817. controls how the text will look in a client that does not support
  818. flowed text, the default is to wrap after 66 characters. If hard
  819. newline characters are not present in the buffer, no flow encoding
  820. occurs.
  821. You can customize the value of the @code{mml-enable-flowed} variable
  822. to enable or disable the flowed encoding usage when newline
  823. characters are present in the buffer.
  824. On decoding flowed text, lines with soft newline characters are filled
  825. together and wrapped after the column decided by
  826. @code{fill-flowed-display-column}. The default is to wrap after
  827. @code{fill-column}.
  828. @table @code
  829. @item mm-fill-flowed
  830. @vindex mm-fill-flowed
  831. If non-@code{nil} a format=flowed article will be displayed flowed.
  832. @end table
  833. @node Interface Functions
  834. @chapter Interface Functions
  835. @cindex interface functions
  836. @cindex mail-parse
  837. The @code{mail-parse} library is an abstraction over the actual
  838. low-level libraries that are described in the next chapter.
  839. Standards change, and so programs have to change to fit in the new
  840. mold. For instance, RFC2045 describes a syntax for the
  841. @code{Content-Type} header that only allows @acronym{ASCII} characters in the
  842. parameter list. RFC2231 expands on RFC2045 syntax to provide a scheme
  843. for continuation headers and non-@acronym{ASCII} characters.
  844. The traditional way to deal with this is just to update the library
  845. functions to parse the new syntax. However, this is sometimes the wrong
  846. thing to do. In some instances it may be vital to be able to understand
  847. both the old syntax as well as the new syntax, and if there is only one
  848. library, one must choose between the old version of the library and the
  849. new version of the library.
  850. The Emacs @acronym{MIME} library takes a different tack. It defines a
  851. series of low-level libraries (@file{rfc2047.el}, @file{rfc2231.el}
  852. and so on) that parses strictly according to the corresponding
  853. standard. However, normal programs would not use the functions
  854. provided by these libraries directly, but instead use the functions
  855. provided by the @code{mail-parse} library. The functions in this
  856. library are just aliases to the corresponding functions in the latest
  857. low-level libraries. Using this scheme, programs get a consistent
  858. interface they can use, and library developers are free to create
  859. write code that handles new standards.
  860. The following functions are defined by this library:
  861. @table @code
  862. @item mail-header-parse-content-type
  863. @findex mail-header-parse-content-type
  864. Parse a @code{Content-Type} header and return a list on the following
  865. format:
  866. @lisp
  867. ("type/subtype"
  868. (attribute1 . value1)
  869. (attribute2 . value2)
  870. ...)
  871. @end lisp
  872. Here's an example:
  873. @example
  874. (mail-header-parse-content-type
  875. "image/gif; name=\"b980912.gif\"")
  876. @result{} ("image/gif" (name . "b980912.gif"))
  877. @end example
  878. @item mail-header-parse-content-disposition
  879. @findex mail-header-parse-content-disposition
  880. Parse a @code{Content-Disposition} header and return a list on the same
  881. format as the function above.
  882. @item mail-content-type-get
  883. @findex mail-content-type-get
  884. Takes two parameters---a list on the format above, and an attribute.
  885. Returns the value of the attribute.
  886. @example
  887. (mail-content-type-get
  888. '("image/gif" (name . "b980912.gif")) 'name)
  889. @result{} "b980912.gif"
  890. @end example
  891. @item mail-header-encode-parameter
  892. @findex mail-header-encode-parameter
  893. Takes a parameter string and returns an encoded version of the string.
  894. This is used for parameters in headers like @code{Content-Type} and
  895. @code{Content-Disposition}.
  896. @item mail-header-remove-comments
  897. @findex mail-header-remove-comments
  898. Return a comment-free version of a header.
  899. @example
  900. (mail-header-remove-comments
  901. "Gnus/5.070027 (Pterodactyl Gnus v0.27) (Finnish Landrace)")
  902. @result{} "Gnus/5.070027 "
  903. @end example
  904. @item mail-header-remove-whitespace
  905. @findex mail-header-remove-whitespace
  906. Remove linear white space from a header. Space inside quoted strings
  907. and comments is preserved.
  908. @example
  909. (mail-header-remove-whitespace
  910. "image/gif; name=\"Name with spaces\"")
  911. @result{} "image/gif;name=\"Name with spaces\""
  912. @end example
  913. @item mail-header-get-comment
  914. @findex mail-header-get-comment
  915. Return the last comment in a header.
  916. @example
  917. (mail-header-get-comment
  918. "Gnus/5.070027 (Pterodactyl Gnus v0.27) (Finnish Landrace)")
  919. @result{} "Finnish Landrace"
  920. @end example
  921. @item mail-header-parse-address
  922. @findex mail-header-parse-address
  923. Parse an address and return a list containing the mailbox and the
  924. plaintext name.
  925. @example
  926. (mail-header-parse-address
  927. "Hrvoje Niksic <hniksic@@srce.hr>")
  928. @result{} ("hniksic@@srce.hr" . "Hrvoje Niksic")
  929. @end example
  930. @item mail-header-parse-addresses
  931. @findex mail-header-parse-addresses
  932. Parse a string with list of addresses and return a list of elements like
  933. the one described above.
  934. @example
  935. (mail-header-parse-addresses
  936. "Hrvoje Niksic <hniksic@@srce.hr>, Steinar Bang <sb@@metis.no>")
  937. @result{} (("hniksic@@srce.hr" . "Hrvoje Niksic")
  938. ("sb@@metis.no" . "Steinar Bang"))
  939. @end example
  940. @item mail-header-parse-date
  941. @findex mail-header-parse-date
  942. Parse a date string and return an Emacs time structure.
  943. @item mail-narrow-to-head
  944. @findex mail-narrow-to-head
  945. Narrow the buffer to the header section of the buffer. Point is placed
  946. at the beginning of the narrowed buffer.
  947. @item mail-header-narrow-to-field
  948. @findex mail-header-narrow-to-field
  949. Narrow the buffer to the header under point. Understands continuation
  950. headers.
  951. @item mail-header-fold-field
  952. @findex mail-header-fold-field
  953. Fold the header under point.
  954. @item mail-header-unfold-field
  955. @findex mail-header-unfold-field
  956. Unfold the header under point.
  957. @item mail-header-field-value
  958. @findex mail-header-field-value
  959. Return the value of the field under point.
  960. @item mail-encode-encoded-word-region
  961. @findex mail-encode-encoded-word-region
  962. Encode the non-@acronym{ASCII} words in the region. For instance,
  963. @samp{Naïve} is encoded as @samp{=?iso-8859-1?q?Na=EFve?=}.
  964. @item mail-encode-encoded-word-buffer
  965. @findex mail-encode-encoded-word-buffer
  966. Encode the non-@acronym{ASCII} words in the current buffer. This function is
  967. meant to be called narrowed to the headers of a message.
  968. @item mail-encode-encoded-word-string
  969. @findex mail-encode-encoded-word-string
  970. Encode the words that need encoding in a string, and return the result.
  971. @example
  972. (mail-encode-encoded-word-string
  973. "This is naïve, baby")
  974. @result{} "This is =?iso-8859-1?q?na=EFve,?= baby"
  975. @end example
  976. @item mail-decode-encoded-word-region
  977. @findex mail-decode-encoded-word-region
  978. Decode the encoded words in the region.
  979. @item mail-decode-encoded-word-string
  980. @findex mail-decode-encoded-word-string
  981. Decode the encoded words in the string and return the result.
  982. @example
  983. (mail-decode-encoded-word-string
  984. "This is =?iso-8859-1?q?na=EFve,?= baby")
  985. @result{} "This is naïve, baby"
  986. @end example
  987. @end table
  988. Currently, @code{mail-parse} is an abstraction over @code{ietf-drums},
  989. @code{rfc2047}, @code{rfc2045} and @code{rfc2231}. These are documented
  990. in the subsequent sections.
  991. @node Basic Functions
  992. @chapter Basic Functions
  993. This chapter describes the basic, ground-level functions for parsing and
  994. handling. Covered here is parsing @code{From} lines, removing comments
  995. from header lines, decoding encoded words, parsing date headers and so
  996. on. High-level functionality is dealt with in the first chapter
  997. (@pxref{Decoding and Viewing}).
  998. @menu
  999. * rfc2045:: Encoding @code{Content-Type} headers.
  1000. * rfc2231:: Parsing @code{Content-Type} headers.
  1001. * ietf-drums:: Handling mail headers defined by RFC822bis.
  1002. * rfc2047:: En/decoding encoded words in headers.
  1003. * time-date:: Functions for parsing dates and manipulating time.
  1004. * qp:: Quoted-Printable en/decoding.
  1005. * base64:: Base64 en/decoding.
  1006. * binhex:: Binhex decoding.
  1007. * uudecode:: Uuencode decoding.
  1008. * yenc:: Yenc decoding.
  1009. * rfc1843:: Decoding HZ-encoded text.
  1010. * mailcap:: How parts are displayed is specified by the @file{.mailcap} file
  1011. @end menu
  1012. @node rfc2045
  1013. @section rfc2045
  1014. RFC2045 is the ``main'' @acronym{MIME} document, and as such, one would
  1015. imagine that there would be a lot to implement. But there isn't, since
  1016. most of the implementation details are delegated to the subsequent
  1017. RFCs.
  1018. So @file{rfc2045.el} has only a single function:
  1019. @table @code
  1020. @item rfc2045-encode-string
  1021. @findex rfc2045-encode-string
  1022. Takes a parameter and a value and returns a @samp{PARAM=VALUE} string.
  1023. @var{value} will be quoted if there are non-safe characters in it.
  1024. @end table
  1025. @node rfc2231
  1026. @section rfc2231
  1027. RFC2231 defines a syntax for the @code{Content-Type} and
  1028. @code{Content-Disposition} headers. Its snappy name is @dfn{MIME
  1029. Parameter Value and Encoded Word Extensions: Character Sets, Languages,
  1030. and Continuations}.
  1031. In short, these headers look something like this:
  1032. @example
  1033. Content-Type: application/x-stuff;
  1034. title*0*=us-ascii'en'This%20is%20even%20more%20;
  1035. title*1*=%2A%2A%2Afun%2A%2A%2A%20;
  1036. title*2="isn't it!"
  1037. @end example
  1038. They usually aren't this bad, though.
  1039. The following functions are defined by this library:
  1040. @table @code
  1041. @item rfc2231-parse-string
  1042. @findex rfc2231-parse-string
  1043. Parse a @code{Content-Type} header and return a list describing its
  1044. elements.
  1045. @example
  1046. (rfc2231-parse-string
  1047. "application/x-stuff;
  1048. title*0*=us-ascii'en'This%20is%20even%20more%20;
  1049. title*1*=%2A%2A%2Afun%2A%2A%2A%20;
  1050. title*2=\"isn't it!\"")
  1051. @result{} ("application/x-stuff"
  1052. (title . "This is even more ***fun*** isn't it!"))
  1053. @end example
  1054. @item rfc2231-get-value
  1055. @findex rfc2231-get-value
  1056. Takes one of the lists on the format above and returns
  1057. the value of the specified attribute.
  1058. @item rfc2231-encode-string
  1059. @findex rfc2231-encode-string
  1060. Encode a parameter in headers likes @code{Content-Type} and
  1061. @code{Content-Disposition}.
  1062. @end table
  1063. @node ietf-drums
  1064. @section ietf-drums
  1065. @dfn{drums} is an IETF working group that is working on the replacement
  1066. for RFC822.
  1067. The functions provided by this library include:
  1068. @table @code
  1069. @item ietf-drums-remove-comments
  1070. @findex ietf-drums-remove-comments
  1071. Remove the comments from the argument and return the results.
  1072. @item ietf-drums-remove-whitespace
  1073. @findex ietf-drums-remove-whitespace
  1074. Remove linear white space from the string and return the results.
  1075. Spaces inside quoted strings and comments are left untouched.
  1076. @item ietf-drums-get-comment
  1077. @findex ietf-drums-get-comment
  1078. Return the last most comment from the string.
  1079. @item ietf-drums-parse-address
  1080. @findex ietf-drums-parse-address
  1081. Parse an address string and return a list that contains the mailbox and
  1082. the plain text name.
  1083. @item ietf-drums-parse-addresses
  1084. @findex ietf-drums-parse-addresses
  1085. Parse a string that contains any number of comma-separated addresses and
  1086. return a list that contains mailbox/plain text pairs.
  1087. @item ietf-drums-parse-date
  1088. @findex ietf-drums-parse-date
  1089. Parse a date string and return an Emacs time structure.
  1090. @item ietf-drums-narrow-to-header
  1091. @findex ietf-drums-narrow-to-header
  1092. Narrow the buffer to the header section of the current buffer.
  1093. @end table
  1094. @node rfc2047
  1095. @section rfc2047
  1096. RFC2047 (Message Header Extensions for Non-@acronym{ASCII} Text) specifies how
  1097. non-@acronym{ASCII} text in headers are to be encoded. This is actually rather
  1098. complicated, so a number of variables are necessary to tweak what this
  1099. library does.
  1100. The following variables are tweakable:
  1101. @table @code
  1102. @item rfc2047-header-encoding-alist
  1103. @vindex rfc2047-header-encoding-alist
  1104. This is an alist of header / encoding-type pairs. Its main purpose is
  1105. to prevent encoding of certain headers.
  1106. The keys can either be header regexps, or @code{t}.
  1107. The values can be @code{nil}, in which case the header(s) in question
  1108. won't be encoded, @code{mime}, which means that they will be encoded, or
  1109. @code{address-mime}, which means the header(s) will be encoded carefully
  1110. assuming they contain addresses.
  1111. @item rfc2047-charset-encoding-alist
  1112. @vindex rfc2047-charset-encoding-alist
  1113. RFC2047 specifies two forms of encoding---@code{Q} (a
  1114. Quoted-Printable-like encoding) and @code{B} (base64). This alist
  1115. specifies which charset should use which encoding.
  1116. @item rfc2047-encode-function-alist
  1117. @vindex rfc2047-encode-function-alist
  1118. This is an alist of encoding / function pairs. The encodings are
  1119. @code{Q}, @code{B} and @code{nil}.
  1120. @item rfc2047-encoded-word-regexp
  1121. @vindex rfc2047-encoded-word-regexp
  1122. When decoding words, this library looks for matches to this regexp.
  1123. @item rfc2047-encoded-word-regexp-loose
  1124. @vindex rfc2047-encoded-word-regexp-loose
  1125. This is a version from which the regexp for the Q encoding pattern of
  1126. @code{rfc2047-encoded-word-regexp} is made loose.
  1127. @item rfc2047-encode-encoded-words
  1128. @vindex rfc2047-encode-encoded-words
  1129. The boolean variable specifies whether encoded words
  1130. (e.g., @samp{=?us-ascii?q?hello?=}) should be encoded again.
  1131. @code{rfc2047-encoded-word-regexp} is used to look for such words.
  1132. @item rfc2047-allow-irregular-q-encoded-words
  1133. @vindex rfc2047-allow-irregular-q-encoded-words
  1134. The boolean variable specifies whether irregular Q encoded words
  1135. (e.g., @samp{=?us-ascii?q?hello??=}) should be decoded. If it is
  1136. non-@code{nil}, @code{rfc2047-encoded-word-regexp-loose} is used instead
  1137. of @code{rfc2047-encoded-word-regexp} to look for encoded words.
  1138. @end table
  1139. Those were the variables, and these are this functions:
  1140. @table @code
  1141. @item rfc2047-narrow-to-field
  1142. @findex rfc2047-narrow-to-field
  1143. Narrow the buffer to the header on the current line.
  1144. @item rfc2047-encode-message-header
  1145. @findex rfc2047-encode-message-header
  1146. Should be called narrowed to the header of a message. Encodes according
  1147. to @code{rfc2047-header-encoding-alist}.
  1148. @item rfc2047-encode-region
  1149. @findex rfc2047-encode-region
  1150. Encodes all encodable words in the region specified.
  1151. @item rfc2047-encode-string
  1152. @findex rfc2047-encode-string
  1153. Encode a string and return the results.
  1154. @item rfc2047-decode-region
  1155. @findex rfc2047-decode-region
  1156. Decode the encoded words in the region.
  1157. @item rfc2047-decode-string
  1158. @findex rfc2047-decode-string
  1159. Decode a string and return the results.
  1160. @item rfc2047-encode-parameter
  1161. @findex rfc2047-encode-parameter
  1162. Encode a parameter in the RFC2047-like style. This is a substitution
  1163. for the @code{rfc2231-encode-string} function, that is the standard but
  1164. many mailers don't support it. @xref{rfc2231}.
  1165. @end table
  1166. @node time-date
  1167. @section time-date
  1168. While not really a part of the @acronym{MIME} library, it is convenient to
  1169. document this library here. It deals with parsing @code{Date} headers
  1170. and manipulating time. (Not by using tesseracts, though, I'm sorry to
  1171. say.)
  1172. These functions convert between five formats: A date string, an Emacs
  1173. time structure, a decoded time list, a second number, and a day number.
  1174. Here's a bunch of time/date/second/day examples:
  1175. @example
  1176. (parse-time-string "Sat Sep 12 12:21:54 1998 +0200")
  1177. @result{} (54 21 12 12 9 1998 6 nil 7200)
  1178. (date-to-time "Sat Sep 12 12:21:54 1998 +0200")
  1179. @result{} (13818 19266)
  1180. (float-time '(13818 19266))
  1181. @result{} 905595714.0
  1182. (seconds-to-time 905595714.0)
  1183. @result{} (13818 19266 0 0)
  1184. (time-to-days '(13818 19266))
  1185. @result{} 729644
  1186. (days-to-time 729644)
  1187. @result{} (961933 512)
  1188. (time-since '(13818 19266))
  1189. @result{} (6797 9607 984839 247000)
  1190. (time-less-p '(13818 19266) '(13818 19145))
  1191. @result{} nil
  1192. (subtract-time '(13818 19266) '(13818 19145))
  1193. @result{} (0 121)
  1194. (days-between "Sat Sep 12 12:21:54 1998 +0200"
  1195. "Sat Sep 07 12:21:54 1998 +0200")
  1196. @result{} 5
  1197. (date-leap-year-p 2000)
  1198. @result{} t
  1199. (time-to-day-in-year '(13818 19266))
  1200. @result{} 255
  1201. (time-to-number-of-days
  1202. (time-since
  1203. (date-to-time "Mon, 01 Jan 2001 02:22:26 GMT")))
  1204. @result{} 4314.095589286675
  1205. @end example
  1206. And finally, we have @code{safe-date-to-time}, which does the same as
  1207. @code{date-to-time}, but returns a zero time if the date is
  1208. syntactically malformed.
  1209. The five data representations used are the following:
  1210. @table @var
  1211. @item date
  1212. An RFC822 (or similar) date string. For instance: @code{"Sat Sep 12
  1213. 12:21:54 1998 +0200"}.
  1214. @item time
  1215. An internal Emacs time. For instance: @code{(13818 26466 0 0)}.
  1216. @item seconds
  1217. A floating point representation of the internal Emacs time. For
  1218. instance: @code{905595714.0}.
  1219. @item days
  1220. An integer number representing the number of days since 00000101. For
  1221. instance: @code{729644}.
  1222. @item decoded time
  1223. A list of decoded time. For instance: @code{(54 21 12 12 9 1998 6 t
  1224. 7200)}.
  1225. @end table
  1226. All the examples above represent the same moment.
  1227. These are the functions available:
  1228. @table @code
  1229. @item date-to-time
  1230. Take a date and return a time.
  1231. @item float-time
  1232. Take a time and return seconds. (This is a built-in function.)
  1233. @item seconds-to-time
  1234. Take seconds and return a time.
  1235. @item time-to-days
  1236. Take a time and return days.
  1237. @item days-to-time
  1238. Take days and return a time.
  1239. @item date-to-day
  1240. Take a date and return days.
  1241. @item time-to-number-of-days
  1242. Take a time and return the number of days that represents.
  1243. @item safe-date-to-time
  1244. Take a date and return a time. If the date is not syntactically valid,
  1245. return a ``zero'' time.
  1246. @item time-less-p
  1247. Take two times and say whether the first time is less (i.e., earlier)
  1248. than the second time.
  1249. @item time-since
  1250. Take a time and return a time saying how long it was since that time.
  1251. @item subtract-time
  1252. Take two times and subtract the second from the first. I.e., return
  1253. the time between the two times.
  1254. @item days-between
  1255. Take two days and return the number of days between those two days.
  1256. @item date-leap-year-p
  1257. Take a year number and say whether it's a leap year.
  1258. @item time-to-day-in-year
  1259. Take a time and return the day number within the year that the time is
  1260. in.
  1261. @end table
  1262. @node qp
  1263. @section qp
  1264. This library deals with decoding and encoding Quoted-Printable text.
  1265. Very briefly explained, qp encoding means translating all 8-bit
  1266. characters (and lots of control characters) into things that look like
  1267. @samp{=EF}; that is, an equal sign followed by the byte encoded as a hex
  1268. string.
  1269. The following functions are defined by the library:
  1270. @table @code
  1271. @item quoted-printable-decode-region
  1272. @findex quoted-printable-decode-region
  1273. QP-decode all the encoded text in the specified region.
  1274. @item quoted-printable-decode-string
  1275. @findex quoted-printable-decode-string
  1276. Decode the QP-encoded text in a string and return the results.
  1277. @item quoted-printable-encode-region
  1278. @findex quoted-printable-encode-region
  1279. QP-encode all the encodable characters in the specified region. The third
  1280. optional parameter @var{fold} specifies whether to fold long lines.
  1281. (Long here means 72.)
  1282. @item quoted-printable-encode-string
  1283. @findex quoted-printable-encode-string
  1284. QP-encode all the encodable characters in a string and return the
  1285. results.
  1286. @end table
  1287. @node base64
  1288. @section base64
  1289. @cindex base64
  1290. Base64 is an encoding that encodes three bytes into four characters,
  1291. thereby increasing the size by about 33%. The alphabet used for
  1292. encoding is very resistant to mangling during transit.
  1293. The following functions are defined by this library:
  1294. @table @code
  1295. @item base64-encode-region
  1296. @findex base64-encode-region
  1297. base64 encode the selected region. Return the length of the encoded
  1298. text. Optional third argument @var{no-line-break} means do not break
  1299. long lines into shorter lines.
  1300. @item base64-encode-string
  1301. @findex base64-encode-string
  1302. base64 encode a string and return the result.
  1303. @item base64-decode-region
  1304. @findex base64-decode-region
  1305. base64 decode the selected region. Return the length of the decoded
  1306. text. If the region can't be decoded, return @code{nil} and don't
  1307. modify the buffer.
  1308. @item base64-decode-string
  1309. @findex base64-decode-string
  1310. base64 decode a string and return the result. If the string can't be
  1311. decoded, @code{nil} is returned.
  1312. @end table
  1313. @node binhex
  1314. @section binhex
  1315. @cindex binhex
  1316. @cindex Apple
  1317. @cindex Macintosh
  1318. @code{binhex} is an encoding that originated in Macintosh environments.
  1319. The following function is supplied to deal with these:
  1320. @table @code
  1321. @item binhex-decode-region
  1322. @findex binhex-decode-region
  1323. Decode the encoded text in the region. If given a third parameter, only
  1324. decode the @code{binhex} header and return the filename.
  1325. @end table
  1326. @node uudecode
  1327. @section uudecode
  1328. @cindex uuencode
  1329. @cindex uudecode
  1330. @code{uuencode} is probably still the most popular encoding of binaries
  1331. used on Usenet, although @code{base64} rules the mail world.
  1332. The following function is supplied by this package:
  1333. @table @code
  1334. @item uudecode-decode-region
  1335. @findex uudecode-decode-region
  1336. Decode the text in the region.
  1337. @end table
  1338. @node yenc
  1339. @section yenc
  1340. @cindex yenc
  1341. @code{yenc} is used for encoding binaries on Usenet. The following
  1342. function is supplied by this package:
  1343. @table @code
  1344. @item yenc-decode-region
  1345. @findex yenc-decode-region
  1346. Decode the encoded text in the region.
  1347. @end table
  1348. @node rfc1843
  1349. @section rfc1843
  1350. @cindex rfc1843
  1351. @cindex HZ
  1352. @cindex Chinese
  1353. RFC1843 deals with mixing Chinese and @acronym{ASCII} characters in messages. In
  1354. essence, RFC1843 switches between @acronym{ASCII} and Chinese by doing this:
  1355. @example
  1356. This sentence is in @acronym{ASCII}.
  1357. The next sentence is in GB.~@{<:Ky2;S@{#,NpJ)l6HK!#~@}Bye.
  1358. @end example
  1359. Simple enough, and widely used in China.
  1360. The following functions are available to handle this encoding:
  1361. @table @code
  1362. @item rfc1843-decode-region
  1363. Decode HZ-encoded text in the region.
  1364. @item rfc1843-decode-string
  1365. Decode a HZ-encoded string and return the result.
  1366. @end table
  1367. @node mailcap
  1368. @section mailcap
  1369. The @file{~/.mailcap} file is parsed by most @acronym{MIME}-aware message
  1370. handlers and describes how elements are supposed to be displayed.
  1371. Here's an example file:
  1372. @example
  1373. image/*; gimp -8 %s
  1374. audio/wav; wavplayer %s
  1375. application/msword; catdoc %s ; copiousoutput ; nametemplate=%s.doc
  1376. @end example
  1377. This says that all image files should be displayed with @code{gimp},
  1378. that WAVE audio files should be played by @code{wavplayer}, and that
  1379. MS-WORD files should be inlined by @code{catdoc}.
  1380. The @code{mailcap} library parses this file, and provides functions for
  1381. matching types.
  1382. @table @code
  1383. @item mailcap-mime-data
  1384. @vindex mailcap-mime-data
  1385. This variable is an alist of alists containing backup viewing rules.
  1386. @end table
  1387. Interface functions:
  1388. @table @code
  1389. @item mailcap-parse-mailcaps
  1390. @findex mailcap-parse-mailcaps
  1391. Parse the @file{~/.mailcap} file.
  1392. @item mailcap-mime-info
  1393. Takes a @acronym{MIME} type as its argument and returns the matching viewer.
  1394. @end table
  1395. @node Standards
  1396. @chapter Standards
  1397. The Emacs @acronym{MIME} library implements handling of various elements
  1398. according to a (somewhat) large number of RFCs, drafts and standards
  1399. documents. This chapter lists the relevant ones. They can all be
  1400. fetched from @uref{http://quimby.gnus.org/notes/}.
  1401. @table @dfn
  1402. @item RFC822
  1403. @itemx STD11
  1404. Standard for the Format of ARPA Internet Text Messages.
  1405. @item RFC1036
  1406. Standard for Interchange of USENET Messages
  1407. @item RFC2045
  1408. Format of Internet Message Bodies
  1409. @item RFC2046
  1410. Media Types
  1411. @item RFC2047
  1412. Message Header Extensions for Non-@acronym{ASCII} Text
  1413. @item RFC2048
  1414. Registration Procedures
  1415. @item RFC2049
  1416. Conformance Criteria and Examples
  1417. @item RFC2231
  1418. @acronym{MIME} Parameter Value and Encoded Word Extensions: Character Sets,
  1419. Languages, and Continuations
  1420. @item RFC1843
  1421. HZ---A Data Format for Exchanging Files of Arbitrarily Mixed Chinese and
  1422. @acronym{ASCII} characters
  1423. @item draft-ietf-drums-msg-fmt-05.txt
  1424. Draft for the successor of RFC822
  1425. @item RFC2112
  1426. The @acronym{MIME} Multipart/Related Content-type
  1427. @item RFC1892
  1428. The Multipart/Report Content Type for the Reporting of Mail System
  1429. Administrative Messages
  1430. @item RFC2183
  1431. Communicating Presentation Information in Internet Messages: The
  1432. Content-Disposition Header Field
  1433. @item RFC2646
  1434. Documentation of the text/plain format parameter for flowed text.
  1435. @end table
  1436. @node GNU Free Documentation License
  1437. @chapter GNU Free Documentation License
  1438. @include doclicense.texi
  1439. @node Index
  1440. @chapter Index
  1441. @printindex cp
  1442. @bye
  1443. @c Local Variables:
  1444. @c mode: texinfo
  1445. @c coding: utf-8
  1446. @c End: