# HG changeset patch # User Glenn Morris # Date 1253849944 0 # Node ID d05b41e0a7ef0fc242523b395c7eb0485fdc198d # Parent 43be71d128b24642ed44540d96a94372e07af92d (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. diff -r 43be71d128b2 -r d05b41e0a7ef lisp/ChangeLog --- a/lisp/ChangeLog Fri Sep 25 03:36:16 2009 +0000 +++ b/lisp/ChangeLog Fri Sep 25 03:39:04 2009 +0000 @@ -1,3 +1,16 @@ +2009-09-25 Glenn Morris + + * mail/rmailmm.el (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. + 2009-09-25 David Engster * progmodes/hideshow.el (hs-show-block): Run `hs-show-hook'. (Bug#4548) diff -r 43be71d128b2 -r d05b41e0a7ef lisp/mail/rmailmm.el --- a/lisp/mail/rmailmm.el Fri Sep 25 03:36:16 2009 +0000 +++ b/lisp/mail/rmailmm.el Fri Sep 25 03:39:04 2009 +0000 @@ -39,15 +39,18 @@ ;;; User options. -;; FIXME should these be in an rmail group? +(defgroup rmail-mime nil + "Rmail MIME handling options." + :prefix "rmail-mime-" + :group 'rmail) + (defcustom rmail-mime-media-type-handlers-alist '(("multipart/.*" rmail-mime-multipart-handler) ("text/.*" rmail-mime-text-handler) ("text/\\(x-\\)?patch" rmail-mime-bulk-handler) ;; FIXME this handler not defined anywhere? ;;; ("application/pgp-signature" rmail-mime-application/pgp-signature-handler) - ("\\(audio\\|video\\|application\\)/.*" rmail-mime-bulk-handler) - ("image/.*" rmail-mime-image-handler)) + ("\\(image\\|audio\\|video\\|application\\)/.*" rmail-mime-bulk-handler)) "Functions to handle various content types. This is an alist with elements of the form (REGEXP FUNCTION ...). The first item is a regular expression matching a content-type. @@ -56,8 +59,8 @@ Note that this only applies to items with an inline Content-Disposition, all others are handled by `rmail-mime-bulk-handler'." :type '(alist :key-type regexp :value-type (repeat function)) - :version "23.2" ; added image-handler - :group 'mime) + :version "23.1" + :group 'rmail-mime) (defcustom rmail-mime-attachment-dirs-alist `(("text/.*" "~/Documents") @@ -70,16 +73,22 @@ The first directory that exists is used." :type '(alist :key-type regexp :value-type (repeat directory)) :version "23.1" - :group 'mime) + :group 'rmail-mime) + +(defcustom rmail-mime-show-images 'button + "What to do with image attachments that Emacs is capable of displaying. +If nil, do nothing special. If `button', add an extra button +that when pushed displays the image in the buffer. Anything else +means to automatically display the image in the buffer." + :type '(choice (const :tag "Add button to view image" button) + (const :tag "No special treatment" nil) + (other :tag "Always show" show)) + :version "23.2" + :group 'rmail-mime) ;;; End of user options. -(defvar rmail-mime-total-number-of-bulk-attachments 0 - "The total number of bulk attachments in the message. -If more than 3, offer a way to save all attachments at once.") -(put 'rmail-mime-total-number-of-bulk-attachments 'permanent-local t) - ;;; Buttons (defun rmail-mime-save (button) @@ -134,15 +143,29 @@ (rmail-mime-show t) (set-buffer-multibyte t))) + +(defun rmail-mime-insert-image (type data) + "Insert an image of type TYPE, where DATA is the image data." + (end-of-line) + (insert ?\n) + (insert-image (create-image data type t))) + +(defun rmail-mime-image (button) + "Display the image associated with BUTTON." + (let ((inhibit-read-only t)) + (rmail-mime-insert-image (button-get button 'image-type) + (button-get button 'image-data)))) + +(define-button-type 'rmail-mime-image 'action 'rmail-mime-image) + + (defun rmail-mime-bulk-handler (content-type content-disposition - content-transfer-encoding &optional image) + content-transfer-encoding) "Handle the current buffer as an attachment to download. -Optional argument IMAGE non-nil means if Emacs can display the -attachment as an image, add an option to do so." - (setq rmail-mime-total-number-of-bulk-attachments - (1+ rmail-mime-total-number-of-bulk-attachments)) - ;; Find the default directory for this media type +For images that Emacs is capable of displaying, the behavior +depends upon the value of `rmail-mime-show-images'." + ;; Find the default directory for this media type. (let* ((directory (catch 'directory (dolist (entry rmail-mime-attachment-dirs-alist) (when (string-match (car entry) (car content-type)) @@ -153,7 +176,8 @@ (cdr (assq 'filename (cdr content-disposition))) "noname")) (label (format "\nAttached %s file: " (car content-type))) - (data (buffer-string))) + (data (buffer-string)) + type) (delete-region (point-min) (point-max)) (insert label) (insert-button filename @@ -162,30 +186,23 @@ 'filename filename 'directory (file-name-as-directory directory) 'data data) - (when (and image - (string-match "image/\\(.*\\)" (setq image (car content-type))) - (setq image (concat "." (match-string 1 image)) - image (image-type-from-file-name image)) - (memq image image-types) - (image-type-available-p image)) + (when (and rmail-mime-show-images + (string-match "image/\\(.*\\)" (setq type (car content-type))) + (setq type (concat "." (match-string 1 type)) + type (image-type-from-file-name type)) + (memq type image-types) + (image-type-available-p type)) + (setq data (string-as-unibyte data)) (insert " ") ;; FIXME ought to check or at least display the image size. - (insert-button "Display" - :type 'rmail-mime-image - 'help-echo "mouse-2, RET: Show image" - 'image-type image - 'image-data (string-as-unibyte data))))) - -(defun rmail-mime-image (button) - "Display the image associated with BUTTON." - (let ((type (button-get button 'image-type)) - (data (button-get button 'image-data)) - (inhibit-read-only t)) - (end-of-line) - (insert ?\n) - (insert-image (create-image data type t)))) - -(define-button-type 'rmail-mime-image 'action 'rmail-mime-image) + (cond ((eq rmail-mime-show-images 'button) + (insert-button "Display" + :type 'rmail-mime-image + 'help-echo "mouse-2, RET: Show image" + 'image-type type + 'image-data data)) + (t + (rmail-mime-insert-image type data)))))) (defun test-rmail-mime-bulk-handler () "Test of a mail used as an example in RFC 2183." @@ -208,15 +225,6 @@ (insert mail) (rmail-mime-show))) -;; FIXME should rmail-mime-bulk-handler instead just always do this? -(defun rmail-mime-image-handler (content-type content-disposition - content-transfer-encoding) - "Handle the current buffer as an image. -Like `rmail-mime-bulk-handler', but if possible adds a second -button to display the image in the buffer." - (rmail-mime-bulk-handler content-type content-disposition - content-transfer-encoding t)) - (defun rmail-mime-multipart-handler (content-type content-disposition content-transfer-encoding) @@ -244,8 +252,6 @@ (when (and (search-forward boundary nil t) (looking-at "[ \t]*\n")) (delete-region (point-min) (match-end 0))) - ;; Reset the counter - (setq rmail-mime-total-number-of-bulk-attachments 0) ;; Loop over all body parts, where beg points at the beginning of ;; the part and end points at the end of the part. next points at ;; the beginning of the next part.