aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2009-09-25 03:39:04 +0000
committerGlenn Morris2009-09-25 03:39:04 +0000
commite8652dd9c52c805b7e33695b2770a52c4606a5d8 (patch)
treec00e1f89b793eea6f030a130db260cdfc5b6d874
parent78427304a6464a5391b0002146bc52a388723403 (diff)
downloademacs-e8652dd9c52c805b7e33695b2770a52c4606a5d8.tar.gz
emacs-e8652dd9c52c805b7e33695b2770a52c4606a5d8.zip
(rmail-mime): New custom group.
Move all defcustoms in this file into this group. (rmail-mime-media-type-handlers-alist): Revert previous change. (rmail-mime-show-images): New option. (rmail-mime-total-number-of-bulk-attachments): Remove variable and all references to it, since it wasn't actually used for anything. (rmail-mime-insert-image): New function. (rmail-mime-image): Use rmail-mime-insert-image. (rmail-mime-bulk-handler): Remove optional `image' argument, instead obey the value of `rmail-mime-show-images' option.
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/mail/rmailmm.el108
2 files changed, 70 insertions, 51 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e9685a08fcb..58662b7e898 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,16 @@
12009-09-25 Glenn Morris <rgm@gnu.org>
2
3 * mail/rmailmm.el (rmail-mime): New custom group.
4 Move all defcustoms in this file into this group.
5 (rmail-mime-media-type-handlers-alist): Revert previous change.
6 (rmail-mime-show-images): New option.
7 (rmail-mime-total-number-of-bulk-attachments): Remove variable and all
8 references to it, since it wasn't actually used for anything.
9 (rmail-mime-insert-image): New function.
10 (rmail-mime-image): Use rmail-mime-insert-image.
11 (rmail-mime-bulk-handler): Remove optional `image' argument, instead
12 obey the value of `rmail-mime-show-images' option.
13
12009-09-25 David Engster <deng@randomsample.de> 142009-09-25 David Engster <deng@randomsample.de>
2 15
3 * progmodes/hideshow.el (hs-show-block): Run `hs-show-hook'. (Bug#4548) 16 * progmodes/hideshow.el (hs-show-block): Run `hs-show-hook'. (Bug#4548)
diff --git a/lisp/mail/rmailmm.el b/lisp/mail/rmailmm.el
index 71248b047bc..f7f7fb7609f 100644
--- a/lisp/mail/rmailmm.el
+++ b/lisp/mail/rmailmm.el
@@ -39,15 +39,18 @@
39 39
40;;; User options. 40;;; User options.
41 41
42;; FIXME should these be in an rmail group? 42(defgroup rmail-mime nil
43 "Rmail MIME handling options."
44 :prefix "rmail-mime-"
45 :group 'rmail)
46
43(defcustom rmail-mime-media-type-handlers-alist 47(defcustom rmail-mime-media-type-handlers-alist
44 '(("multipart/.*" rmail-mime-multipart-handler) 48 '(("multipart/.*" rmail-mime-multipart-handler)
45 ("text/.*" rmail-mime-text-handler) 49 ("text/.*" rmail-mime-text-handler)
46 ("text/\\(x-\\)?patch" rmail-mime-bulk-handler) 50 ("text/\\(x-\\)?patch" rmail-mime-bulk-handler)
47 ;; FIXME this handler not defined anywhere? 51 ;; FIXME this handler not defined anywhere?
48;;; ("application/pgp-signature" rmail-mime-application/pgp-signature-handler) 52;;; ("application/pgp-signature" rmail-mime-application/pgp-signature-handler)
49 ("\\(audio\\|video\\|application\\)/.*" rmail-mime-bulk-handler) 53 ("\\(image\\|audio\\|video\\|application\\)/.*" rmail-mime-bulk-handler))
50 ("image/.*" rmail-mime-image-handler))
51 "Functions to handle various content types. 54 "Functions to handle various content types.
52This is an alist with elements of the form (REGEXP FUNCTION ...). 55This is an alist with elements of the form (REGEXP FUNCTION ...).
53The first item is a regular expression matching a content-type. 56The first item is a regular expression matching a content-type.
@@ -56,8 +59,8 @@ decreasing preference. These are called until one returns non-nil.
56Note that this only applies to items with an inline Content-Disposition, 59Note that this only applies to items with an inline Content-Disposition,
57all others are handled by `rmail-mime-bulk-handler'." 60all others are handled by `rmail-mime-bulk-handler'."
58 :type '(alist :key-type regexp :value-type (repeat function)) 61 :type '(alist :key-type regexp :value-type (repeat function))
59 :version "23.2" ; added image-handler 62 :version "23.1"
60 :group 'mime) 63 :group 'rmail-mime)
61 64
62(defcustom rmail-mime-attachment-dirs-alist 65(defcustom rmail-mime-attachment-dirs-alist
63 `(("text/.*" "~/Documents") 66 `(("text/.*" "~/Documents")
@@ -70,16 +73,22 @@ The remaining elements are directories, in order of decreasing preference.
70The first directory that exists is used." 73The first directory that exists is used."
71 :type '(alist :key-type regexp :value-type (repeat directory)) 74 :type '(alist :key-type regexp :value-type (repeat directory))
72 :version "23.1" 75 :version "23.1"
73 :group 'mime) 76 :group 'rmail-mime)
77
78(defcustom rmail-mime-show-images 'button
79 "What to do with image attachments that Emacs is capable of displaying.
80If nil, do nothing special. If `button', add an extra button
81that when pushed displays the image in the buffer. Anything else
82means to automatically display the image in the buffer."
83 :type '(choice (const :tag "Add button to view image" button)
84 (const :tag "No special treatment" nil)
85 (other :tag "Always show" show))
86 :version "23.2"
87 :group 'rmail-mime)
74 88
75;;; End of user options. 89;;; End of user options.
76 90
77 91
78(defvar rmail-mime-total-number-of-bulk-attachments 0
79 "The total number of bulk attachments in the message.
80If more than 3, offer a way to save all attachments at once.")
81(put 'rmail-mime-total-number-of-bulk-attachments 'permanent-local t)
82
83;;; Buttons 92;;; Buttons
84 93
85(defun rmail-mime-save (button) 94(defun rmail-mime-save (button)
@@ -134,15 +143,29 @@ MIME-Version: 1.0
134 (rmail-mime-show t) 143 (rmail-mime-show t)
135 (set-buffer-multibyte t))) 144 (set-buffer-multibyte t)))
136 145
146
147(defun rmail-mime-insert-image (type data)
148 "Insert an image of type TYPE, where DATA is the image data."
149 (end-of-line)
150 (insert ?\n)
151 (insert-image (create-image data type t)))
152
153(defun rmail-mime-image (button)
154 "Display the image associated with BUTTON."
155 (let ((inhibit-read-only t))
156 (rmail-mime-insert-image (button-get button 'image-type)
157 (button-get button 'image-data))))
158
159(define-button-type 'rmail-mime-image 'action 'rmail-mime-image)
160
161
137(defun rmail-mime-bulk-handler (content-type 162(defun rmail-mime-bulk-handler (content-type
138 content-disposition 163 content-disposition
139 content-transfer-encoding &optional image) 164 content-transfer-encoding)
140 "Handle the current buffer as an attachment to download. 165 "Handle the current buffer as an attachment to download.
141Optional argument IMAGE non-nil means if Emacs can display the 166For images that Emacs is capable of displaying, the behavior
142attachment as an image, add an option to do so." 167depends upon the value of `rmail-mime-show-images'."
143 (setq rmail-mime-total-number-of-bulk-attachments 168 ;; Find the default directory for this media type.
144 (1+ rmail-mime-total-number-of-bulk-attachments))
145 ;; Find the default directory for this media type
146 (let* ((directory (catch 'directory 169 (let* ((directory (catch 'directory
147 (dolist (entry rmail-mime-attachment-dirs-alist) 170 (dolist (entry rmail-mime-attachment-dirs-alist)
148 (when (string-match (car entry) (car content-type)) 171 (when (string-match (car entry) (car content-type))
@@ -153,7 +176,8 @@ attachment as an image, add an option to do so."
153 (cdr (assq 'filename (cdr content-disposition))) 176 (cdr (assq 'filename (cdr content-disposition)))
154 "noname")) 177 "noname"))
155 (label (format "\nAttached %s file: " (car content-type))) 178 (label (format "\nAttached %s file: " (car content-type)))
156 (data (buffer-string))) 179 (data (buffer-string))
180 type)
157 (delete-region (point-min) (point-max)) 181 (delete-region (point-min) (point-max))
158 (insert label) 182 (insert label)
159 (insert-button filename 183 (insert-button filename
@@ -162,30 +186,23 @@ attachment as an image, add an option to do so."
162 'filename filename 186 'filename filename
163 'directory (file-name-as-directory directory) 187 'directory (file-name-as-directory directory)
164 'data data) 188 'data data)
165 (when (and image 189 (when (and rmail-mime-show-images
166 (string-match "image/\\(.*\\)" (setq image (car content-type))) 190 (string-match "image/\\(.*\\)" (setq type (car content-type)))
167 (setq image (concat "." (match-string 1 image)) 191 (setq type (concat "." (match-string 1 type))
168 image (image-type-from-file-name image)) 192 type (image-type-from-file-name type))
169 (memq image image-types) 193 (memq type image-types)
170 (image-type-available-p image)) 194 (image-type-available-p type))
195 (setq data (string-as-unibyte data))
171 (insert " ") 196 (insert " ")
172 ;; FIXME ought to check or at least display the image size. 197 ;; FIXME ought to check or at least display the image size.
173 (insert-button "Display" 198 (cond ((eq rmail-mime-show-images 'button)
174 :type 'rmail-mime-image 199 (insert-button "Display"
175 'help-echo "mouse-2, RET: Show image" 200 :type 'rmail-mime-image
176 'image-type image 201 'help-echo "mouse-2, RET: Show image"
177 'image-data (string-as-unibyte data))))) 202 'image-type type
178 203 'image-data data))
179(defun rmail-mime-image (button) 204 (t
180 "Display the image associated with BUTTON." 205 (rmail-mime-insert-image type data))))))
181 (let ((type (button-get button 'image-type))
182 (data (button-get button 'image-data))
183 (inhibit-read-only t))
184 (end-of-line)
185 (insert ?\n)
186 (insert-image (create-image data type t))))
187
188(define-button-type 'rmail-mime-image 'action 'rmail-mime-image)
189 206
190(defun test-rmail-mime-bulk-handler () 207(defun test-rmail-mime-bulk-handler ()
191 "Test of a mail used as an example in RFC 2183." 208 "Test of a mail used as an example in RFC 2183."
@@ -208,15 +225,6 @@ lgAAAABJRU5ErkJggg==
208 (insert mail) 225 (insert mail)
209 (rmail-mime-show))) 226 (rmail-mime-show)))
210 227
211;; FIXME should rmail-mime-bulk-handler instead just always do this?
212(defun rmail-mime-image-handler (content-type content-disposition
213 content-transfer-encoding)
214 "Handle the current buffer as an image.
215Like `rmail-mime-bulk-handler', but if possible adds a second
216button to display the image in the buffer."
217 (rmail-mime-bulk-handler content-type content-disposition
218 content-transfer-encoding t))
219
220(defun rmail-mime-multipart-handler (content-type 228(defun rmail-mime-multipart-handler (content-type
221 content-disposition 229 content-disposition
222 content-transfer-encoding) 230 content-transfer-encoding)
@@ -244,8 +252,6 @@ format."
244 (when (and (search-forward boundary nil t) 252 (when (and (search-forward boundary nil t)
245 (looking-at "[ \t]*\n")) 253 (looking-at "[ \t]*\n"))
246 (delete-region (point-min) (match-end 0))) 254 (delete-region (point-min) (match-end 0)))
247 ;; Reset the counter
248 (setq rmail-mime-total-number-of-bulk-attachments 0)
249 ;; Loop over all body parts, where beg points at the beginning of 255 ;; Loop over all body parts, where beg points at the beginning of
250 ;; the part and end points at the end of the part. next points at 256 ;; the part and end points at the end of the part. next points at
251 ;; the beginning of the next part. 257 ;; the beginning of the next part.