:group 'news
:group 'multimedia)
+(defgroup mime-security ()
+ "MIME security in mail and news articles."
+ :link '(custom-manual "(emacs-mime)Customization")
+ :group 'mail
+ :group 'news
+ :group 'multimedia)
+
;;; Convenience macros.
(defmacro mm-handle-buffer (handle)
`(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)
(defvar mm-dissect-default-type "text/plain")
(autoload 'mml2015-verify "mml2015")
+(autoload 'mml2015-verify-test "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")))
+ '(("application/pgp-signature" mml2015-verify "PGP" mml2015-verify-test)
+ ("application/pkcs7-signature" mml-smime-verify "S/MIME" nil)
+ ("application/x-pkcs7-signature" mml-smime-verify "S/MIME" nil)))
-(defcustom mm-verify-option nil
+(defcustom mm-verify-option 'known
"Option of verifying signed parts.
`never', not verify; `always', always verify;
`known', only verify known protocols. Otherwise, ask user."
(item never)
(item :tag "only known protocols" known)
(item :tag "ask" nil))
- :group 'gnus-article)
+ :group 'mime-security)
(autoload 'mml2015-decrypt "mml2015")
+(autoload 'mml2015-decrypt-test "mml2015")
(defvar mm-decrypt-function-alist
- '(("application/pgp-encrypted" mml2015-decrypt "PGP")))
+ '(("application/pgp-encrypted" mml2015-decrypt "PGP" mml2015-decrypt-test)))
-(defcustom mm-decrypt-option nil
+(defcustom mm-decrypt-option 'known
"Option of decrypting signed parts.
`never', not decrypt; `always', always decrypt;
`known', only decrypt known protocols. Otherwise, ask user."
(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)
+ :group 'mime-security)
(defvar mm-viewer-completion-map
(let ((map (make-sparse-keymap 'mm-viewer-completion-map)))
;;; 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
(insert-buffer-substring obuf beg)
(current-buffer))))
+(defun mm-display-parts (handle &optional no-default)
+ (if (stringp (car handle))
+ (mapcar 'mm-display-parts (cdr handle))
+ (if (bufferp (car handle))
+ (save-restriction
+ (narrow-to-region (point) (point))
+ (mm-display-part handle)
+ (goto-char (point-max)))
+ (mapcar 'mm-display-parts handle))))
+
(defun mm-display-part (handle &optional no-default)
"Display the MIME part represented by HANDLE.
Returns nil if the part is removed; inline if displayed inline;
(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)))
(and (mm-valid-image-format-p format)
(mm-image-fit-p handle)))
-(defun mm-find-part-by-type (handles type &optional notp)
+(defun mm-find-part-by-type (handles type &optional notp recursive)
"Search in HANDLES for part with TYPE.
-If NOTP, returns first non-matching part."
+If NOTP, returns first non-matching part.
+If RECURSIVE, search recursively."
(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))
+ (if (and recursive (stringp (caar handles)))
+ (if (setq handle (mm-find-part-by-type (cdar handles) type
+ notp recursive))
+ (setq handles nil))
+ (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-possibly-verify-or-decrypt (parts ctl)
(let ((subtype (cadr (split-string (car ctl) "/")))
- protocol func)
+ protocol func functest)
(cond
((equal subtype "signed")
- (setq protocol (mail-content-type-get ctl 'protocol))
+ (unless (and (setq protocol (mail-content-type-get ctl 'protocol))
+ (not (equal protocol "multipart/mixed")))
+ ;; The message is broken or draft-ietf-openpgp-multsig-01.
+ (let ((protocols mm-verify-function-alist))
+ (while protocols
+ (if (and (or (not (setq functest (nth 3 (car protocols))))
+ (funcall functest parts ctl))
+ (mm-find-part-by-type parts (caar protocols) nil t))
+ (setq protocol (caar protocols)
+ protocols nil)
+ (setq protocols (cdr protocols))))))
(setq func (nth 1 (assoc protocol mm-verify-function-alist)))
(if (cond