X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=pgg-gpg.el;h=43421e61b47e179649d233b9c03b538ce29bae27;hb=09b8b8a922e6f95b8fbaafc59abc1ad5dca51afc;hp=5b29a76f31d3e4de0992a4373cac0f36ab3611c2;hpb=3b32957b3c4affb5daa02e14b892630a1621916d;p=elisp%2Fsemi.git diff --git a/pgg-gpg.el b/pgg-gpg.el index 5b29a76..43421e6 100644 --- a/pgg-gpg.el +++ b/pgg-gpg.el @@ -25,6 +25,7 @@ ;;; Code: +(require 'mel) ; binary-to-text-funcall (eval-when-compile (require 'pgg)) (defgroup pgg-gpg () @@ -50,6 +51,9 @@ (defvar pgg-gpg-messages-coding-system pgg-messages-coding-system "Coding system used when reading from a GnuPG external process.") +(defvar pgg-gpg-messages-locale pgg-messages-locale + "Locale set before running a GnuPG external process.") + (defvar pgg-scheme-gpg-instance nil) ;;;###autoload @@ -59,30 +63,34 @@ (luna-make-entity 'pgg-scheme-gpg)))) (defun pgg-gpg-process-region (start end passphrase program args) - (let* ((output-file-name - (concat temporary-file-directory (make-temp-name "pgg-output"))) + (let* ((output-file-name (make-temp-file + (expand-file-name "pgg-output" + temporary-file-directory))) (args `("--status-fd" "2" ,@(if passphrase '("--passphrase-fd" "0")) + "--yes" ; overwrite "--output" ,output-file-name ,@pgg-gpg-extra-args ,@args)) (output-buffer pgg-output-buffer) (errors-buffer pgg-errors-buffer) - (orig-mode (default-file-modes)) (process-connection-type nil) + (process-environment process-environment) process status exit-status) + (when pgg-gpg-messages-locale + (setq process-environment (copy-sequence process-environment)) + (setenv "LC_ALL" pgg-gpg-messages-locale) + (setenv "LANGUAGE" pgg-gpg-messages-locale)) (with-current-buffer (get-buffer-create errors-buffer) (buffer-disable-undo) (erase-buffer)) (unwind-protect (progn - (set-default-file-modes 448) (setq process - (apply #'binary-start-process "*GnuPG*" errors-buffer + (apply #'binary-to-text-funcall + pgg-gpg-messages-coding-system + #'start-process "*GnuPG*" errors-buffer program args)) - (if (fboundp 'set-process-coding-system) - (set-process-coding-system process - pgg-gpg-messages-coding-system)) (set-process-sentinel process #'ignore) (when passphrase (process-send-string process (concat passphrase "\n"))) @@ -107,8 +115,7 @@ (if (and process (eq 'run (process-status process))) (interrupt-process process)) (if (file-exists-p output-file-name) - (delete-file output-file-name)) - (set-default-file-modes orig-mode)))) + (delete-file output-file-name))))) (defun pgg-gpg-possibly-cache-passphrase (passphrase) (if (and pgg-cache-passphrase @@ -131,12 +138,9 @@ (with-temp-buffer (apply #'call-process pgg-gpg-program nil t nil args) (goto-char (point-min)) - (if (re-search-forward "^\\(sec\\|pub\\):" nil t) - (substring - (nth 3 (split-string - (buffer-substring (match-end 0) - (progn (end-of-line)(point))) - ":")) 8))))) + (if (re-search-forward "^\\(sec\\|pub\\):[^:]*:[^:]*:[^:]*:\\([^:]*\\)" + nil t) + (substring (match-string 2) 8))))) (luna-define-method pgg-scheme-encrypt-region ((scheme pgg-scheme-gpg) start end recipients) @@ -201,9 +205,12 @@ (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))))) + (delete-matching-lines "^\\[GNUPG:] ") + ;; XXX: copy contents of pgg-errors-buffer into + ;; pgg-output-buffer for backward compatibility. + (with-current-buffer pgg-output-buffer + (set-buffer-multibyte t) + (insert-buffer-substring pgg-errors-buffer)))))) (luna-define-method pgg-scheme-insert-key ((scheme pgg-scheme-gpg)) (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id)) @@ -233,9 +240,13 @@ (aref status 11))) (if (zerop (aref status 9)) "" - "\tSecret keys are imported.\n"))) - (append-to-buffer pgg-output-buffer (point-min)(point-max)) - (pgg-process-when-success))) + "\tSecret keys are imported.\n")) + ;; XXX: copy contents of pgg-errors-buffer into + ;; pgg-output-buffer for backward compatibility. + (with-current-buffer pgg-output-buffer + (set-buffer-multibyte t) + (insert-buffer-substring pgg-errors-buffer)) + t))) (provide 'pgg-gpg)