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, 2001, 2002 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, 2001, 2002 Free Software
53 Permission is granted to copy, distribute and/or modify this document
54 under the terms of the GNU Free Documentation License, Version 1.1 or
55 any later version published by the Free Software Foundation; with the
56 Invariant Sections being none, with the Front-Cover texts being ``A GNU
57 Manual'', and with the Back-Cover Texts as in (a) below. A copy of the
58 license is included in the section entitled ``GNU Free Documentation
59 License'' in the Emacs manual.
61 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
62 this GNU Manual, like GNU software. Copies published by the Free
63 Software Foundation raise funds for GNU development.''
65 This document is part of a collection distributed under the GNU Free
66 Documentation License. If you want to distribute this document
67 separately from the collection, you can do so by adding a copy of the
68 license to the document, as described in section 6 of the license.
77 This manual documents the libraries used to compose and display
80 This is not a manual meant for users; it's a manual directed at people
81 who want to write functions and commands that manipulate @sc{mime}
84 @sc{mime} is short for @dfn{Multipurpose Internet Mail Extensions}.
85 This standard is documented in a number of RFCs; mainly RFC2045 (Format
86 of Internet Message Bodies), RFC2046 (Media Types), RFC2047 (Message
87 Header Extensions for Non-ASCII Text), RFC2048 (Registration
88 Procedures), RFC2049 (Conformance Criteria and Examples). It is highly
89 recommended that anyone who intends writing @sc{mime}-compliant software
90 read at least RFC2045 and RFC2047.
93 * Interface Functions:: An abstraction over the basic functions.
94 * Basic Functions:: Utility and basic parsing functions.
95 * Decoding and Viewing:: A framework for decoding and viewing.
96 * Composing:: MML; a language for describing @sc{mime} parts.
97 * Standards:: A summary of RFCs and working documents used.
98 * Index:: Function and variable index.
102 @node Interface Functions
103 @chapter Interface Functions
104 @cindex interface functions
107 The @code{mail-parse} library is an abstraction over the actual
108 low-level libraries that are described in the next chapter.
110 Standards change, and so programs have to change to fit in the new
111 mold. For instance, RFC2045 describes a syntax for the
112 @code{Content-Type} header that only allows ASCII characters in the
113 parameter list. RFC2231 expands on RFC2045 syntax to provide a scheme
114 for continuation headers and non-ASCII characters.
116 The traditional way to deal with this is just to update the library
117 functions to parse the new syntax. However, this is sometimes the wrong
118 thing to do. In some instances it may be vital to be able to understand
119 both the old syntax as well as the new syntax, and if there is only one
120 library, one must choose between the old version of the library and the
121 new version of the library.
123 The Emacs @sc{mime} library takes a different tack. It defines a
124 series of low-level libraries (@file{rfc2047.el}, @file{rfc2231.el}
125 and so on) that parses strictly according to the corresponding
126 standard. However, normal programs would not use the functions
127 provided by these libraries directly, but instead use the functions
128 provided by the @code{mail-parse} library. The functions in this
129 library are just aliases to the corresponding functions in the latest
130 low-level libraries. Using this scheme, programs get a consistent
131 interface they can use, and library developers are free to create
132 write code that handles new standards.
134 The following functions are defined by this library:
137 @item mail-header-parse-content-type
138 @findex mail-header-parse-content-type
139 Parse a @code{Content-Type} header and return a list on the following
144 (attribute1 . value1)
145 (attribute2 . value2)
152 (mail-header-parse-content-type
153 "image/gif; name=\"b980912.gif\"")
154 @result{} ("image/gif" (name . "b980912.gif"))
157 @item mail-header-parse-content-disposition
158 @findex mail-header-parse-content-disposition
159 Parse a @code{Content-Disposition} header and return a list on the same
160 format as the function above.
162 @item mail-content-type-get
163 @findex mail-content-type-get
164 Takes two parameters---a list on the format above, and an attribute.
165 Returns the value of the attribute.
168 (mail-content-type-get
169 '("image/gif" (name . "b980912.gif")) 'name)
170 @result{} "b980912.gif"
173 @item mail-header-encode-parameter
174 @findex mail-header-encode-parameter
175 Takes a parameter string and returns an encoded version of the string.
176 This is used for parameters in headers like @code{Content-Type} and
177 @code{Content-Disposition}.
179 @item mail-header-remove-comments
180 @findex mail-header-remove-comments
181 Return a comment-free version of a header.
184 (mail-header-remove-comments
185 "Gnus/5.070027 (Pterodactyl Gnus v0.27) (Finnish Landrace)")
186 @result{} "Gnus/5.070027 "
189 @item mail-header-remove-whitespace
190 @findex mail-header-remove-whitespace
191 Remove linear white space from a header. Space inside quoted strings
192 and comments is preserved.
195 (mail-header-remove-whitespace
196 "image/gif; name=\"Name with spaces\"")
197 @result{} "image/gif;name=\"Name with spaces\""
200 @item mail-header-get-comment
201 @findex mail-header-get-comment
202 Return the last comment in a header.
205 (mail-header-get-comment
206 "Gnus/5.070027 (Pterodactyl Gnus v0.27) (Finnish Landrace)")
207 @result{} "Finnish Landrace"
210 @item mail-header-parse-address
211 @findex mail-header-parse-address
212 Parse an address and return a list containing the mailbox and the
216 (mail-header-parse-address
217 "Hrvoje Niksic <hniksic@@srce.hr>")
218 @result{} ("hniksic@@srce.hr" . "Hrvoje Niksic")
221 @item mail-header-parse-addresses
222 @findex mail-header-parse-addresses
223 Parse a string with list of addresses and return a list of elements like
224 the one described above.
227 (mail-header-parse-addresses
228 "Hrvoje Niksic <hniksic@@srce.hr>, Steinar Bang <sb@@metis.no>")
229 @result{} (("hniksic@@srce.hr" . "Hrvoje Niksic")
230 ("sb@@metis.no" . "Steinar Bang"))
233 @item mail-header-parse-date
234 @findex mail-header-parse-date
235 Parse a date string and return an Emacs time structure.
237 @item mail-narrow-to-head
238 @findex mail-narrow-to-head
239 Narrow the buffer to the header section of the buffer. Point is placed
240 at the beginning of the narrowed buffer.
242 @item mail-header-narrow-to-field
243 @findex mail-header-narrow-to-field
244 Narrow the buffer to the header under point. Understands continuation
247 @item mail-header-fold-field
248 @findex mail-header-fold-field
249 Fold the header under point.
251 @item mail-header-unfold-field
252 @findex mail-header-unfold-field
253 Unfold the header under point.
255 @item mail-header-field-value
256 @findex mail-header-field-value
257 Return the value of the field under point.
259 @item mail-encode-encoded-word-region
260 @findex mail-encode-encoded-word-region
261 Encode the non-ASCII words in the region. For instance,
262 @samp{Naïve} is encoded as @samp{=?iso-8859-1?q?Na=EFve?=}.
264 @item mail-encode-encoded-word-buffer
265 @findex mail-encode-encoded-word-buffer
266 Encode the non-ASCII words in the current buffer. This function is
267 meant to be called narrowed to the headers of a message.
269 @item mail-encode-encoded-word-string
270 @findex mail-encode-encoded-word-string
271 Encode the words that need encoding in a string, and return the result.
274 (mail-encode-encoded-word-string
275 "This is naïve, baby")
276 @result{} "This is =?iso-8859-1?q?na=EFve,?= baby"
279 @item mail-decode-encoded-word-region
280 @findex mail-decode-encoded-word-region
281 Decode the encoded words in the region.
283 @item mail-decode-encoded-word-string
284 @findex mail-decode-encoded-word-string
285 Decode the encoded words in the string and return the result.
288 (mail-decode-encoded-word-string
289 "This is =?iso-8859-1?q?na=EFve,?= baby")
290 @result{} "This is naïve, baby"
295 Currently, @code{mail-parse} is an abstraction over @code{ietf-drums},
296 @code{rfc2047}, @code{rfc2045} and @code{rfc2231}. These are documented
297 in the subsequent sections.
301 @node Basic Functions
302 @chapter Basic Functions
304 This chapter describes the basic, ground-level functions for parsing and
305 handling. Covered here is parsing @code{From} lines, removing comments
306 from header lines, decoding encoded words, parsing date headers and so
307 on. High-level functionality is dealt with in the next chapter
308 (@pxref{Decoding and Viewing}).
311 * rfc2045:: Encoding @code{Content-Type} headers.
312 * rfc2231:: Parsing @code{Content-Type} headers.
313 * ietf-drums:: Handling mail headers defined by RFC822bis.
314 * rfc2047:: En/decoding encoded words in headers.
315 * time-date:: Functions for parsing dates and manipulating time.
316 * qp:: Quoted-Printable en/decoding.
317 * base64:: Base64 en/decoding.
318 * binhex:: Binhex decoding.
319 * uudecode:: Uuencode decoding.
320 * rfc1843:: Decoding HZ-encoded text.
321 * mailcap:: How parts are displayed is specified by the @file{.mailcap} file
328 RFC2045 is the ``main'' @sc{mime} document, and as such, one would
329 imagine that there would be a lot to implement. But there isn't, since
330 most of the implementation details are delegated to the subsequent
333 So @file{rfc2045.el} has only a single function:
336 @item rfc2045-encode-string
337 @findex rfc2045-encode-string
338 Takes a parameter and a value and returns a @samp{PARAM=VALUE} string.
339 @var{value} will be quoted if there are non-safe characters in it.
346 RFC2231 defines a syntax for the @code{Content-Type} and
347 @code{Content-Disposition} headers. Its snappy name is @dfn{MIME
348 Parameter Value and Encoded Word Extensions: Character Sets, Languages,
351 In short, these headers look something like this:
354 Content-Type: application/x-stuff;
355 title*0*=us-ascii'en'This%20is%20even%20more%20;
356 title*1*=%2A%2A%2Afun%2A%2A%2A%20;
360 They usually aren't this bad, though.
362 The following functions are defined by this library:
365 @item rfc2231-parse-string
366 @findex rfc2231-parse-string
367 Parse a @code{Content-Type} header and return a list describing its
371 (rfc2231-parse-string
372 "application/x-stuff;
373 title*0*=us-ascii'en'This%20is%20even%20more%20;
374 title*1*=%2A%2A%2Afun%2A%2A%2A%20;
375 title*2=\"isn't it!\"")
376 @result{} ("application/x-stuff"
377 (title . "This is even more ***fun*** isn't it!"))
380 @item rfc2231-get-value
381 @findex rfc2231-get-value
382 Takes one of the lists on the format above and returns
383 the value of the specified attribute.
385 @item rfc2231-encode-string
386 @findex rfc2231-encode-string
387 Encode a parameter in headers likes @code{Content-Type} and
388 @code{Content-Disposition}.
396 @dfn{drums} is an IETF working group that is working on the replacement
399 The functions provided by this library include:
402 @item ietf-drums-remove-comments
403 @findex ietf-drums-remove-comments
404 Remove the comments from the argument and return the results.
406 @item ietf-drums-remove-whitespace
407 @findex ietf-drums-remove-whitespace
408 Remove linear white space from the string and return the results.
409 Spaces inside quoted strings and comments are left untouched.
411 @item ietf-drums-get-comment
412 @findex ietf-drums-get-comment
413 Return the last most comment from the string.
415 @item ietf-drums-parse-address
416 @findex ietf-drums-parse-address
417 Parse an address string and return a list that contains the mailbox and
420 @item ietf-drums-parse-addresses
421 @findex ietf-drums-parse-addresses
422 Parse a string that contains any number of comma-separated addresses and
423 return a list that contains mailbox/plain text pairs.
425 @item ietf-drums-parse-date
426 @findex ietf-drums-parse-date
427 Parse a date string and return an Emacs time structure.
429 @item ietf-drums-narrow-to-header
430 @findex ietf-drums-narrow-to-header
431 Narrow the buffer to the header section of the current buffer.
439 RFC2047 (Message Header Extensions for Non-ASCII Text) specifies how
440 non-ASCII text in headers are to be encoded. This is actually rather
441 complicated, so a number of variables are necessary to tweak what this
444 The following variables are tweakable:
447 @item rfc2047-default-charset
448 @vindex rfc2047-default-charset
449 Characters in this charset should not be decoded by this library.
450 This defaults to @code{iso-8859-1}.
452 @item rfc2047-header-encoding-list
453 @vindex rfc2047-header-encoding-list
454 This is an alist of header / encoding-type pairs. Its main purpose is
455 to prevent encoding of certain headers.
457 The keys can either be header regexps, or @code{t}.
459 The values can be either @code{nil}, in which case the header(s) in
460 question won't be encoded, or @code{mime}, which means that they will be
463 @item rfc2047-charset-encoding-alist
464 @vindex rfc2047-charset-encoding-alist
465 RFC2047 specifies two forms of encoding---@code{Q} (a
466 Quoted-Printable-like encoding) and @code{B} (base64). This alist
467 specifies which charset should use which encoding.
469 @item rfc2047-encoding-function-alist
470 @vindex rfc2047-encoding-function-alist
471 This is an alist of encoding / function pairs. The encodings are
472 @code{Q}, @code{B} and @code{nil}.
474 @item rfc2047-q-encoding-alist
475 @vindex rfc2047-q-encoding-alist
476 The @code{Q} encoding isn't quite the same for all headers. Some
477 headers allow a narrower range of characters, and that is what this
478 variable is for. It's an alist of header regexps / allowable character
481 @item rfc2047-encoded-word-regexp
482 @vindex rfc2047-encoded-word-regexp
483 When decoding words, this library looks for matches to this regexp.
487 Those were the variables, and these are this functions:
490 @item rfc2047-narrow-to-field
491 @findex rfc2047-narrow-to-field
492 Narrow the buffer to the header on the current line.
494 @item rfc2047-encode-message-header
495 @findex rfc2047-encode-message-header
496 Should be called narrowed to the header of a message. Encodes according
497 to @code{rfc2047-header-encoding-alist}.
499 @item rfc2047-encode-region
500 @findex rfc2047-encode-region
501 Encodes all encodable words in the region specified.
503 @item rfc2047-encode-string
504 @findex rfc2047-encode-string
505 Encode a string and return the results.
507 @item rfc2047-decode-region
508 @findex rfc2047-decode-region
509 Decode the encoded words in the region.
511 @item rfc2047-decode-string
512 @findex rfc2047-decode-string
513 Decode a string and return the results.
521 While not really a part of the @sc{mime} library, it is convenient to
522 document this library here. It deals with parsing @code{Date} headers
523 and manipulating time. (Not by using tesseracts, though, I'm sorry to
526 These functions convert between five formats: A date string, an Emacs
527 time structure, a decoded time list, a second number, and a day number.
529 Here's a bunch of time/date/second/day examples:
532 (parse-time-string "Sat Sep 12 12:21:54 1998 +0200")
533 @result{} (54 21 12 12 9 1998 6 nil 7200)
535 (date-to-time "Sat Sep 12 12:21:54 1998 +0200")
536 @result{} (13818 19266)
538 (time-to-seconds '(13818 19266))
539 @result{} 905595714.0
541 (seconds-to-time 905595714.0)
542 @result{} (13818 19266 0)
544 (time-to-days '(13818 19266))
547 (days-to-time 729644)
548 @result{} (961933 65536)
550 (time-since '(13818 19266))
553 (time-less-p '(13818 19266) '(13818 19145))
556 (subtract-time '(13818 19266) '(13818 19145))
559 (days-between "Sat Sep 12 12:21:54 1998 +0200"
560 "Sat Sep 07 12:21:54 1998 +0200")
563 (date-leap-year-p 2000)
566 (time-to-day-in-year '(13818 19266))
569 (time-to-number-of-days
571 (date-to-time "Mon, 01 Jan 2001 02:22:26 GMT")))
572 @result{} 4.146122685185185
575 And finally, we have @code{safe-date-to-time}, which does the same as
576 @code{date-to-time}, but returns a zero time if the date is
577 syntactically malformed.
579 The five data representations used are the following:
583 An RFC822 (or similar) date string. For instance: @code{"Sat Sep 12
584 12:21:54 1998 +0200"}.
587 An internal Emacs time. For instance: @code{(13818 26466)}.
590 A floating point representation of the internal Emacs time. For
591 instance: @code{905595714.0}.
594 An integer number representing the number of days since 00000101. For
595 instance: @code{729644}.
598 A list of decoded time. For instance: @code{(54 21 12 12 9 1998 6 t
602 All the examples above represent the same moment.
604 These are the functions available:
608 Take a date and return a time.
610 @item time-to-seconds
611 Take a time and return seconds.
613 @item seconds-to-time
614 Take seconds and return a time.
617 Take a time and return days.
620 Take days and return a time.
623 Take a date and return days.
625 @item time-to-number-of-days
626 Take a time and return the number of days that represents.
628 @item safe-date-to-time
629 Take a date and return a time. If the date is not syntactically valid,
630 return a "zero" date.
633 Take two times and say whether the first time is less (i. e., earlier)
634 than the second time.
637 Take a time and return a time saying how long it was since that time.
640 Take two times and subtract the second from the first. I. e., return
641 the time between the two times.
644 Take two days and return the number of days between those two days.
646 @item date-leap-year-p
647 Take a year number and say whether it's a leap year.
649 @item time-to-day-in-year
650 Take a time and return the day number within the year that the time is
659 This library deals with decoding and encoding Quoted-Printable text.
661 Very briefly explained, qp encoding means translating all 8-bit
662 characters (and lots of control characters) into things that look like
663 @samp{=EF}; that is, an equal sign followed by the byte encoded as a hex
666 The following functions are defined by the library:
669 @item quoted-printable-decode-region
670 @findex quoted-printable-decode-region
671 QP-decode all the encoded text in the specified region.
673 @item quoted-printable-decode-string
674 @findex quoted-printable-decode-string
675 Decode the QP-encoded text in a string and return the results.
677 @item quoted-printable-encode-region
678 @findex quoted-printable-encode-region
679 QP-encode all the encodable characters in the specified region. The third
680 optional parameter @var{fold} specifies whether to fold long lines.
681 (Long here means 72.)
683 @item quoted-printable-encode-string
684 @findex quoted-printable-encode-string
685 QP-encode all the encodable characters in a string and return the
695 Base64 is an encoding that encodes three bytes into four characters,
696 thereby increasing the size by about 33%. The alphabet used for
697 encoding is very resistant to mangling during transit.
699 The following functions are defined by this library:
702 @item base64-encode-region
703 @findex base64-encode-region
704 base64 encode the selected region. Return the length of the encoded
705 text. Optional third argument @var{no-line-break} means do not break
706 long lines into shorter lines.
708 @item base64-encode-string
709 @findex base64-encode-string
710 base64 encode a string and return the result.
712 @item base64-decode-region
713 @findex base64-decode-region
714 base64 decode the selected region. Return the length of the decoded
715 text. If the region can't be decoded, return @code{nil} and don't
718 @item base64-decode-string
719 @findex base64-decode-string
720 base64 decode a string and return the result. If the string can't be
721 decoded, @code{nil} is returned.
732 @code{binhex} is an encoding that originated in Macintosh environments.
733 The following function is supplied to deal with these:
736 @item binhex-decode-region
737 @findex binhex-decode-region
738 Decode the encoded text in the region. If given a third parameter, only
739 decode the @code{binhex} header and return the filename.
749 @code{uuencode} is probably still the most popular encoding of binaries
750 used on Usenet, although @code{base64} rules the mail world.
752 The following function is supplied by this package:
755 @item uudecode-decode-region
756 @findex uudecode-decode-region
757 Decode the text in the region.
767 RFC1843 deals with mixing Chinese and ASCII characters in messages. In
768 essence, RFC1843 switches between ASCII and Chinese by doing this:
771 This sentence is in ASCII.
772 The next sentence is in GB.~@{<:Ky2;S@{#,NpJ)l6HK!#~@}Bye.
775 Simple enough, and widely used in China.
777 The following functions are available to handle this encoding:
780 @item rfc1843-decode-region
781 Decode HZ-encoded text in the region.
783 @item rfc1843-decode-string
784 Decode a HZ-encoded string and return the result.
792 The @file{~/.mailcap} file is parsed by most @sc{mime}-aware message
793 handlers and describes how elements are supposed to be displayed.
794 Here's an example file:
798 audio/wav; wavplayer %s
799 application/msword; catdoc %s ; copiousoutput ; nametemplate=%s.doc
802 This says that all image files should be displayed with @code{gimp},
803 that WAVE audio files should be played by @code{wavplayer}, and that
804 MS-WORD files should be inlined by @code{catdoc}.
806 The @code{mailcap} library parses this file, and provides functions for
810 @item mailcap-mime-data
811 @vindex mailcap-mime-data
812 This variable is an alist of alists containing backup viewing rules.
819 @item mailcap-parse-mailcaps
820 @findex mailcap-parse-mailcaps
821 Parse the @code{~/.mailcap} file.
823 @item mailcap-mime-info
824 Takes a @sc{mime} type as its argument and returns the matching viewer.
831 @node Decoding and Viewing
832 @chapter Decoding and Viewing
834 This chapter deals with decoding and viewing @sc{mime} messages on a
837 The main idea is to first analyze a @sc{mime} article, and then allow
838 other programs to do things based on the list of @dfn{handles} that are
839 returned as a result of this analysis.
842 * Dissection:: Analyzing a @sc{mime} message.
843 * Non-MIME:: Analyzing a non-@sc{mime} message.
844 * Handles:: Handle manipulations.
845 * Display:: Displaying handles.
846 * Customization:: Variables that affect display.
847 * New Viewers:: How to write your own viewers.
854 The @code{mm-dissect-buffer} is the function responsible for dissecting
855 a @sc{mime} article. If given a multipart message, it will recursively
856 descend the message, following the structure, and return a tree of
857 @sc{mime} handles that describes the structure of the message.
862 Gnus also understands some non-@sc{mime} attachments, such as
863 postscript, uuencode, binhex, shar, forward, gnatsweb, pgp. Each of
864 these features can be disabled by add an item into
865 @code{mm-uu-configure-list}. For example,
869 (add-to-list 'mm-uu-configure-list '(pgp-signed . disabled))
891 Non-@sc{mime} forwarded message.
899 PGP signed clear text.
902 @findex pgp-encrypted
903 PGP encrypted clear text.
910 @findex emacs-sources
911 Emacs source code. This item works only in the groups matching
912 @code{mm-uu-emacs-sources-regexp}.
919 A @sc{mime} handle is a list that fully describes a @sc{mime}
922 The following macros can be used to access elements in a handle:
925 @item mm-handle-buffer
926 @findex mm-handle-buffer
927 Return the buffer that holds the contents of the undecoded @sc{mime}
931 @findex mm-handle-type
932 Return the parsed @code{Content-Type} of the part.
934 @item mm-handle-encoding
935 @findex mm-handle-encoding
936 Return the @code{Content-Transfer-Encoding} of the part.
938 @item mm-handle-undisplayer
939 @findex mm-handle-undisplayer
940 Return the object that can be used to remove the displayed part (if it
943 @item mm-handle-set-undisplayer
944 @findex mm-handle-set-undisplayer
945 Set the undisplayer object.
947 @item mm-handle-disposition
948 @findex mm-handle-disposition
949 Return the parsed @code{Content-Disposition} of the part.
951 @item mm-handle-disposition
952 @findex mm-handle-disposition
953 Return the description of the part.
955 @item mm-get-content-id
956 Returns the handle(s) referred to by @code{Content-ID}.
964 Functions for displaying, removing and saving.
967 @item mm-display-part
968 @findex mm-display-part
972 @findex mm-remove-part
973 Remove the part (if it has been displayed).
976 @findex mm-inlinable-p
977 Say whether a @sc{mime} type can be displayed inline.
979 @item mm-automatic-display-p
980 @findex mm-automatic-display-p
981 Say whether a @sc{mime} type should be displayed automatically.
983 @item mm-destroy-part
984 @findex mm-destroy-part
985 Free all resources occupied by a part.
989 Offer to save the part in a file.
993 Offer to pipe the part to some process.
995 @item mm-interactively-view-part
996 @findex mm-interactively-view-part
997 Prompt for a mailcap method to use to view the part.
1003 @section Customization
1007 @item mm-inline-media-tests
1008 This is an alist where the key is a @sc{mime} type, the second element
1009 is a function to display the part @dfn{inline} (i.e., inside Emacs), and
1010 the third element is a form to be @code{eval}ed to say whether the part
1011 can be displayed inline.
1013 This variable specifies whether a part @emph{can} be displayed inline,
1014 and, if so, how to do it. It does not say whether parts are
1015 @emph{actually} displayed inline.
1017 @item mm-inlined-types
1018 This, on the other hand, says what types are to be displayed inline, if
1019 they satisfy the conditions set by the variable above. It's a list of
1020 @sc{mime} media types.
1022 @item mm-automatic-display
1023 This is a list of types that are to be displayed ``automatically'', but
1024 only if the above variable allows it. That is, only inlinable parts can
1025 be displayed automatically.
1027 @item mm-attachment-override-types
1028 Some @sc{mime} agents create parts that have a content-disposition of
1029 @samp{attachment}. This variable allows overriding that disposition and
1030 displaying the part inline. (Note that the disposition is only
1031 overridden if we are able to, and want to, display the part inline.)
1033 @item mm-discouraged-alternatives
1034 List of @sc{mime} types that are discouraged when viewing
1035 @samp{multipart/alternative}. Viewing agents are supposed to view the
1036 last possible part of a message, as that is supposed to be the richest.
1037 However, users may prefer other types instead, and this list says what
1038 types are most unwanted. If, for instance, @samp{text/html} parts are
1039 very unwanted, and @samp{text/richtech} parts are somewhat unwanted,
1040 you could say something like:
1043 (setq mm-discouraged-alternatives
1044 '("text/html" "text/richtext")
1045 mm-automatic-display
1046 (remove "text/html" mm-automatic-display))
1049 @item mm-inline-large-images-p
1050 When displaying inline images that are larger than the window, XEmacs
1051 does not enable scrolling, which means that you cannot see the whole
1052 image. To prevent this, the library tries to determine the image size
1053 before displaying it inline, and if it doesn't fit the window, the
1054 library will display it externally (e.g. with @samp{ImageMagick} or
1055 @samp{xv}). Setting this variable to @code{t} disables this check and
1056 makes the library display all inline images as inline, regardless of
1059 @item mm-inline-override-type
1060 @code{mm-inlined-types} may include regular expressions, for example to
1061 specify that all @samp{text/.*} parts be displayed inline. If a user
1062 prefers to have a type that matches such a regular expression be treated
1063 as an attachment, that can be accomplished by setting this variable to a
1064 list containing that type. For example assuming @code{mm-inlined-types}
1065 includes @samp{text/.*}, then including @samp{text/html} in this
1066 variable will cause @samp{text/html} parts to be treated as attachments.
1068 @item mm-inline-text-html-renderer
1069 @findex mm-inline-text-html-render-with-w3
1070 @findex mm-inline-text-html-render-with-w3m
1071 This function will be used to convert the @sc{html} to the text. There are
1072 two pre-defined functions: @code{mm-inline-text-html-render-with-w3},
1073 which uses Emacs/w3; and @code{mm-inline-text-html-render-with-w3m},
1074 which uses emacs-w3m (see @uref{http://emacs-w3m.namazu.org/} for more
1075 information about emacs-w3m). The function will be called with a
1076 @sc{mime} handle as the argument.
1078 @item mm-inline-text-html-with-images
1079 Some @sc{html} mails might have the trick of spammers using
1080 @samp{<img>} tags. It is likely to be intended to verify whether you
1081 have read the mail. You can prevent your personal informations from
1082 leaking by setting this option to @code{nil} (which is the default).
1083 It is currently ignored by Emacs/w3. For emacs-w3m, you may use the
1084 command @kbd{t} on the image anchor to show an image even if it is
1085 @code{nil}.@footnote{The command @kbd{T} will load all images. If you
1086 have set the option @code{w3m-key-binding} to @code{info}, use @kbd{i}
1087 or @kbd{I} instead.}
1089 @item mm-inline-text-html-with-w3m-keymap
1090 You can use emacs-w3m command keys in the inlined text/html part by
1091 setting this option to non-@code{nil}. The default value is @code{t}.
1097 @section New Viewers
1099 Here's an example viewer for displaying @code{text/enriched} inline:
1102 (defun mm-display-enriched-inline (handle)
1105 (mm-insert-part handle)
1106 (save-window-excursion
1107 (enriched-decode (point-min) (point-max))
1108 (setq text (buffer-string))))
1109 (mm-insert-inline handle text)))
1112 We see that the function takes a @sc{mime} handle as its parameter. It
1113 then goes to a temporary buffer, inserts the text of the part, does some
1114 work on the text, stores the result, goes back to the buffer it was
1115 called from and inserts the result.
1117 The two important helper functions here are @code{mm-insert-part} and
1118 @code{mm-insert-inline}. The first function inserts the text of the
1119 handle in the current buffer. It handles charset and/or content
1120 transfer decoding. The second function just inserts whatever text you
1121 tell it to insert, but it also sets things up so that the text can be
1122 ``undisplayed' in a convenient manner.
1128 @cindex MIME Composing
1130 @cindex MIME Meta Language
1132 Creating a @sc{mime} message is boring and non-trivial. Therefore, a
1133 library called @code{mml} has been defined that parses a language called
1134 MML (@sc{mime} Meta Language) and generates @sc{mime} messages.
1136 @findex mml-generate-mime
1137 The main interface function is @code{mml-generate-mime}. It will
1138 examine the contents of the current (narrowed-to) buffer and return a
1139 string containing the @sc{mime} message.
1142 * Simple MML Example:: An example MML document.
1143 * MML Definition:: All valid MML elements.
1144 * Advanced MML Example:: Another example MML document.
1145 * Charset Translation:: How charsets are mapped from @sc{mule} to @sc{mime}.
1146 * Conversion:: Going from @sc{mime} to MML and vice versa.
1147 * Flowed text:: Soft and hard newlines.
1151 @node Simple MML Example
1152 @section Simple MML Example
1154 Here's a simple @samp{multipart/alternative}:
1157 <#multipart type=alternative>
1158 This is a plain text part.
1159 <#part type=text/enriched>
1160 <center>This is a centered enriched part</center>
1164 After running this through @code{mml-generate-mime}, we get this:
1167 Content-Type: multipart/alternative; boundary="=-=-="
1173 This is a plain text part.
1176 Content-Type: text/enriched
1179 <center>This is a centered enriched part</center>
1185 @node MML Definition
1186 @section MML Definition
1188 The MML language is very simple. It looks a bit like an SGML
1189 application, but it's not.
1191 The main concept of MML is the @dfn{part}. Each part can be of a
1192 different type or use a different charset. The way to delineate a part
1193 is with a @samp{<#part ...>} tag. Multipart parts can be introduced
1194 with the @samp{<#multipart ...>} tag. Parts are ended by the
1195 @samp{<#/part>} or @samp{<#/multipart>} tags. Parts started with the
1196 @samp{<#part ...>} tags are also closed by the next open tag.
1198 There's also the @samp{<#external ...>} tag. These introduce
1199 @samp{external/message-body} parts.
1201 Each tag can contain zero or more parameters on the form
1202 @samp{parameter=value}. The values may be enclosed in quotation marks,
1203 but that's not necessary unless the value contains white space. So
1204 @samp{filename=/home/user/#hello$^yes} is perfectly valid.
1206 The following parameters have meaning in MML; parameters that have no
1207 meaning are ignored. The MML parameter names are the same as the
1208 @sc{mime} parameter names; the things in the parentheses say which
1209 header it will be used in.
1213 The @sc{mime} type of the part (@code{Content-Type}).
1216 Use the contents of the file in the body of the part
1217 (@code{Content-Disposition}).
1220 The contents of the body of the part are to be encoded in the character
1221 set speficied (@code{Content-Type}).
1224 Might be used to suggest a file name if the part is to be saved
1225 to a file (@code{Content-Type}).
1228 Valid values are @samp{inline} and @samp{attachment}
1229 (@code{Content-Disposition}).
1232 Valid values are @samp{7bit}, @samp{8bit}, @samp{quoted-printable} and
1233 @samp{base64} (@code{Content-Transfer-Encoding}).
1236 A description of the part (@code{Content-Description}).
1239 RFC822 date when the part was created (@code{Content-Disposition}).
1241 @item modification-date
1242 RFC822 date when the part was modified (@code{Content-Disposition}).
1245 RFC822 date when the part was read (@code{Content-Disposition}).
1248 Who to encrypt/sign the part to. This field is used to override any
1249 auto-detection based on the To/CC headers.
1252 The size (in octets) of the part (@code{Content-Disposition}).
1255 What technology to sign this MML part with (@code{smime}, @code{pgp}
1259 What technology to encrypt this MML part with (@code{smime},
1260 @code{pgp} or @code{pgpmime})
1264 Parameters for @samp{application/octet-stream}:
1268 Type of the part; informal---meant for human readers
1269 (@code{Content-Type}).
1272 Parameters for @samp{message/external-body}:
1276 A word indicating the supported access mechanism by which the file may
1277 be obtained. Values include @samp{ftp}, @samp{anon-ftp}, @samp{tftp},
1278 @samp{localfile}, and @samp{mailserver}. (@code{Content-Type}.)
1281 The RFC822 date after which the file may no longer be fetched.
1282 (@code{Content-Type}.)
1285 The size (in octets) of the file. (@code{Content-Type}.)
1288 Valid values are @samp{read} and @samp{read-write}
1289 (@code{Content-Type}).
1293 Parameters for @samp{sign=smime}:
1298 File containing key and certificate for signer.
1302 Parameters for @samp{encrypt=smime}:
1307 File containing certificate for recipient.
1312 @node Advanced MML Example
1313 @section Advanced MML Example
1315 Here's a complex multipart message. It's a @samp{multipart/mixed} that
1316 contains many parts, one of which is a @samp{multipart/alternative}.
1319 <#multipart type=mixed>
1320 <#part type=image/jpeg filename=~/rms.jpg disposition=inline>
1321 <#multipart type=alternative>
1322 This is a plain text part.
1323 <#part type=text/enriched name=enriched.txt>
1324 <center>This is a centered enriched part</center>
1326 This is a new plain text part.
1327 <#part disposition=attachment>
1328 This plain text part is an attachment.
1332 And this is the resulting @sc{mime} message:
1335 Content-Type: multipart/mixed; boundary="=-=-="
1343 Content-Type: image/jpeg;
1344 filename="~/rms.jpg"
1345 Content-Disposition: inline;
1346 filename="~/rms.jpg"
1347 Content-Transfer-Encoding: base64
1349 /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRof
1350 Hh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/wAALCAAwADABAREA/8QAHwAA
1351 AQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQR
1352 BRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RF
1353 RkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ip
1354 qrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/9oACAEB
1355 AAA/AO/rifFHjldNuGsrDa0qcSSHkA+gHrXKw+LtWLrMb+RgTyhbr+HSug07xNqV9fQtZrNI
1356 AyiaE/NuBPOOOP0rvRNE880KOC8TbXXGCv1FPqjrF4LDR7u5L7SkTFT/ALWOP1xXgTuXfc7E
1357 sx6nua6rwp4IvvEM8chCxWxOdzn7wz6V9AaB4S07w9p5itow0rDLSY5Pt9K43xO66P4xs71m
1358 2QXiGCbA4yOVJ9+1aYORkdK434lyNH4ahCnG66VT9Nj15JFbPdX0MS43M4VQf5/yr2vSpLnw
1359 5ZW8dlCZ8KFXjOPX0/mK6rSPEGt3Angu44fNEReHYNvIH3TzXDeKNO8RX+kSX2ouZkicTIOc
1360 L+g7E810ulFjpVtv3bwgB3HJyK5L4quY/C9sVxk3ij/xx6850u7t1mtp/wDlpEw3An3Jr3Dw
1361 34gsbWza4nBlhC5LDsaW6+IFgupQyCF3iHH7gA7c9R9ay7zx6t7aX9jHC4smhfBkGCvHGfrm
1362 tLQ7hbnRrV1GPkAP1x1/Hr+Ncr8Vzjwrbf8AX6v/AKA9eQRyYlQk8Yx9K6XTNbkgia2ciSIn
1363 7p5Ga9Atte0LTLKO6it4i7dVRFJDcZ4PvXN+JvEMF9bILVGXJLSZ4zkjivRPDaeX4b08HOTC
1364 pOffmua+KkbS+GLVUGT9tT/0B68eeIpIFYjB70+OOVXyoOM9+M1eaWeCLzHPyHGO/NVWvJJm
1365 jQ8KGH1NfQWhXSXmh2c8eArRLwO3HSv/2Q==
1368 Content-Type: multipart/alternative; boundary="==-=-="
1374 This is a plain text part.
1377 Content-Type: text/enriched;
1381 <center>This is a centered enriched part</center>
1387 This is a new plain text part.
1390 Content-Disposition: attachment
1393 This plain text part is an attachment.
1398 @node Charset Translation
1399 @section Charset Translation
1402 During translation from MML to @sc{mime}, for each @sc{mime} part which
1403 has been composed inside Emacs, an appropriate charset has to be chosen.
1405 @vindex mail-parse-charset
1406 If you are running a non-@sc{mule} Emacs, this process is simple: If the
1407 part contains any non-ASCII (8-bit) characters, the @sc{mime} charset
1408 given by @code{mail-parse-charset} (a symbol) is used. (Never set this
1409 variable directly, though. If you want to change the default charset,
1410 please consult the documentation of the package which you use to process
1412 @xref{Various Message Variables, , Various Message Variables, message,
1413 Message Manual}, for example.)
1414 If there are only ASCII characters, the @sc{mime} charset US-ASCII is
1420 @vindex mm-mime-mule-charset-alist
1421 Things are slightly more complicated when running Emacs with @sc{mule}
1422 support. In this case, a list of the @sc{mule} charsets used in the
1423 part is obtained, and the @sc{mule} charsets are translated to @sc{mime}
1424 charsets by consulting the variable @code{mm-mime-mule-charset-alist}.
1425 If this results in a single @sc{mime} charset, this is used to encode
1426 the part. But if the resulting list of @sc{mime} charsets contains more
1427 than one element, two things can happen: If it is possible to encode the
1428 part via UTF-8, this charset is used. (For this, Emacs must support
1429 the @code{utf-8} coding system, and the part must consist entirely of
1430 characters which have Unicode counterparts.) If UTF-8 is not available
1431 for some reason, the part is split into several ones, so that each one
1432 can be encoded with a single @sc{mime} charset. The part can only be
1433 split at line boundaries, though---if more than one @sc{mime} charset is
1434 required to encode a single line, it is not possible to encode the part.
1440 A (multipart) @sc{mime} message can be converted to MML with the
1441 @code{mime-to-mml} function. It works on the message in the current
1442 buffer, and substitutes MML markup for @sc{mime} boundaries.
1443 Non-textual parts do not have their contents in the buffer, but instead
1444 have the contents in separate buffers that are referred to from the MML
1448 An MML message can be converted back to @sc{mime} by the
1449 @code{mml-to-mime} function.
1451 These functions are in certain senses ``lossy''---you will not get back
1452 an identical message if you run @sc{mime-to-mml} and then
1453 @sc{mml-to-mime}. Not only will trivial things like the order of the
1454 headers differ, but the contents of the headers may also be different.
1455 For instance, the original message may use base64 encoding on text,
1456 while @sc{mml-to-mime} may decide to use quoted-printable encoding, and
1459 In essence, however, these two functions should be the inverse of each
1460 other. The resulting contents of the message should remain equivalent,
1465 @section Flowed text
1466 @cindex format=flowed
1468 The Emacs @sc{mime} library will respect the @code{use-hard-newlines}
1469 variable (@pxref{Hard and Soft Newlines, ,Hard and Soft Newlines,
1470 emacs, Emacs Manual}) when encoding a message, and the
1471 ``format=flowed'' Content-Type parameter when decoding a message.
1473 On encoding text, lines terminated by soft newline characters are
1474 filled together and wrapped after the column decided by
1475 @code{fill-flowed-encode-column}. This variable controls how the text
1476 will look in a client that does not support flowed text, the default
1477 is to wrap after 66 characters. If hard newline characters are not
1478 present in the buffer, no flow encoding occurs.
1480 On decoding flowed text, lines with soft newline characters are filled
1481 together and wrapped after the column decided by
1482 @code{fill-flowed-display-column}. The default is to wrap after
1488 The Emacs @sc{mime} library implements handling of various elements
1489 according to a (somewhat) large number of RFCs, drafts and standards
1490 documents. This chapter lists the relevant ones. They can all be
1491 fetched from @uref{http://quimby.gnus.org/notes/}.
1496 Standard for the Format of ARPA Internet Text Messages.
1499 Standard for Interchange of USENET Messages
1502 Format of Internet Message Bodies
1508 Message Header Extensions for Non-ASCII Text
1511 Registration Procedures
1514 Conformance Criteria and Examples
1517 @sc{mime} Parameter Value and Encoded Word Extensions: Character Sets,
1518 Languages, and Continuations
1521 HZ - A Data Format for Exchanging Files of Arbitrarily Mixed Chinese and
1524 @item draft-ietf-drums-msg-fmt-05.txt
1525 Draft for the successor of RFC822
1528 The @sc{mime} Multipart/Related Content-type
1531 The Multipart/Report Content Type for the Reporting of Mail System
1532 Administrative Messages
1535 Communicating Presentation Information in Internet Messages: The
1536 Content-Disposition Header Field
1539 Documentation of the text/plain format parameter for flowed text.
1555 @c coding: iso-8859-1