1 \input texinfo @c -*-mode: texinfo; coding: latin-1 -*-
3 @setfilename ../info/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,99,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,99,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 @sc{ascii} characters in the
112 parameter list. RFC2231 expands on RFC2045 syntax to provide a scheme
113 for continuation headers and non-@sc{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:
135 @defun mail-header-parse-content-type string
136 Parse @var{string}, a @code{Content-Type} header, and return a
137 content-type list in the following format:
141 (attribute1 . value1)
142 (attribute2 . value2)
149 (mail-header-parse-content-type
150 "image/gif; name=\"b980912.gif\"")
151 @result{} ("image/gif" (name . "b980912.gif"))
155 @defun mail-header-parse-content-disposition string
156 Parse @var{string}, a @code{Content-Disposition} header, and return a
157 content-type list in the format above.
160 @defun mail-content-type-get ct attribute
161 @findex mail-content-type-get
162 Returns the value of the given @var{attribute} from the content-type
166 (mail-content-type-get
167 '("image/gif" (name . "b980912.gif")) 'name)
168 @result{} "b980912.gif"
172 @defun mail-header-encode-parameter param value
173 Takes a parameter string @samp{@var{param}=@var{value}} and returns an
174 encoded version of it. This is used for parameters in headers like
175 @samp{Content-Type} and @samp{Content-Disposition}.
178 @defun mail-header-remove-comments string
179 Return a comment-free version of @var{string}.
182 (mail-header-remove-comments
183 "Gnus/5.070027 (Pterodactyl Gnus v0.27) (Finnish Landrace)")
184 @result{} "Gnus/5.070027 "
188 @defun mail-header-remove-whitespace string
189 Remove linear white space from @var{string}. Space inside quoted
190 strings and comments is preserved.
193 (mail-header-remove-whitespace
194 "image/gif; name=\"Name with spaces\"")
195 @result{} "image/gif;name=\"Name with spaces\""
199 @defun mail-header-get-comment string
200 Return the last comment in @var{string}.
203 (mail-header-get-comment
204 "Gnus/5.070027 (Pterodactyl Gnus v0.27) (Finnish Landrace)")
205 @result{} "Finnish Landrace"
210 @defun mail-header-parse-address string
211 Parse an address string @var{string} and return a list containing the
212 mailbox and the plaintext name.
215 (mail-header-parse-address
216 "Hrvoje Niksic <hniksic@@srce.hr>")
217 @result{} ("hniksic@@srce.hr" . "Hrvoje Niksic")
221 @defun mail-header-parse-addresses string
222 Parse @var{string} as a list of addresses and return a list of elements
223 like 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"))
233 @defun mail-header-parse-date string
234 Parse a date @var{string} and return an Emacs time structure.
237 @defun 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.
242 @defun mail-header-narrow-to-field
243 Narrow the buffer to the header under point.
246 @defun mail-encode-encoded-word-region start end
247 Encode the non-@sc{ascii} words in the region @var{start}to @var{end}. For
248 instance, @samp{Naïve} is encoded as @samp{=?iso-8859-1?q?Na=EFve?=}.
251 @defun mail-encode-encoded-word-buffer
252 Encode the non-@sc{ascii} words in the current buffer. This function is
253 meant to be called with the buffer narrowed to the headers of a message.
256 @defun mail-encode-encoded-word-string string
257 Encode the words that need encoding in @var{string}, and return the
261 (mail-encode-encoded-word-string
262 "This is naïve, baby")
263 @result{} "This is =?iso-8859-1?q?na=EFve,?= baby"
267 @defun mail-decode-encoded-word-region start end
268 Decode the encoded words in the region @var{start}to @var{end}.
271 @defun mail-decode-encoded-word-string string
272 Decode the encoded words in @var{string} and return the result.
275 (mail-decode-encoded-word-string
276 "This is =?iso-8859-1?q?na=EFve,?= baby")
277 @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 mailcap files
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:
321 @defun rfc2045-encode-string parameter value
322 @findex rfc2045-encode-string
323 Takes a @var{parameter} and a @var{value} and returns a
324 @samp{@var{param}=@var{value}} string. @var{value} will be quoted if
325 there are non-safe characters in it.
332 RFC2231 defines a syntax for the @samp{Content-Type} and
333 @samp{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:
350 @defun rfc2231-parse-string string
351 Parse a @samp{Content-Type} header @var{string} and return a list
352 describing its elements.
355 (rfc2231-parse-string
356 "application/x-stuff;
357 title*0*=us-ascii'en'This%20is%20even%20more%20;
358 title*1*=%2A%2A%2Afun%2A%2A%2A%20;
359 title*2=\"isn't it!\"")
360 @result{} ("application/x-stuff"
361 (title . "This is even more ***fun*** isn't it!"))
365 @defun rfc2231-get-value ct attribute
366 Takes a list @var{ct} of the format above and returns the value of the
367 specified @var{attribute}.
370 @defun rfc2231-encode-string parameter value
371 Encode the string @samp{@var{parameter}=@var{value}} for inclusion in
372 headers likes @samp{Content-Type} and @samp{Content-Disposition}.
378 @dfn{drums} is an IETF working group that is working on the replacement
381 The functions provided by this library include:
383 @defun ietf-drums-remove-comments string
384 Remove the comments from @var{string} and return the result.
387 @defun ietf-drums-remove-whitespace string
388 Remove linear white space from @var{string} and return the result.
389 Spaces inside quoted strings and comments are left untouched.
392 @defun ietf-drums-get-comment string
393 Return the last most comment from @var{string}.
396 @defun ietf-drums-parse-address string
397 Parse an address @var{string} and return a list of the mailbox and the
401 @defun ietf-drums-parse-addresses string
402 Parse @var{string}, containing any number of comma-separated addresses,
403 and return a list of mailbox/plain text pairs.
406 @defun ietf-drums-parse-date string
407 Parse the date @var{string} and return an Emacs time structure.
410 @defun ietf-drums-narrow-to-header
411 Narrow the buffer to the header section of the current buffer.
418 RFC2047 (Message Header Extensions for Non-ASCII Text) specifies how
419 non-@sc{ascii} text in headers are to be encoded. This is actually rather
420 complicated, so a number of variables are necessary to tweak what this
423 The following variables are tweakable:
425 @defvar rfc2047-default-charset
426 Characters in this charset should not be decoded by this library.
427 This defaults to @samp{iso-8859-1}.
430 @defvar rfc2047-header-encoding-list
431 This is an alist of header / encoding-type pairs. Its main purpose is
432 to prevent encoding of certain headers.
435 The keys can either be header regexps, or @code{t}.
437 The values can be either @code{nil}, in which case the header(s) in
438 question won't be encoded, or @code{mime}, which means that they will be
441 @defvar rfc2047-charset-encoding-alist
442 RFC2047 specifies two forms of encoding---@code{Q} (a
443 Quoted-Printable-like encoding) and @code{B} (base64). This alist
444 specifies which charset should use which encoding.
447 @defvar rfc2047-encoding-function-alist
448 This is an alist of encoding / function pairs. The encodings are
449 @code{Q}, @code{B} and @code{nil}.
452 @defvar rfc2047-q-encoding-alist
453 The @code{Q} encoding isn't quite the same for all headers. Some
454 headers allow a narrower range of characters, and that is what this
455 variable is for. It's an alist of header regexps and allowable character
459 @defvar rfc2047-encoded-word-regexp
460 When decoding words, this library looks for matches to this regexp.
463 Those were the variables, and these are the functions:
465 @defun rfc2047-narrow-to-field
466 Narrow the buffer to the header on the current line.
469 @defun rfc2047-encode-message-header
470 Should be called narrowed to the header of a message. Encodes according
471 to @code{rfc2047-header-encoding-alist}.
474 @defun rfc2047-encode-region start end
475 Encodes all encodable words in the region @var{start} to @var{end}.
478 @defun rfc2047-encode-string string
479 Encode @var{string} and return the result.
482 @defun rfc2047-decode-region start end
483 Decode the encoded words in the region @var{start} to @var{end}.
486 @defun rfc2047-decode-string string
487 Decode @var{string} and return the result.
495 While not really a part of the @sc{mime} library, it is convenient to
496 document this library here. It deals with parsing @samp{Date} headers
497 and manipulating time. (Not by using tesseracts, though, I'm sorry to
500 These functions convert between five formats: a date string, an Emacs
501 time structure, a decoded time list, a number of seconds, and a day number.
503 The functions have quite self-explanatory names, so the following just
504 gives an overview of which functions are available.
506 @findex parse-time-string
508 @findex time-to-seconds
509 @findex seconds-to-time
514 @findex subtract-time
516 @findex date-leap-year-p
517 @findex time-to-day-in-year
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-day '(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))
557 @findex safe-date-to-time
558 And finally, we have @code{safe-date-to-time}, which does the same as
559 @code{date-to-time}, but returns a zero time if the date is
560 syntactically malformed.
567 This library deals with decoding and encoding Quoted-Printable text.
569 Very briefly explained, QP encoding means translating all 8-bit
570 characters (and lots of control characters) into things that look like
571 @samp{=EF}; that is, an equal sign followed by the byte encoded as a hex
572 string. It is defined in RFC 2045.
574 The following functions are defined by the library:
576 @deffn Command quoted-printable-decode-region @var{from} @var{to} &optional @var{coding-system}
577 QP-decode all the encoded text in the region. If @var{coding-system}
578 is non-nil, decode bytes into characters with that coding-system. It
579 is probably better not to use @var{coding-system}; instead decode into
580 a unibyte buffer, decode that appropriately and then interpret it as
584 @defun quoted-printable-decode-string @var{string} &optional @var{coding-system}
585 Return a QP-encoded copy of @var{string}. If @var{coding-system} is
586 non-nil, decode bytes into characters with that coding-system.
589 @deffn Command quoted-printable-encode-region @var{from} @var{to} &optional @var{fold} @var{class}
590 QP-encode all the region. If @var{fold} is non-@var{nil}, fold lines
591 at 76 characters, as required by the RFC. If @var{class} is
592 non-@code{nil}, translate the characters matched by that class, which
593 should be in the form expected by @var{skip-chars-forward} and should
594 probably not contain literal eight-bit characters. Specifying
595 @var{class} makes sense to do extra encoding in header fields.
597 If variable @var{mm-use-ultra-safe-encoding} is defined and
598 non-@code{nil}, fold lines unconditionally and encode @samp{From } and
599 @samp{-} at the start of lines..
602 @defun quoted-printable-encode-string string
603 Return a QP-encoded copy of @var{string}.
610 Base64 is an encoding that encodes three bytes into four characters,
611 thereby increasing the size by about 33%. The alphabet used for
612 encoding is very resistant to mangling during transit. @xref{Base
613 64,,Base 64 Encoding, elisp, The Emacs Lisp Reference Manual}.
621 Binhex is an encoding that originated in Macintosh environments.
622 The following function is supplied to deal with these:
624 @defun binhex-decode-region start end &optional header-only
625 Decode the encoded text in the region @var{start} to @var{end}. If
626 @var{header-only} is non-@code{nil}, only decode the @samp{binhex}
627 header and return the filename.
636 Uuencoding is probably still the most popular encoding of binaries
637 used on Usenet, although Base64 rules the mail world.
639 The following function is supplied by this package:
641 @defun uudecode-decode-region start end &optional file-name
642 Decode the text in the region @var{start} to @var{end}. If
643 @var{file-name} is non-@code{nil}, save the result to @var{file-name}.
653 RFC1843 deals with mixing Chinese and @sc{ascii} characters in messages. In
654 essence, RFC1843 switches between @sc{ascii} and Chinese by doing this:
657 This sentence is in ASCII.
658 The next sentence is in GB.~@{<:Ky2;S@{#,NpJ)l6HK!#~@}Bye.
661 Simple enough, and widely used in China.
663 The following functions are available to handle this encoding:
665 @defun rfc1843-decode-region start end
666 Decode HZ-encoded text in the region @var{start} to @var{end}.
669 @defun rfc1843-decode-string string
670 Decode the HZ-encoded @var{string} and return the result.
677 As specified by RFC 1524, @sc{mime}-aware message handlers parse
678 @dfn{mailcap} files from a default list, which can be overridden by the
679 @code{MAILCAP} environment variable. These describe how elements are
680 supposed to be displayed. Here's an example file:
684 audio/wav; wavplayer %s
687 This says that all image files should be displayed with @command{gimp},
688 and that realaudio files should be played by @command{rvplayer}.
690 The @code{mailcap} library parses such files, and provides functions for
693 @defvar mailcap-mime-data
694 This variable is an alist of alists containing backup viewing rules for
695 @sc{mime} types. These are overridden by rules for a type found in
696 mailcap files. The outer alist is keyed on the major content-type and
697 the inner alists are keyed on the minor content-type (which can be a
700 @c Fixme: document this properly!
705 (viewer . mailcap-save-binary-file)
707 (type . "application/octet-stream"))
710 (test fboundp 'view-mode)
711 (type . "text/plain")))
715 @defopt mailcap-default-mime-data
716 This variable is the default value of @code{mailcap-mime-data}. It
717 exists to allow setting the value using Custom. It is merged with
718 values from mailcap files by @code{mailcap-parse-mailcaps}.
721 Although it is not specified by the RFC, @sc{mime} tools normally use a
722 common means of associating file extensions with defualt @sc{mime} types
723 in the absence of other information about the type of a file. The
724 information is found in per-user files @file{~/.mime.types} and system
725 @file{mime.types} files found in quasi-standard places. Here is an
729 application/x-dvi dvi
730 audio/mpeg mpga mpega mp2 mp3
731 image/jpeg jpeg jpg jpe
735 @defvar mailcap-mime-extensions
736 This variable is an alist @sc{mime} types keyed by file extensions.
737 This is overridden by entries found in @file{mime.types} files.
740 @defopt mailcap-default-mime-extensions
741 This variable is the default value of @code{mailcap-mime-extensions}.
742 It exists to allow setting the value using Custom. It is merged with
743 values from mailcap files by @code{mailcap-parse-mimetypes}.
748 @defun mailcap-parse-mailcaps &optional path force
749 Parse all the mailcap files specified in a path string @var{path} and
750 merge them with the values from @code{mailcap-mime-data}. Components of
751 @var{path} are separated by the @code{path-separator} character
752 appropriate for the system. If @var{force} is non-@code{nil}, the files
753 are re-parsed even if they have been parsed already. If @var{path} is
754 omitted, use the value of environment variable @code{MAILCAPS} if it is
755 set; otherwise (on Unix) use the path defined in RFC 1524, plus
756 @file{/usr/local/etc/mailcap}.
759 @defun mailcap-parse-mimetypes &optional path force
760 Parse all the mimetypes specified in a Unix-style path string @var{path}
761 and merge them with the values from @code{mailcap-mime-extensions}.
762 Components of @var{path} are separated by the @code{path-separator}
763 character appropriate for the system. If @var{path} is omitted, use the
764 value of environment variable @code{MIMETYPES} if set; otherwise use a
765 default path consistent with that used by @code{mailcap-parse-mailcaps}.
766 If @var{force} is non-@code{nil}, the files are re-parsed even if they
767 have been parsed already.
770 @defun mailcap-mime-info string &optional request
771 Gets the viewer command for content-type @var{string}. @code{nil} is
772 returned if none is found. Expects @var{string} to be a complete
773 content-type header line.
775 If @var{request} is non-@code{nil} it specifies what information to
776 return. If it is nil or the empty string, the viewer (second field of
777 the mailcap entry) will be returned. If it is a string, then the
778 mailcap field corresponding to that string will be returned
779 (@samp{print}, @samp{description}, whatever). If it is a number, all
780 the information for this viewer is returned. If it is @code{all}, then
781 all possible viewers for this type is returned.
784 @defun mailcap-mime-types
785 This function returns a list of all the defined media types.
788 @defun mailcap-extension-to-mime extension
789 This function returns the content type defined for a file with the given
794 @node Decoding and Viewing
795 @chapter Decoding and Viewing
797 This chapter deals with decoding and viewing @sc{mime} messages on a
800 The main idea is to first analyze a @sc{mime} article, and then allow
801 other programs to do things based on the list of @dfn{handles} that are
802 returned as a result of this analysis.
805 * Dissection:: Analyzing a @sc{mime} message.
806 * Handles:: Handle manipulations.
807 * Display:: Displaying handles.
808 * Customization:: Variables that affect display.
809 * New Viewers:: How to write your own viewers.
816 The @code{mm-dissect-buffer} is the function responsible for dissecting
817 a @sc{mime} article. If given a multipart message, it will recursively
818 descend the message, following the structure, and return a tree of
819 @sc{mime} handles that describes the structure of the message.
825 A @sc{mime} handle is a list that fully describes a @sc{mime} component.
827 The following macros can be used to access elements from the
828 @var{handle} argument:
830 @defmac mm-handle-buffer handle
831 Return the buffer that holds the contents of the undecoded @sc{mime}
835 @defmac mm-handle-type handle
836 Return the parsed @samp{Content-Type} of the part.
839 @defmac mm-handle-encoding handle
840 Return the @samp{Content-Transfer-Encoding} of the part.
843 @defmac mm-handle-undisplayer handle
844 Return the function that can be used to remove the displayed part (if it
848 @defmac mm-handle-set-undisplayer handle function
849 Set the undisplayer function for the part to function.
852 @defmac mm-handle-disposition
853 Return the parsed @samp{Content-Disposition} of the part.
856 @defmac mm-handle-disposition
857 Return the description of the part.
860 @defmac mm-get-content-id id
861 Returns the handle(s) referred to by @var{id}, the @samp{Content-ID} of
869 Functions for displaying, removing and saving. In the descriptions
870 below, `the part' means the @sc{mime} part represented by the
871 @var{handle} argument.
873 @defun mm-display-part handle &optional no-default
874 Display the part. Return @code{nil} if the part is removed,
875 @code{inline} if it is displayed inline or @code{external} if it is
876 displayed externally. If @var{no-default} is non-@code{nil}, the part
877 is not displayed unless the @sc{mime} type of @var{handle} is defined to
878 be displayed inline or there is an display method defined for it; i.e.@:
879 no default external method will be used.
882 @defun mm-remove-part handle
883 Remove the part if it has been displayed.
886 @defun mm-inlinable-p handle
887 Return non-@code{nil} if the part can be displayed inline.
890 @defun mm-automatic-display-p handle
891 Return non-@code{nil} if the user has requested automatic display of the
892 @sc{mime} type of the part.
895 @defun mm-destroy-part handle
896 Free all the resources used by the part.
899 @defun mm-save-part handle
900 Save the part to a file. The user is prompted for a file name to use.
903 @defun mm-pipe-part handle
904 Pipe the part through a shell command. The user is prompted for the
908 @defun mm-interactively-view-part handle
909 Prompt for a mailcap method to use to view the part and display it
910 externally using that method.
915 @section Customization
917 The display of @sc{mime} types may be customized with the following
920 @defopt mm-inline-media-tests
921 This is an alist where the key is a @sc{mime} type, the second element
922 is a function to display the part @dfn{inline} (i.e., inside Emacs), and
923 the third element is a form to be @code{eval}ed to say whether the part
924 can be displayed inline.
926 This variable specifies whether a part @emph{can} be displayed inline,
927 and, if so, how to do it. It does not say whether parts are
928 @emph{actually} displayed inline.
931 @defopt mm-inlined-types
932 This, on the other hand, says what types are to be displayed inline, if
933 they satisfy the conditions set by the variable above. It's a list of
934 @sc{mime} media types.
937 @defopt mm-automatic-display
938 This is a list of types that are to be displayed ``automatically'', but
939 only if the above variable allows it. That is, only inlinable parts can
940 be displayed automatically.
943 @defopt mm-attachment-override-types
944 Some @sc{mime} agents create parts that have a content-disposition of
945 @samp{attachment}. This variable allows overriding that disposition and
946 displaying the part inline. (Note that the disposition is only
947 overridden if we are able to, and want to, display the part inline.)
950 @defopt mm-discouraged-alternatives
951 List of @sc{mime} types that are discouraged when viewing
952 @samp{multipart/alternative}. Viewing agents are supposed to view the
953 last possible part of a message, as that is supposed to be the richest.
954 However, users may prefer other types instead, and this list says what
955 types are most unwanted. If, for instance, @samp{text/html} parts are
956 very unwanted, and @samp{text/richtech} parts are somewhat unwanted,
957 then the value of this variable should be set to:
960 ("text/html" "text/richtext")
964 @defopt mm-inline-large-images-p
965 When displaying inline images that are larger than the window, XEmacs
966 does not enable scrolling, which means that you cannot see the whole
967 image. To prevent this, the library tries to determine the image size
968 before displaying it inline, and if it doesn't fit the window, the
969 library will display it externally (e.g. with @samp{ImageMagick} or
970 @samp{xv}). Setting this variable to @code{t} disables this check and
971 makes the library display all inline images as inline, regardless of
975 @defopt mm-inline-override-p
976 @code{mm-inlined-types} may include regular expressions, for example to
977 specify that all @samp{text/.*} parts be displayed inline. If a user
978 prefers to have a type that matches such a regular expression be treated
979 as an attachment, that can be accomplished by setting this variable to a
980 list containing that type. For example assuming @code{mm-inlined-types}
981 includes @samp{text/.*}, then including @samp{text/html} in this
982 variable will cause @samp{text/html} parts to be treated as attachments.
989 Here's an example viewer for displaying @samp{text/enriched} inline:
992 (defun mm-display-enriched-inline (handle)
995 (mm-insert-part handle)
996 (save-window-excursion
997 (enriched-decode (point-min) (point-max))
998 (setq text (buffer-string))))
999 (mm-insert-inline handle text)))
1002 We see that the function takes a @sc{mime} handle as its parameter. It
1003 then goes to a temporary buffer, inserts the text of the part, does some
1004 work on the text, stores the result, goes back to the buffer it was
1005 called from and inserts the result.
1007 The two important helper functions here are @code{mm-insert-part} and
1008 @code{mm-insert-inline}. The first function inserts the text of the
1009 handle in the current buffer. It handles charset and/or content
1010 transfer decoding. The second function just inserts whatever text you
1011 tell it to insert, but it also sets things up so that the text can be
1012 ``undisplayed' in a convenient manner.
1018 @cindex MIME Composing
1020 @cindex MIME Meta Language
1022 Creating a @sc{mime} message is boring and non-trivial. Therefore, a
1023 library called @code{mml} has been defined that parses a language called
1024 MML (@sc{mime} Meta Language) and generates @sc{mime} messages.
1026 @findex mml-generate-mime
1027 The main interface function is @code{mml-generate-mime}. It will
1028 examine the contents of the current (narrowed-to) buffer and return a
1029 string containing the @sc{mime} message.
1032 * Simple MML Example:: An example MML document.
1033 * MML Definition:: All valid MML elements.
1034 * Advanced MML Example:: Another example MML document.
1035 * Charset Translation:: How charsets are mapped from Mule to MIME.
1036 * Conversion:: Going from @sc{mime} to MML and vice versa.
1040 @node Simple MML Example
1041 @section Simple MML Example
1043 Here's a simple @samp{multipart/alternative}:
1046 <#multipart type=alternative>
1047 This is a plain text part.
1048 <#part type=text/enriched>
1049 <center>This is a centered enriched part</center>
1053 After running this through @code{mml-generate-mime}, we get this:
1056 Content-Type: multipart/alternative; boundary="=-=-="
1062 This is a plain text part.
1065 Content-Type: text/enriched
1068 <center>This is a centered enriched part</center>
1074 @node MML Definition
1075 @section MML Definition
1077 The MML language is very simple. It looks a bit like an SGML
1078 application, but it's not.
1080 The main concept of MML is the @dfn{part}. Each part can be of a
1081 different type or use a different charset. The way to delineate a part
1082 is with a @samp{<#part ...>} tag. Multipart parts can be introduced
1083 with the @samp{<#multipart ...>} tag. Parts are ended by the
1084 @samp{<#/part>} or @samp{<#/multipart>} tags. Parts started with the
1085 @samp{<#part ...>} tags are also closed by the next open tag.
1087 There's also the @samp{<#external ...>} tag. These introduce
1088 @samp{external/message-body} parts.
1090 Each tag can contain zero or more parameters on the form
1091 @samp{parameter=value}. The values may be enclosed in quotation marks,
1092 but that's not necessary unless the value contains white space. So
1093 @samp{filename=/home/user/#hello$^yes} is perfectly valid.
1095 The following parameters have meaning in MML; parameters that have no
1096 meaning are ignored. The MML parameter names are the same as the
1097 @sc{mime} parameter names; the things in the parentheses say which
1098 header it will be used in.
1102 The @sc{mime} type of the part (@samp{Content-Type}).
1105 Use the contents of the file in the body of the part
1106 (@samp{Content-Disposition}).
1109 The contents of the body of the part are to be encoded in the character
1110 set speficied (@samp{Content-Type}).
1113 Might be used to suggest a file name if the part is to be saved
1114 to a file (@samp{Content-Type}).
1117 Valid values are @samp{inline} and @samp{attachment}
1118 (@samp{Content-Disposition}).
1121 Valid values are @samp{7bit}, @samp{8bit}, @samp{quoted-printable} and
1122 @samp{base64} (@samp{Content-Transfer-Encoding}).
1125 A description of the part (@samp{Content-Description}).
1128 RFC822 date when the part was created (@samp{Content-Disposition}).
1130 @item modification-date
1131 RFC822 date when the part was modified (@samp{Content-Disposition}).
1134 RFC822 date when the part was read (@samp{Content-Disposition}).
1137 The size (in octets) of the part (@samp{Content-Disposition}).
1141 Parameters for @samp{application/octet-stream}:
1145 Type of the part; informal---meant for human readers
1146 (@samp{Content-Type}).
1149 Parameters for @samp{message/external-body}:
1153 A word indicating the supported access mechanism by which the file may
1154 be obtained. Values include @samp{ftp}, @samp{anon-ftp}, @samp{tftp},
1155 @samp{localfile}, and @samp{mailserver}. (@samp{Content-Type}.)
1158 The RFC822 date after which the file may no longer be fetched.
1159 (@samp{Content-Type}.)
1162 The size (in octets) of the file. (@samp{Content-Type}.)
1165 Valid values are @samp{read} and @samp{read-write}
1166 (@samp{Content-Type}).
1171 @node Advanced MML Example
1172 @section Advanced MML Example
1174 Here's a complex multipart message. It's a @samp{multipart/mixed} that
1175 contains many parts, one of which is a @samp{multipart/alternative}.
1178 <#multipart type=mixed>
1179 <#part type=image/jpeg filename=~/rms.jpg disposition=inline>
1180 <#multipart type=alternative>
1181 This is a plain text part.
1182 <#part type=text/enriched name=enriched.txt>
1183 <center>This is a centered enriched part</center>
1185 This is a new plain text part.
1186 <#part disposition=attachment>
1187 This plain text part is an attachment.
1191 And this is the resulting @sc{mime} message:
1194 Content-Type: multipart/mixed; boundary="=-=-="
1202 Content-Type: image/jpeg;
1203 filename="~/rms.jpg"
1204 Content-Disposition: inline;
1205 filename="~/rms.jpg"
1206 Content-Transfer-Encoding: base64
1208 /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRof
1209 Hh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/wAALCAAwADABAREA/8QAHwAA
1210 AQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQR
1211 BRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RF
1212 RkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ip
1213 qrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/9oACAEB
1214 AAA/AO/rifFHjldNuGsrDa0qcSSHkA+gHrXKw+LtWLrMb+RgTyhbr+HSug07xNqV9fQtZrNI
1215 AyiaE/NuBPOOOP0rvRNE880KOC8TbXXGCv1FPqjrF4LDR7u5L7SkTFT/ALWOP1xXgTuXfc7E
1216 sx6nua6rwp4IvvEM8chCxWxOdzn7wz6V9AaB4S07w9p5itow0rDLSY5Pt9K43xO66P4xs71m
1217 2QXiGCbA4yOVJ9+1aYORkdK434lyNH4ahCnG66VT9Nj15JFbPdX0MS43M4VQf5/yr2vSpLnw
1218 5ZW8dlCZ8KFXjOPX0/mK6rSPEGt3Angu44fNEReHYNvIH3TzXDeKNO8RX+kSX2ouZkicTIOc
1219 L+g7E810ulFjpVtv3bwgB3HJyK5L4quY/C9sVxk3ij/xx6850u7t1mtp/wDlpEw3An3Jr3Dw
1220 34gsbWza4nBlhC5LDsaW6+IFgupQyCF3iHH7gA7c9R9ay7zx6t7aX9jHC4smhfBkGCvHGfrm
1221 tLQ7hbnRrV1GPkAP1x1/Hr+Ncr8Vzjwrbf8AX6v/AKA9eQRyYlQk8Yx9K6XTNbkgia2ciSIn
1222 7p5Ga9Atte0LTLKO6it4i7dVRFJDcZ4PvXN+JvEMF9bILVGXJLSZ4zkjivRPDaeX4b08HOTC
1223 pOffmua+KkbS+GLVUGT9tT/0B68eeIpIFYjB70+OOVXyoOM9+M1eaWeCLzHPyHGO/NVWvJJm
1224 jQ8KGH1NfQWhXSXmh2c8eArRLwO3HSv/2Q==
1227 Content-Type: multipart/alternative; boundary="==-=-="
1233 This is a plain text part.
1236 Content-Type: text/enriched;
1240 <center>This is a centered enriched part</center>
1246 This is a new plain text part.
1249 Content-Disposition: attachment
1252 This plain text part is an attachment.
1257 @node Charset Translation
1258 @section Charset Translation
1261 During translation from MML to @sc{mime}, for each @sc{mime} part which
1262 has been composed inside Emacs, an appropriate @sc{mime} charset has to
1265 @vindex mail-parse-charset
1266 If you are running a non-Mule Emacs, this process is simple: if the part
1267 contains any non-@sc{ascii} (8-bit) characters, the @sc{mime} charset
1268 given by @code{mail-parse-charset} (a symbol) is used. (Never set this
1269 variable directly, though. If you want to change the default charset,
1270 please consult the documentation of the package which you use to process
1271 @sc{mime} messages. @xref{Various Message Variables, , Various Message
1272 Variables, message, Message Manual}, for example.) If there are only
1273 @sc{ascii} characters, the @sc{mime} charset @samp{US-ASCII} is used, of
1279 @vindex mm-mime-mule-charset-alist
1280 Things are slightly more complicated when running Emacs with Mule
1281 support. In this case, a list of the Mule charsets used in the part is
1282 obtained, and the corresponding @sc{mime} charsets are determined. If
1283 this results in a single @sc{mime} charset, this is used to encode the
1284 part. But if the resulting list of @sc{mime} charsets contains more
1285 than one element, two things can happen: if it is possible to encode the
1286 part via UTF-8, this charset is used. (For this, Emacs must support the
1287 @code{utf-8} coding system, and the part must consist entirely of
1288 characters which have Unicode counterparts.) If UTF-8 is not available,
1289 the part is split into several, so that each one can be encoded with a
1290 single @sc{mime} charset. The part can only be split at line
1291 boundaries, though---if more than one @sc{mime} charset is required to
1292 encode a single line, it is not possible to encode the part.
1298 A (multipart) @sc{mime} message can be converted to MML with the
1299 @code{mime-to-mml} function. It works on the message in the current
1300 buffer, and substitutes MML markup for @sc{mime} boundaries.
1301 Non-textual parts do not have their contents in the buffer, but instead
1302 have the contents in separate buffers that are referred to from the MML
1306 An MML message can be converted back to @sc{mime} by the
1307 @code{mml-to-mime} function.
1309 These functions are in certain senses ``lossy''---you will not get back
1310 an identical message if you run @sc{mime-to-mml} and then
1311 @sc{mml-to-mime}. Not only will trivial things like the order of the
1312 headers differ, but the contents of the headers may also be different.
1313 For instance, the original message may use base64 encoding on text,
1314 while @sc{mml-to-mime} may decide to use quoted-printable encoding, and
1317 In essence, however, these two functions should be the inverse of each
1318 other. The resulting contents of the message should remain equivalent,
1325 The Emacs @sc{mime} library implements handling of various elements
1326 according to a (somewhat) large number of RFCs, drafts and standards
1327 documents. This chapter lists the relevant ones. They can all be
1328 fetched from @samp{http://quimby.gnus.org/notes/}.
1333 Standard for the Format of ARPA Internet Text Messages.
1336 Standard for Interchange of USENET Messages
1339 A User Agent Configuration Mechanism For Multimedia Mail Format
1343 Format of Internet Message Bodies
1349 Message Header Extensions for Non-ASCII Text
1352 Registration Procedures
1355 Conformance Criteria and Examples
1358 MIME Parameter Value and Encoded Word Extensions: Character Sets,
1359 Languages, and Continuations
1362 HZ - A Data Format for Exchanging Files of Arbitrarily Mixed Chinese and
1365 @item draft-ietf-drums-msg-fmt-05.txt
1366 Draft for the successor of RFC822
1369 The MIME Multipart/Related Content-type
1372 The Multipart/Report Content Type for the Reporting of Mail System
1373 Administrative Messages
1376 Communicating Presentation Information in Internet Messages: The
1377 Content-Disposition Header Field