(eval-when-compile (require 'cl))
(eval-and-compile
- (autoload 'mm-inline-partial "mm-partial"))
+ (autoload 'mm-inline-partial "mm-partial")
+ (autoload 'mm-inline-external-body "mm-extern"))
(defgroup mime-display ()
"Display of MIME in mail and news articles."
:link '(custom-manual "(emacs-mime)Customization")
:group 'mail
- :group 'news)
+ :group 'news
+ :group 'multimedia)
;;; Convenience macros.
`(setcar (nthcdr 6 ,handle) ,contents))
(defmacro mm-handle-id (handle)
`(nth 7 ,handle))
+(defmacro mm-handle-multipart-original-buffer (handle)
+ `(get-text-property 0 'buffer (car ,handle)))
+(defmacro mm-handle-multipart-ctl-parameter (handle parameter)
+ `(get-text-property 0 ,parameter (car ,handle)))
+
(defmacro mm-make-handle (&optional buffer type encoding undisplayer
disposition description cache
id)
("text/x-patch" mm-display-patch-inline
(lambda (handle)
(locate-library "diff-mode")))
+ ("application/emacs-lisp" mm-display-elisp-inline identity)
("text/html"
mm-inline-text
(lambda (handle)
("message/delivery-status" mm-inline-text identity)
("message/rfc822" mm-inline-message identity)
("message/partial" mm-inline-partial identity)
+ ("message/external-body" mm-inline-external-body identity)
("text/.*" mm-inline-text identity)
("audio/wav" mm-inline-audio
(lambda (handle)
(and (or (featurep 'nas-sound) (featurep 'native-sound))
(device-sound-enabled-p))))
("application/pgp-signature" ignore identity)
+ ("application/x-pkcs7-signature" ignore identity)
+ ("application/pkcs7-signature" ignore identity)
("multipart/alternative" ignore identity)
("multipart/mixed" ignore identity)
("multipart/related" ignore identity))
(defcustom mm-inlined-types
'("image/.*" "text/.*" "message/delivery-status" "message/rfc822"
- "message/partial"
- "application/pgp-signature")
+ "message/partial" "message/external-body" "application/emacs-lisp"
+ "application/pgp-signature" "application/x-pkcs7-signature"
+ "application/pkcs7-signature")
"List of media types that are to be displayed inline."
:type '(repeat string)
:group 'mime-display)
(defcustom mm-automatic-display
'("text/plain" "text/enriched" "text/richtext" "text/html"
"text/x-vcard" "image/.*" "message/delivery-status" "multipart/.*"
- "message/rfc822" "text/x-patch" "application/pgp-signature")
+ "message/rfc822" "text/x-patch" "application/pgp-signature"
+ "application/emacs-lisp" "application/x-pkcs7-signature"
+ "application/pkcs7-signature")
"A list of MIME types to be displayed automatically."
:type '(repeat string)
:group 'mime-display)
;; "message/rfc822".
(defvar mm-dissect-default-type "text/plain")
+(autoload 'mml2015-verify "mml2015")
+(autoload 'mml-smime-verify "mml-smime")
+
+(defvar mm-verify-function-alist
+ '(("application/pgp-signature" mml2015-verify "PGP")
+ ("application/pkcs7-signature" mml-smime-verify "S/MIME")
+ ("application/x-pkcs7-signature" mml-smime-verify "S/MIME")))
+
+(defcustom mm-verify-option nil
+ "Option of verifying signed parts.
+`never', not verify; `always', always verify;
+`known', only verify known protocols. Otherwise, ask user."
+ :type '(choice (item always)
+ (item never)
+ (item :tag "only known protocols" known)
+ (item :tag "ask" nil))
+ :group 'gnus-article)
+
+(autoload 'mml2015-decrypt "mml2015")
+
+(defvar mm-decrypt-function-alist
+ '(("application/pgp-encrypted" mml2015-decrypt "PGP")))
+
+(defcustom mm-decrypt-option nil
+ "Option of decrypting signed parts.
+`never', not decrypt; `always', always decrypt;
+`known', only decrypt known protocols. Otherwise, ask user."
+ :type '(choice (item always)
+ (item never)
+ (item :tag "only known protocols" known)
+ (item :tag "ask" nil))
+ :group 'gnus-article)
+
+(defcustom mm-snarf-option nil
+ "Option of snarfing PGP key.
+`never', not snarf; `always', always snarf;
+`known', only snarf known protocols. Otherwise, ask user."
+ :type '(choice (item always)
+ (item never)
+ (item :tag "only known protocols" known)
+ (item :tag "ask" nil))
+ :group 'gnus-article)
+
+(defvar mm-viewer-completion-map
+ (let ((map (make-sparse-keymap 'mm-viewer-completion-map)))
+ (set-keymap-parent map minibuffer-local-completion-map)
+ map)
+ "Keymap for input viewer with completion.")
+
+;; Should we bind other key to minibuffer-complete-word?
+(define-key mm-viewer-completion-map " " 'self-insert-command)
+
;;; The functions.
+(defun mm-alist-to-plist (alist)
+ "Convert association list ALIST into the equivalent property-list form.
+The plist is returned. This converts from
+
+\((a . 1) (b . 2) (c . 3))
+
+into
+
+\(a 1 b 2 c 3)
+
+The original alist is not modified. See also `destructive-alist-to-plist'."
+ (let (plist)
+ (while alist
+ (let ((el (car alist)))
+ (setq plist (cons (cdr el) (cons (car el) plist))))
+ (setq alist (cdr alist)))
+ (nreverse plist)))
+
(defun mm-dissect-buffer (&optional no-strict-mime)
"Dissect the current buffer and return a list of MIME handles."
(save-excursion
(let ((mm-dissect-default-type (if (equal subtype "digest")
"message/rfc822"
"text/plain")))
+ (add-text-properties 0 (length (car ctl))
+ (mm-alist-to-plist (cdr ctl)) (car ctl))
+
+ ;; what really needs to be done here is a way to link a
+ ;; MIME handle back to it's parent MIME handle (in a multilevel
+ ;; MIME article). That would probably require changing
+ ;; the mm-handle API so we simply store the multipart buffert
+ ;; name as a text property of the "multipart/whatever" string.
+ (add-text-properties 0 (length (car ctl))
+ (list 'buffer (mm-copy-to-buffer))
+ (car ctl))
(cons (car ctl) (mm-dissect-multipart ctl))))
(t
(mm-dissect-singlepart
(if (re-search-backward close-delimiter nil t)
(match-beginning 0)
(point-max)))))
- (while (search-forward boundary end t)
+ (setq boundary (concat (regexp-quote boundary) "[ \t]*$"))
+ (while (re-search-forward boundary end t)
(goto-char (match-beginning 0))
(when start
(save-excursion
(save-restriction
(narrow-to-region start end)
(setq parts (nconc (list (mm-dissect-buffer t)) parts)))))
- (nreverse parts)))
+ (mm-possibly-verify-or-decrypt (nreverse parts) ctl)))
(defun mm-copy-to-buffer ()
"Copy the contents of the current buffer to a fresh buffer."
(let ((cur (current-buffer)))
(if (eq method 'mailcap-save-binary-file)
(progn
- (set-buffer (generate-new-buffer "*mm*"))
+ (set-buffer (generate-new-buffer " *mm*"))
(setq method nil))
(mm-insert-part handle)
(let ((win (get-buffer-window cur t)))
(when win
(select-window win)))
- (switch-to-buffer (generate-new-buffer "*mm*")))
+ (switch-to-buffer (generate-new-buffer " *mm*")))
(buffer-disable-undo)
(mm-set-buffer-file-coding-system mm-binary-coding-system)
(insert-buffer-substring cur)
+ (goto-char (point-min))
(message "Viewing with %s" method)
(let ((mm (current-buffer))
(non-viewer (assq 'non-viewer
(progn
(call-process shell-file-name nil
(setq buffer
- (generate-new-buffer "*mm*"))
+ (generate-new-buffer " *mm*"))
nil
shell-command-switch
(mm-mailcap-command
(unwind-protect
(start-process "*display*"
(setq buffer
- (generate-new-buffer "*mm*"))
+ (generate-new-buffer " *mm*"))
shell-file-name
shell-command-switch
(mm-mailcap-command
(push "<" out)
(push (mm-quote-arg file) out)))
(mapconcat 'identity (nreverse out) "")))
-
+
(defun mm-remove-parts (handles)
"Remove the displayed MIME parts represented by HANDLES."
(if (and (listp handles)
(while (setq handle (pop handles))
(cond
((stringp handle)
- ;; Do nothing.
- )
+ (when (buffer-live-p (get-text-property 0 'buffer handle))
+ (kill-buffer (get-text-property 0 'buffer handle))))
((and (listp handle)
(stringp (car handle)))
(mm-remove-parts (cdr handle)))
(while (setq handle (pop handles))
(cond
((stringp handle)
- ;; Do nothing.
- )
+ (when (buffer-live-p (get-text-property 0 'buffer handle))
+ (kill-buffer (get-text-property 0 'buffer handle))))
((and (listp handle)
(stringp (car handle)))
(mm-destroy-parts (cdr handle)))
(save-excursion
(if (member (mm-handle-media-supertype handle) '("text" "message"))
(with-temp-buffer
- (if (eq (or (mm-handle-encoding handle)
- (with-current-buffer (mm-handle-buffer handle)
- (mm-body-7-or-8)))
- '8bit)
- ;; Emacs MULE can not handle some 8bit characters in
- ;; multibyte character!!
- (let ((text (with-current-buffer
- (mm-handle-buffer handle)
- (mm-with-unibyte-current-buffer
- (buffer-string)))))
- (mm-with-unibyte-current-buffer
- (insert text)))
- (insert-buffer-substring (mm-handle-buffer handle)))
+ (insert-buffer-substring (mm-handle-buffer handle))
(mm-decode-content-transfer-encoding
(mm-handle-encoding handle)
(mm-handle-media-type handle))
(or filename name "")
(or mm-default-directory default-directory))))
(setq mm-default-directory (file-name-directory file))
- (when (or (not (file-exists-p file))
- (yes-or-no-p (format "File %s already exists; overwrite? "
- file)))
- (mm-save-part-to-file handle file))))
+ (and (or (not (file-exists-p file))
+ (yes-or-no-p (format "File %s already exists; overwrite? "
+ file)))
+ (progn
+ (mm-save-part-to-file handle file)
+ file))))
(defun mm-save-part-to-file (handle file)
(mm-with-unibyte-buffer
(methods
(mapcar (lambda (i) (list (cdr (assoc 'viewer i))))
(mailcap-mime-info type 'all)))
- (method (completing-read "Viewer: " methods)))
+ (method (let ((minibuffer-local-completion-map
+ mm-viewer-completion-map))
+ (completing-read "Viewer: " methods))))
(when (string= method "")
(error "No method given"))
(if (string-match "^[^% \t]+$" method)
(prog1
(setq spec
(ignore-errors
- (if (fboundp 'make-glyph)
- (cond
- ((equal type "xbm")
- ;; xbm images require special handling, since
- ;; the only way to create glyphs from these
- ;; (without a ton of work) is to write them
- ;; out to a file, and then create a file
- ;; specifier.
- (let ((file (make-temp-name
- (expand-file-name "emm.xbm"
- mm-tmp-directory))))
- (unwind-protect
- (progn
- (write-region (point-min) (point-max) file)
- (make-glyph (list (cons 'x file))))
- (ignore-errors
- (delete-file file)))))
- (t
- (make-glyph
- (vector (intern type) :data (buffer-string)))))
- (create-image (buffer-string) (intern type) 'data-p))))
+ ;; Avoid testing `make-glyph' since W3 may define
+ ;; a bogus version of it.
+ (if (fboundp 'create-image)
+ (create-image (buffer-string) (intern type) 'data-p)
+ (cond
+ ((equal type "xbm")
+ ;; xbm images require special handling, since
+ ;; the only way to create glyphs from these
+ ;; (without a ton of work) is to write them
+ ;; out to a file, and then create a file
+ ;; specifier.
+ (let ((file (make-temp-name
+ (expand-file-name "emm.xbm"
+ mm-tmp-directory))))
+ (unwind-protect
+ (progn
+ (write-region (point-min) (point-max) file)
+ (make-glyph (list (cons 'x file))))
+ (ignore-errors
+ (delete-file file)))))
+ (t
+ (make-glyph
+ (vector (intern type) :data (buffer-string))))))))
(mm-handle-set-cache handle spec))))))
(defun mm-image-fit-p (handle)
(defun mm-valid-and-fit-image-p (format handle)
"Say whether FORMAT can be displayed natively and HANDLE fits the window."
- (and window-system
- (mm-valid-image-format-p format)
+ (and (mm-valid-image-format-p format)
(mm-image-fit-p handle)))
+(defun mm-find-part-by-type (handles type &optional notp)
+ "Search in HANDLES for part with TYPE.
+If NOTP, returns first non-matching part."
+ (let (handle)
+ (while handles
+ (if (if notp
+ (not (equal (mm-handle-media-type (car handles)) type))
+ (equal (mm-handle-media-type (car handles)) type))
+ (setq handle (car handles)
+ handles nil))
+ (setq handles (cdr handles)))
+ handle))
+
+(defun mm-find-raw-part-by-type (ctl type &optional notp)
+ (goto-char (point-min))
+ (let* ((boundary (concat "\n--" (mail-content-type-get ctl 'boundary)))
+ (close-delimiter (concat (regexp-quote boundary) "--[ \t]*$"))
+ start
+ (end (save-excursion
+ (goto-char (point-max))
+ (if (re-search-backward close-delimiter nil t)
+ (match-beginning 0)
+ (point-max))))
+ result)
+ (setq boundary (concat (regexp-quote boundary) "[ \t]*$"))
+ (while (and (not result)
+ (re-search-forward boundary end t))
+ (goto-char (match-beginning 0))
+ (when start
+ (save-excursion
+ (save-restriction
+ (narrow-to-region start (point))
+ (when (let ((ctl (ignore-errors
+ (mail-header-parse-content-type
+ (mail-fetch-field "content-type")))))
+ (if notp
+ (not (equal (car ctl) type))
+ (equal (car ctl) type)))
+ (setq result (buffer-substring (point-min) (point-max)))))))
+ (forward-line 2)
+ (setq start (point)))
+ (when (and (not result) start)
+ (save-excursion
+ (save-restriction
+ (narrow-to-region start end)
+ (when (let ((ctl (ignore-errors
+ (mail-header-parse-content-type
+ (mail-fetch-field "content-type")))))
+ (if notp
+ (not (equal (car ctl) type))
+ (equal (car ctl) type)))
+ (setq result (buffer-substring (point-min) (point-max)))))))
+ result))
+
+(defun mm-possibly-verify-or-decrypt (parts ctl)
+ (let ((subtype (cadr (split-string (car ctl) "/")))
+ protocol func)
+ (cond
+ ((equal subtype "signed")
+ (setq protocol (mail-content-type-get ctl 'protocol))
+ (setq func (nth 1 (assoc protocol mm-verify-function-alist)))
+ (if (cond
+ ((eq mm-verify-option 'never) nil)
+ ((eq mm-verify-option 'always) t)
+ ((eq mm-verify-option 'known) func)
+ (t (y-or-n-p
+ (format "Verify signed (%s) part? "
+ (or (nth 2 (assoc protocol mm-verify-function-alist))
+ (format "protocol=%s" protocol))))))
+ (condition-case err
+ (save-excursion
+ (if func
+ (funcall func parts ctl)
+ (error (format "Unknown sign protocol (%s)" protocol))))
+ (error
+ (unless (y-or-n-p (format "%s, continue? " err))
+ (error "Verify failure."))))))
+ ((equal subtype "encrypted")
+ (setq protocol (mail-content-type-get ctl 'protocol))
+ (setq func (nth 1 (assoc protocol mm-decrypt-function-alist)))
+ (if (cond
+ ((eq mm-decrypt-option 'never) nil)
+ ((eq mm-decrypt-option 'always) t)
+ ((eq mm-decrypt-option 'known) func)
+ (t (y-or-n-p
+ (format "Decrypt (%s) part? "
+ (or (nth 2 (assoc protocol mm-decrypt-function-alist))
+ (format "protocol=%s" protocol))))))
+ (condition-case err
+ (save-excursion
+ (if func
+ (setq parts (funcall func parts ctl))
+ (error (format "Unknown encrypt protocol (%s)" protocol))))
+ (error
+ (unless (y-or-n-p (format "%s, continue? " err))
+ (error "Decrypt failure."))))))
+ (t nil))
+ parts))
+
(provide 'mm-decode)
;;; mm-decode.el ends here