Mercurial > emacs
annotate lisp/mail/rmailmm.el @ 108398:1789ed4b257e
Merge from mainline.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Sun, 17 Jan 2010 00:12:59 +0000 |
parents | 1d1d5d9bd884 |
children | a1e356d208cd |
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 |
106815 | 3 ;; Copyright (C) 2006, 2007, 2008, 2009, 2010 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 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
9 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
10 ;; This file is part of GNU Emacs. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
11 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
12 ;; 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
|
13 ;; 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
|
14 ;; 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
|
15 ;; (at your option) any later version. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
16 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
17 ;; 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
|
18 ;; 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
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
20 ;; GNU General Public License for more details. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
21 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
22 ;; 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
|
23 ;; 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
|
24 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
25 ;;; Commentary: |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
26 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
27 ;; Essentially based on the design of Alexander Pohoyda's MIME |
102317 | 28 ;; extensions (mime-display.el and mime.el). |
29 ;; Call `M-x rmail-mime' when viewing an Rmail message. | |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
30 |
105176
debabf496159
(rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents:
105175
diff
changeset
|
31 ;; Todo: |
debabf496159
(rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents:
105175
diff
changeset
|
32 |
debabf496159
(rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents:
105175
diff
changeset
|
33 ;; Handle multipart/alternative. |
105211
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
34 ;; 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
|
35 |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
36 ;;; Code: |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
37 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
38 (require 'rmail) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
39 (require 'mail-parse) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
40 |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
41 ;;; User options. |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
42 |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
43 (defgroup rmail-mime nil |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
44 "Rmail MIME handling options." |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
45 :prefix "rmail-mime-" |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
46 :group 'rmail) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
47 |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
48 (defcustom rmail-mime-media-type-handlers-alist |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
49 '(("multipart/.*" rmail-mime-multipart-handler) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
50 ("text/.*" rmail-mime-text-handler) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
51 ("text/\\(x-\\)?patch" rmail-mime-bulk-handler) |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
52 ("\\(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
|
53 "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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 Note that this only applies to items with an inline Content-Disposition, |
debabf496159
(rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents:
105175
diff
changeset
|
59 all others are handled by `rmail-mime-bulk-handler'." |
102421
62a954f574fa
(rmail-mime-media-type-handlers-alist): Fix doc and custom type.
Glenn Morris <rgm@gnu.org>
parents:
102403
diff
changeset
|
60 :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
|
61 :version "23.1" |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
62 :group 'rmail-mime) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
63 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
64 (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
|
65 `(("text/.*" "~/Documents") |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
66 ("image/.*" "~/Pictures") |
101890
4f858364bb26
(rmail-mime-attachment-dirs-alist): Use temporary-file-directory.
Chong Yidong <cyd@stupidchicken.com>
parents:
101380
diff
changeset
|
67 (".*" "~/Desktop" "~" ,temporary-file-directory)) |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
68 "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
|
69 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
|
70 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
|
71 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
|
72 The first directory that exists is used." |
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
73 :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
|
74 :version "23.1" |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
75 :group 'rmail-mime) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
76 |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
77 (defcustom rmail-mime-show-images 'button |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
78 "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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 automatically display the image in the buffer." |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
84 :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
|
85 (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
|
86 (number :tag "Show if smaller than certain size") |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
87 (other :tag "Always show" show)) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
88 :version "23.2" |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
89 :group 'rmail-mime) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
90 |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
91 ;;; End of user options. |
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
92 |
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
93 |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
94 ;;; Buttons |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
95 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
96 (defun rmail-mime-save (button) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
97 "Save the attachment using info in the BUTTON." |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
98 (let* ((filename (button-get button 'filename)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
99 (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
|
100 (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
|
101 (ofilename filename)) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
102 (setq filename (expand-file-name |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
103 (read-file-name (format "Save as (default: %s): " filename) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
104 directory |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
105 (expand-file-name filename directory)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
106 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
|
107 ;; 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
|
108 ;; 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
|
109 (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
|
110 (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
|
111 (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
|
112 (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
|
113 (with-temp-buffer |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
114 (set-buffer-file-coding-system 'no-conversion) |
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
|
115 (insert 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
|
116 (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
|
117 |
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
|
118 (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
|
119 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
120 ;;; Handlers |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
121 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
122 (defun rmail-mime-text-handler (content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
123 content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
124 content-transfer-encoding) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
125 "Handle the current buffer as a plain text MIME part." |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
126 (let* ((charset (cdr (assq 'charset (cdr content-type)))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
127 (coding-system (when charset |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
128 (intern (downcase charset))))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
129 (when (coding-system-p coding-system) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
130 (decode-coding-region (point-min) (point-max) coding-system)))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
131 |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
132 ;; FIXME move to the test/ directory? |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
133 (defun test-rmail-mime-handler () |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
134 "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
|
135 (let ((mail "To: alex@gnu.org |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
136 Content-Type: text/plain; charset=koi8-r |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
137 Content-Transfer-Encoding: 8bit |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
138 MIME-Version: 1.0 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
139 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
140 \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
|
141 (switch-to-buffer (get-buffer-create "*test*")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
142 (erase-buffer) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
143 (set-buffer-multibyte nil) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
144 (insert mail) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
145 (rmail-mime-show t) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
146 (set-buffer-multibyte t))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
147 |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
148 |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
149 (defun rmail-mime-insert-image (type data) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
150 "Insert an image of type TYPE, where DATA is the image data." |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
151 (end-of-line) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
152 (insert ?\n) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
153 (insert-image (create-image data type t))) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
154 |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
155 (defun rmail-mime-image (button) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
156 "Display the image associated with BUTTON." |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
157 (let ((inhibit-read-only t)) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
158 (rmail-mime-insert-image (button-get button 'image-type) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
159 (button-get button 'image-data)))) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
160 |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
161 (define-button-type 'rmail-mime-image 'action 'rmail-mime-image) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
162 |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
163 |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
164 (defun rmail-mime-bulk-handler (content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
165 content-disposition |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
166 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
|
167 "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
|
168 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
|
169 depends upon the value of `rmail-mime-show-images'." |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
170 ;; Find the default directory for this media type. |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
171 (let* ((directory (catch 'directory |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
172 (dolist (entry rmail-mime-attachment-dirs-alist) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
173 (when (string-match (car entry) (car content-type)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
174 (dolist (dir (cdr entry)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
175 (when (file-directory-p dir) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
176 (throw 'directory dir))))))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
177 (filename (or (cdr (assq 'name (cdr content-type))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
178 (cdr (assq 'filename (cdr content-disposition))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
179 "noname")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
180 (label (format "\nAttached %s file: " (car content-type))) |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
181 (data (buffer-string)) |
105198
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
182 (udata (string-as-unibyte data)) |
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
183 (size (length udata)) |
105211
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
184 (osize size) |
105198
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
185 (units '(B kB MB GB)) |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
186 type) |
105198
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
187 (while (and (> size 1024.0) ; cribbed from gnus-agent-expire-done-message |
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
188 (cdr units)) |
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
189 (setq size (/ size 1024.0) |
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
190 units (cdr units))) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
191 (delete-region (point-min) (point-max)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
192 (insert label) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
193 (insert-button filename |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
194 :type 'rmail-mime-save |
105176
debabf496159
(rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents:
105175
diff
changeset
|
195 'help-echo "mouse-2, RET: Save attachment" |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
196 'filename filename |
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
|
197 'directory (file-name-as-directory directory) |
105176
debabf496159
(rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents:
105175
diff
changeset
|
198 'data data) |
105198
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
199 (insert (format " (%.0f%s)" size (car units))) |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
200 (when (and rmail-mime-show-images |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
201 (string-match "image/\\(.*\\)" (setq type (car content-type))) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
202 (setq type (concat "." (match-string 1 type)) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
203 type (image-type-from-file-name type)) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
204 (memq type image-types) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
205 (image-type-available-p type)) |
105176
debabf496159
(rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents:
105175
diff
changeset
|
206 (insert " ") |
105211
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
207 (cond ((or (eq rmail-mime-show-images 'button) |
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
208 (and (numberp rmail-mime-show-images) |
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
209 (>= osize rmail-mime-show-images))) |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
210 (insert-button "Display" |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
211 :type 'rmail-mime-image |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
212 'help-echo "mouse-2, RET: Show image" |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
213 'image-type type |
105198
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
214 'image-data udata)) |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
215 (t |
105198
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
216 (rmail-mime-insert-image type udata)))))) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
217 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
218 (defun test-rmail-mime-bulk-handler () |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
219 "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
|
220 (let ((mail "Content-Type: image/jpeg |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
221 Content-Disposition: attachment; filename=genome.jpeg; |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
222 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
|
223 Content-Description: a complete map of the human genome |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
224 Content-Transfer-Encoding: base64 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
225 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
226 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAABGdBTUEAALGPC/xhBQAAAAZQ |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
227 TFRF////AAAAVcLTfgAAAPZJREFUeNq9ldsOwzAIQ+3//+l1WlvA5ZLsoUiTto4TB+ISoAjy |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
228 +ITfRBfcAmgRFFeAm+J6uhdKdFhFWUgDkFsK0oUp/9G2//Kj7Jx+5tSKOdBscgUYiKHRS/me |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
229 WATQdRUvAK0Bnmshmtn79PpaLBbbOZkjKvRnjRZoRswOkG1wFchKew2g9wXVJVZL/m4+B+vv |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
230 9AxQQR2Q33SgAYJzzVACdAWjAfRYzYFO9n6SLnydtQHSMxYDMAKqZ/8FS/lTK+zuq3CtK64L |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
231 UDwbgUEAUmk2Zyg101d6PhCDySgAvTvDgKiuOrc4dLxUb7UMnhGIexyI+d6U+ABuNAP4Simx |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
232 lgAAAABJRU5ErkJggg== |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
233 ")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
234 (switch-to-buffer (get-buffer-create "*test*")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
235 (erase-buffer) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
236 (insert mail) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
237 (rmail-mime-show))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
238 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
239 (defun rmail-mime-multipart-handler (content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
240 content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
241 content-transfer-encoding) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
242 "Handle the current buffer as a multipart MIME body. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
243 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
|
244 CONTENT-DISPOSITION, and CONTENT-TRANSFER-ENCODING are the values |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
245 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
|
246 format." |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
247 ;; Some MUAs start boundaries with "--", while it should start |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
248 ;; with "CRLF--", as defined by RFC 2046: |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
249 ;; 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
|
250 ;; 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
|
251 ;; 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
|
252 ;; of the preceding part. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
253 ;; We currently don't handle that. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
254 (let ((boundary (cdr (assq 'boundary content-type))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
255 beg end next) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
256 (unless boundary |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
257 (rmail-mm-get-boundary-error-message |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
258 "No boundary defined" content-type content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
259 content-transfer-encoding)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
260 (setq boundary (concat "\n--" boundary)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
261 ;; Hide the body before the first bodypart |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
262 (goto-char (point-min)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
263 (when (and (search-forward boundary nil t) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
264 (looking-at "[ \t]*\n")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
265 (delete-region (point-min) (match-end 0))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
266 ;; 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
|
267 ;; the part and end points at the end of the part. next points at |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
268 ;; the beginning of the next part. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
269 (setq beg (point-min)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
270 (while (search-forward boundary nil t) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
271 (setq end (match-beginning 0)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
272 ;; 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
|
273 ;; 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
|
274 ;; `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
|
275 (cond ((looking-at "--[ \t]*$") |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
276 (setq next (point-max-marker))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
277 ((looking-at "[ \t]*\n") |
105175
721db724bb12
(rmail-mime-multipart-handler): Accept the case where
Glenn Morris <rgm@gnu.org>
parents:
105019
diff
changeset
|
278 (setq next (copy-marker (match-end 0) t))) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
279 (t |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
280 (rmail-mm-get-boundary-error-message |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
281 "Malformed boundary" content-type content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
282 content-transfer-encoding))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
283 (delete-region end next) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
284 ;; Handle the part. |
105211
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
285 (save-restriction |
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
286 (narrow-to-region beg end) |
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
287 (rmail-mime-show)) |
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
288 (goto-char (setq beg next))))) |
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
289 |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
290 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
291 (defun test-rmail-mime-multipart-handler () |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
292 "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
|
293 (let ((mail "From: Nathaniel Borenstein <nsb@bellcore.com> |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
294 To: Ned Freed <ned@innosoft.com> |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
295 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
|
296 Subject: Sample message |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
297 MIME-Version: 1.0 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
298 Content-type: multipart/mixed; boundary=\"simple boundary\" |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
299 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
300 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
|
301 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
|
302 explanatory note to non-MIME conformant readers. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
303 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
304 --simple boundary |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
305 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
306 This is implicitly typed plain US-ASCII text. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
307 It does NOT end with a linebreak. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
308 --simple boundary |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
309 Content-type: text/plain; charset=us-ascii |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
310 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
311 This is explicitly typed plain US-ASCII text. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
312 It DOES end with a linebreak. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
313 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
314 --simple boundary-- |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
315 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
316 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
|
317 (switch-to-buffer (get-buffer-create "*test*")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
318 (erase-buffer) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
319 (insert mail) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
320 (rmail-mime-show t))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
321 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
322 ;;; Main code |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
323 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
324 (defun rmail-mime-handle (content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
325 content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
326 content-transfer-encoding) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
327 "Handle the current buffer as a MIME part. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
328 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
|
329 point should be at the beginning of the body. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
330 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
331 CONTENT-TYPE, CONTENT-DISPOSITION, and CONTENT-TRANSFER-ENCODING |
106339
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
332 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
|
333 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
|
334 have the form |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
335 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
336 \(VALUE . ALIST) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
337 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
338 In other words: |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
339 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
340 \(VALUE (ATTRIBUTE . VALUE) (ATTRIBUTE . VALUE) ...) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
341 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
342 VALUE is a string and ATTRIBUTE is a symbol. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
343 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
344 Consider the following header, for example: |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
345 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
346 Content-Type: multipart/mixed; |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
347 boundary=\"----=_NextPart_000_0104_01C617E4.BDEC4C40\" |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
348 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
349 The parsed header value: |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
350 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
351 \(\"multipart/mixed\" |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
352 \(\"boundary\" . \"----=_NextPart_000_0104_01C617E4.BDEC4C40\"))" |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
353 ;; Handle the content transfer encodings we know. Unknown transfer |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
354 ;; encodings will be passed on to the various handlers. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
355 (cond ((string= content-transfer-encoding "base64") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
356 (when (ignore-errors |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
357 (base64-decode-region (point) (point-max))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
358 (setq content-transfer-encoding nil))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
359 ((string= content-transfer-encoding "quoted-printable") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
360 (quoted-printable-decode-region (point) (point-max)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
361 (setq content-transfer-encoding nil)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
362 ((string= content-transfer-encoding "8bit") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
363 ;; FIXME: Is this the correct way? |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
364 (set-buffer-multibyte nil))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
365 ;; 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
|
366 ;; handler. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
367 (if (string= "inline" (car content-disposition)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
368 (let ((stop nil)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
369 (dolist (entry rmail-mime-media-type-handlers-alist) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
370 (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
|
371 (progn |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
372 (setq stop (funcall (cadr entry) content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
373 content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
374 content-transfer-encoding)))))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
375 ;; Everything else is an attachment. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
376 (rmail-mime-bulk-handler content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
377 content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
378 content-transfer-encoding))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
379 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
380 (defun rmail-mime-show (&optional show-headers) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
381 "Handle the current buffer as a MIME message. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
382 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
|
383 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
|
384 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
|
385 called recursively if multiple parts are available. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
386 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
387 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
|
388 modified." |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
389 (let ((end (point-min)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
390 content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
391 content-transfer-encoding |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
392 content-disposition) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
393 ;; `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
|
394 ;; of the headers. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
395 (goto-char (point-min)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
396 ;; 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
|
397 ;; with a newline. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
398 (if (eq (char-after) ?\n) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
399 (setq end (1+ (point))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
400 (when (search-forward "\n\n" nil t) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
401 (setq end (match-end 0)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
402 (save-restriction |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
403 (narrow-to-region (point-min) end) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
404 ;; FIXME: Default disposition of the multipart entities should |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
405 ;; be inherited. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
406 (setq content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
407 (mail-fetch-field "Content-Type") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
408 content-transfer-encoding |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
409 (mail-fetch-field "Content-Transfer-Encoding") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
410 content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
411 (mail-fetch-field "Content-Disposition"))))) |
106339
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
412 ;; 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
|
413 ;; are not completely so. Hopefully mail-header-parse-* DTRT. |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
414 (if content-transfer-encoding |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
415 (setq content-transfer-encoding (downcase content-transfer-encoding))) |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
416 (setq content-type |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
417 (if content-type |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
418 (mail-header-parse-content-type content-type) |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
419 ;; FIXME: Default "message/rfc822" in a "multipart/digest" |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
420 ;; according to RFC 2046. |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
421 '("text/plain"))) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
422 (setq content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
423 (if content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
424 (mail-header-parse-content-disposition content-disposition) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
425 ;; 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
|
426 ;; suitable according to RFC 2183. We like inline. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
427 '("inline"))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
428 ;; Unrecognized disposition types are to be treated like |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
429 ;; attachment according to RFC 2183. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
430 (unless (member (car content-disposition) '("inline" "attachment")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
431 (setq content-disposition '("attachment"))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
432 ;; Hide headers and handle the part. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
433 (save-restriction |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
434 (cond ((string= (car content-type) "message/rfc822") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
435 (narrow-to-region end (point-max))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
436 ((not show-headers) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
437 (delete-region (point-min) end))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
438 (rmail-mime-handle content-type content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
439 content-transfer-encoding)))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
440 |
105176
debabf496159
(rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents:
105175
diff
changeset
|
441 (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
|
442 "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
|
443 (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
|
444 |
102317 | 445 ;;;###autoload |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
446 (defun rmail-mime () |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
447 "Process the current Rmail message as a MIME message. |
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
448 This creates a temporary \"*RMAIL*\" buffer holding a decoded |
105176
debabf496159
(rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents:
105175
diff
changeset
|
449 copy of the message. Inline content-types are handled according to |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
450 `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
|
451 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
|
452 attachments as specfied by `rmail-mime-attachment-dirs-alist'." |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
453 (interactive) |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
454 (let ((data (rmail-apply-in-message rmail-current-message 'buffer-string)) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
455 (buf (get-buffer-create "*RMAIL*"))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
456 (set-buffer buf) |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
457 (setq buffer-undo-list t) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
458 (let ((inhibit-read-only t)) |
106178
3f65383da746
(rmail-mime): Decode in fundamental-mode. (Bug#4993)
Glenn Morris <rgm@gnu.org>
parents:
105211
diff
changeset
|
459 ;; Decoding the message in fundamental mode for speed, only |
3f65383da746
(rmail-mime): Decode in fundamental-mode. (Bug#4993)
Glenn Morris <rgm@gnu.org>
parents:
105211
diff
changeset
|
460 ;; switching to rmail-mime-mode at the end for display. Eg |
3f65383da746
(rmail-mime): Decode in fundamental-mode. (Bug#4993)
Glenn Morris <rgm@gnu.org>
parents:
105211
diff
changeset
|
461 ;; quoted-printable-decode-region gets very slow otherwise (Bug#4993). |
3f65383da746
(rmail-mime): Decode in fundamental-mode. (Bug#4993)
Glenn Morris <rgm@gnu.org>
parents:
105211
diff
changeset
|
462 (fundamental-mode) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
463 (erase-buffer) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
464 (insert data) |
106178
3f65383da746
(rmail-mime): Decode in fundamental-mode. (Bug#4993)
Glenn Morris <rgm@gnu.org>
parents:
105211
diff
changeset
|
465 (rmail-mime-show t) |
105176
debabf496159
(rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents:
105175
diff
changeset
|
466 (rmail-mime-mode) |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
467 (set-buffer-modified-p nil)) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
468 (view-buffer buf))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
469 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
470 (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
|
471 "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
|
472 (error "%s; type: %s; disposition: %s; encoding: %s" |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
473 message type disposition encoding)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
474 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
475 (provide 'rmailmm) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
476 |
104907
6a35503cf20b
Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents:
102421
diff
changeset
|
477 ;; Local Variables: |
6a35503cf20b
Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents:
102421
diff
changeset
|
478 ;; generated-autoload-file: "rmail.el" |
6a35503cf20b
Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents:
102421
diff
changeset
|
479 ;; End: |
6a35503cf20b
Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents:
102421
diff
changeset
|
480 |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
481 ;; arch-tag: 3f2c5e5d-1aef-4512-bc20-fd737c9d5dd9 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
482 ;;; rmailmm.el ends here |