OSDN Git Service

(epa-file-write-region): Respect epa-armor and
[epg/epg.git] / pgg-epg.el
index 055157e..16fe555 100644 (file)
 
 ;;; Code:
 
-(require 'epg)
+(require 'epa)
 (eval-when-compile (require 'pgg))
 
 (defvar pgg-epg-secret-key-id-list nil)
 
 (defun pgg-epg-passphrase-callback (context key-id ignore)
   (if (eq key-id 'SYM)
-      (epg-passphrase-callback-function context key-id nil)
+      (epa-passphrase-callback-function context key-id nil)
     (let* ((entry (assoc key-id epg-user-id-alist))
           (passphrase
            (pgg-read-passphrase
@@ -65,7 +65,7 @@ If optional PASSPHRASE is not specified, it will be obtained from the
 passphrase cache or user."
   (let ((context (epg-make-context))
        (inhibit-redisplay t)           ;Gnus users don't like flickering
-       cipher)
+       cipher recipient-keys)
     (epg-context-set-armor context t)
     (epg-context-set-textmode context pgg-text-mode)
     (epg-context-set-passphrase-callback context #'pgg-epg-passphrase-callback)
@@ -76,15 +76,24 @@ passphrase cache or user."
       (erase-buffer))
     (condition-case error
        (setq cipher
-             (epg-encrypt-string context
-                                 (buffer-substring start end)
-                                 (mapcar
-                                  (lambda (recipient)
-                                    (car (epg-list-keys context recipient)))
-                                  (if pgg-encrypt-for-me
-                                      (cons pgg-default-user-id recipients)
-                                    recipients))
-                                 sign t)
+             (epg-encrypt-string
+              context
+              (buffer-substring start end)
+              (apply #'nconc
+                     (mapcar
+                      (lambda (recipient)
+                        (setq recipient-keys
+                              (epg-list-keys context recipient))
+                        (unless (or recipient-keys
+                                    (y-or-n-p
+                                     (format "No public key for %s; skip it? "
+                                             recipient)))
+                          (error "No public key for %s" recipient))
+                        recipient-keys)
+                      (if pgg-encrypt-for-me
+                          (cons pgg-default-user-id recipients)
+                        recipients)))
+              sign t)
              pgg-epg-secret-key-id-list nil)
       (error
        (while pgg-epg-secret-key-id-list
@@ -132,7 +141,8 @@ passphrase cache or user."
         (pgg-remove-passphrase-from-cache (car pgg-epg-secret-key-id-list))
         (setq pgg-epg-secret-key-id-list (cdr pgg-epg-secret-key-id-list)))
        (signal (car error) (cdr error))))
-    (if pgg-text-mode
+    (if (and pgg-text-mode
+            (fboundp 'decode-coding-string))
        (setq plain (decode-coding-string plain 'raw-text)))
     (save-excursion
       (set-buffer (get-buffer-create pgg-output-buffer))
@@ -252,7 +262,7 @@ Add all public keys in region between START and END to the keyring."
             (fprint (epg-signature-fingerprint (car pgg-epg-signatures)))
             (trust-good-enough-p
              (memq (epg-signature-validity (car pgg-epg-signatures))
-                   '(marginal fully ultimate))))
+                   '(marginal full ultimate))))
        (cond ((and signer fprint)
               (concat (cdr signer)
                       (unless trust-good-enough-p
@@ -265,6 +275,12 @@ Add all public keys in region between START and END to the keyring."
               "From unknown user")))
     "From unknown user"))
 
+(defun pgg-epg-lookup-key (string &optional type)
+  "Search keys associated with STRING."
+  (mapcar (lambda (key)
+           (epg-sub-key-id (car (epg-key-sub-key-list key))))
+         (epg-list-keys (epg-make-context) string (not (null type)))))
+
 (provide 'pgg-epg)
 
 ;;; pgg-epg.el ends here