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