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