Mercurial > emacs
annotate lisp/mail/rmailmm.el @ 109918:1ae553f27229
merge emacs-23
author | Kenichi Handa <handa@etlken> |
---|---|
date | Fri, 13 Aug 2010 15:35:36 +0900 |
parents | d03ee75f7be2 |
children | 280c8ae2476d 0e19494fd75d |
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) |
109330
d03ee75f7be2
mail/rmailmm.el (rmail-mime-save): Make the temp buffer unibyte,
Eli Zaretskii <eliz@gnu.org>
parents:
106953
diff
changeset
|
115 ;; 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
|
116 ;; 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
|
117 ;; 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
|
118 (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
|
119 (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
|
120 (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
|
121 |
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
|
122 (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
|
123 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
124 ;;; Handlers |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
125 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
126 (defun rmail-mime-text-handler (content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
127 content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
128 content-transfer-encoding) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
129 "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
|
130 (let* ((charset (cdr (assq 'charset (cdr content-type)))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
131 (coding-system (when charset |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
132 (intern (downcase charset))))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
133 (when (coding-system-p coding-system) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
134 (decode-coding-region (point-min) (point-max) coding-system)))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
135 |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
136 ;; FIXME move to the test/ directory? |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
137 (defun test-rmail-mime-handler () |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
138 "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
|
139 (let ((mail "To: alex@gnu.org |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
140 Content-Type: text/plain; charset=koi8-r |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
141 Content-Transfer-Encoding: 8bit |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
142 MIME-Version: 1.0 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
143 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
144 \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
|
145 (switch-to-buffer (get-buffer-create "*test*")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
146 (erase-buffer) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
147 (set-buffer-multibyte nil) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
148 (insert mail) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
149 (rmail-mime-show t) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
150 (set-buffer-multibyte t))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
151 |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
152 |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
153 (defun rmail-mime-insert-image (type data) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
154 "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
|
155 (end-of-line) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
156 (insert ?\n) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
157 (insert-image (create-image data type t))) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
158 |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
159 (defun rmail-mime-image (button) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
160 "Display the image associated with BUTTON." |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
161 (let ((inhibit-read-only t)) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
162 (rmail-mime-insert-image (button-get button 'image-type) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
163 (button-get button 'image-data)))) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
164 |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
165 (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
|
166 |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
167 |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
168 (defun rmail-mime-bulk-handler (content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
169 content-disposition |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
170 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
|
171 "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
|
172 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
|
173 depends upon the value of `rmail-mime-show-images'." |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
174 ;; Find the default directory for this media type. |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
175 (let* ((directory (catch 'directory |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
176 (dolist (entry rmail-mime-attachment-dirs-alist) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
177 (when (string-match (car entry) (car content-type)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
178 (dolist (dir (cdr entry)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
179 (when (file-directory-p dir) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
180 (throw 'directory dir))))))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
181 (filename (or (cdr (assq 'name (cdr content-type))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
182 (cdr (assq 'filename (cdr content-disposition))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
183 "noname")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
184 (label (format "\nAttached %s file: " (car content-type))) |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
185 (data (buffer-string)) |
105198
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
186 (udata (string-as-unibyte data)) |
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
187 (size (length udata)) |
105211
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
188 (osize size) |
105198
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
189 (units '(B kB MB GB)) |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
190 type) |
105198
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
191 (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
|
192 (cdr units)) |
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
193 (setq size (/ size 1024.0) |
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
194 units (cdr units))) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
195 (delete-region (point-min) (point-max)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
196 (insert label) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
197 (insert-button filename |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
198 :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
|
199 'help-echo "mouse-2, RET: Save attachment" |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
200 '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
|
201 '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
|
202 'data data) |
105198
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
203 (insert (format " (%.0f%s)" size (car units))) |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
204 (when (and rmail-mime-show-images |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
205 (string-match "image/\\(.*\\)" (setq type (car content-type))) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
206 (setq type (concat "." (match-string 1 type)) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
207 type (image-type-from-file-name type)) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
208 (memq type image-types) |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
209 (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
|
210 (insert " ") |
105211
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
211 (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
|
212 (and (numberp rmail-mime-show-images) |
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
213 (>= osize rmail-mime-show-images))) |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
214 (insert-button "Display" |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
215 :type 'rmail-mime-image |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
216 'help-echo "mouse-2, RET: Show image" |
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
217 'image-type type |
105198
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
218 'image-data udata)) |
105193
d05b41e0a7ef
(rmail-mime): New custom group.
Glenn Morris <rgm@gnu.org>
parents:
105176
diff
changeset
|
219 (t |
105198
550b90cc7226
(rmail-mime-bulk-handler): Print the size of attachments.
Glenn Morris <rgm@gnu.org>
parents:
105193
diff
changeset
|
220 (rmail-mime-insert-image type udata)))))) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
221 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
222 (defun test-rmail-mime-bulk-handler () |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
223 "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
|
224 (let ((mail "Content-Type: image/jpeg |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
225 Content-Disposition: attachment; filename=genome.jpeg; |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
226 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
|
227 Content-Description: a complete map of the human genome |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
228 Content-Transfer-Encoding: base64 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
229 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
230 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAABGdBTUEAALGPC/xhBQAAAAZQ |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
231 TFRF////AAAAVcLTfgAAAPZJREFUeNq9ldsOwzAIQ+3//+l1WlvA5ZLsoUiTto4TB+ISoAjy |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
232 +ITfRBfcAmgRFFeAm+J6uhdKdFhFWUgDkFsK0oUp/9G2//Kj7Jx+5tSKOdBscgUYiKHRS/me |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
233 WATQdRUvAK0Bnmshmtn79PpaLBbbOZkjKvRnjRZoRswOkG1wFchKew2g9wXVJVZL/m4+B+vv |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
234 9AxQQR2Q33SgAYJzzVACdAWjAfRYzYFO9n6SLnydtQHSMxYDMAKqZ/8FS/lTK+zuq3CtK64L |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
235 UDwbgUEAUmk2Zyg101d6PhCDySgAvTvDgKiuOrc4dLxUb7UMnhGIexyI+d6U+ABuNAP4Simx |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
236 lgAAAABJRU5ErkJggg== |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
237 ")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
238 (switch-to-buffer (get-buffer-create "*test*")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
239 (erase-buffer) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
240 (insert mail) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
241 (rmail-mime-show))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
242 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
243 (defun rmail-mime-multipart-handler (content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
244 content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
245 content-transfer-encoding) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
246 "Handle the current buffer as a multipart MIME body. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
247 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
|
248 CONTENT-DISPOSITION, and CONTENT-TRANSFER-ENCODING are the values |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
249 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
|
250 format." |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
251 ;; Some MUAs start boundaries with "--", while it should start |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
252 ;; with "CRLF--", as defined by RFC 2046: |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
253 ;; 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
|
254 ;; 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
|
255 ;; 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
|
256 ;; of the preceding part. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
257 ;; We currently don't handle that. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
258 (let ((boundary (cdr (assq 'boundary content-type))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
259 beg end next) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
260 (unless boundary |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
261 (rmail-mm-get-boundary-error-message |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
262 "No boundary defined" content-type content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
263 content-transfer-encoding)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
264 (setq boundary (concat "\n--" boundary)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
265 ;; Hide the body before the first bodypart |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
266 (goto-char (point-min)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
267 (when (and (search-forward boundary nil t) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
268 (looking-at "[ \t]*\n")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
269 (delete-region (point-min) (match-end 0))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
270 ;; 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
|
271 ;; 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
|
272 ;; the beginning of the next part. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
273 (setq beg (point-min)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
274 (while (search-forward boundary nil t) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
275 (setq end (match-beginning 0)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
276 ;; 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
|
277 ;; 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
|
278 ;; `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
|
279 (cond ((looking-at "--[ \t]*$") |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
280 (setq next (point-max-marker))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
281 ((looking-at "[ \t]*\n") |
105175
721db724bb12
(rmail-mime-multipart-handler): Accept the case where
Glenn Morris <rgm@gnu.org>
parents:
105019
diff
changeset
|
282 (setq next (copy-marker (match-end 0) t))) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
283 (t |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
284 (rmail-mm-get-boundary-error-message |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
285 "Malformed boundary" content-type content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
286 content-transfer-encoding))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
287 (delete-region end next) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
288 ;; Handle the part. |
105211
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
289 (save-restriction |
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
290 (narrow-to-region beg end) |
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
291 (rmail-mime-show)) |
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
292 (goto-char (setq beg next))))) |
7c61dadc38f9
(rmail-mime-show-images, rmail-mime-bulk-handler):
Glenn Morris <rgm@gnu.org>
parents:
105198
diff
changeset
|
293 |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
294 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
295 (defun test-rmail-mime-multipart-handler () |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
296 "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
|
297 (let ((mail "From: Nathaniel Borenstein <nsb@bellcore.com> |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
298 To: Ned Freed <ned@innosoft.com> |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
299 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
|
300 Subject: Sample message |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
301 MIME-Version: 1.0 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
302 Content-type: multipart/mixed; boundary=\"simple boundary\" |
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 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
|
305 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
|
306 explanatory note to non-MIME conformant readers. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
307 |
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 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
310 This is implicitly typed plain US-ASCII text. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
311 It does NOT end with a linebreak. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
312 --simple boundary |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
313 Content-type: text/plain; charset=us-ascii |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
314 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
315 This is explicitly typed plain US-ASCII text. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
316 It DOES end with a linebreak. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
317 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
318 --simple boundary-- |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
319 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
320 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
|
321 (switch-to-buffer (get-buffer-create "*test*")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
322 (erase-buffer) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
323 (insert mail) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
324 (rmail-mime-show t))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
325 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
326 ;;; Main code |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
327 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
328 (defun rmail-mime-handle (content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
329 content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
330 content-transfer-encoding) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
331 "Handle the current buffer as a MIME part. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
332 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
|
333 point should be at the beginning of the body. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
334 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
335 CONTENT-TYPE, CONTENT-DISPOSITION, and CONTENT-TRANSFER-ENCODING |
106339
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
336 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
|
337 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
|
338 have the form |
101360
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 . ALIST) |
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 In other words: |
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 \(VALUE (ATTRIBUTE . VALUE) (ATTRIBUTE . VALUE) ...) |
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 VALUE is a string and ATTRIBUTE is a symbol. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
347 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
348 Consider the following header, for example: |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
349 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
350 Content-Type: multipart/mixed; |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
351 boundary=\"----=_NextPart_000_0104_01C617E4.BDEC4C40\" |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
352 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
353 The parsed header value: |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
354 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
355 \(\"multipart/mixed\" |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
356 \(\"boundary\" . \"----=_NextPart_000_0104_01C617E4.BDEC4C40\"))" |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
357 ;; Handle the content transfer encodings we know. Unknown transfer |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
358 ;; encodings will be passed on to the various handlers. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
359 (cond ((string= content-transfer-encoding "base64") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
360 (when (ignore-errors |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
361 (base64-decode-region (point) (point-max))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
362 (setq content-transfer-encoding nil))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
363 ((string= content-transfer-encoding "quoted-printable") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
364 (quoted-printable-decode-region (point) (point-max)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
365 (setq content-transfer-encoding nil)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
366 ((string= content-transfer-encoding "8bit") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
367 ;; 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
|
368 ;; 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
|
369 ;; (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
|
370 (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
|
371 )) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
372 ;; 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
|
373 ;; handler. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
374 (if (string= "inline" (car content-disposition)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
375 (let ((stop nil)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
376 (dolist (entry rmail-mime-media-type-handlers-alist) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
377 (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
|
378 (progn |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
379 (setq stop (funcall (cadr entry) content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
380 content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
381 content-transfer-encoding)))))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
382 ;; Everything else is an attachment. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
383 (rmail-mime-bulk-handler content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
384 content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
385 content-transfer-encoding))) |
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 (defun rmail-mime-show (&optional show-headers) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
388 "Handle the current buffer as a MIME message. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
389 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
|
390 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
|
391 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
|
392 called recursively if multiple parts are available. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
393 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
394 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
|
395 modified." |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
396 (let ((end (point-min)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
397 content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
398 content-transfer-encoding |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
399 content-disposition) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
400 ;; `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
|
401 ;; of the headers. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
402 (goto-char (point-min)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
403 ;; 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
|
404 ;; with a newline. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
405 (if (eq (char-after) ?\n) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
406 (setq end (1+ (point))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
407 (when (search-forward "\n\n" nil t) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
408 (setq end (match-end 0)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
409 (save-restriction |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
410 (narrow-to-region (point-min) end) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
411 ;; FIXME: Default disposition of the multipart entities should |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
412 ;; be inherited. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
413 (setq content-type |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
414 (mail-fetch-field "Content-Type") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
415 content-transfer-encoding |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
416 (mail-fetch-field "Content-Transfer-Encoding") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
417 content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
418 (mail-fetch-field "Content-Disposition"))))) |
106339
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
419 ;; 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
|
420 ;; are not completely so. Hopefully mail-header-parse-* DTRT. |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
421 (if content-transfer-encoding |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
422 (setq content-transfer-encoding (downcase content-transfer-encoding))) |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
423 (setq content-type |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
424 (if content-type |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
425 (mail-header-parse-content-type content-type) |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
426 ;; FIXME: Default "message/rfc822" in a "multipart/digest" |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
427 ;; according to RFC 2046. |
656eabdc03be
(rmail-mime-handle): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106178
diff
changeset
|
428 '("text/plain"))) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
429 (setq content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
430 (if content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
431 (mail-header-parse-content-disposition content-disposition) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
432 ;; 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
|
433 ;; suitable according to RFC 2183. We like inline. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
434 '("inline"))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
435 ;; Unrecognized disposition types are to be treated like |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
436 ;; attachment according to RFC 2183. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
437 (unless (member (car content-disposition) '("inline" "attachment")) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
438 (setq content-disposition '("attachment"))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
439 ;; Hide headers and handle the part. |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
440 (save-restriction |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
441 (cond ((string= (car content-type) "message/rfc822") |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
442 (narrow-to-region end (point-max))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
443 ((not show-headers) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
444 (delete-region (point-min) end))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
445 (rmail-mime-handle content-type content-disposition |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
446 content-transfer-encoding)))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
447 |
105176
debabf496159
(rmail-mime-media-type-handlers-alist): Doc fix. Add image handler.
Glenn Morris <rgm@gnu.org>
parents:
105175
diff
changeset
|
448 (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
|
449 "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
|
450 (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
|
451 |
102317 | 452 ;;;###autoload |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
453 (defun rmail-mime () |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
454 "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
|
455 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
|
456 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
|
457 `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
|
458 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
|
459 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
|
460 (interactive) |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
461 (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
|
462 (buf (get-buffer-create "*RMAIL*"))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
463 (set-buffer buf) |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
464 (setq buffer-undo-list t) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
465 (let ((inhibit-read-only t)) |
106178
3f65383da746
(rmail-mime): Decode in fundamental-mode. (Bug#4993)
Glenn Morris <rgm@gnu.org>
parents:
105211
diff
changeset
|
466 ;; 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
|
467 ;; 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
|
468 ;; 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
|
469 (fundamental-mode) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
470 (erase-buffer) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
471 (insert data) |
106178
3f65383da746
(rmail-mime): Decode in fundamental-mode. (Bug#4993)
Glenn Morris <rgm@gnu.org>
parents:
105211
diff
changeset
|
472 (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
|
473 (rmail-mime-mode) |
102403
b7059e95eba9
(rmail-mime-media-type-handlers-alist)
Glenn Morris <rgm@gnu.org>
parents:
102317
diff
changeset
|
474 (set-buffer-modified-p nil)) |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
475 (view-buffer buf))) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
476 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
477 (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
|
478 "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
|
479 (error "%s; type: %s; disposition: %s; encoding: %s" |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
480 message type disposition encoding)) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
481 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
482 (provide 'rmailmm) |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
483 |
104907
6a35503cf20b
Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents:
102421
diff
changeset
|
484 ;; Local Variables: |
6a35503cf20b
Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents:
102421
diff
changeset
|
485 ;; generated-autoload-file: "rmail.el" |
6a35503cf20b
Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents:
102421
diff
changeset
|
486 ;; End: |
6a35503cf20b
Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents:
102421
diff
changeset
|
487 |
101360
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
488 ;; arch-tag: 3f2c5e5d-1aef-4512-bc20-fd737c9d5dd9 |
b10df8502c4a
Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff
changeset
|
489 ;;; rmailmm.el ends here |