Merge from gnus--rel--5.10
[gnus] / lisp / mml2015.el
index 3332270..14f095c 100644 (file)
@@ -136,6 +136,11 @@ Whether the passphrase is cached at all is controlled by
   :group 'mime-security
   :type 'boolean)
 
+(defcustom mml2015-always-trust t
+  "If t, GnuPG skip key validation on encryption."
+  :group 'mime-security
+  :type 'boolean)
+
 ;;; mailcrypt wrapper
 
 (eval-and-compile
@@ -829,7 +834,7 @@ Whether the passphrase is cached at all is controlled by
     (if (condition-case err
            (prog1
                (mm-with-unibyte-buffer
-                 (insert (encode-coding-string text coding-system))
+                 (insert (mm-encode-coding-string text coding-system))
                  (pgg-verify-region (point-min) (point-max) nil t))
              (goto-char (point-min))
              (while (search-forward "\r\n" nil t)
@@ -938,7 +943,8 @@ Whether the passphrase is cached at all is controlled by
   (autoload 'epg-passphrase-callback-function "epg")
   (autoload 'epg-context-set-passphrase-callback "epg")
   (autoload 'epg-configuration "epg-config")
-  (autoload 'epg-expand-group "epg-config"))
+  (autoload 'epg-expand-group "epg-config")
+  (autoload 'epa-select-keys "epa"))
 
 (eval-when-compile
   (defvar password-cache-expiry)
@@ -951,13 +957,14 @@ Whether the passphrase is cached at all is controlled by
 (defun mml2015-epg-passphrase-callback (context key-id ignore)
   (if (eq key-id 'SYM)
       (epg-passphrase-callback-function context key-id nil)
-    (let* ((entry (assoc key-id epg-user-id-alist))
+    (let* (entry
           (passphrase
            (password-read
-            (format "GnuPG passphrase for %s: "
-                    (if entry
-                        (cdr entry)
-                      key-id))
+            (if (eq key-id 'PIN)
+                "Passphrase for PIN: "
+              (if (setq entry (assoc key-id epg-user-id-alist))
+                  (format "Passphrase for %s %s: " key-id (cdr entry))
+                (format "Passphrase for %s: " key-id)))
             (if (eq key-id 'PIN)
                 "PIN"
               key-id))))
@@ -1053,14 +1060,13 @@ Whether the passphrase is cached at all is controlled by
       (goto-char (point-min))
       (while (search-forward "\r\n" nil t)
        (replace-match "\n" t t))
+      (mm-set-handle-multipart-parameter
+       mm-security-handle 'gnus-info "OK")
       (if (epg-context-result-for context 'verify)
          (mm-set-handle-multipart-parameter
-          mm-security-handle 'gnus-info
-          (concat "OK\n"
-                  (epg-verify-result-to-string
-                   (epg-context-result-for context 'verify))))
-       (mm-set-handle-multipart-parameter
-        mm-security-handle 'gnus-info "OK")))))
+          mm-security-handle 'gnus-details
+          (epg-verify-result-to-string
+           (epg-context-result-for context 'verify)))))))
 
 (defun mml2015-epg-verify (handle ctl)
   (catch 'error
@@ -1097,8 +1103,8 @@ Whether the passphrase is cached at all is controlled by
 (defun mml2015-epg-clear-verify ()
   (let ((inhibit-redisplay t)
        (context (epg-make-context))
-       (signature (encode-coding-string (buffer-string)
-                                        buffer-file-coding-system))
+       (signature (mm-encode-coding-string (buffer-string)
+                                           buffer-file-coding-system))
        plain)
     (condition-case error
        (setq plain (epg-verify-string context signature))
@@ -1117,18 +1123,23 @@ Whether the passphrase is cached at all is controlled by
          (epg-context-result-for context 'verify))))))
 
 (defun mml2015-epg-sign (cont)
-  (let ((inhibit-redisplay t)
+  (let* ((inhibit-redisplay t)
        (context (epg-make-context))
        (boundary (mml-compute-boundary cont))
-       signers signature micalg)
-    (if mml2015-verbose
-       (setq signers (epa-select-keys context "Select keys for signing.
+       (signers
+        (or (message-options-get 'mml2015-epg-signers)
+            (message-options-set
+             'mml2015-epg-signers
+             (if mml2015-verbose
+                 (epa-select-keys context "\
+Select keys for signing.
 If no one is selected, default secret key is used.  "
-                                      mml2015-signers t))
-      (if mml2015-signers
-         (setq signers (mapcar (lambda (name)
-                                 (car (epg-list-keys context name t)))
-                               mml2015-signers))))
+                                  mml2015-signers t)
+               (if mml2015-signers
+                   (mapcar (lambda (name)
+                             (car (epg-list-keys context name t)))
+                           mml2015-signers))))))
+       signature micalg)
     (epg-context-set-armor context t)
     (epg-context-set-textmode context t)
     (epg-context-set-signers context signers)
@@ -1152,7 +1163,7 @@ If no one is selected, default secret key is used.  "
     (insert (format "Content-Type: multipart/signed; boundary=\"%s\";\n"
                    boundary))
     (if micalg
-       (insert (format "\tmicalg=%s; "
+       (insert (format "\tmicalg=pgp-%s; "
                        (downcase
                         (cdr (assq micalg
                                    epg-digest-algorithm-alist))))))
@@ -1169,51 +1180,55 @@ If no one is selected, default secret key is used.  "
 (defun mml2015-epg-encrypt (cont &optional sign)
   (let ((inhibit-redisplay t)
        (context (epg-make-context))
-       (recipients
-        (if (message-options-get 'message-recipients)
-            (split-string
-             (message-options-get 'message-recipients)
-             "[ \f\t\n\r\v,]+")))
-       cipher signers config
+       (config (epg-configuration))
+       (recipients (message-options-get 'mml2015-epg-recipients))
+       cipher signers
        (boundary (mml-compute-boundary cont)))
-    ;; We should remove this check if epg-0.0.6 is released.
-    (if (and (condition-case nil
-                (require 'epg-config)
-              (error))
-            (functionp #'epg-expand-group))
-       (setq config (epg-configuration)
-             recipients
-             (apply #'nconc
-                    (mapcar (lambda (recipient)
-                              (or (epg-expand-group config recipient)
-                                  (list recipient)))
-                            recipients))))
-    (if mml2015-verbose
-       (setq recipients
-             (epa-select-keys context "Select recipients for encryption.
-If no one is selected, symmetric encryption will be performed.  "
-                              recipients))
+    (unless recipients
       (setq recipients
-           (delq nil (mapcar (lambda (name)
-                               (car (epg-list-keys context name)))
-                             recipients))))
-    (if mml2015-encrypt-to-self
-       (if mml2015-signers
-           (setq recipients
-                 (nconc recipients
-                        (mapcar (lambda (name)
-                                  (car (epg-list-keys context name)))
-                                mml2015-signers)))
-         (error "mml2015-signers not set")))
-    (when sign
+           (apply #'nconc
+                  (mapcar
+                   (lambda (recipient)
+                     (or (epg-expand-group config recipient)
+                         (list recipient)))
+                   (split-string
+                    (or (message-options-get 'message-recipients)
+                        (message-options-set 'message-recipients
+                                             (read-string "Recipients: ")))
+                    "[ \f\t\n\r\v,]+"))))
       (if mml2015-verbose
-         (setq signers (epa-select-keys context "Select keys for signing.
+         (setq recipients
+               (epa-select-keys context "\
+Select recipients for encryption.
+If no one is selected, symmetric encryption will be performed.  "
+                                recipients))
+       (setq recipients
+             (delq nil (mapcar (lambda (name)
+                                 (car (epg-list-keys context name)))
+                               recipients))))
+      (if mml2015-encrypt-to-self
+         (if mml2015-signers
+             (setq recipients
+                   (nconc recipients
+                          (mapcar (lambda (name)
+                                    (car (epg-list-keys context name)))
+                                  mml2015-signers)))
+           (error "mml2015-signers not set")))
+      (message-options-set 'mml2015-epg-recipients recipients))
+    (when sign
+      (setq signers
+           (or (message-options-get 'mml2015-epg-signers)
+               (message-options-set
+                'mml2015-epg-signers
+                (if mml2015-verbose
+                    (epa-select-keys context "\
+Select keys for signing.
 If no one is selected, default secret key is used.  "
-                                        mml2015-signers t))
-       (if mml2015-signers
-           (setq signers (mapcar (lambda (name)
-                                   (car (epg-list-keys context name t)))
-                                 mml2015-signers))))
+                                     mml2015-signers t)
+                  (if mml2015-signers
+                      (mapcar (lambda (name)
+                                (car (epg-list-keys context name t)))
+                              mml2015-signers))))))
       (epg-context-set-signers context signers))
     (epg-context-set-armor context t)
     (epg-context-set-textmode context t)
@@ -1223,7 +1238,8 @@ If no one is selected, default secret key is used.  "
         #'mml2015-epg-passphrase-callback))
     (condition-case error
        (setq cipher
-             (epg-encrypt-string context (buffer-string) recipients sign)
+             (epg-encrypt-string context (buffer-string) recipients sign
+                                 mml2015-always-trust)
              mml2015-epg-secret-key-id-list nil)
       (error
        (while mml2015-epg-secret-key-id-list