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