summaryrefslogtreecommitdiff
path: root/lisp/gnus/mm-decode.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2019-09-30 08:41:43 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2019-09-30 08:41:43 +0200
commit5d33839c3fc40308cd29dbd0991888ead81fbfa7 (patch)
tree47abda629562e94d15820ee3b74a7e3b4bead5c4 /lisp/gnus/mm-decode.el
parent542b78eddeba3f020349c2d02ba2d21e8613d99d (diff)
downloademacs-5d33839c3fc40308cd29dbd0991888ead81fbfa7.tar.gz
Refactor mm-decode and friends to be explicit about when errors happen
* lisp/gnus/mm-decode.el (mm-sec-status): (mm-sec-error): New functions to handle decryption problems more explicitly (bug#18393). (mm-possibly-verify-or-decrypt): Use the `sec-error' data to determine whether the operation failed or not. * lisp/gnus/mml-smime.el: Ditto. * lisp/gnus/mml2015.el: Used throughout.
Diffstat (limited to 'lisp/gnus/mm-decode.el')
-rw-r--r--lisp/gnus/mm-decode.el34
1 files changed, 21 insertions, 13 deletions
diff --git a/lisp/gnus/mm-decode.el b/lisp/gnus/mm-decode.el
index 3de7a0464bb..22e7e118e2e 100644
--- a/lisp/gnus/mm-decode.el
+++ b/lisp/gnus/mm-decode.el
@@ -1646,14 +1646,22 @@ If RECURSIVE, search recursively."
(setq result (buffer-string))))))
result))
-(defvar mm-security-handle nil)
-
(defsubst mm-set-handle-multipart-parameter (handle parameter value)
;; HANDLE could be a CTL.
(when handle
(put-text-property 0 (length (car handle)) parameter value
(car handle))))
+;; Interface functions and variables for the decryption/verification
+;; functions.
+(defvar mm-security-handle nil)
+(defun mm-sec-status (&rest keys)
+ (cl-loop for (key val) on keys by #'cddr
+ do (mm-set-handle-multipart-parameter mm-security-handle key val)))
+
+(defun mm-sec-error (&rest keys)
+ (apply #'mm-sec-status (append '(sec-error t) keys)))
+
(autoload 'mm-view-pkcs7 "mm-view")
(defun mm-possibly-verify-or-decrypt (parts ctl &optional from)
@@ -1706,9 +1714,8 @@ If RECURSIVE, search recursively."
(save-excursion
(if func
(setq parts (funcall func parts ctl))
- (mm-set-handle-multipart-parameter
- mm-security-handle 'gnus-details
- (format "Unknown sign protocol (%s)" protocol))))))
+ (mm-sec-error 'gnus-details
+ (format "Unknown sign protocol (%s)" protocol))))))
((equal subtype "encrypted")
(unless (setq protocol
(mm-handle-multipart-ctl-parameter ctl 'protocol))
@@ -1738,22 +1745,23 @@ If RECURSIVE, search recursively."
(save-excursion
(if func
(setq parts (funcall func parts ctl))
- (mm-set-handle-multipart-parameter
- mm-security-handle 'gnus-details
+ (mm-sec-error
+ 'gnus-details
(format "Unknown encrypt protocol (%s)" protocol)))))))
;; Check the results (which are now in `parts').
- (let ((info (get-text-property 0 'gnus-info (car mm-security-handle))))
- (if (or (not info)
- (equal info "")
- (not (equal subtype "encrypted"))
- (member "OK" (split-string info "\n")))
+ (let ((err (get-text-property 0 'sec-error (car mm-security-handle))))
+ (if (or (not err)
+ (not (equal subtype "encrypted")))
parts
;; We had an error during decryption. Report what it is.
(list
(mm-make-handle
(with-current-buffer (generate-new-buffer " *mm*")
(insert "Error! Result from decryption:\n\n"
- info "\n\n"
+ (or (get-text-property 0 'gnus-details
+ (car mm-security-handle))
+ "")
+ "\n\n"
(or (get-text-property 0 'gnus-details
(car mm-security-handle))
""))