Indent.
[gnus] / lisp / pgg-gpg.el
index beea098..a9f6494 100644 (file)
@@ -39,7 +39,9 @@
 (defcustom pgg-gpg-extra-args nil
   "Extra arguments for every GnuPG invocation."
   :group 'pgg-gpg
-  :type 'string)
+  :type '(choice
+         (const :tag "None" nil)
+         (string :tag "Arguments")))
 
 (defvar pgg-gpg-user-id nil
   "GnuPG ID of your default identity.")
   "Encrypt the current region between START and END.
 If optional argument SIGN is non-nil, do a combined sign and encrypt."
   (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
+        (passphrase
+         (when sign
+           (pgg-read-passphrase
+            (format "GnuPG passphrase for %s: " pgg-gpg-user-id)
+            (pgg-gpg-lookup-key pgg-gpg-user-id 'encrypt))))
         (args
-         `("--batch" "--armor" "--always-trust"
-           ,(if sign "--sign --encrypt" "--encrypt")
-           ,@(if recipients
-                 (apply #'nconc
-                        (mapcar (lambda (rcpt)
-                                  (list "--remote-user" rcpt))
-                                (append recipients
-                                        (if pgg-encrypt-for-me
-                                            (list pgg-gpg-user-id)))))))))
+         (append
+          (list "--batch" "--armor" "--always-trust" "--encrypt")
+          (if sign (list "--sign" "--local-user" pgg-gpg-user-id))
+          (if recipients
+              (apply #'nconc
+                     (mapcar (lambda (rcpt)
+                               (list "--remote-user" rcpt))
+                             (append recipients
+                                     (if pgg-encrypt-for-me
+                                         (list pgg-gpg-user-id)))))))))
     (pgg-as-lbt start end 'CRLF
-      (pgg-gpg-process-region start end nil pgg-gpg-program args))
+      (pgg-gpg-process-region start end passphrase pgg-gpg-program args))
+    (when sign
+      (with-current-buffer pgg-errors-buffer
+       (pgg-gpg-possibly-cache-passphrase passphrase)))
     (pgg-process-when-success)))
 
 (defun pgg-gpg-decrypt-region (start end)
@@ -183,14 +194,13 @@ If optional argument SIGN is non-nil, do a combined sign and encrypt."
     (pgg-gpg-process-region start end nil pgg-gpg-program args)
     (with-current-buffer pgg-errors-buffer
       (goto-char (point-min))
-      (while (re-search-forward "^gpg: " nil t)
-       (replace-match ""))
+      (while (re-search-forward "^gpg: \\(.*\\)\n" nil t)
+       (with-current-buffer pgg-output-buffer
+         (insert-buffer-substring pgg-errors-buffer
+                                  (match-beginning 1) (match-end 0)))
+       (delete-region (match-beginning 0) (match-end 0)))
       (goto-char (point-min))
-      (prog1 (re-search-forward "^\\[GNUPG:] GOODSIG\\>" nil t)
-       (goto-char (point-min))
-       (delete-matching-lines "^warning\\|\\[GNUPG:]")
-       (set-buffer pgg-output-buffer)
-       (insert-buffer-substring pgg-errors-buffer)))))
+      (re-search-forward "^\\[GNUPG:] GOODSIG\\>" nil t))))
 
 (defun pgg-gpg-insert-key ()
   "Insert public key at point."