;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Code:
+(require 'mel) ; binary-to-text-funcall
(eval-when-compile (require 'pgg))
(defgroup pgg-gpg ()
(defvar pgg-gpg-user-id nil
"GnuPG ID of your default identity.")
+(defvar pgg-gpg-messages-locale pgg-messages-locale
+ "Locale set before running a GnuPG external process.")
+
(defvar pgg-scheme-gpg-instance nil)
;;;###autoload
(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)
- (as-binary-output-file
- (setq process
- (apply #'start-process "*GnuPG*" errors-buffer program args)))
+ (let ((coding-system-for-write 'binary))
+ (setq process
+ (apply #'start-process "*GnuPG*" errors-buffer
+ program args)))
(set-process-sentinel process #'ignore)
(when passphrase
(process-send-string process (concat passphrase "\n")))
(buffer-disable-undo)
(erase-buffer)
(if (file-exists-p output-file-name)
- (insert-file-contents-as-raw-text-CRLF output-file-name))
+ (let ((coding-system-for-read 'raw-text-dos))
+ (insert-file-contents output-file-name)))
(set-buffer errors-buffer)
(if (memq status '(stop signal))
(error "%s exited abnormally: '%s'" program exit-status))
(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
(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)
- (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
+ (let* ((user-id (or pgg-overriding-user-id pgg-gpg-user-id
+ pgg-default-user-id))
(args
`("--batch" "--armor" "--always-trust" "--encrypt"
,@(if recipients
(list "--remote-user" rcpt))
(append recipients
(if pgg-encrypt-for-me
- (list pgg-gpg-user-id)))))))))
+ (list user-id)))))))))
(pgg-as-lbt start end 'CRLF
(pgg-gpg-process-region start end nil pgg-gpg-program args))
(pgg-process-when-success)))
(luna-define-method pgg-scheme-decrypt-region ((scheme pgg-scheme-gpg)
start end)
- (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
+ (let* ((user-id (or pgg-overriding-user-id pgg-gpg-user-id
+ pgg-default-user-id))
(passphrase
(pgg-read-passphrase
(format "GnuPG passphrase for %s: " pgg-gpg-user-id)
- (pgg-scheme-lookup-key scheme pgg-gpg-user-id 'encrypt)))
+ (pgg-scheme-lookup-key scheme user-id 'encrypt)))
(args '("--batch" "--decrypt")))
(pgg-gpg-process-region start end passphrase pgg-gpg-program args)
(with-current-buffer pgg-errors-buffer
(luna-define-method pgg-scheme-sign-region ((scheme pgg-scheme-gpg)
start end &optional cleartext)
- (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
+ (let* ((user-id (or pgg-overriding-user-id pgg-gpg-user-id
+ pgg-default-user-id))
(passphrase
(pgg-read-passphrase
- (format "GnuPG passphrase for %s: " pgg-gpg-user-id)
- (pgg-scheme-lookup-key scheme pgg-gpg-user-id 'sign)))
+ (format "GnuPG passphrase for %s: " user-id)
+ (pgg-scheme-lookup-key scheme user-id 'sign)))
(args
(list (if cleartext "--clearsign" "--detach-sign")
"--armor" "--batch" "--verbose"
- "--local-user" pgg-gpg-user-id))
+ "--local-user" user-id))
(inhibit-read-only t)
buffer-read-only)
(pgg-as-lbt start end 'CRLF
(let ((args '("--batch" "--verify")))
(when (stringp signature)
(setq args (append args (list signature))))
+ (setq args (append args '("-")))
(pgg-gpg-process-region start end nil pgg-gpg-program args)
(with-current-buffer pgg-errors-buffer
(goto-char (point-min))
(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))
- (args (list "--batch" "--export" "--armor"
- pgg-gpg-user-id)))
+ (let* ((user-id (or pgg-overriding-user-id pgg-gpg-user-id
+ pgg-default-user-id))
+ (args (list "--batch" "--export" "--armor" user-id)))
(pgg-gpg-process-region (point)(point) nil pgg-gpg-program args)
(insert-buffer-substring pgg-output-buffer)))
(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)