annotate lisp/mail/rmailmm.el @ 112415:555faf6e40d0

mm-decode.el (mm-preferred-alternative-precedence): Don't bug out on nested related parts. nnfolder.el (nnfolder-request-expire-articles): Return the list of unexpired articles. This fixes the regression that led expiry marks to disappear from nnfolder groups.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Sat, 22 Jan 2011 12:34:50 +0000
parents ef719132ddfa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1 ;;; rmailmm.el --- MIME decoding and display stuff for RMAIL
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
2
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 112073
diff changeset
3 ;; Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
4
101380
50eed64d8f54 Comment (add Author: header).
Glenn Morris <rgm@gnu.org>
parents: 101370
diff changeset
5 ;; Author: Alexander Pohoyda
50eed64d8f54 Comment (add Author: header).
Glenn Morris <rgm@gnu.org>
parents: 101370
diff changeset
6 ;; Alex Schroeder
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
7 ;; Maintainer: FSF
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
8 ;; Keywords: mail
110015
280c8ae2476d Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents: 109330
diff changeset
9 ;; Package: rmail
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
10
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
12
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
16 ;; (at your option) any later version.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
17
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
22
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
25
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
26 ;;; Commentary:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
27
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
28 ;; Essentially based on the design of Alexander Pohoyda's MIME
102317
562b3a7e1016 Update commentary.
Glenn Morris <rgm@gnu.org>
parents: 101890
diff changeset
29 ;; extensions (mime-display.el and mime.el).
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
30
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
31 ;; This file provides two operation modes for viewing a MIME message.
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
32
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
33 ;; (1) When rmail-enable-mime is non-nil (now it is the default), the
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
34 ;; function `rmail-show-mime' is automatically called. That function
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
35 ;; shows a MIME message directly in RMAIL's view buffer.
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
36
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
37 ;; (2) When rmail-enable-mime is nil, the command 'v' (or M-x
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
38 ;; rmail-mime) shows a MIME message in a new buffer "*RMAIL*".
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
39
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
40 ;; Both operations share the intermediate functions rmail-mime-process
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
41 ;; and rmail-mime-process-multipart as below.
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
42
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
43 ;; rmail-show-mime
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
44 ;; +- rmail-mime-parse
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
45 ;; | +- rmail-mime-process <--+------------+
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
46 ;; | | +---------+ |
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
47 ;; | + rmail-mime-process-multipart --+
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
48 ;; |
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
49 ;; + rmail-mime-insert <----------------+
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
50 ;; +- rmail-mime-insert-text |
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
51 ;; +- rmail-mime-insert-bulk |
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
52 ;; +- rmail-mime-insert-multipart --+
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
53 ;;
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
54 ;; rmail-mime
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
55 ;; +- rmail-mime-show <----------------------------------+
112098
40af77a50adc Merge changes from emacs-23 branch
Chong Yidong <cyd@stupidchicken.com>
parents: 111945 112073
diff changeset
56 ;; +- rmail-mime-process |
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
57 ;; +- rmail-mime-handle |
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
58 ;; +- rmail-mime-text-handler |
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
59 ;; +- rmail-mime-bulk-handler |
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
60 ;; | + rmail-mime-insert-bulk
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
61 ;; +- rmail-mime-multipart-handler |
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
62 ;; +- rmail-mime-process-multipart --+
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
63
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
64 ;; In addition, for the case of rmail-enable-mime being non-nil, this
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
65 ;; file provides two functions rmail-insert-mime-forwarded-message and
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
66 ;; rmail-insert-mime-resent-message for composing forwarded and resent
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
67 ;; messages respectively.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
68
105176
debabf496159 (rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents: 105175
diff changeset
69 ;; Todo:
debabf496159 (rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents: 105175
diff changeset
70
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
71 ;; Make rmail-mime-media-type-handlers-alist usable in the first
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
72 ;; operation mode.
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
73 ;; Handle multipart/alternative in the second operation mode.
105211
7c61dadc38f9 (rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents: 105198
diff changeset
74 ;; Offer the option to call external/internal viewers (doc-view, xpdf, etc).
105176
debabf496159 (rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents: 105175
diff changeset
75
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
76 ;;; Code:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
77
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
78 (require 'rmail)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
79 (require 'mail-parse)
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
80 (require 'message)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
81
102403
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
82 ;;; User options.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
83
105193
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
84 (defgroup rmail-mime nil
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
85 "Rmail MIME handling options."
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
86 :prefix "rmail-mime-"
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
87 :group 'rmail)
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
88
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
89 (defcustom rmail-mime-media-type-handlers-alist
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
90 '(("multipart/.*" rmail-mime-multipart-handler)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
91 ("text/.*" rmail-mime-text-handler)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
92 ("text/\\(x-\\)?patch" rmail-mime-bulk-handler)
105193
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
93 ("\\(image\\|audio\\|video\\|application\\)/.*" rmail-mime-bulk-handler))
102403
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
94 "Functions to handle various content types.
102421
62a954f574fa (rmail-mime-media-type-handlers-alist): Fix doc and custom type.
Glenn Morris <rgm@gnu.org>
parents: 102403
diff changeset
95 This is an alist with elements of the form (REGEXP FUNCTION ...).
62a954f574fa (rmail-mime-media-type-handlers-alist): Fix doc and custom type.
Glenn Morris <rgm@gnu.org>
parents: 102403
diff changeset
96 The first item is a regular expression matching a content-type.
62a954f574fa (rmail-mime-media-type-handlers-alist): Fix doc and custom type.
Glenn Morris <rgm@gnu.org>
parents: 102403
diff changeset
97 The remaining elements are handler functions to run, in order of
105176
debabf496159 (rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents: 105175
diff changeset
98 decreasing preference. These are called until one returns non-nil.
debabf496159 (rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents: 105175
diff changeset
99 Note that this only applies to items with an inline Content-Disposition,
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
100 all others are handled by `rmail-mime-bulk-handler'.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
101 Note also that this alist is ignored when the variable
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
102 `rmail-enable-mime' is non-nil."
102421
62a954f574fa (rmail-mime-media-type-handlers-alist): Fix doc and custom type.
Glenn Morris <rgm@gnu.org>
parents: 102403
diff changeset
103 :type '(alist :key-type regexp :value-type (repeat function))
105193
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
104 :version "23.1"
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
105 :group 'rmail-mime)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
106
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
107 (defcustom rmail-mime-attachment-dirs-alist
101890
4f858364bb26 (rmail-mime-attachment-dirs-alist): Use temporary-file-directory.
Chong Yidong <cyd@stupidchicken.com>
parents: 101380
diff changeset
108 `(("text/.*" "~/Documents")
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
109 ("image/.*" "~/Pictures")
101890
4f858364bb26 (rmail-mime-attachment-dirs-alist): Use temporary-file-directory.
Chong Yidong <cyd@stupidchicken.com>
parents: 101380
diff changeset
110 (".*" "~/Desktop" "~" ,temporary-file-directory))
102403
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
111 "Default directories to save attachments of various types into.
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
112 This is an alist with elements of the form (REGEXP DIR ...).
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
113 The first item is a regular expression matching a content-type.
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
114 The remaining elements are directories, in order of decreasing preference.
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
115 The first directory that exists is used."
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
116 :type '(alist :key-type regexp :value-type (repeat directory))
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
117 :version "23.1"
105193
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
118 :group 'rmail-mime)
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
119
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
120 (defcustom rmail-mime-show-images 'button
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
121 "What to do with image attachments that Emacs is capable of displaying.
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
122 If nil, do nothing special. If `button', add an extra button
105211
7c61dadc38f9 (rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents: 105198
diff changeset
123 that when pushed displays the image in the buffer. If a number,
7c61dadc38f9 (rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents: 105198
diff changeset
124 automatically show images if they are smaller than that size (in
7c61dadc38f9 (rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents: 105198
diff changeset
125 bytes), otherwise add a display button. Anything else means to
7c61dadc38f9 (rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents: 105198
diff changeset
126 automatically display the image in the buffer."
105193
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
127 :type '(choice (const :tag "Add button to view image" button)
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
128 (const :tag "No special treatment" nil)
105211
7c61dadc38f9 (rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents: 105198
diff changeset
129 (number :tag "Show if smaller than certain size")
105193
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
130 (other :tag "Always show" show))
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
131 :version "23.2"
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
132 :group 'rmail-mime)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
133
102403
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
134 ;;; End of user options.
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
135
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
136 ;;; Global variables that always have let-binding when referred.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
137
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
138 (defvar rmail-mime-mbox-buffer nil
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
139 "Buffer containing the mbox data.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
140 The value is usually nil, and bound to a proper value while
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
141 processing MIME.")
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
142
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
143 (defvar rmail-mime-view-buffer nil
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
144 "Buffer showing a message.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
145 The value is usually nil, and bound to a proper value while
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
146 processing MIME.")
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
147
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
148 (defvar rmail-mime-coding-system nil
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
149 "The first coding-system used for decoding a MIME entity.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
150 The value is usually nil, and bound to non-nil while inserting
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
151 MIME entities.")
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
152
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
153 ;;; MIME-entity object
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
154
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
155 (defun rmail-mime-entity (type disposition transfer-encoding
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
156 display header tagline body children handler)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
157 "Retrun a newly created MIME-entity object from arguments.
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
158
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
159 A MIME-entity is a vector of 9 elements:
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
160
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
161 [TYPE DISPOSITION TRANSFER-ENCODING DISPLAY HEADER TAGLINE BODY
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
162 CHILDREN HANDLER]
112098
40af77a50adc Merge changes from emacs-23 branch
Chong Yidong <cyd@stupidchicken.com>
parents: 111945 112073
diff changeset
163
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
164 TYPE and DISPOSITION correspond to MIME headers Content-Type and
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
165 Cotent-Disposition respectively, and has this format:
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
166
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
167 \(VALUE (ATTRIBUTE . VALUE) (ATTRIBUTE . VALUE) ...)
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
168
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
169 VALUE is a string and ATTRIBUTE is a symbol.
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
170
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
171 Consider the following header, for example:
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
172
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
173 Content-Type: multipart/mixed;
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
174 boundary=\"----=_NextPart_000_0104_01C617E4.BDEC4C40\"
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
175
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
176 The corresponding TYPE argument must be:
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
177
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
178 \(\"multipart/mixed\"
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
179 \(\"boundary\" . \"----=_NextPart_000_0104_01C617E4.BDEC4C40\"))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
180
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
181 TRANSFER-ENCODING corresponds to MIME header
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
182 Content-Transfer-Encoding, and is a lowercased string.
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
183
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
184 DISPLAY is a vector [CURRENT NEW], where CURRENT indicates how
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
185 the header, tagline, and body of the entity are displayed now,
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
186 and NEW indicates how their displaying should be updated.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
187 Both elements are vector [HEADER-DISPLAY TAGLINE-DISPLAY BODY-DISPLAY],
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
188 where each element is a symbol for the corresponding item that
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
189 has these values:
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
190 nil: not displayed
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
191 t: displayed by the decoded presentation form
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
192 raw: displayed by the raw MIME data (for the header and body only)
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
193
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
194 HEADER and BODY are vectors [BEG END DISPLAY-FLAG], where BEG and
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
195 END specify the region of the header or body lines in RMAIL's
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
196 data (mbox) buffer, and DISPLAY-FLAG non-nil means that the
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
197 header or body is, by default, displayed by the decoded
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
198 presentation form.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
199
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
200 TAGLINE is a vector [TAG BULK-DATA DISPLAY-FLAG], where TAG is a
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
201 string indicating the depth and index number of the entity,
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
202 BULK-DATA is a cons (SIZE . TYPE) indicating the size and type of
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
203 an attached data, DISPLAY-FLAG non-nil means that the tagline is,
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
204 by default, displayed.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
205
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
206 CHILDREN is a list of child MIME-entities. A \"multipart/*\"
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
207 entity have one or more children. A \"message/rfc822\" entity
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
208 has just one child. Any other entity has no child.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
209
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
210 HANDLER is a function to insert the entity according to DISPLAY.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
211 It is called with one argument ENTITY."
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
212 (vector type disposition transfer-encoding
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
213 display header tagline body children handler))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
214
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
215 ;; Accessors for a MIME-entity object.
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
216 (defsubst rmail-mime-entity-type (entity) (aref entity 0))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
217 (defsubst rmail-mime-entity-disposition (entity) (aref entity 1))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
218 (defsubst rmail-mime-entity-transfer-encoding (entity) (aref entity 2))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
219 (defsubst rmail-mime-entity-display (entity) (aref entity 3))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
220 (defsubst rmail-mime-entity-header (entity) (aref entity 4))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
221 (defsubst rmail-mime-entity-tagline (entity) (aref entity 5))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
222 (defsubst rmail-mime-entity-body (entity) (aref entity 6))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
223 (defsubst rmail-mime-entity-children (entity) (aref entity 7))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
224 (defsubst rmail-mime-entity-handler (entity) (aref entity 8))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
225
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
226 (defsubst rmail-mime-message-p ()
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
227 "Non-nil if and only if the current message is a MIME."
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
228 (or (get-text-property (point) 'rmail-mime-entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
229 (get-text-property (point-min) 'rmail-mime-entity)))
102403
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
230
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
231 ;;; Buttons
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
232
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
233 (defun rmail-mime-save (button)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
234 "Save the attachment using info in the BUTTON."
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
235 (let* ((rmail-mime-mbox-buffer rmail-view-buffer)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
236 (filename (button-get button 'filename))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
237 (directory (button-get button 'directory))
105019
a4b91a313ddf (rmail-mime-save): If file exists, don't try to be clever and add a
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
238 (data (button-get button 'data))
a4b91a313ddf (rmail-mime-save): If file exists, don't try to be clever and add a
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
239 (ofilename filename))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
240 (setq filename (expand-file-name
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
241 (read-file-name (format "Save as (default: %s): " filename)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
242 directory
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
243 (expand-file-name filename directory))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
244 directory))
105019
a4b91a313ddf (rmail-mime-save): If file exists, don't try to be clever and add a
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
245 ;; If arg is just a directory, use the default file name, but in
a4b91a313ddf (rmail-mime-save): If file exists, don't try to be clever and add a
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
246 ;; that directory (copied from write-file).
a4b91a313ddf (rmail-mime-save): If file exists, don't try to be clever and add a
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
247 (if (file-directory-p filename)
a4b91a313ddf (rmail-mime-save): If file exists, don't try to be clever and add a
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
248 (setq filename (expand-file-name
a4b91a313ddf (rmail-mime-save): If file exists, don't try to be clever and add a
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
249 (file-name-nondirectory ofilename)
a4b91a313ddf (rmail-mime-save): If file exists, don't try to be clever and add a
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
250 (file-name-as-directory filename))))
a4b91a313ddf (rmail-mime-save): If file exists, don't try to be clever and add a
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
251 (with-temp-buffer
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
252 (set-buffer-file-coding-system 'no-conversion)
109330
d03ee75f7be2 mail/rmailmm.el (rmail-mime-save): Make the temp buffer unibyte,
Eli Zaretskii <eliz@gnu.org>
parents: 106953
diff changeset
253 ;; Needed e.g. by jka-compr, so if the attachment is a compressed
d03ee75f7be2 mail/rmailmm.el (rmail-mime-save): Make the temp buffer unibyte,
Eli Zaretskii <eliz@gnu.org>
parents: 106953
diff changeset
254 ;; file, the magic signature compares equal with the unibyte
d03ee75f7be2 mail/rmailmm.el (rmail-mime-save): Make the temp buffer unibyte,
Eli Zaretskii <eliz@gnu.org>
parents: 106953
diff changeset
255 ;; signature string recorded in jka-compr-compression-info-list.
d03ee75f7be2 mail/rmailmm.el (rmail-mime-save): Make the temp buffer unibyte,
Eli Zaretskii <eliz@gnu.org>
parents: 106953
diff changeset
256 (set-buffer-multibyte nil)
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
257 (setq buffer-undo-list t)
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
258 (if (stringp data)
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
259 (insert data)
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
260 ;; DATA is a MIME-entity object.
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
261 (let ((transfer-encoding (rmail-mime-entity-transfer-encoding data))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
262 (body (rmail-mime-entity-body data)))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
263 (insert-buffer-substring rmail-mime-mbox-buffer
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
264 (aref body 0) (aref body 1))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
265 (cond ((string= transfer-encoding "base64")
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
266 (ignore-errors (base64-decode-region (point-min) (point-max))))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
267 ((string= transfer-encoding "quoted-printable")
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
268 (quoted-printable-decode-region (point-min) (point-max))))))
105019
a4b91a313ddf (rmail-mime-save): If file exists, don't try to be clever and add a
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
269 (write-region nil nil filename nil nil nil t))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
270
105019
a4b91a313ddf (rmail-mime-save): If file exists, don't try to be clever and add a
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
271 (define-button-type 'rmail-mime-save 'action 'rmail-mime-save)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
272
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
273 (defun rmail-mime-entity-segment (pos &optional entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
274 "Return a vector describing the displayed region of a MIME-entity at POS.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
275 Optional 2nd argument ENTITY is the MIME-entity at POS.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
276 The value is a vector [ INDEX HEADER TAGLINE BODY END], where
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
277 INDEX: index into the returned vector indicating where POS is (1..3).
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
278 HEADER: the position of the beginning of a header
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
279 TAGLINE: the position of the beginning of a tagline
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
280 BODY: the position of the beginning of a body
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
281 END: the position of the end of the entity."
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
282 (save-excursion
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
283 (or entity
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
284 (setq entity (get-text-property pos 'rmail-mime-entity)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
285 (if (not entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
286 (vector 1 (point) (point) (point) (point))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
287 (let ((current (aref (rmail-mime-entity-display entity) 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
288 (beg (if (and (> pos (point-min))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
289 (eq (get-text-property (1- pos) 'rmail-mime-entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
290 entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
291 (previous-single-property-change pos 'rmail-mime-entity
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
292 nil (point-min))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
293 pos))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
294 (index 1)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
295 tagline-beg body-beg end)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
296 (goto-char beg)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
297 (if (aref current 0)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
298 (search-forward "\n\n" nil t))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
299 (setq tagline-beg (point))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
300 (if (>= pos tagline-beg)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
301 (setq index 2))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
302 (if (aref current 1)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
303 (forward-line 1))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
304 (setq body-beg (point))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
305 (if (>= pos body-beg)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
306 (setq index 3))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
307 (if (aref current 2)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
308 (let ((tag (aref (rmail-mime-entity-tagline entity) 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
309 tag2)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
310 (setq end (next-single-property-change beg 'rmail-mime-entity
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
311 nil (point-max)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
312 (while (and (< end (point-max))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
313 (setq entity (get-text-property end 'rmail-mime-entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
314 tag2 (aref (rmail-mime-entity-tagline entity) 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
315 (and (> (length tag2) 0)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
316 (eq (string-match tag tag2) 0)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
317 (setq end (next-single-property-change end 'rmail-mime-entity
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
318 nil (point-max)))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
319 (setq end body-beg))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
320 (vector index beg tagline-beg body-beg end)))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
321
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
322 (defun rmail-mime-shown-mode (entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
323 "Make MIME-entity ENTITY displayed by the default way."
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
324 (let ((new (aref (rmail-mime-entity-display entity) 1)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
325 (aset new 0 (aref (rmail-mime-entity-header entity) 2))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
326 (aset new 1 (aref (rmail-mime-entity-tagline entity) 2))
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
327 (aset new 2 (aref (rmail-mime-entity-body entity) 2)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
328 (dolist (child (rmail-mime-entity-children entity))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
329 (rmail-mime-shown-mode child)))
112098
40af77a50adc Merge changes from emacs-23 branch
Chong Yidong <cyd@stupidchicken.com>
parents: 111945 112073
diff changeset
330
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
331 (defun rmail-mime-hidden-mode (entity)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
332 "Make MIME-entity ENTITY displayed in the hidden mode."
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
333 (let ((new (aref (rmail-mime-entity-display entity) 1)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
334 (aset new 0 nil)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
335 (aset new 1 t)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
336 (aset new 2 nil))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
337 (dolist (child (rmail-mime-entity-children entity))
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
338 (rmail-mime-hidden-mode child)))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
339
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
340 (defun rmail-mime-raw-mode (entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
341 "Make MIME-entity ENTITY displayed in the raw mode."
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
342 (let ((new (aref (rmail-mime-entity-display entity) 1)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
343 (aset new 0 'raw)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
344 (aset new 1 nil)
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
345 (aset new 2 'raw))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
346 (dolist (child (rmail-mime-entity-children entity))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
347 (rmail-mime-raw-mode child)))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
348
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
349 (defun rmail-mime-toggle-raw (entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
350 "Toggle on and off the raw display mode of MIME-entity ENTITY."
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
351 (let* ((pos (if (eobp) (1- (point-max)) (point)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
352 (entity (get-text-property pos 'rmail-mime-entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
353 (current (aref (rmail-mime-entity-display entity) 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
354 (segment (rmail-mime-entity-segment pos entity)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
355 (if (not (eq (aref current 0) 'raw))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
356 ;; Enter the raw mode.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
357 (rmail-mime-raw-mode entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
358 ;; Enter the shown mode.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
359 (rmail-mime-shown-mode entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
360 (let ((inhibit-read-only t)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
361 (modified (buffer-modified-p)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
362 (save-excursion
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
363 (goto-char (aref segment 1))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
364 (rmail-mime-insert entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
365 (restore-buffer-modified-p modified)))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
366
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
367 (defun rmail-mime-toggle-hidden ()
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
368 "Hide or show the body of MIME-entity at point."
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
369 (interactive)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
370 (when (rmail-mime-message-p)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
371 (let* ((rmail-mime-mbox-buffer rmail-view-buffer)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
372 (rmail-mime-view-buffer (current-buffer))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
373 (pos (if (eobp) (1- (point-max)) (point)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
374 (entity (get-text-property pos 'rmail-mime-entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
375 (current (aref (rmail-mime-entity-display entity) 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
376 (segment (rmail-mime-entity-segment pos entity)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
377 (if (aref current 2)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
378 ;; Enter the hidden mode.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
379 (progn
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
380 ;; If point is in the body part, move it to the tagline
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
381 ;; (or the header if tagline is not displayed).
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
382 (if (= (aref segment 0) 3)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
383 (goto-char (aref segment 2)))
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
384 (rmail-mime-hidden-mode entity)
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
385 ;; If the current entity is the topmost one, display the
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
386 ;; header.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
387 (if (and rmail-mime-mbox-buffer (= (aref segment 1) (point-min)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
388 (let ((new (aref (rmail-mime-entity-display entity) 1)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
389 (aset new 0 t))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
390 ;; Enter the shown mode.
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
391 (rmail-mime-shown-mode entity)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
392 ;; Force this body shown.
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
393 (aset (aref (rmail-mime-entity-display entity) 1) 2 t))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
394 (let ((inhibit-read-only t)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
395 (modified (buffer-modified-p))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
396 (rmail-mime-mbox-buffer rmail-view-buffer)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
397 (rmail-mime-view-buffer rmail-buffer))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
398 (save-excursion
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
399 (goto-char (aref segment 1))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
400 (rmail-mime-insert entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
401 (restore-buffer-modified-p modified))))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
402
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
403 (define-key rmail-mode-map "\t" 'forward-button)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
404 (define-key rmail-mode-map [backtab] 'backward-button)
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
405 (define-key rmail-mode-map "\r" 'rmail-mime-toggle-hidden)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
406
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
407 ;;; Handlers
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
408
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
409 (defun rmail-mime-insert-tagline (entity &rest item-list)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
410 "Insert a tag line for MIME-entity ENTITY.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
411 ITEM-LIST is a list of strings or button-elements (list) to be added
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
412 to the tag line."
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
413 (insert "[")
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
414 (let ((tag (aref (rmail-mime-entity-tagline entity) 0)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
415 (if (> (length tag) 0) (insert (substring tag 1) ":")))
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
416 (insert (car (rmail-mime-entity-type entity)) " ")
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
417 (insert-button (let ((new (aref (rmail-mime-entity-display entity) 1)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
418 (if (aref new 2) "Hide" "Show"))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
419 :type 'rmail-mime-toggle
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
420 'help-echo "mouse-2, RET: Toggle show/hide")
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
421 (dolist (item item-list)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
422 (when item
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
423 (if (stringp item)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
424 (insert item)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
425 (apply 'insert-button item))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
426 (insert "]\n"))
112098
40af77a50adc Merge changes from emacs-23 branch
Chong Yidong <cyd@stupidchicken.com>
parents: 111945 112073
diff changeset
427
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
428 (defun rmail-mime-update-tagline (entity)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
429 "Update the current tag line for MIME-entity ENTITY."
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
430 (let ((inhibit-read-only t)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
431 (modified (buffer-modified-p))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
432 ;; If we are going to show the body, the new button label is
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
433 ;; "Hide". Otherwise, it's "Show".
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
434 (label (if (aref (aref (rmail-mime-entity-display entity) 1) 2) "Hide"
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
435 "Show"))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
436 (button (next-button (point))))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
437 ;; Go to the second character of the button "Show" or "Hide".
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
438 (goto-char (1+ (button-start button)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
439 (setq button (button-at (point)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
440 (save-excursion
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
441 (insert label)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
442 (delete-region (point) (button-end button)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
443 (delete-region (button-start button) (point))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
444 (put-text-property (point) (button-end button) 'rmail-mime-entity entity)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
445 (restore-buffer-modified-p modified)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
446 (forward-line 1)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
447
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
448 (defun rmail-mime-insert-header (header)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
449 "Decode and insert a MIME-entity header HEADER in the current buffer.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
450 HEADER is a vector [BEG END DEFAULT-STATUS].
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
451 See `rmail-mime-entity' for the detail."
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
452 (let ((pos (point))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
453 (last-coding-system-used nil))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
454 (save-restriction
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
455 (narrow-to-region pos pos)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
456 (with-current-buffer rmail-mime-mbox-buffer
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
457 (let ((rmail-buffer rmail-mime-mbox-buffer)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
458 (rmail-view-buffer rmail-mime-view-buffer))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
459 (save-excursion
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
460 (goto-char (aref header 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
461 (rmail-copy-headers (point) (aref header 1)))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
462 (rfc2047-decode-region pos (point))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
463 (if (and last-coding-system-used (not rmail-mime-coding-system))
112263
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
464 (setq rmail-mime-coding-system (cons last-coding-system-used nil)))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
465 (goto-char (point-min))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
466 (rmail-highlight-headers)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
467 (goto-char (point-max))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
468 (insert "\n"))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
469
112263
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
470 (defun rmail-mime-find-header-encoding (header)
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
471 "Retun the last coding system used to decode HEADER.
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
472 HEADER is a header component of a MIME-entity object (see
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
473 `rmail-mime-entity')."
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
474 (with-temp-buffer
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
475 (let ((last-coding-system-used nil))
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
476 (with-current-buffer rmail-mime-mbox-buffer
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
477 (let ((rmail-buffer rmail-mime-mbox-buffer)
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
478 (rmail-view-buffer rmail-mime-view-buffer))
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
479 (save-excursion
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
480 (goto-char (aref header 0))
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
481 (rmail-copy-headers (point) (aref header 1)))))
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
482 (rfc2047-decode-region (point-min) (point-max))
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
483 last-coding-system-used)))
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
484
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
485 (defun rmail-mime-text-handler (content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
486 content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
487 content-transfer-encoding)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
488 "Handle the current buffer as a plain text MIME part."
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
489 (rmail-mime-insert-text
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
490 (rmail-mime-entity content-type content-disposition
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
491 content-transfer-encoding
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
492 (vector (vector nil nil nil) (vector nil nil t))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
493 (vector nil nil nil) (vector "" (cons nil nil) t)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
494 (vector nil nil nil) nil 'rmail-mime-insert-text))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
495 t)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
496
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
497 (defun rmail-mime-insert-decoded-text (entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
498 "Decode and insert the text body of MIME-entity ENTITY."
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
499 (let* ((content-type (rmail-mime-entity-type entity))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
500 (charset (cdr (assq 'charset (cdr content-type))))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
501 (coding-system (if charset
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
502 (coding-system-from-name charset)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
503 (body (rmail-mime-entity-body entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
504 (pos (point)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
505 (or (and coding-system (coding-system-p coding-system))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
506 (setq coding-system 'undecided))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
507 (if (stringp (aref body 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
508 (insert (aref body 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
509 (let ((transfer-encoding (rmail-mime-entity-transfer-encoding entity)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
510 (insert-buffer-substring rmail-mime-mbox-buffer
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
511 (aref body 0) (aref body 1))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
512 (cond ((string= transfer-encoding "base64")
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
513 (ignore-errors (base64-decode-region pos (point))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
514 ((string= transfer-encoding "quoted-printable")
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
515 (quoted-printable-decode-region pos (point))))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
516 (decode-coding-region pos (point) coding-system)
112263
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
517 (if (or (not rmail-mime-coding-system) (consp rmail-mime-coding-system))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
518 (setq rmail-mime-coding-system coding-system))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
519 (or (bolp) (insert "\n"))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
520
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
521 (defun rmail-mime-insert-text (entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
522 "Presentation handler for a plain text MIME entity."
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
523 (let ((current (aref (rmail-mime-entity-display entity) 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
524 (new (aref (rmail-mime-entity-display entity) 1))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
525 (header (rmail-mime-entity-header entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
526 (tagline (rmail-mime-entity-tagline entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
527 (body (rmail-mime-entity-body entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
528 (beg (point))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
529 (segment (rmail-mime-entity-segment (point) entity)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
530
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
531 (or (integerp (aref body 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
532 (let ((data (buffer-string)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
533 (aset body 0 data)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
534 (delete-region (point-min) (point-max))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
535
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
536 ;; header
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
537 (if (eq (aref current 0) (aref new 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
538 (goto-char (aref segment 2))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
539 (if (aref current 0)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
540 (delete-char (- (aref segment 2) (aref segment 1))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
541 (if (aref new 0)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
542 (rmail-mime-insert-header header)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
543 ;; tagline
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
544 (if (eq (aref current 1) (aref new 1))
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
545 (if (or (not (aref current 1))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
546 (eq (aref current 2) (aref new 2)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
547 (forward-char (- (aref segment 3) (aref segment 2)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
548 (rmail-mime-update-tagline entity))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
549 (if (aref current 1)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
550 (delete-char (- (aref segment 3) (aref segment 2))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
551 (if (aref new 1)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
552 (rmail-mime-insert-tagline entity)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
553 ;; body
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
554 (if (eq (aref current 2) (aref new 2))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
555 (forward-char (- (aref segment 4) (aref segment 3)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
556 (if (aref current 2)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
557 (delete-char (- (aref segment 4) (aref segment 3))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
558 (if (aref new 2)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
559 (rmail-mime-insert-decoded-text entity)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
560 (put-text-property beg (point) 'rmail-mime-entity entity)))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
561
102403
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
562 ;; FIXME move to the test/ directory?
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
563 (defun test-rmail-mime-handler ()
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
564 "Test of a mail using no MIME parts at all."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
565 (let ((mail "To: alex@gnu.org
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
566 Content-Type: text/plain; charset=koi8-r
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
567 Content-Transfer-Encoding: 8bit
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
568 MIME-Version: 1.0
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
569
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
570 \372\304\322\301\327\323\324\327\325\312\324\305\41"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
571 (switch-to-buffer (get-buffer-create "*test*"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
572 (erase-buffer)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
573 (set-buffer-multibyte nil)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
574 (insert mail)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
575 (rmail-mime-show t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
576 (set-buffer-multibyte t)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
577
105193
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
578
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
579 (defun rmail-mime-insert-image (entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
580 "Decode and insert the image body of MIME-entity ENTITY."
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
581 (let* ((content-type (car (rmail-mime-entity-type entity)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
582 (bulk-data (aref (rmail-mime-entity-tagline entity) 1))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
583 (body (rmail-mime-entity-body entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
584 data)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
585 (if (stringp (aref body 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
586 (setq data (aref body 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
587 (let ((rmail-mime-mbox-buffer rmail-view-buffer)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
588 (transfer-encoding (rmail-mime-entity-transfer-encoding entity)))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
589 (with-temp-buffer
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
590 (set-buffer-multibyte nil)
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
591 (setq buffer-undo-list t)
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
592 (insert-buffer-substring rmail-mime-mbox-buffer
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
593 (aref body 0) (aref body 1))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
594 (cond ((string= transfer-encoding "base64")
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
595 (ignore-errors (base64-decode-region (point-min) (point-max))))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
596 ((string= transfer-encoding "quoted-printable")
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
597 (quoted-printable-decode-region (point-min) (point-max))))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
598 (setq data
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
599 (buffer-substring-no-properties (point-min) (point-max))))))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
600 (insert-image (create-image data (cdr bulk-data) t))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
601 (insert "\n")))
105193
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
602
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
603 (defun rmail-mime-toggle-button (button)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
604 "Hide or show the body of the MIME-entity associated with BUTTON."
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
605 (save-excursion
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
606 (goto-char (button-start button))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
607 (rmail-mime-toggle-hidden)))
105193
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
608
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
609 (define-button-type 'rmail-mime-toggle 'action 'rmail-mime-toggle-button)
105193
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
610
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
611
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
612 (defun rmail-mime-bulk-handler (content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
613 content-disposition
105193
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
614 content-transfer-encoding)
105176
debabf496159 (rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents: 105175
diff changeset
615 "Handle the current buffer as an attachment to download.
105193
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
616 For images that Emacs is capable of displaying, the behavior
d05b41e0a7ef (rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 105176
diff changeset
617 depends upon the value of `rmail-mime-show-images'."
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
618 (rmail-mime-insert-bulk
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
619 (rmail-mime-entity content-type content-disposition content-transfer-encoding
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
620 (vector (vector nil nil nil) (vector nil t nil))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
621 (vector nil nil nil) (vector "" (cons nil nil) t)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
622 (vector nil nil nil) nil 'rmail-mime-insert-bulk)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
623
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
624 (defun rmail-mime-set-bulk-data (entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
625 "Setup the information about the attachment object for MIME-entity ENTITY.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
626 The value is non-nil if and only if the attachment object should be shown
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
627 directly."
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
628 (let ((content-type (car (rmail-mime-entity-type entity)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
629 (size (cdr (assq 'size (cdr (rmail-mime-entity-disposition entity)))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
630 (bulk-data (aref (rmail-mime-entity-tagline entity) 1))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
631 (body (rmail-mime-entity-body entity))
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
632 type to-show)
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
633 (cond (size
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
634 (setq size (string-to-number size)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
635 ((stringp (aref body 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
636 (setq size (length (aref body 0))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
637 (t
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
638 ;; Rough estimation of the size.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
639 (let ((encoding (rmail-mime-entity-transfer-encoding entity)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
640 (setq size (- (aref body 1) (aref body 0)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
641 (cond ((string= encoding "base64")
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
642 (setq size (/ (* size 3) 4)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
643 ((string= encoding "quoted-printable")
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
644 (setq size (/ (* size 7) 3)))))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
645
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
646 (cond
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
647 ((string-match "text/" content-type)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
648 (setq type 'text))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
649 ((string-match "image/\\(.*\\)" content-type)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
650 (setq type (image-type-from-file-name
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
651 (concat "." (match-string 1 content-type))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
652 (if (and (memq type image-types)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
653 (image-type-available-p type))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
654 (if (and rmail-mime-show-images
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
655 (not (eq rmail-mime-show-images 'button))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
656 (or (not (numberp rmail-mime-show-images))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
657 (< size rmail-mime-show-images)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
658 (setq to-show t))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
659 (setq type nil))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
660 (setcar bulk-data size)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
661 (setcdr bulk-data type)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
662 to-show))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
663
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
664 (defun rmail-mime-insert-bulk (entity)
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
665 "Presentation handler for an attachment MIME entity."
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
666 (let* ((content-type (rmail-mime-entity-type entity))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
667 (content-disposition (rmail-mime-entity-disposition entity))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
668 (current (aref (rmail-mime-entity-display entity) 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
669 (new (aref (rmail-mime-entity-display entity) 1))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
670 (header (rmail-mime-entity-header entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
671 (tagline (rmail-mime-entity-tagline entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
672 (bulk-data (aref tagline 1))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
673 (body (rmail-mime-entity-body entity))
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
674 ;; Find the default directory for this media type.
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
675 (directory (catch 'directory
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
676 (dolist (entry rmail-mime-attachment-dirs-alist)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
677 (when (string-match (car entry) (car content-type))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
678 (dolist (dir (cdr entry))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
679 (when (file-directory-p dir)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
680 (throw 'directory dir)))))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
681 (filename (or (cdr (assq 'name (cdr content-type)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
682 (cdr (assq 'filename (cdr content-disposition)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
683 "noname"))
105198
550b90cc7226 (rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents: 105193
diff changeset
684 (units '(B kB MB GB))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
685 (segment (rmail-mime-entity-segment (point) entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
686 beg data size)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
687
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
688 (if (integerp (aref body 0))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
689 (setq data entity
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
690 size (car bulk-data))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
691 (if (stringp (aref body 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
692 (setq data (aref body 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
693 (setq data (string-as-unibyte (buffer-string)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
694 (aset body 0 data)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
695 (rmail-mime-set-bulk-data entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
696 (delete-region (point-min) (point-max)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
697 (setq size (length data)))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
698 (while (and (> size 1024.0) ; cribbed from gnus-agent-expire-done-message
105198
550b90cc7226 (rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents: 105193
diff changeset
699 (cdr units))
550b90cc7226 (rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents: 105193
diff changeset
700 (setq size (/ size 1024.0)
550b90cc7226 (rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents: 105193
diff changeset
701 units (cdr units)))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
702
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
703 (setq beg (point))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
704
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
705 ;; header
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
706 (if (eq (aref current 0) (aref new 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
707 (goto-char (aref segment 2))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
708 (if (aref current 0)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
709 (delete-char (- (aref segment 2) (aref segment 1))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
710 (if (aref new 0)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
711 (rmail-mime-insert-header header)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
712
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
713 ;; tagline
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
714 (if (eq (aref current 1) (aref new 1))
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
715 (if (or (not (aref current 1))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
716 (eq (aref current 2) (aref new 2)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
717 (forward-char (- (aref segment 3) (aref segment 2)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
718 (rmail-mime-update-tagline entity))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
719 (if (aref current 1)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
720 (delete-char (- (aref segment 3) (aref segment 2))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
721 (if (aref new 1)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
722 (rmail-mime-insert-tagline
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
723 entity
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
724 " Save:"
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
725 (list filename
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
726 :type 'rmail-mime-save
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
727 'help-echo "mouse-2, RET: Save attachment"
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
728 'filename filename
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
729 'directory (file-name-as-directory directory)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
730 'data data)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
731 (format " (%.0f%s)" size (car units))
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
732 ;; We don't need this button because the "type" string of a
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
733 ;; tagline is the button to do this.
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
734 ;; (if (cdr bulk-data)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
735 ;; " ")
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
736 ;; (if (cdr bulk-data)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
737 ;; (list "Toggle show/hide"
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
738 ;; :type 'rmail-mime-image
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
739 ;; 'help-echo "mouse-2, RET: Toggle show/hide"
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
740 ;; 'image-type (cdr bulk-data)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
741 ;; 'image-data data))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
742 )))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
743 ;; body
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
744 (if (eq (aref current 2) (aref new 2))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
745 (forward-char (- (aref segment 4) (aref segment 3)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
746 (if (aref current 2)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
747 (delete-char (- (aref segment 4) (aref segment 3))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
748 (if (aref new 2)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
749 (cond ((eq (cdr bulk-data) 'text)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
750 (rmail-mime-insert-decoded-text entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
751 ((cdr bulk-data)
112240
6fd3dcdcc675 Fix handling of unknown MIME type (bug#7651).
Kenichi Handa <handa@m17n.org>
parents: 112218
diff changeset
752 (rmail-mime-insert-image entity))
6fd3dcdcc675 Fix handling of unknown MIME type (bug#7651).
Kenichi Handa <handa@m17n.org>
parents: 112218
diff changeset
753 (t
6fd3dcdcc675 Fix handling of unknown MIME type (bug#7651).
Kenichi Handa <handa@m17n.org>
parents: 112218
diff changeset
754 ;; As we don't know how to display the body, just
6fd3dcdcc675 Fix handling of unknown MIME type (bug#7651).
Kenichi Handa <handa@m17n.org>
parents: 112218
diff changeset
755 ;; insert it as a text.
6fd3dcdcc675 Fix handling of unknown MIME type (bug#7651).
Kenichi Handa <handa@m17n.org>
parents: 112218
diff changeset
756 (rmail-mime-insert-decoded-text entity)))))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
757 (put-text-property beg (point) 'rmail-mime-entity entity)))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
758
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
759 (defun test-rmail-mime-bulk-handler ()
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
760 "Test of a mail used as an example in RFC 2183."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
761 (let ((mail "Content-Type: image/jpeg
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
762 Content-Disposition: attachment; filename=genome.jpeg;
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
763 modification-date=\"Wed, 12 Feb 1997 16:29:51 -0500\";
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
764 Content-Description: a complete map of the human genome
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
765 Content-Transfer-Encoding: base64
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
766
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
767 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAABGdBTUEAALGPC/xhBQAAAAZQ
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
768 TFRF////AAAAVcLTfgAAAPZJREFUeNq9ldsOwzAIQ+3//+l1WlvA5ZLsoUiTto4TB+ISoAjy
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
769 +ITfRBfcAmgRFFeAm+J6uhdKdFhFWUgDkFsK0oUp/9G2//Kj7Jx+5tSKOdBscgUYiKHRS/me
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
770 WATQdRUvAK0Bnmshmtn79PpaLBbbOZkjKvRnjRZoRswOkG1wFchKew2g9wXVJVZL/m4+B+vv
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
771 9AxQQR2Q33SgAYJzzVACdAWjAfRYzYFO9n6SLnydtQHSMxYDMAKqZ/8FS/lTK+zuq3CtK64L
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
772 UDwbgUEAUmk2Zyg101d6PhCDySgAvTvDgKiuOrc4dLxUb7UMnhGIexyI+d6U+ABuNAP4Simx
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
773 lgAAAABJRU5ErkJggg==
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
774 "))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
775 (switch-to-buffer (get-buffer-create "*test*"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
776 (erase-buffer)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
777 (insert mail)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
778 (rmail-mime-show)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
779
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
780 (defun rmail-mime-multipart-handler (content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
781 content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
782 content-transfer-encoding)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
783 "Handle the current buffer as a multipart MIME body.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
784 The current buffer should be narrowed to the body. CONTENT-TYPE,
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
785 CONTENT-DISPOSITION, and CONTENT-TRANSFER-ENCODING are the values
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
786 of the respective parsed headers. See `rmail-mime-handle' for their
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
787 format."
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
788 (rmail-mime-process-multipart
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
789 content-type content-disposition content-transfer-encoding nil)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
790 t)
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
791
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
792 (defun rmail-mime-process-multipart (content-type
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
793 content-disposition
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
794 content-transfer-encoding
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
795 parse-tag)
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
796 "Process the current buffer as a multipart MIME body.
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
797
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
798 If PARSE-TAG is nil, modify the current buffer directly for
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
799 showing the MIME body and return nil.
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
800
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
801 Otherwise, PARSE-TAG is a string indicating the depth and index
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
802 number of the entity. In this case, parse the current buffer and
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
803 return a list of MIME-entity objects.
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
804
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
805 The other arguments are the same as `rmail-mime-multipart-handler'."
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
806 ;; Some MUAs start boundaries with "--", while it should start
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
807 ;; with "CRLF--", as defined by RFC 2046:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
808 ;; The boundary delimiter MUST occur at the beginning of a line,
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
809 ;; i.e., following a CRLF, and the initial CRLF is considered to
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
810 ;; be attached to the boundary delimiter line rather than part
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
811 ;; of the preceding part.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
812 ;; We currently don't handle that.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
813 (let ((boundary (cdr (assq 'boundary content-type)))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
814 (subtype (cadr (split-string (car content-type) "/")))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
815 (index 0)
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
816 beg end next entities)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
817 (unless boundary
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
818 (rmail-mm-get-boundary-error-message
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
819 "No boundary defined" content-type content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
820 content-transfer-encoding))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
821 (setq boundary (concat "\n--" boundary))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
822 ;; Hide the body before the first bodypart
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
823 (goto-char (point-min))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
824 (when (and (search-forward boundary nil t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
825 (looking-at "[ \t]*\n"))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
826 (if parse-tag
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
827 (narrow-to-region (match-end 0) (point-max))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
828 (delete-region (point-min) (match-end 0))))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
829
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
830 ;; Change content-type to the proper default one for the children.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
831 (cond ((string-match "mixed" subtype)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
832 (setq content-type '("text/plain")))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
833 ((string-match "digest" subtype)
112240
6fd3dcdcc675 Fix handling of unknown MIME type (bug#7651).
Kenichi Handa <handa@m17n.org>
parents: 112218
diff changeset
834 (setq content-type '("message/rfc822")))
6fd3dcdcc675 Fix handling of unknown MIME type (bug#7651).
Kenichi Handa <handa@m17n.org>
parents: 112218
diff changeset
835 (t
6fd3dcdcc675 Fix handling of unknown MIME type (bug#7651).
Kenichi Handa <handa@m17n.org>
parents: 112218
diff changeset
836 (setq content-type nil)))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
837
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
838 ;; Loop over all body parts, where beg points at the beginning of
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
839 ;; the part and end points at the end of the part. next points at
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
840 ;; the beginning of the next part. The current point is just
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
841 ;; after the boundary tag.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
842 (setq beg (point-min))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
843 (while (search-forward boundary nil t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
844 (setq end (match-beginning 0))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
845 ;; If this is the last boundary according to RFC 2046, hide the
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
846 ;; epilogue, else hide the boundary only. Use a marker for
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
847 ;; `next' because `rmail-mime-show' may change the buffer.
105175
721db724bb12 (rmail-mime-multipart-handler): Accept the case where
Glenn Morris <rgm@gnu.org>
parents: 105019
diff changeset
848 (cond ((looking-at "--[ \t]*$")
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
849 (setq next (point-max-marker)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
850 ((looking-at "[ \t]*\n")
105175
721db724bb12 (rmail-mime-multipart-handler): Accept the case where
Glenn Morris <rgm@gnu.org>
parents: 105019
diff changeset
851 (setq next (copy-marker (match-end 0) t)))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
852 (t
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
853 (rmail-mm-get-boundary-error-message
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
854 "Malformed boundary" content-type content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
855 content-transfer-encoding)))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
856
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
857 (setq index (1+ index))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
858 ;; Handle the part.
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
859 (if parse-tag
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
860 (save-restriction
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
861 (narrow-to-region beg end)
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
862 (let ((child (rmail-mime-process
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
863 nil (format "%s/%d" parse-tag index)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
864 content-type content-disposition)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
865 ;; Display a tagline.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
866 (aset (aref (rmail-mime-entity-display child) 1) 1
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
867 (aset (rmail-mime-entity-tagline child) 2 t))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
868 (push child entities)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
869
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
870 (delete-region end next)
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
871 (save-restriction
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
872 (narrow-to-region beg end)
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
873 (rmail-mime-show)))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
874 (goto-char (setq beg next)))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
875
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
876 (when parse-tag
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
877 (setq entities (nreverse entities))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
878 (if (string-match "alternative" subtype)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
879 ;; Find the best entity to show, and hide all the others.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
880 (let (best second)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
881 (dolist (child entities)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
882 (if (string= (or (car (rmail-mime-entity-disposition child))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
883 (car content-disposition))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
884 "inline")
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
885 (if (string-match "text/plain"
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
886 (car (rmail-mime-entity-type child)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
887 (setq best child)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
888 (if (string-match "text/.*"
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
889 (car (rmail-mime-entity-type child)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
890 (setq second child)))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
891 (or best (not second) (setq best second))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
892 (dolist (child entities)
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
893 (unless (eq best child)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
894 (aset (rmail-mime-entity-body child) 2 nil)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
895 (rmail-mime-hidden-mode child)))))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
896 entities)))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
897
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
898 (defun test-rmail-mime-multipart-handler ()
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
899 "Test of a mail used as an example in RFC 2046."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
900 (let ((mail "From: Nathaniel Borenstein <nsb@bellcore.com>
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
901 To: Ned Freed <ned@innosoft.com>
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
902 Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
903 Subject: Sample message
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
904 MIME-Version: 1.0
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
905 Content-type: multipart/mixed; boundary=\"simple boundary\"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
906
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
907 This is the preamble. It is to be ignored, though it
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
908 is a handy place for composition agents to include an
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
909 explanatory note to non-MIME conformant readers.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
910
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
911 --simple boundary
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
912
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
913 This is implicitly typed plain US-ASCII text.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
914 It does NOT end with a linebreak.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
915 --simple boundary
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
916 Content-type: text/plain; charset=us-ascii
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
917
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
918 This is explicitly typed plain US-ASCII text.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
919 It DOES end with a linebreak.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
920
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
921 --simple boundary--
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
922
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
923 This is the epilogue. It is also to be ignored."))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
924 (switch-to-buffer (get-buffer-create "*test*"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
925 (erase-buffer)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
926 (insert mail)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
927 (rmail-mime-show t)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
928
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
929 (defun rmail-mime-insert-multipart (entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
930 "Presentation handler for a multipart MIME entity."
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
931 (let ((current (aref (rmail-mime-entity-display entity) 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
932 (new (aref (rmail-mime-entity-display entity) 1))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
933 (header (rmail-mime-entity-header entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
934 (tagline (rmail-mime-entity-tagline entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
935 (body (rmail-mime-entity-body entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
936 (beg (point))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
937 (segment (rmail-mime-entity-segment (point) entity)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
938 ;; header
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
939 (if (eq (aref current 0) (aref new 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
940 (goto-char (aref segment 2))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
941 (if (aref current 0)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
942 (delete-char (- (aref segment 2) (aref segment 1))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
943 (if (aref new 0)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
944 (rmail-mime-insert-header header)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
945 ;; tagline
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
946 (if (eq (aref current 1) (aref new 1))
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
947 (if (or (not (aref current 1))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
948 (eq (aref current 2) (aref new 2)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
949 (forward-char (- (aref segment 3) (aref segment 2)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
950 (rmail-mime-update-tagline entity))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
951 (if (aref current 1)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
952 (delete-char (- (aref segment 3) (aref segment 2))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
953 (if (aref new 1)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
954 (rmail-mime-insert-tagline entity)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
955
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
956 (put-text-property beg (point) 'rmail-mime-entity entity)
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
957
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
958 ;; body
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
959 (if (eq (aref current 2) (aref new 2))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
960 (forward-char (- (aref segment 4) (aref segment 3)))
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
961 (dolist (child (rmail-mime-entity-children entity))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
962 (rmail-mime-insert child)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
963 entity))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
964
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
965 ;;; Main code
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
966
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
967 (defun rmail-mime-handle (content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
968 content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
969 content-transfer-encoding)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
970 "Handle the current buffer as a MIME part.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
971 The current buffer should be narrowed to the respective body, and
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
972 point should be at the beginning of the body.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
973
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
974 CONTENT-TYPE, CONTENT-DISPOSITION, and CONTENT-TRANSFER-ENCODING
106339
656eabdc03be (rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 106178
diff changeset
975 are the values of the respective parsed headers. The latter should
656eabdc03be (rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 106178
diff changeset
976 be downcased. The parsed headers for CONTENT-TYPE and CONTENT-DISPOSITION
656eabdc03be (rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 106178
diff changeset
977 have the form
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
978
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
979 \(VALUE . ALIST)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
980
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
981 In other words:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
982
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
983 \(VALUE (ATTRIBUTE . VALUE) (ATTRIBUTE . VALUE) ...)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
984
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
985 VALUE is a string and ATTRIBUTE is a symbol.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
986
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
987 Consider the following header, for example:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
988
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
989 Content-Type: multipart/mixed;
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
990 boundary=\"----=_NextPart_000_0104_01C617E4.BDEC4C40\"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
991
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
992 The parsed header value:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
993
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
994 \(\"multipart/mixed\"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
995 \(\"boundary\" . \"----=_NextPart_000_0104_01C617E4.BDEC4C40\"))"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
996 ;; Handle the content transfer encodings we know. Unknown transfer
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
997 ;; encodings will be passed on to the various handlers.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
998 (cond ((string= content-transfer-encoding "base64")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
999 (when (ignore-errors
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1000 (base64-decode-region (point) (point-max)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1001 (setq content-transfer-encoding nil)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1002 ((string= content-transfer-encoding "quoted-printable")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1003 (quoted-printable-decode-region (point) (point-max))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1004 (setq content-transfer-encoding nil))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1005 ((string= content-transfer-encoding "8bit")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1006 ;; FIXME: Is this the correct way?
106953
a1e356d208cd * mail/rmailmm.el (rmail-mime-handle): Don't set the buffer to unibyte
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1007 ;; No, of course not, it just means there's no decoding to do.
a1e356d208cd * mail/rmailmm.el (rmail-mime-handle): Don't set the buffer to unibyte
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1008 ;; (set-buffer-multibyte nil)
a1e356d208cd * mail/rmailmm.el (rmail-mime-handle): Don't set the buffer to unibyte
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1009 (setq content-transfer-encoding nil)
a1e356d208cd * mail/rmailmm.el (rmail-mime-handle): Don't set the buffer to unibyte
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1010 ))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1011 ;; Inline stuff requires work. Attachments are handled by the bulk
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1012 ;; handler.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1013 (if (string= "inline" (car content-disposition))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1014 (let ((stop nil))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1015 (dolist (entry rmail-mime-media-type-handlers-alist)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1016 (when (and (string-match (car entry) (car content-type)) (not stop))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1017 (progn
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1018 (setq stop (funcall (cadr entry) content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1019 content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1020 content-transfer-encoding))))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1021 ;; Everything else is an attachment.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1022 (rmail-mime-bulk-handler content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1023 content-disposition
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1024 content-transfer-encoding))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1025 (save-restriction
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1026 (widen)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1027 (let ((entity (get-text-property (1- (point)) 'rmail-mime-entity))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1028 current new)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1029 (when entity
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1030 (setq current (aref (rmail-mime-entity-display entity) 0)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1031 new (aref (rmail-mime-entity-display entity) 1))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1032 (dotimes (i 3)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1033 (aset current i (aref new i)))))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1034
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1035 (defun rmail-mime-show (&optional show-headers)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1036 "Handle the current buffer as a MIME message.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1037 If SHOW-HEADERS is non-nil, then the headers of the current part
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1038 will shown as usual for a MIME message. The headers are also
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1039 shown for the content type message/rfc822. This function will be
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1040 called recursively if multiple parts are available.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1041
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1042 The current buffer must contain a single message. It will be
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1043 modified."
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1044 (rmail-mime-process show-headers nil))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1045
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1046 (defun rmail-mime-process (show-headers parse-tag &optional
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1047 default-content-type
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1048 default-content-disposition)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1049 (let ((end (point-min))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1050 content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1051 content-transfer-encoding
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1052 content-disposition)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1053 ;; `point-min' returns the beginning and `end' points at the end
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1054 ;; of the headers.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1055 (goto-char (point-min))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1056 ;; If we're showing a part without headers, then it will start
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1057 ;; with a newline.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1058 (if (eq (char-after) ?\n)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1059 (setq end (1+ (point)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1060 (when (search-forward "\n\n" nil t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1061 (setq end (match-end 0))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1062 (save-restriction
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1063 (narrow-to-region (point-min) end)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1064 ;; FIXME: Default disposition of the multipart entities should
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1065 ;; be inherited.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1066 (setq content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1067 (mail-fetch-field "Content-Type")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1068 content-transfer-encoding
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1069 (mail-fetch-field "Content-Transfer-Encoding")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1070 content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1071 (mail-fetch-field "Content-Disposition")))))
106339
656eabdc03be (rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 106178
diff changeset
1072 ;; Per RFC 2045, C-T-E is case insensitive (bug#5070), but the others
656eabdc03be (rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 106178
diff changeset
1073 ;; are not completely so. Hopefully mail-header-parse-* DTRT.
656eabdc03be (rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 106178
diff changeset
1074 (if content-transfer-encoding
656eabdc03be (rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 106178
diff changeset
1075 (setq content-transfer-encoding (downcase content-transfer-encoding)))
656eabdc03be (rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 106178
diff changeset
1076 (setq content-type
656eabdc03be (rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 106178
diff changeset
1077 (if content-type
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1078 (or (mail-header-parse-content-type content-type)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1079 '("text/plain"))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1080 (or default-content-type '("text/plain"))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1081 (setq content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1082 (if content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1083 (mail-header-parse-content-disposition content-disposition)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1084 ;; If none specified, we are free to choose what we deem
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1085 ;; suitable according to RFC 2183. We like inline.
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1086 (or default-content-disposition '("inline"))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1087 ;; Unrecognized disposition types are to be treated like
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1088 ;; attachment according to RFC 2183.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1089 (unless (member (car content-disposition) '("inline" "attachment"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1090 (setq content-disposition '("attachment")))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1091
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1092 (if parse-tag
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1093 (let* ((is-inline (string= (car content-disposition) "inline"))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1094 (header (vector (point-min) end nil))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1095 (tagline (vector parse-tag (cons nil nil) t))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1096 (body (vector end (point-max) is-inline))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1097 (new (vector (aref header 2) (aref tagline 2) (aref body 2)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1098 children handler entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1099 (cond ((string-match "multipart/.*" (car content-type))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1100 (save-restriction
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1101 (narrow-to-region (1- end) (point-max))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1102 (setq children (rmail-mime-process-multipart
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1103 content-type
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1104 content-disposition
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1105 content-transfer-encoding
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1106 parse-tag)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1107 handler 'rmail-mime-insert-multipart)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1108 ((string-match "message/rfc822" (car content-type))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1109 (save-restriction
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1110 (narrow-to-region end (point-max))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1111 (let* ((msg (rmail-mime-process t parse-tag
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1112 '("text/plain") '("inline")))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1113 (msg-new (aref (rmail-mime-entity-display msg) 1)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1114 ;; Show header of the child.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1115 (aset msg-new 0 t)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1116 (aset (rmail-mime-entity-header msg) 2 t)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1117 ;; Hide tagline of the child.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1118 (aset msg-new 1 nil)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1119 (aset (rmail-mime-entity-tagline msg) 2 nil)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1120 (setq children (list msg)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1121 handler 'rmail-mime-insert-multipart))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1122 ((and is-inline (string-match "text/" (car content-type)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1123 ;; Don't need a tagline.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1124 (aset new 1 (aset tagline 2 nil))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1125 (setq handler 'rmail-mime-insert-text))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1126 (t
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1127 ;; Force hidden mode.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1128 (aset new 1 (aset tagline 2 t))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1129 (aset new 2 (aset body 2 nil))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1130 (setq handler 'rmail-mime-insert-bulk)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1131 (setq entity (rmail-mime-entity content-type
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1132 content-disposition
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1133 content-transfer-encoding
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1134 (vector (vector nil nil nil) new)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1135 header tagline body children handler))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1136 (if (and (eq handler 'rmail-mime-insert-bulk)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1137 (rmail-mime-set-bulk-data entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1138 ;; Show the body.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1139 (aset new 2 (aset body 2 t)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1140 entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1141
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1142 ;; Hide headers and handle the part.
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1143 (put-text-property (point-min) (point-max) 'rmail-mime-entity
112098
40af77a50adc Merge changes from emacs-23 branch
Chong Yidong <cyd@stupidchicken.com>
parents: 111945 112073
diff changeset
1144 (rmail-mime-entity
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1145 content-type content-disposition
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1146 content-transfer-encoding
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1147 (vector (vector 'raw nil 'raw) (vector 'raw nil 'raw))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1148 (vector nil nil 'raw) (vector "" (cons nil nil) nil)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1149 (vector nil nil 'raw) nil nil))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1150 (save-restriction
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1151 (cond ((string= (car content-type) "message/rfc822")
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1152 (narrow-to-region end (point-max)))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1153 ((not show-headers)
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1154 (delete-region (point-min) end)))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1155 (rmail-mime-handle content-type content-disposition
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1156 content-transfer-encoding)))))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1157
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1158 (defun rmail-mime-parse ()
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1159 "Parse the current Rmail message as a MIME message.
112073
24ab54013884 Fix error handling of MIME parsing.
Kenichi Handa <handa@m17n.org>
parents: 112062
diff changeset
1160 The value is a MIME-entiy object (see `rmail-mime-entity').
24ab54013884 Fix error handling of MIME parsing.
Kenichi Handa <handa@m17n.org>
parents: 112062
diff changeset
1161 If an error occurs, return an error message string."
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1162 (let ((rmail-mime-mbox-buffer (if (rmail-buffers-swapped-p)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1163 rmail-view-buffer
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1164 (current-buffer))))
112073
24ab54013884 Fix error handling of MIME parsing.
Kenichi Handa <handa@m17n.org>
parents: 112062
diff changeset
1165 (condition-case err
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1166 (with-current-buffer rmail-mime-mbox-buffer
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1167 (save-excursion
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1168 (goto-char (point-min))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1169 (let* ((entity (rmail-mime-process t ""
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1170 '("text/plain") '("inline")))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1171 (new (aref (rmail-mime-entity-display entity) 1)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1172 ;; Show header.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1173 (aset new 0 (aset (rmail-mime-entity-header entity) 2 t))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1174 ;; Show tagline if and only if body is not shown.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1175 (if (aref new 2)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1176 (aset new 1 (aset (rmail-mime-entity-tagline entity) 2 nil))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1177 (aset new 1 (aset (rmail-mime-entity-tagline entity) 2 t)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1178 entity)))
112073
24ab54013884 Fix error handling of MIME parsing.
Kenichi Handa <handa@m17n.org>
parents: 112062
diff changeset
1179 (error (format "%s" err)))))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1180
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1181 (defun rmail-mime-insert (entity)
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1182 "Insert a MIME-entity ENTITY in the current buffer.
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1183
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1184 This function will be called recursively if multiple parts are
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1185 available."
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1186 (let ((current (aref (rmail-mime-entity-display entity) 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1187 (new (aref (rmail-mime-entity-display entity) 1)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1188 (if (not (eq (aref new 0) 'raw))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1189 ;; Not a raw-mode. Each handler should handle it.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1190 (funcall (rmail-mime-entity-handler entity) entity)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1191 (let ((header (rmail-mime-entity-header entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1192 (tagline (rmail-mime-entity-tagline entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1193 (body (rmail-mime-entity-body entity))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1194 (beg (point))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1195 (segment (rmail-mime-entity-segment (point) entity)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1196 ;; header
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1197 (if (eq (aref current 0) (aref new 0))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1198 (goto-char (aref segment 2))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1199 (if (aref current 0)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1200 (delete-char (- (aref segment 2) (aref segment 1))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1201 (insert-buffer-substring rmail-mime-mbox-buffer
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1202 (aref header 0) (aref header 1)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1203 ;; tagline
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1204 (if (aref current 1)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1205 (delete-char (- (aref segment 3) (aref segment 2))))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1206 ;; body
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1207 (let ((children (rmail-mime-entity-children entity)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1208 (if children
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1209 (progn
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1210 (put-text-property beg (point) 'rmail-mime-entity entity)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1211 (dolist (child children)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1212 (rmail-mime-insert child)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1213 (if (eq (aref current 2) (aref new 2))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1214 (forward-char (- (aref segment 4) (aref segment 3)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1215 (if (aref current 2)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1216 (delete-char (- (aref segment 4) (aref segment 3))))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1217 (insert-buffer-substring rmail-mime-mbox-buffer
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1218 (aref body 0) (aref body 1))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1219 (or (bolp) (insert "\n")))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1220 (put-text-property beg (point) 'rmail-mime-entity entity)))))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1221 (dotimes (i 3)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1222 (aset current i (aref new i)))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1223
105176
debabf496159 (rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents: 105175
diff changeset
1224 (define-derived-mode rmail-mime-mode fundamental-mode "RMIME"
debabf496159 (rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents: 105175
diff changeset
1225 "Major mode used in `rmail-mime' buffers."
debabf496159 (rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents: 105175
diff changeset
1226 (setq font-lock-defaults '(rmail-font-lock-keywords t t nil nil)))
debabf496159 (rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents: 105175
diff changeset
1227
102317
562b3a7e1016 Update commentary.
Glenn Morris <rgm@gnu.org>
parents: 101890
diff changeset
1228 ;;;###autoload
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1229 (defun rmail-mime (&optional arg)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1230 "Toggle displaying of a MIME message.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1231
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1232 The actualy behavior depends on the value of `rmail-enable-mime'.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1233
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1234 If `rmail-enable-mime' is t (default), this command change the
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1235 displaying of a MIME message between decoded presentation form
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1236 and raw data.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1237
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1238 With ARG, toggle the displaying of the current MIME entity only.
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1239
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1240 If `rmail-enable-mime' is nil, this creates a temporary
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1241 \"*RMAIL*\" buffer holding a decoded copy of the message. Inline
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1242 content-types are handled according to
102403
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
1243 `rmail-mime-media-type-handlers-alist'. By default, this
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
1244 displays text and multipart messages, and offers to download
b7059e95eba9 (rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents: 102317
diff changeset
1245 attachments as specfied by `rmail-mime-attachment-dirs-alist'."
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1246 (interactive "P")
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1247 (if rmail-enable-mime
112257
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1248 (with-current-buffer rmail-buffer
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1249 (if (rmail-mime-message-p)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1250 (let ((rmail-mime-mbox-buffer rmail-view-buffer)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1251 (rmail-mime-view-buffer rmail-buffer)
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1252 (entity (get-text-property (point) 'rmail-mime-entity)))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1253 (if arg
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1254 (if entity
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1255 (rmail-mime-toggle-raw entity))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1256 (goto-char (point-min))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1257 (rmail-mime-toggle-raw
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1258 (get-text-property (point) 'rmail-mime-entity))))
103d72f0a1d5 Another improvement of MIME handling in rmail.
Kenichi Handa <handa@m17n.org>
parents: 112240
diff changeset
1259 (message "Not a MIME message")))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1260 (let* ((data (rmail-apply-in-message rmail-current-message 'buffer-string))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1261 (buf (get-buffer-create "*RMAIL*"))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1262 (rmail-mime-mbox-buffer rmail-view-buffer)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1263 (rmail-mime-view-buffer buf))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1264 (set-buffer buf)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1265 (setq buffer-undo-list t)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1266 (let ((inhibit-read-only t))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1267 ;; Decoding the message in fundamental mode for speed, only
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1268 ;; switching to rmail-mime-mode at the end for display. Eg
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1269 ;; quoted-printable-decode-region gets very slow otherwise (Bug#4993).
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1270 (fundamental-mode)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1271 (erase-buffer)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1272 (insert data)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1273 (rmail-mime-show t)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1274 (rmail-mime-mode)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1275 (set-buffer-modified-p nil))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1276 (view-buffer buf))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1277
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1278 (defun rmail-mm-get-boundary-error-message (message type disposition encoding)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1279 "Return MESSAGE with more information on the main mime components."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1280 (error "%s; type: %s; disposition: %s; encoding: %s"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1281 message type disposition encoding))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1282
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1283 (defun rmail-show-mime ()
111885
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1284 "Function to set in `rmail-show-mime-function' (which see)."
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1285 (let ((entity (rmail-mime-parse))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1286 (rmail-mime-mbox-buffer rmail-buffer)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1287 (rmail-mime-view-buffer rmail-view-buffer)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1288 (rmail-mime-coding-system nil))
112073
24ab54013884 Fix error handling of MIME parsing.
Kenichi Handa <handa@m17n.org>
parents: 112062
diff changeset
1289 (if (vectorp entity)
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1290 (with-current-buffer rmail-mime-view-buffer
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1291 (erase-buffer)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1292 (rmail-mime-insert entity)
112263
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
1293 (if (consp rmail-mime-coding-system)
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
1294 ;; Decoding is done by rfc2047-decode-region only for a
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
1295 ;; header. But, as the used coding system may have been
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
1296 ;; overriden by mm-charset-override-alist, we can't
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
1297 ;; trust (car rmail-mime-coding-system). So, here we
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
1298 ;; try the decoding again with mm-charset-override-alist
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
1299 ;; bound to nil.
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
1300 (let ((mm-charset-override-alist nil))
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
1301 (setq rmail-mime-coding-system
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
1302 (rmail-mime-find-header-encoding
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
1303 (rmail-mime-entity-header entity)))))
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
1304 (set-buffer-file-coding-system
932e0e85675a Fix setting of buffer-file-coding-system of RMAIL buffer.
Kenichi Handa <handa@m17n.org>
parents: 112257
diff changeset
1305 (coding-system-base rmail-mime-coding-system) t t))
112073
24ab54013884 Fix error handling of MIME parsing.
Kenichi Handa <handa@m17n.org>
parents: 112062
diff changeset
1306 ;; Decoding failed. ENTITY is an error message. Insert the
24ab54013884 Fix error handling of MIME parsing.
Kenichi Handa <handa@m17n.org>
parents: 112062
diff changeset
1307 ;; original message body as is, and show warning.
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1308 (let ((region (with-current-buffer rmail-mime-mbox-buffer
111885
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1309 (goto-char (point-min))
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1310 (re-search-forward "^$" nil t)
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1311 (forward-line 1)
112073
24ab54013884 Fix error handling of MIME parsing.
Kenichi Handa <handa@m17n.org>
parents: 112062
diff changeset
1312 (vector (point-min) (point) (point-max)))))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1313 (with-current-buffer rmail-mime-view-buffer
111885
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1314 (let ((inhibit-read-only t))
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1315 (erase-buffer)
112073
24ab54013884 Fix error handling of MIME parsing.
Kenichi Handa <handa@m17n.org>
parents: 112062
diff changeset
1316 (rmail-mime-insert-header region)
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1317 (insert-buffer-substring rmail-mime-mbox-buffer
112073
24ab54013884 Fix error handling of MIME parsing.
Kenichi Handa <handa@m17n.org>
parents: 112062
diff changeset
1318 (aref region 1) (aref region 2))))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1319 (set-buffer-file-coding-system 'no-conversion t t)
112073
24ab54013884 Fix error handling of MIME parsing.
Kenichi Handa <handa@m17n.org>
parents: 112062
diff changeset
1320 (message "MIME decoding failed: %s" entity)))))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1321
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1322 (setq rmail-show-mime-function 'rmail-show-mime)
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1323
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1324 (defun rmail-insert-mime-forwarded-message (forward-buffer)
111885
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1325 "Function to set in `rmail-insert-mime-forwarded-message-function' (which see)."
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1326 (let ((rmail-mime-mbox-buffer
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1327 (with-current-buffer forward-buffer rmail-view-buffer)))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1328 (save-restriction
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1329 (narrow-to-region (point) (point))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1330 (message-forward-make-body-mime rmail-mime-mbox-buffer))))
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1331
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1332 (setq rmail-insert-mime-forwarded-message-function
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1333 'rmail-insert-mime-forwarded-message)
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1334
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1335 (defun rmail-insert-mime-resent-message (forward-buffer)
111885
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1336 "Function to set in `rmail-insert-mime-resent-message-function' (which see)."
111769
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1337 (insert-buffer-substring
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1338 (with-current-buffer forward-buffer rmail-view-buffer))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1339 (goto-char (point-min))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1340 (when (looking-at "From ")
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1341 (forward-line 1)
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1342 (delete-region (point-min) (point))))
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1343
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1344 (setq rmail-insert-mime-resent-message-function
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1345 'rmail-insert-mime-resent-message)
0e19494fd75d Improve rmail's MIME handling.
Kenichi Handa <handa@m17n.org>
parents: 109330
diff changeset
1346
111885
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1347 (defun rmail-search-mime-message (msg regexp)
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1348 "Function to set in `rmail-search-mime-message-function' (which see)."
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1349 (save-restriction
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1350 (narrow-to-region (rmail-msgbeg msg) (rmail-msgend msg))
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1351 (let* ((rmail-mime-mbox-buffer (current-buffer))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1352 (rmail-mime-view-buffer rmail-view-buffer)
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1353 (header-end (save-excursion
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1354 (re-search-forward "^$" nil 'move) (point)))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1355 (body-end (point-max))
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1356 (entity (rmail-mime-parse)))
112098
40af77a50adc Merge changes from emacs-23 branch
Chong Yidong <cyd@stupidchicken.com>
parents: 111945 112073
diff changeset
1357 (or
111885
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1358 ;; At first, just search the headers.
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1359 (with-temp-buffer
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1360 (insert-buffer-substring rmail-mime-mbox-buffer nil header-end)
111885
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1361 (rfc2047-decode-region (point-min) (point))
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1362 (goto-char (point-min))
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1363 (re-search-forward regexp nil t))
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1364 ;; Next, search the body.
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1365 (if (and entity
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1366 (let* ((content-type (rmail-mime-entity-type entity))
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1367 (charset (cdr (assq 'charset (cdr content-type)))))
112098
40af77a50adc Merge changes from emacs-23 branch
Chong Yidong <cyd@stupidchicken.com>
parents: 111945 112073
diff changeset
1368 (or (not (string-match "text/.*" (car content-type)))
111885
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1369 (and charset
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1370 (not (string= (downcase charset) "us-ascii"))))))
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1371 ;; Search the decoded MIME message.
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1372 (with-temp-buffer
112062
34341d09c440 Enable display mode of MIME message in rmail.
Kenichi Handa <handa@m17n.org>
parents: 111885
diff changeset
1373 (rmail-mime-insert entity)
111885
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1374 (goto-char (point-min))
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1375 (re-search-forward regexp nil t))
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1376 ;; Search the body without decoding.
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1377 (goto-char header-end)
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1378 (re-search-forward regexp nil t))))))
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1379
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1380 (setq rmail-search-mime-message-function 'rmail-search-mime-message)
bbc996a3871b Implement rmail-search-mime-message-function.
Kenichi Handa <handa@m17n.org>
parents: 111773
diff changeset
1381
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1382 (provide 'rmailmm)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1383
104907
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 102421
diff changeset
1384 ;; Local Variables:
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 102421
diff changeset
1385 ;; generated-autoload-file: "rmail.el"
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 102421
diff changeset
1386 ;; End:
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 102421
diff changeset
1387
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1388 ;;; rmailmm.el ends here