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