* pgg-def.el (pgg-cache-passphrase): New user option.
[elisp/semi.git] / pgg-gpg.el
index c98504e..d6bda0d 100644 (file)
     (with-current-buffer (get-buffer-create output-buffer)
       (buffer-disable-undo)
       (erase-buffer))
-    (setq process
-         (apply #'start-process-shell-command "*GnuPG*" output-buffer
-                program args))
+    (as-binary-process
+     (setq process
+          (apply #'start-process-shell-command "*GnuPG*" output-buffer
+                 program args)))
     (set-process-sentinel process 'ignore)
     (when passphrase
       (process-send-string process (concat passphrase "\n")))
          exit-status (process-exit-status process))
     (delete-process process)
     (with-current-buffer output-buffer
-      (goto-char (point-min))
-      (while (search-forward "\r$" nil t)
-       (replace-match ""))
+      (pgg-convert-lbt-region (point-min)(point-max) 'LF)
+
       (if (memq status '(stop signal))
          (error "%s exited abnormally: '%s'" program exit-status))
       (if (= 127 exit-status)
 (luna-define-method encrypt-region ((scheme pgg-scheme-gpg) 
                                    start end recipients)
   (let* ((pgg-gpg-user-id pgg-default-user-id)
-        (passphrase
-         (pgg-read-passphrase 
-          (format "GnuPG passphrase for %s: " pgg-gpg-user-id)
-          (luna-send scheme 'lookup-key-string
-                     scheme pgg-gpg-user-id 'encrypt)))
         (args 
          `("--batch" "--armor" "--always-trust" "--encrypt"
            ,@(if recipients
                         (mapcar (lambda (rcpt) 
                                   (list "--remote-user" 
                                         (concat "\"" rcpt "\""))) 
-                                recipients)))))
-        (inhibit-read-only t)
-        buffer-read-only)
-    (goto-char start)
-    (setq end (set-marker (make-marker) (point-max)))
-    (while (progn (end-of-line) (> (marker-position end) (point)))
-      (insert "\r")
-      (forward-line 1))
-    (pgg-gpg-process-region start end passphrase pgg-gpg-program args)
-    (goto-char start)
-    (while (re-search-forward "\r$" end t)
-      (replace-match ""))
+                                (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-process-when-success
-      (goto-char (point-min))
-      (while (re-search-forward "\r$" nil t)
-       (replace-match ""))
-      (let ((packet 
-            (cdr (assq 1 (pgg-parse-armor-region 
-                          (point-min)(point-max))))))
-       (pgg-add-passphrase-cache 
-        (cdr (assq 'key-identifier packet))
-        passphrase)))
+      (pgg-convert-lbt-region (point-min)(point-max) 'LF))
     ))
 
 (luna-define-method decrypt-region ((scheme pgg-scheme-gpg) 
                "--local-user" pgg-gpg-user-id))
         (inhibit-read-only t)
         buffer-read-only)
-    (goto-char start)
-    (setq end (set-marker (make-marker) (point-max)))
-    (while (progn (end-of-line) (> (marker-position end) (point)))
-      (insert "\r")
-      (forward-line 1))
-    (pgg-gpg-process-region start end passphrase pgg-gpg-program args)
-    (goto-char start)
-    (while (re-search-forward "\r$" end t)
-      (replace-match ""))
+    (pgg-as-lbt start end 'CRLF
+      (pgg-gpg-process-region start end passphrase pgg-gpg-program args)
+      )
     (pgg-process-when-success
-      (goto-char (point-min))
-      (while (re-search-forward "\r$" nil t)
-       (replace-match ""))
+      (pgg-convert-lbt-region (point-min)(point-max) 'LF)
       (when (re-search-forward "^-+BEGIN PGP SIGNATURE" nil t);XXX
        (let ((packet 
               (cdr (assq 2 (pgg-parse-armor-region 
                             (progn (beginning-of-line 2)
                                    (point))
                             (point-max))))))
-         (pgg-add-passphrase-cache 
-          (cdr (assq 'key-identifier packet))
-          passphrase))))
+         (if pgg-cache-passphrase
+             (pgg-add-passphrase-cache 
+              (cdr (assq 'key-identifier packet))
+              passphrase)))))
     ))
 
 (luna-define-method verify-region ((scheme pgg-scheme-gpg) 
 (provide 'pgg-gpg)
 
 ;;; pgg-gpg.el ends here
-