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