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