1 \input texinfo @c -*-texinfo-*-
3 @setfilename emacs-mime
4 @settitle Emacs MIME Manual
10 * Emacs MIME: (emacs-mime). The MIME de/composition library.
15 @setchapternewpage odd
19 This file documents the Emacs MIME interface functionality.
21 Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
23 Permission is granted to copy, distribute and/or modify this document
24 under the terms of the GNU Free Documentation License, Version 1.1 or
25 any later version published by the Free Software Foundation; with no
26 Invariant Sections, with the Front-Cover texts being ``A GNU
27 Manual'', and with the Back-Cover Texts as in (a) below. A copy of the
28 license is included in the section entitled ``GNU Free Documentation
29 License'' in the Emacs manual.
31 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
32 this GNU Manual, like GNU software. Copies published by the Free
33 Software Foundation raise funds for GNU development.''
35 This document is part of a collection distributed under the GNU Free
36 Documentation License. If you want to distribute this document
37 separately from the collection, you can do so by adding a copy of the
38 license to the document, as described in section 6 of the license.
44 @title Emacs MIME Manual
46 @author by Lars Magne Ingebrigtsen
49 @vskip 0pt plus 1filll
50 Copyright @copyright{} 1998, 1999, 2000 Free Software Foundation, Inc.
52 Permission is granted to copy, distribute and/or modify this document
53 under the terms of the GNU Free Documentation License, Version 1.1 or
54 any later version published by the Free Software Foundation; with the
55 Invariant Sections being none, with the Front-Cover texts being ``A GNU
56 Manual'', and with the Back-Cover Texts as in (a) below. A copy of the
57 license is included in the section entitled ``GNU Free Documentation
58 License'' in the Emacs manual.
60 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
61 this GNU Manual, like GNU software. Copies published by the Free
62 Software Foundation raise funds for GNU development.''
64 This document is part of a collection distributed under the GNU Free
65 Documentation License. If you want to distribute this document
66 separately from the collection, you can do so by adding a copy of the
67 license to the document, as described in section 6 of the license.
76 This manual documents the libraries used to compose and display
79 This is not a manual meant for users; it's a manual directed at people
80 who want to write functions and commands that manipulate @sc{mime}
83 @sc{mime} is short for @dfn{Multipurpose Internet Mail Extensions}.
84 This standard is documented in a number of RFCs; mainly RFC2045 (Format
85 of Internet Message Bodies), RFC2046 (Media Types), RFC2047 (Message
86 Header Extensions for Non-ASCII Text), RFC2048 (Registration
87 Procedures), RFC2049 (Conformance Criteria and Examples). It is highly
88 recommended that anyone who intends writing @sc{mime}-compliant software
89 read at least RFC2045 and RFC2047.
92 * Interface Functions:: An abstraction over the basic functions.
93 * Basic Functions:: Utility and basic parsing functions.
94 * Decoding and Viewing:: A framework for decoding and viewing.
95 * Composing:: MML; a language for describing MIME parts.
96 * Standards:: A summary of RFCs and working documents used.
97 * Index:: Function and variable index.
101 @node Interface Functions
102 @chapter Interface Functions
103 @cindex interface functions
106 The @code{mail-parse} library is an abstraction over the actual
107 low-level libraries that are described in the next chapter.
109 Standards change, and so programs have to change to fit in the new
110 mold. For instance, RFC2045 describes a syntax for the
111 @code{Content-Type} header that only allows ASCII characters in the
112 parameter list. RFC2231 expands on RFC2045 syntax to provide a scheme
113 for continuation headers and non-ASCII characters.
115 The traditional way to deal with this is just to update the library
116 functions to parse the new syntax. However, this is sometimes the wrong
117 thing to do. In some instances it may be vital to be able to understand
118 both the old syntax as well as the new syntax, and if there is only one
119 library, one must choose between the old version of the library and the
120 new version of the library.
122 The Emacs MIME library takes a different tack. It defines a series of
123 low-level libraries (@file{rfc2047.el}, @file{rfc2231.el} and so on)
124 that parses strictly according to the corresponding standard. However,
125 normal programs would not use the functions provided by these libraries
126 directly, but instead use the functions provided by the
127 @code{mail-parse} library. The functions in this library are just
128 aliases to the corresponding functions in the latest low-level
129 libraries. Using this scheme, programs get a consistent interface they
130 can use, and library developers are free to create write code that
131 handles new standards.
133 The following functions are defined by this library:
136 @item mail-header-parse-content-type
137 @findex mail-header-parse-content-type
138 Parse a @code{Content-Type} header and return a list on the following
143 (attribute1 . value1)
144 (attribute2 . value2)
151 (mail-header-parse-content-type
152 "image/gif; name=\"b980912.gif\"")
153 @result{} ("image/gif" (name . "b980912.gif"))
156 @item mail-header-parse-content-disposition
157 @findex mail-header-parse-content-disposition
158 Parse a @code{Content-Disposition} header and return a list on the same
159 format as the function above.
161 @item mail-content-type-get
162 @findex mail-content-type-get
163 Takes two parameters---a list on the format above, and an attribute.
164 Returns the value of the attribute.
167 (mail-content-type-get
168 '("image/gif" (name . "b980912.gif")) 'name)
169 @result{} "b980912.gif"
172 @item mail-header-encode-parameter
173 @findex mail-header-encode-parameter
174 Takes a parameter string and returns an encoded version of the string.
175 This is used for parameters in headers like @code{Content-Type} and
176 @code{Content-Disposition}.
178 @item mail-header-remove-comments
179 @findex mail-header-remove-comments
180 Return a comment-free version of a header.
183 (mail-header-remove-comments
184 "Gnus/5.070027 (Pterodactyl Gnus v0.27) (Finnish Landrace)")
185 @result{} "Gnus/5.070027 "
188 @item mail-header-remove-whitespace
189 @findex mail-header-remove-whitespace
190 Remove linear white space from a header. Space inside quoted strings
191 and comments is preserved.
194 (mail-header-remove-whitespace
195 "image/gif; name=\"Name with spaces\"")
196 @result{} "image/gif;name=\"Name with spaces\""
199 @item mail-header-get-comment
200 @findex mail-header-get-comment
201 Return the last comment in a header.
204 (mail-header-get-comment
205 "Gnus/5.070027 (Pterodactyl Gnus v0.27) (Finnish Landrace)")
206 @result{} "Finnish Landrace"
209 @item mail-header-parse-address
210 @findex mail-header-parse-address
211 Parse an address and return a list containing the mailbox and the
215 (mail-header-parse-address
216 "Hrvoje Niksic <hniksic@@srce.hr>")
217 @result{} ("hniksic@@srce.hr" . "Hrvoje Niksic")
220 @item mail-header-parse-addresses
221 @findex mail-header-parse-addresses
222 Parse a string with list of addresses and return a list of elements like
223 the one described above.
226 (mail-header-parse-addresses
227 "Hrvoje Niksic <hniksic@@srce.hr>, Steinar Bang <sb@@metis.no>")
228 @result{} (("hniksic@@srce.hr" . "Hrvoje Niksic")
229 ("sb@@metis.no" . "Steinar Bang"))
232 @item mail-header-parse-date
233 @findex mail-header-parse-date
234 Parse a date string and return an Emacs time structure.
236 @item mail-narrow-to-head
237 @findex mail-narrow-to-head
238 Narrow the buffer to the header section of the buffer. Point is placed
239 at the beginning of the narrowed buffer.
241 @item mail-header-narrow-to-field
242 @findex mail-header-narrow-to-field
243 Narrow the buffer to the header under point.
245 @item mail-encode-encoded-word-region
246 @findex mail-encode-encoded-word-region
247 Encode the non-ASCII words in the region. For instance,
248 @samp{Naïve} is encoded as @samp{=?iso-8859-1?q?Na=EFve?=}.
250 @item mail-encode-encoded-word-buffer
251 @findex mail-encode-encoded-word-buffer
252 Encode the non-ASCII words in the current buffer. This function is
253 meant to be called narrowed to the headers of a message.
255 @item mail-encode-encoded-word-string
256 @findex mail-encode-encoded-word-string
257 Encode the words that need encoding in a string, and return the result.
260 (mail-encode-encoded-word-string
261 "This is naïve, baby")
262 @result{} "This is =?iso-8859-1?q?na=EFve,?= baby"
265 @item mail-decode-encoded-word-region
266 @findex mail-decode-encoded-word-region
267 Decode the encoded words in the region.
269 @item mail-decode-encoded-word-string
270 @findex mail-decode-encoded-word-string
271 Decode the encoded words in the string and return the result.
274 (mail-decode-encoded-word-string
275 "This is =?iso-8859-1?q?na=EFve,?= baby")
276 @result{} "This is naïve, baby"
281 Currently, @code{mail-parse} is an abstraction over @code{ietf-drums},
282 @code{rfc2047}, @code{rfc2045} and @code{rfc2231}. These are documented
283 in the subsequent sections.
287 @node Basic Functions
288 @chapter Basic Functions
290 This chapter describes the basic, ground-level functions for parsing and
291 handling. Covered here is parsing @code{From} lines, removing comments
292 from header lines, decoding encoded words, parsing date headers and so
293 on. High-level functionality is dealt with in the next chapter
294 (@pxref{Decoding and Viewing}).
297 * rfc2045:: Encoding @code{Content-Type} headers.
298 * rfc2231:: Parsing @code{Content-Type} headers.
299 * ietf-drums:: Handling mail headers defined by RFC822bis.
300 * rfc2047:: En/decoding encoded words in headers.
301 * time-date:: Functions for parsing dates and manipulating time.
302 * qp:: Quoted-Printable en/decoding.
303 * base64:: Base64 en/decoding.
304 * binhex:: Binhex decoding.
305 * uudecode:: Uuencode decoding.
306 * rfc1843:: Decoding HZ-encoded text.
307 * mailcap:: How parts are displayed is specified by the @file{.mailcap} file
314 RFC2045 is the ``main'' @sc{mime} document, and as such, one would
315 imagine that there would be a lot to implement. But there isn't, since
316 most of the implementation details are delegated to the subsequent
319 So @file{rfc2045.el} has only a single function:
322 @item rfc2045-encode-string
323 @findex rfc2045-encode-string
324 Takes a parameter and a value and returns a @samp{PARAM=VALUE} string.
325 @var{value} will be quoted if there are non-safe characters in it.
332 RFC2231 defines a syntax for the @code{Content-Type} and
333 @code{Content-Disposition} headers. Its snappy name is @dfn{MIME
334 Parameter Value and Encoded Word Extensions: Character Sets, Languages,
337 In short, these headers look something like this:
340 Content-Type: application/x-stuff;
341 title*0*=us-ascii'en'This%20is%20even%20more%20;
342 title*1*=%2A%2A%2Afun%2A%2A%2A%20;
346 They usually aren't this bad, though.
348 The following functions are defined by this library:
351 @item rfc2231-parse-string
352 @findex rfc2231-parse-string
353 Parse a @code{Content-Type} header and return a list describing its
357 (rfc2231-parse-string
358 "application/x-stuff;
359 title*0*=us-ascii'en'This%20is%20even%20more%20;
360 title*1*=%2A%2A%2Afun%2A%2A%2A%20;
361 title*2=\"isn't it!\"")
362 @result{} ("application/x-stuff"
363 (title . "This is even more ***fun*** isn't it!"))
366 @item rfc2231-get-value
367 @findex rfc2231-get-value
368 Takes one of the lists on the format above and returns
369 the value of the specified attribute.
371 @item rfc2231-encode-string
372 @findex rfc2231-encode-string
373 Encode a parameter in headers likes @code{Content-Type} and
374 @code{Content-Disposition}.
382 @dfn{drums} is an IETF working group that is working on the replacement
385 The functions provided by this library include:
388 @item ietf-drums-remove-comments
389 @findex ietf-drums-remove-comments
390 Remove the comments from the argument and return the results.
392 @item ietf-drums-remove-whitespace
393 @findex ietf-drums-remove-whitespace
394 Remove linear white space from the string and return the results.
395 Spaces inside quoted strings and comments are left untouched.
397 @item ietf-drums-get-comment
398 @findex ietf-drums-get-comment
399 Return the last most comment from the string.
401 @item ietf-drums-parse-address
402 @findex ietf-drums-parse-address
403 Parse an address string and return a list that contains the mailbox and
406 @item ietf-drums-parse-addresses
407 @findex ietf-drums-parse-addresses
408 Parse a string that contains any number of comma-separated addresses and
409 return a list that contains mailbox/plain text pairs.
411 @item ietf-drums-parse-date
412 @findex ietf-drums-parse-date
413 Parse a date string and return an Emacs time structure.
415 @item ietf-drums-narrow-to-header
416 @findex ietf-drums-narrow-to-header
417 Narrow the buffer to the header section of the current buffer.
425 RFC2047 (Message Header Extensions for Non-ASCII Text) specifies how
426 non-ASCII text in headers are to be encoded. This is actually rather
427 complicated, so a number of variables are necessary to tweak what this
430 The following variables are tweakable:
433 @item rfc2047-default-charset
434 @vindex rfc2047-default-charset
435 Characters in this charset should not be decoded by this library.
436 This defaults to @code{iso-8859-1}.
438 @item rfc2047-header-encoding-list
439 @vindex rfc2047-header-encoding-list
440 This is an alist of header / encoding-type pairs. Its main purpose is
441 to prevent encoding of certain headers.
443 The keys can either be header regexps, or @code{t}.
445 The values can be either @code{nil}, in which case the header(s) in
446 question won't be encoded, or @code{mime}, which means that they will be
449 @item rfc2047-charset-encoding-alist
450 @vindex rfc2047-charset-encoding-alist
451 RFC2047 specifies two forms of encoding---@code{Q} (a
452 Quoted-Printable-like encoding) and @code{B} (base64). This alist
453 specifies which charset should use which encoding.
455 @item rfc2047-encoding-function-alist
456 @vindex rfc2047-encoding-function-alist
457 This is an alist of encoding / function pairs. The encodings are
458 @code{Q}, @code{B} and @code{nil}.
460 @item rfc2047-q-encoding-alist
461 @vindex rfc2047-q-encoding-alist
462 The @code{Q} encoding isn't quite the same for all headers. Some
463 headers allow a narrower range of characters, and that is what this
464 variable is for. It's an alist of header regexps / allowable character
467 @item rfc2047-encoded-word-regexp
468 @vindex rfc2047-encoded-word-regexp
469 When decoding words, this library looks for matches to this regexp.
473 Those were the variables, and these are this functions:
476 @item rfc2047-narrow-to-field
477 @findex rfc2047-narrow-to-field
478 Narrow the buffer to the header on the current line.
480 @item rfc2047-encode-message-header
481 @findex rfc2047-encode-message-header
482 Should be called narrowed to the header of a message. Encodes according
483 to @code{rfc2047-header-encoding-alist}.
485 @item rfc2047-encode-region
486 @findex rfc2047-encode-region
487 Encodes all encodable words in the region specified.
489 @item rfc2047-encode-string
490 @findex rfc2047-encode-string
491 Encode a string and return the results.
493 @item rfc2047-decode-region
494 @findex rfc2047-decode-region
495 Decode the encoded words in the region.
497 @item rfc2047-decode-string
498 @findex rfc2047-decode-string
499 Decode a string and return the results.
507 While not really a part of the @sc{mime} library, it is convenient to
508 document this library here. It deals with parsing @code{Date} headers
509 and manipulating time. (Not by using tesseracts, though, I'm sorry to
512 These functions convert between five formats: A date string, an Emacs
513 time structure, a decoded time list, a second number, and a day number.
515 The functions have quite self-explanatory names, so the following just
516 gives an overview of which functions are available.
519 (parse-time-string "Sat Sep 12 12:21:54 1998 +0200")
520 @result{} (54 21 12 12 9 1998 6 nil 7200)
522 (date-to-time "Sat Sep 12 12:21:54 1998 +0200")
523 @result{} (13818 19266)
525 (time-to-seconds '(13818 19266))
526 @result{} 905595714.0
528 (seconds-to-time 905595714.0)
529 @result{} (13818 19266 0)
531 (time-to-days '(13818 19266))
534 (days-to-time 729644)
535 @result{} (961933 65536)
537 (time-since '(13818 19266))
540 (time-less-p '(13818 19266) '(13818 19145))
543 (subtract-time '(13818 19266) '(13818 19145))
546 (days-between "Sat Sep 12 12:21:54 1998 +0200"
547 "Sat Sep 07 12:21:54 1998 +0200")
550 (date-leap-year-p 2000)
553 (time-to-day-in-year '(13818 19266))
556 (time-to-number-of-days
558 (date-to-time "Mon, 01 Jan 2001 02:22:26 GMT")))
559 @result{} 4.146122685185185
562 And finally, we have @code{safe-date-to-time}, which does the same as
563 @code{date-to-time}, but returns a zero time if the date is
564 syntactically malformed.
571 This library deals with decoding and encoding Quoted-Printable text.
573 Very briefly explained, qp encoding means translating all 8-bit
574 characters (and lots of control characters) into things that look like
575 @samp{=EF}; that is, an equal sign followed by the byte encoded as a hex
578 The following functions are defined by the library:
581 @item quoted-printable-decode-region
582 @findex quoted-printable-decode-region
583 QP-decode all the encoded text in the specified region.
585 @item quoted-printable-decode-string
586 @findex quoted-printable-decode-string
587 Decode the QP-encoded text in a string and return the results.
589 @item quoted-printable-encode-region
590 @findex quoted-printable-encode-region
591 QP-encode all the encodable characters in the specified region. The third
592 optional parameter @var{fold} specifies whether to fold long lines.
593 (Long here means 72.)
595 @item quoted-printable-encode-string
596 @findex quoted-printable-encode-string
597 QP-encode all the encodable characters in a string and return the
607 Base64 is an encoding that encodes three bytes into four characters,
608 thereby increasing the size by about 33%. The alphabet used for
609 encoding is very resistant to mangling during transit.
611 The following functions are defined by this library:
614 @item base64-encode-region
615 @findex base64-encode-region
616 base64 encode the selected region. Return the length of the encoded
617 text. Optional third argument @var{no-line-break} means do not break
618 long lines into shorter lines.
620 @item base64-encode-string
621 @findex base64-encode-string
622 base64 encode a string and return the result.
624 @item base64-decode-region
625 @findex base64-decode-region
626 base64 decode the selected region. Return the length of the decoded
627 text. If the region can't be decoded, return @code{nil} and don't
630 @item base64-decode-string
631 @findex base64-decode-string
632 base64 decode a string and return the result. If the string can't be
633 decoded, @code{nil} is returned.
644 @code{binhex} is an encoding that originated in Macintosh environments.
645 The following function is supplied to deal with these:
648 @item binhex-decode-region
649 @findex binhex-decode-region
650 Decode the encoded text in the region. If given a third parameter, only
651 decode the @code{binhex} header and return the filename.
661 @code{uuencode} is probably still the most popular encoding of binaries
662 used on Usenet, although @code{base64} rules the mail world.
664 The following function is supplied by this package:
667 @item uudecode-decode-region
668 @findex uudecode-decode-region
669 Decode the text in the region.
679 RFC1843 deals with mixing Chinese and ASCII characters in messages. In
680 essence, RFC1843 switches between ASCII and Chinese by doing this:
683 This sentence is in ASCII.
684 The next sentence is in GB.~@{<:Ky2;S@{#,NpJ)l6HK!#~@}Bye.
687 Simple enough, and widely used in China.
689 The following functions are available to handle this encoding:
692 @item rfc1843-decode-region
693 Decode HZ-encoded text in the region.
695 @item rfc1843-decode-string
696 Decode a HZ-encoded string and return the result.
704 The @file{~/.mailcap} file is parsed by most @sc{mime}-aware message
705 handlers and describes how elements are supposed to be displayed.
706 Here's an example file:
710 audio/wav; wavplayer %s
713 This says that all image files should be displayed with @code{gimp}, and
714 that realaudio files should be played by @code{rvplayer}.
716 The @code{mailcap} library parses this file, and provides functions for
720 @item mailcap-mime-data
721 @vindex mailcap-mime-data
722 This variable is an alist of alists containing backup viewing rules.
729 @item mailcap-parse-mailcaps
730 @findex mailcap-parse-mailcaps
731 Parse the @code{~/.mailcap} file.
733 @item mailcap-mime-info
734 Takes a @sc{mime} type as its argument and returns the matching viewer.
741 @node Decoding and Viewing
742 @chapter Decoding and Viewing
744 This chapter deals with decoding and viewing @sc{mime} messages on a
747 The main idea is to first analyze a @sc{mime} article, and then allow
748 other programs to do things based on the list of @dfn{handles} that are
749 returned as a result of this analysis.
752 * Dissection:: Analyzing a @sc{mime} message.
753 * Handles:: Handle manipulations.
754 * Display:: Displaying handles.
755 * Customization:: Variables that affect display.
756 * New Viewers:: How to write your own viewers.
763 The @code{mm-dissect-buffer} is the function responsible for dissecting
764 a @sc{mime} article. If given a multipart message, it will recursively
765 descend the message, following the structure, and return a tree of
766 @sc{mime} handles that describes the structure of the message.
772 A @sc{mime} handle is a list that fully describes a @sc{mime}
775 The following macros can be used to access elements in a handle:
778 @item mm-handle-buffer
779 @findex mm-handle-buffer
780 Return the buffer that holds the contents of the undecoded @sc{mime}
784 @findex mm-handle-type
785 Return the parsed @code{Content-Type} of the part.
787 @item mm-handle-encoding
788 @findex mm-handle-encoding
789 Return the @code{Content-Transfer-Encoding} of the part.
791 @item mm-handle-undisplayer
792 @findex mm-handle-undisplayer
793 Return the object that can be used to remove the displayed part (if it
796 @item mm-handle-set-undisplayer
797 @findex mm-handle-set-undisplayer
798 Set the undisplayer object.
800 @item mm-handle-disposition
801 @findex mm-handle-disposition
802 Return the parsed @code{Content-Disposition} of the part.
804 @item mm-handle-disposition
805 @findex mm-handle-disposition
806 Return the description of the part.
808 @item mm-get-content-id
809 Returns the handle(s) referred to by @code{Content-ID}.
817 Functions for displaying, removing and saving.
820 @item mm-display-part
821 @findex mm-display-part
825 @findex mm-remove-part
826 Remove the part (if it has been displayed).
829 @findex mm-inlinable-p
830 Say whether a @sc{mime} type can be displayed inline.
832 @item mm-automatic-display-p
833 @findex mm-automatic-display-p
834 Say whether a @sc{mime} type should be displayed automatically.
836 @item mm-destroy-part
837 @findex mm-destroy-part
838 Free all resources occupied by a part.
842 Offer to save the part in a file.
846 Offer to pipe the part to some process.
848 @item mm-interactively-view-part
849 @findex mm-interactively-view-part
850 Prompt for a mailcap method to use to view the part.
856 @section Customization
860 @item mm-inline-media-tests
861 This is an alist where the key is a @sc{mime} type, the second element
862 is a function to display the part @dfn{inline} (i.e., inside Emacs), and
863 the third element is a form to be @code{eval}ed to say whether the part
864 can be displayed inline.
866 This variable specifies whether a part @emph{can} be displayed inline,
867 and, if so, how to do it. It does not say whether parts are
868 @emph{actually} displayed inline.
870 @item mm-inlined-types
871 This, on the other hand, says what types are to be displayed inline, if
872 they satisfy the conditions set by the variable above. It's a list of
873 @sc{mime} media types.
875 @item mm-automatic-display
876 This is a list of types that are to be displayed ``automatically'', but
877 only if the above variable allows it. That is, only inlinable parts can
878 be displayed automatically.
880 @item mm-attachment-override-types
881 Some @sc{mime} agents create parts that have a content-disposition of
882 @samp{attachment}. This variable allows overriding that disposition and
883 displaying the part inline. (Note that the disposition is only
884 overridden if we are able to, and want to, display the part inline.)
886 @item mm-discouraged-alternatives
887 List of @sc{mime} types that are discouraged when viewing
888 @samp{multipart/alternative}. Viewing agents are supposed to view the
889 last possible part of a message, as that is supposed to be the richest.
890 However, users may prefer other types instead, and this list says what
891 types are most unwanted. If, for instance, @samp{text/html} parts are
892 very unwanted, and @samp{text/richtech} parts are somewhat unwanted,
893 then the value of this variable should be set to:
896 ("text/html" "text/richtext")
899 @item mm-inline-large-images-p
900 When displaying inline images that are larger than the window, XEmacs
901 does not enable scrolling, which means that you cannot see the whole
902 image. To prevent this, the library tries to determine the image size
903 before displaying it inline, and if it doesn't fit the window, the
904 library will display it externally (e.g. with @samp{ImageMagick} or
905 @samp{xv}). Setting this variable to @code{t} disables this check and
906 makes the library display all inline images as inline, regardless of
909 @item mm-inline-override-p
910 @code{mm-inlined-types} may include regular expressions, for example to
911 specify that all @samp{text/.*} parts be displayed inline. If a user
912 prefers to have a type that matches such a regular expression be treated
913 as an attachment, that can be accomplished by setting this variable to a
914 list containing that type. For example assuming @code{mm-inlined-types}
915 includes @samp{text/.*}, then including @samp{text/html} in this
916 variable will cause @samp{text/html} parts to be treated as attachments.
924 Here's an example viewer for displaying @code{text/enriched} inline:
927 (defun mm-display-enriched-inline (handle)
930 (mm-insert-part handle)
931 (save-window-excursion
932 (enriched-decode (point-min) (point-max))
933 (setq text (buffer-string))))
934 (mm-insert-inline handle text)))
937 We see that the function takes a @sc{mime} handle as its parameter. It
938 then goes to a temporary buffer, inserts the text of the part, does some
939 work on the text, stores the result, goes back to the buffer it was
940 called from and inserts the result.
942 The two important helper functions here are @code{mm-insert-part} and
943 @code{mm-insert-inline}. The first function inserts the text of the
944 handle in the current buffer. It handles charset and/or content
945 transfer decoding. The second function just inserts whatever text you
946 tell it to insert, but it also sets things up so that the text can be
947 ``undisplayed' in a convenient manner.
953 @cindex MIME Composing
955 @cindex MIME Meta Language
957 Creating a @sc{mime} message is boring and non-trivial. Therefore, a
958 library called @code{mml} has been defined that parses a language called
959 MML (@sc{mime} Meta Language) and generates @sc{mime} messages.
961 @findex mml-generate-mime
962 The main interface function is @code{mml-generate-mime}. It will
963 examine the contents of the current (narrowed-to) buffer and return a
964 string containing the @sc{mime} message.
967 * Simple MML Example:: An example MML document.
968 * MML Definition:: All valid MML elements.
969 * Advanced MML Example:: Another example MML document.
970 * Charset Translation:: How charsets are mapped from @sc{mule} to MIME.
971 * Conversion:: Going from @sc{mime} to MML and vice versa.
975 @node Simple MML Example
976 @section Simple MML Example
978 Here's a simple @samp{multipart/alternative}:
981 <#multipart type=alternative>
982 This is a plain text part.
983 <#part type=text/enriched>
984 <center>This is a centered enriched part</center>
988 After running this through @code{mml-generate-mime}, we get this:
991 Content-Type: multipart/alternative; boundary="=-=-="
997 This is a plain text part.
1000 Content-Type: text/enriched
1003 <center>This is a centered enriched part</center>
1009 @node MML Definition
1010 @section MML Definition
1012 The MML language is very simple. It looks a bit like an SGML
1013 application, but it's not.
1015 The main concept of MML is the @dfn{part}. Each part can be of a
1016 different type or use a different charset. The way to delineate a part
1017 is with a @samp{<#part ...>} tag. Multipart parts can be introduced
1018 with the @samp{<#multipart ...>} tag. Parts are ended by the
1019 @samp{<#/part>} or @samp{<#/multipart>} tags. Parts started with the
1020 @samp{<#part ...>} tags are also closed by the next open tag.
1022 There's also the @samp{<#external ...>} tag. These introduce
1023 @samp{external/message-body} parts.
1025 Each tag can contain zero or more parameters on the form
1026 @samp{parameter=value}. The values may be enclosed in quotation marks,
1027 but that's not necessary unless the value contains white space. So
1028 @samp{filename=/home/user/#hello$^yes} is perfectly valid.
1030 The following parameters have meaning in MML; parameters that have no
1031 meaning are ignored. The MML parameter names are the same as the
1032 @sc{mime} parameter names; the things in the parentheses say which
1033 header it will be used in.
1037 The @sc{mime} type of the part (@code{Content-Type}).
1040 Use the contents of the file in the body of the part
1041 (@code{Content-Disposition}).
1044 The contents of the body of the part are to be encoded in the character
1045 set speficied (@code{Content-Type}).
1048 Might be used to suggest a file name if the part is to be saved
1049 to a file (@code{Content-Type}).
1052 Valid values are @samp{inline} and @samp{attachment}
1053 (@code{Content-Disposition}).
1056 Valid values are @samp{7bit}, @samp{8bit}, @samp{quoted-printable} and
1057 @samp{base64} (@code{Content-Transfer-Encoding}).
1060 A description of the part (@code{Content-Description}).
1063 RFC822 date when the part was created (@code{Content-Disposition}).
1065 @item modification-date
1066 RFC822 date when the part was modified (@code{Content-Disposition}).
1069 RFC822 date when the part was read (@code{Content-Disposition}).
1072 The size (in octets) of the part (@code{Content-Disposition}).
1075 What technology to sign this MML part with (@code{smime} or
1079 What technology to encrypt this MML part with (@code{smime} or
1084 Parameters for @samp{application/octet-stream}:
1088 Type of the part; informal---meant for human readers
1089 (@code{Content-Type}).
1092 Parameters for @samp{message/external-body}:
1096 A word indicating the supported access mechanism by which the file may
1097 be obtained. Values include @samp{ftp}, @samp{anon-ftp}, @samp{tftp},
1098 @samp{localfile}, and @samp{mailserver}. (@code{Content-Type}.)
1101 The RFC822 date after which the file may no longer be fetched.
1102 (@code{Content-Type}.)
1105 The size (in octets) of the file. (@code{Content-Type}.)
1108 Valid values are @samp{read} and @samp{read-write}
1109 (@code{Content-Type}).
1113 Parameters for @samp{sign=smime}:
1118 File containing key and certificate for signer.
1122 Parameters for @samp{encrypt=smime}:
1127 File containing certificate for recipient.
1132 @node Advanced MML Example
1133 @section Advanced MML Example
1135 Here's a complex multipart message. It's a @samp{multipart/mixed} that
1136 contains many parts, one of which is a @samp{multipart/alternative}.
1139 <#multipart type=mixed>
1140 <#part type=image/jpeg filename=~/rms.jpg disposition=inline>
1141 <#multipart type=alternative>
1142 This is a plain text part.
1143 <#part type=text/enriched name=enriched.txt>
1144 <center>This is a centered enriched part</center>
1146 This is a new plain text part.
1147 <#part disposition=attachment>
1148 This plain text part is an attachment.
1152 And this is the resulting @sc{mime} message:
1155 Content-Type: multipart/mixed; boundary="=-=-="
1163 Content-Type: image/jpeg;
1164 filename="~/rms.jpg"
1165 Content-Disposition: inline;
1166 filename="~/rms.jpg"
1167 Content-Transfer-Encoding: base64
1169 /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRof
1170 Hh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/wAALCAAwADABAREA/8QAHwAA
1171 AQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQR
1172 BRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RF
1173 RkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ip
1174 qrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/9oACAEB
1175 AAA/AO/rifFHjldNuGsrDa0qcSSHkA+gHrXKw+LtWLrMb+RgTyhbr+HSug07xNqV9fQtZrNI
1176 AyiaE/NuBPOOOP0rvRNE880KOC8TbXXGCv1FPqjrF4LDR7u5L7SkTFT/ALWOP1xXgTuXfc7E
1177 sx6nua6rwp4IvvEM8chCxWxOdzn7wz6V9AaB4S07w9p5itow0rDLSY5Pt9K43xO66P4xs71m
1178 2QXiGCbA4yOVJ9+1aYORkdK434lyNH4ahCnG66VT9Nj15JFbPdX0MS43M4VQf5/yr2vSpLnw
1179 5ZW8dlCZ8KFXjOPX0/mK6rSPEGt3Angu44fNEReHYNvIH3TzXDeKNO8RX+kSX2ouZkicTIOc
1180 L+g7E810ulFjpVtv3bwgB3HJyK5L4quY/C9sVxk3ij/xx6850u7t1mtp/wDlpEw3An3Jr3Dw
1181 34gsbWza4nBlhC5LDsaW6+IFgupQyCF3iHH7gA7c9R9ay7zx6t7aX9jHC4smhfBkGCvHGfrm
1182 tLQ7hbnRrV1GPkAP1x1/Hr+Ncr8Vzjwrbf8AX6v/AKA9eQRyYlQk8Yx9K6XTNbkgia2ciSIn
1183 7p5Ga9Atte0LTLKO6it4i7dVRFJDcZ4PvXN+JvEMF9bILVGXJLSZ4zkjivRPDaeX4b08HOTC
1184 pOffmua+KkbS+GLVUGT9tT/0B68eeIpIFYjB70+OOVXyoOM9+M1eaWeCLzHPyHGO/NVWvJJm
1185 jQ8KGH1NfQWhXSXmh2c8eArRLwO3HSv/2Q==
1188 Content-Type: multipart/alternative; boundary="==-=-="
1194 This is a plain text part.
1197 Content-Type: text/enriched;
1201 <center>This is a centered enriched part</center>
1207 This is a new plain text part.
1210 Content-Disposition: attachment
1213 This plain text part is an attachment.
1218 @node Charset Translation
1219 @section Charset Translation
1222 During translation from MML to @sc{mime}, for each @sc{mime} part which
1223 has been composed inside Emacs, an appropriate charset has to be chosen.
1225 @vindex mail-parse-charset
1226 If you are running a non-@sc{mule} Emacs, this process is simple: If the
1227 part contains any non-ASCII (8-bit) characters, the @sc{mime} charset
1228 given by @code{mail-parse-charset} (a symbol) is used. (Never set this
1229 variable directly, though. If you want to change the default charset,
1230 please consult the documentation of the package which you use to process
1232 @xref{Various Message Variables, , Various Message Variables, message,
1233 Message Manual}, for example.)
1234 If there are only ASCII characters, the @sc{mime} charset US-ASCII is
1240 @vindex mm-mime-mule-charset-alist
1241 Things are slightly more complicated when running Emacs with @sc{mule}
1242 support. In this case, a list of the @sc{mule} charsets used in the
1243 part is obtained, and the @sc{mule} charsets are translated to @sc{mime}
1244 charsets by consulting the variable @code{mm-mime-mule-charset-alist}.
1245 If this results in a single @sc{mime} charset, this is used to encode
1246 the part. But if the resulting list of @sc{mime} charsets contains more
1247 than one element, two things can happen: If it is possible to encode the
1248 part via UTF-8, this charset is used. (For this, Emacs must support
1249 the @code{utf-8} coding system, and the part must consist entirely of
1250 characters which have Unicode counterparts.) If UTF-8 is not available
1251 for some reason, the part is split into several ones, so that each one
1252 can be encoded with a single @sc{mime} charset. The part can only be
1253 split at line boundaries, though---if more than one @sc{mime} charset is
1254 required to encode a single line, it is not possible to encode the part.
1260 A (multipart) @sc{mime} message can be converted to MML with the
1261 @code{mime-to-mml} function. It works on the message in the current
1262 buffer, and substitutes MML markup for @sc{mime} boundaries.
1263 Non-textual parts do not have their contents in the buffer, but instead
1264 have the contents in separate buffers that are referred to from the MML
1268 An MML message can be converted back to @sc{mime} by the
1269 @code{mml-to-mime} function.
1271 These functions are in certain senses ``lossy''---you will not get back
1272 an identical message if you run @sc{mime-to-mml} and then
1273 @sc{mml-to-mime}. Not only will trivial things like the order of the
1274 headers differ, but the contents of the headers may also be different.
1275 For instance, the original message may use base64 encoding on text,
1276 while @sc{mml-to-mime} may decide to use quoted-printable encoding, and
1279 In essence, however, these two functions should be the inverse of each
1280 other. The resulting contents of the message should remain equivalent,
1287 The Emacs @sc{mime} library implements handling of various elements
1288 according to a (somewhat) large number of RFCs, drafts and standards
1289 documents. This chapter lists the relevant ones. They can all be
1290 fetched from @samp{http://quimby.gnus.org/notes/}.
1295 Standard for the Format of ARPA Internet Text Messages.
1298 Standard for Interchange of USENET Messages
1301 Format of Internet Message Bodies
1307 Message Header Extensions for Non-ASCII Text
1310 Registration Procedures
1313 Conformance Criteria and Examples
1316 MIME Parameter Value and Encoded Word Extensions: Character Sets,
1317 Languages, and Continuations
1320 HZ - A Data Format for Exchanging Files of Arbitrarily Mixed Chinese and
1323 @item draft-ietf-drums-msg-fmt-05.txt
1324 Draft for the successor of RFC822
1327 The MIME Multipart/Related Content-type
1330 The Multipart/Report Content Type for the Reporting of Mail System
1331 Administrative Messages
1334 Communicating Presentation Information in Internet Messages: The
1335 Content-Disposition Header Field