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