annotate lisp/pgg-gpg.el @ 110810:07053df95af6

Merge changes made in Gnus trunk. shr.el (shr-render-td): Use a cache for the table rendering function to avoid getting an exponential rendering behaviour in nested tables. shr.el (shr-insert): Rework the line-breaking algorithm. shr.el (shr-insert): Don't leave trailing spaces. shr.el (shr-insert-table): Also insert empty TDs. shr.el (shr-tag-blockquote): Ensure paragraphs after </ul>. gnus-start.el (gnus-get-unread-articles): Require gnus-agent before bidning gnus-agent variables. mm-decode.el (mm-save-part): If given a non-directory result, expand the file name before using to avoid setting mm-default-directory to nil. gnus.el (gnus-carpal): The carpal mode has been removed, but define the variable for backwards compatability. nnimap.el (nnimap-update-info): Remove double setting of high. nnimap.el (nnimap-update-info): Don't ignore groups that have no UIDNEXT. shr.el (require): Require cl when compiling. shr.el (shr-tag-hr): New function.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Thu, 07 Oct 2010 22:26:11 +0000
parents 8d09094063d0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1 ;;; pgg-gpg.el --- GnuPG support for PGG.
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 103476
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
5
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
6 ;; Author: Daiki Ueno <ueno@unixuser.org>
110015
280c8ae2476d Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
7 ;; Symmetric encryption and gpg-agent support added by:
69848
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
8 ;; Sascha Wilde <wilde@sha-bang.de>
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9 ;; Created: 1999/10/28
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
10 ;; Keywords: PGP, OpenPGP, GnuPG
110015
280c8ae2476d Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
11 ;; Package: pgg
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
12
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
13 ;; This file is part of GNU Emacs.
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
14
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; GNU Emacs is free software: you can redistribute it and/or modify
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
16 ;; it under the terms of the GNU General Public License as published by
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
17 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
18 ;; (at your option) any later version.
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
19
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
20 ;; GNU Emacs is distributed in the hope that it will be useful,
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23 ;; GNU General Public License for more details.
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
24
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
25 ;; You should have received a copy of the GNU General Public License
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
26 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
27
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
28 ;;; Code:
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
29
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
30 (eval-when-compile
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
31 (require 'cl) ; for gpg macros
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
32 (require 'pgg))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
33
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
34 (defgroup pgg-gpg ()
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
35 "GnuPG interface."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
36 :group 'pgg)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
37
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
38 (defcustom pgg-gpg-program "gpg"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
39 "The GnuPG executable."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
40 :group 'pgg-gpg
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
41 :type 'string)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
42
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
43 (defcustom pgg-gpg-extra-args nil
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
44 "Extra arguments for every GnuPG invocation."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
45 :group 'pgg-gpg
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
46 :type '(repeat (string :tag "Argument")))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
47
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
48 (defcustom pgg-gpg-recipient-argument "--recipient"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
49 "GnuPG option to specify recipient."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
50 :group 'pgg-gpg
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
51 :type '(choice (const :tag "New `--recipient' option" "--recipient")
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
52 (const :tag "Old `--remote-user' option" "--remote-user")))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
53
74714
8efc97426784 (pgg-gpg-use-agent): Default to t.
Chong Yidong <cyd@stupidchicken.com>
parents: 72686
diff changeset
54 (defcustom pgg-gpg-use-agent t
69848
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
55 "Whether to use gnupg agent for key caching."
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
56 :group 'pgg-gpg
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
57 :type 'boolean)
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
58
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
59 (defvar pgg-gpg-user-id nil
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
60 "GnuPG ID of your default identity.")
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
61
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
62 (defun pgg-gpg-process-region (start end passphrase program args)
75985
49a4f4e58561 (pgg-gpg-process-region): Make USE-AGENT nil if PASSPHRASE is given.
Richard M. Stallman <rms@gnu.org>
parents: 75347
diff changeset
63 (let* ((use-agent (and (null passphrase) (pgg-gpg-use-agent-p)))
69848
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
64 (output-file-name (pgg-make-temp-file "pgg-output"))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
65 (args
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
66 `("--status-fd" "2"
69848
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
67 ,@(if use-agent '("--use-agent")
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
68 (if passphrase '("--passphrase-fd" "0")))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
69 "--yes" ; overwrite
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
70 "--output" ,output-file-name
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
71 ,@pgg-gpg-extra-args ,@args))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
72 (output-buffer pgg-output-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
73 (errors-buffer pgg-errors-buffer)
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
74 (orig-mode (default-file-modes))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
75 (process-connection-type nil)
72653
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
76 (inhibit-redisplay t)
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
77 process status exit-status
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
78 passphrase-with-newline
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
79 encoded-passphrase-with-new-line)
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
80 (with-current-buffer (get-buffer-create errors-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
81 (buffer-disable-undo)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
82 (erase-buffer))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
83 (unwind-protect
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
84 (progn
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
85 (set-default-file-modes 448)
72632
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
86 (let ((coding-system-for-write 'binary))
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
87 (setq process
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
88 (apply #'start-process "*GnuPG*" errors-buffer
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
89 program args)))
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
90 (set-process-sentinel process #'ignore)
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
91 (when passphrase
72653
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
92 (setq passphrase-with-newline (concat passphrase "\n"))
72686
2f8ec29373d1 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72653
diff changeset
93 (if pgg-passphrase-coding-system
72653
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
94 (progn
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
95 (setq encoded-passphrase-with-new-line
74984
21f28d10d73a Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 74714
diff changeset
96 (encode-coding-string
21f28d10d73a Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 74714
diff changeset
97 passphrase-with-newline
21f28d10d73a Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 74714
diff changeset
98 (coding-system-change-eol-conversion
21f28d10d73a Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 74714
diff changeset
99 pgg-passphrase-coding-system 'unix)))
72653
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
100 (pgg-clear-string passphrase-with-newline))
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
101 (setq encoded-passphrase-with-new-line passphrase-with-newline
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
102 passphrase-with-newline nil))
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
103 (process-send-string process encoded-passphrase-with-new-line))
72632
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
104 (process-send-region process start end)
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
105 (process-send-eof process)
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
106 (while (eq 'run (process-status process))
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
107 (accept-process-output process 5))
97237
38f9573be097 (pgg-gpg-process-region): Accept any remaining pending output coming
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
108 ;; Accept any remaining pending output coming after the
38f9573be097 (pgg-gpg-process-region): Accept any remaining pending output coming
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
109 ;; status change.
38f9573be097 (pgg-gpg-process-region): Accept any remaining pending output coming
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
110 (accept-process-output process 5)
72632
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
111 (setq status (process-status process)
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
112 exit-status (process-exit-status process))
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
113 (delete-process process)
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
114 (with-current-buffer (get-buffer-create output-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
115 (buffer-disable-undo)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
116 (erase-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
117 (if (file-exists-p output-file-name)
69791
4192bb0fddd0 2006-04-04 Daiki Ueno <ueno@unixuser.org>
Simon Josefsson <jas@extundo.com>
parents: 69775
diff changeset
118 (let ((coding-system-for-read (if pgg-text-mode
4192bb0fddd0 2006-04-04 Daiki Ueno <ueno@unixuser.org>
Simon Josefsson <jas@extundo.com>
parents: 69775
diff changeset
119 'raw-text
4192bb0fddd0 2006-04-04 Daiki Ueno <ueno@unixuser.org>
Simon Josefsson <jas@extundo.com>
parents: 69775
diff changeset
120 'binary)))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
121 (insert-file-contents output-file-name)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
122 (set-buffer errors-buffer)
72632
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
123 (if (memq status '(stop signal))
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
124 (error "%s exited abnormally: '%s'" program exit-status))
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
125 (if (= 127 exit-status)
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
126 (error "%s could not be found" program))))
72653
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
127 (if passphrase-with-newline
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
128 (pgg-clear-string passphrase-with-newline))
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
129 (if encoded-passphrase-with-new-line
87c011891481 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 72632
diff changeset
130 (pgg-clear-string encoded-passphrase-with-new-line))
72632
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
131 (if (and process (eq 'run (process-status process)))
d69718b12697 Merge from gnus--rel--5.10
Miles Bader <miles@gnu.org>
parents: 69848
diff changeset
132 (interrupt-process process))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
133 (if (file-exists-p output-file-name)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
134 (delete-file output-file-name))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
135 (set-default-file-modes orig-mode))))
69689
d9ccf8ac6466 2006-03-27 Daiki Ueno <ueno@unixuser.org>
Simon Josefsson <jas@extundo.com>
parents: 69646
diff changeset
136
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
137 (defun pgg-gpg-possibly-cache-passphrase (passphrase &optional key notruncate)
69848
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
138 (if (and passphrase
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
139 pgg-cache-passphrase
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
140 (progn
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
141 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
142 (re-search-forward "^\\[GNUPG:] \\(GOOD_PASSPHRASE\\>\\)\\|\\(SIG_CREATED\\)" nil t)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
143 (pgg-add-passphrase-to-cache
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
144 (or key
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
145 (progn
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
146 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
147 (if (re-search-forward
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
148 "^\\[GNUPG:] NEED_PASSPHRASE\\(_PIN\\)? \\w+ ?\\w*" nil t)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
149 (substring (match-string 0) -8))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
150 passphrase
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
151 notruncate)))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
152
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
153 (defvar pgg-gpg-all-secret-keys 'unknown)
69689
d9ccf8ac6466 2006-03-27 Daiki Ueno <ueno@unixuser.org>
Simon Josefsson <jas@extundo.com>
parents: 69646
diff changeset
154
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
155 (defun pgg-gpg-lookup-all-secret-keys ()
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
156 "Return all secret keys present in secret key ring."
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
157 (when (eq pgg-gpg-all-secret-keys 'unknown)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
158 (setq pgg-gpg-all-secret-keys '())
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
159 (let ((args (list "--with-colons" "--no-greeting" "--batch"
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
160 "--list-secret-keys")))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
161 (with-temp-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
162 (apply #'call-process pgg-gpg-program nil t nil args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
163 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
164 (while (re-search-forward
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
165 "^\\(sec\\|pub\\):[^:]*:[^:]*:[^:]*:\\([^:]*\\)" nil t)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
166 (push (substring (match-string 2) 8)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
167 pgg-gpg-all-secret-keys)))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
168 pgg-gpg-all-secret-keys)
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
169
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
170 (defun pgg-gpg-lookup-key (string &optional type)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
171 "Search keys associated with STRING."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
172 (let ((args (list "--with-colons" "--no-greeting" "--batch"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
173 (if type "--list-secret-keys" "--list-keys")
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
174 string)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
175 (with-temp-buffer
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
176 (apply #'call-process pgg-gpg-program nil t nil args)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
177 (goto-char (point-min))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
178 (if (re-search-forward "^\\(sec\\|pub\\):[^:]*:[^:]*:[^:]*:\\([^:]*\\)"
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
179 nil t)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
180 (substring (match-string 2) 8)))))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
181
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
182 (defun pgg-gpg-lookup-key-owner (string &optional all)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
183 "Search keys associated with STRING and return owner of identified key.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
184
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
185 The value may be just the bare key id, or it may be a combination of the
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
186 user name associated with the key and the key id, with the key id enclosed
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
187 in \"<...>\" angle brackets.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
188
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
189 Optional ALL non-nil means search all keys, including secret keys."
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
190 (let ((args (list "--with-colons" "--no-greeting" "--batch"
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
191 (if all "--list-secret-keys" "--list-keys")
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
192 string))
103476
25b1ef6821e2 * pgg-gpg.el (pgg-gpg-lookup-key-owner): Handle colon listings format
Chong Yidong <cyd@stupidchicken.com>
parents: 100908
diff changeset
193 (key-regexp (concat "^\\(sec\\|pub\\|uid\\)"
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
194 ":[^:]*:[^:]*:[^:]*:\\([^:]*\\):[^:]*"
103476
25b1ef6821e2 * pgg-gpg.el (pgg-gpg-lookup-key-owner): Handle colon listings format
Chong Yidong <cyd@stupidchicken.com>
parents: 100908
diff changeset
195 ":[^:]*:[^:]*:[^:]*:\\([^:]+\\):")))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
196 (with-temp-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
197 (apply #'call-process pgg-gpg-program nil t nil args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
198 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
199 (if (re-search-forward key-regexp
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
200 nil t)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
201 (match-string 3)))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
202
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
203 (defun pgg-gpg-key-id-from-key-owner (key-owner)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
204 (cond ((not key-owner) nil)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
205 ;; Extract bare key id from outermost paired angle brackets, if any:
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
206 ((string-match "[^<]*<\\(.+\\)>[^>]*" key-owner)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
207 (substring key-owner (match-beginning 1)(match-end 1)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
208 (key-owner)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
209
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
210 (defun pgg-gpg-encrypt-region (start end recipients &optional sign passphrase)
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
211 "Encrypt the current region between START and END.
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
212
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
213 If optional argument SIGN is non-nil, do a combined sign and encrypt.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
214
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
215 If optional PASSPHRASE is not specified, it will be obtained from the
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
216 passphrase cache or user."
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
217 (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
218 (passphrase (or passphrase
69848
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
219 (when (and sign (not (pgg-gpg-use-agent-p)))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
220 (pgg-read-passphrase
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
221 (format "GnuPG passphrase for %s: "
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
222 pgg-gpg-user-id)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
223 pgg-gpg-user-id))))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
224 (args
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
225 (append
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
226 (list "--batch" "--armor" "--always-trust" "--encrypt")
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
227 (if pgg-text-mode (list "--textmode"))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
228 (if sign (list "--sign" "--local-user" pgg-gpg-user-id))
76110
d6f2673064e7 2007-02-24 Chris Moore <dooglus@gmail.com>
Kim F. Storm <storm@cua.dk>
parents: 75985
diff changeset
229 (if (or recipients pgg-encrypt-for-me)
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
230 (apply #'nconc
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
231 (mapcar (lambda (rcpt)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
232 (list pgg-gpg-recipient-argument rcpt))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
233 (append recipients
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
234 (if pgg-encrypt-for-me
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
235 (list pgg-gpg-user-id)))))))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
236 (pgg-gpg-process-region start end passphrase pgg-gpg-program args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
237 (when sign
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
238 (with-current-buffer pgg-errors-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
239 ;; Possibly cache passphrase under, e.g. "jas", for future sign.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
240 (pgg-gpg-possibly-cache-passphrase passphrase pgg-gpg-user-id)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
241 ;; Possibly cache passphrase under, e.g. B565716F, for future decrypt.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
242 (pgg-gpg-possibly-cache-passphrase passphrase)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
243 (pgg-process-when-success)))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
244
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
245 (defun pgg-gpg-encrypt-symmetric-region (start end &optional passphrase)
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
246 "Encrypt the current region between START and END with symmetric cipher.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
247
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
248 If optional PASSPHRASE is not specified, it will be obtained from the
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
249 passphrase cache or user."
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
250 (let* ((passphrase (or passphrase
69848
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
251 (when (not (pgg-gpg-use-agent-p))
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
252 (pgg-read-passphrase
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
253 "GnuPG passphrase for symmetric encryption: "))))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
254 (args
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
255 (append (list "--batch" "--armor" "--symmetric" )
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
256 (if pgg-text-mode (list "--textmode")))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
257 (pgg-gpg-process-region start end passphrase pgg-gpg-program args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
258 (pgg-process-when-success)))
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
259
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
260 (defun pgg-gpg-decrypt-region (start end &optional passphrase)
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
261 "Decrypt the current region between START and END.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
262
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
263 If optional PASSPHRASE is not specified, it will be obtained from the
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
264 passphrase cache or user."
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
265 (let* ((current-buffer (current-buffer))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
266 (message-keys (with-temp-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
267 (insert-buffer-substring current-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
268 (pgg-decode-armor-region (point-min) (point-max))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
269 (secret-keys (pgg-gpg-lookup-all-secret-keys))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
270 ;; XXX the user is stuck if they need to use the passphrase for
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
271 ;; any but the first secret key for which the message is
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
272 ;; encrypted. ideally, we would incrementally give them a
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
273 ;; chance with subsequent keys each time they fail with one.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
274 (key (pgg-gpg-select-matching-key message-keys secret-keys))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
275 (key-owner (and key (pgg-gpg-lookup-key-owner key t)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
276 (key-id (pgg-gpg-key-id-from-key-owner key-owner))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
277 (pgg-gpg-user-id (or key-id key
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
278 pgg-gpg-user-id pgg-default-user-id))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
279 (passphrase (or passphrase
69848
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
280 (when (not (pgg-gpg-use-agent-p))
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
281 (pgg-read-passphrase
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
282 (format (if (pgg-gpg-symmetric-key-p message-keys)
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
283 "Passphrase for symmetric decryption: "
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
284 "GnuPG passphrase for %s: ")
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
285 (or key-owner "??"))
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
286 pgg-gpg-user-id))))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
287 (args '("--batch" "--decrypt")))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
288 (pgg-gpg-process-region start end passphrase pgg-gpg-program args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
289 (with-current-buffer pgg-errors-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
290 (pgg-gpg-possibly-cache-passphrase passphrase pgg-gpg-user-id)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
291 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
292 (re-search-forward "^\\[GNUPG:] DECRYPTION_OKAY\\>" nil t))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
293
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
294 ;;;###autoload
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
295 (defun pgg-gpg-symmetric-key-p (message-keys)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
296 "True if decoded armor MESSAGE-KEYS has symmetric encryption indicator."
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
297 (let (result)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
298 (dolist (key message-keys result)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
299 (when (and (eq (car key) 3)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
300 (member '(symmetric-key-algorithm) key))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
301 (setq result key)))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
302
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
303 (defun pgg-gpg-select-matching-key (message-keys secret-keys)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
304 "Choose a key from MESSAGE-KEYS that matches one of the keys in SECRET-KEYS."
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
305 (loop for message-key in message-keys
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
306 for message-key-id = (and (equal (car message-key) 1)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
307 (cdr (assq 'key-identifier
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
308 (cdr message-key))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
309 for key = (and message-key-id (pgg-lookup-key message-key-id 'encrypt))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
310 when (and key (member key secret-keys)) return key))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
311
66520
67afcf271a8f (pgg-gpg-select-matching-key): Fixed: look at the right part of the
Eli Zaretskii <eliz@gnu.org>
parents: 66383
diff changeset
312 (defun pgg-gpg-sign-region (start end &optional cleartext passphrase)
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
313 "Make detached signature from text between START and END."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
314 (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
315 (passphrase (or passphrase
69848
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
316 (when (not (pgg-gpg-use-agent-p))
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
317 (pgg-read-passphrase
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
318 (format "GnuPG passphrase for %s: "
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
319 pgg-gpg-user-id)
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
320 pgg-gpg-user-id))))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
321 (args
68762
970bf6e6463b Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents: 68651
diff changeset
322 (append (list (if cleartext "--clearsign" "--detach-sign")
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
323 "--armor" "--batch" "--verbose"
68762
970bf6e6463b Revision: emacs@sv.gnu.org/emacs--devo--0--patch-62
Miles Bader <miles@gnu.org>
parents: 68651
diff changeset
324 "--local-user" pgg-gpg-user-id)
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
325 (if pgg-text-mode (list "--textmode"))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
326 (inhibit-read-only t)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
327 buffer-read-only)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
328 (pgg-gpg-process-region start end passphrase pgg-gpg-program args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
329 (with-current-buffer pgg-errors-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
330 ;; Possibly cache passphrase under, e.g. "jas", for future sign.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
331 (pgg-gpg-possibly-cache-passphrase passphrase pgg-gpg-user-id)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
332 ;; Possibly cache passphrase under, e.g. B565716F, for future decrypt.
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
333 (pgg-gpg-possibly-cache-passphrase passphrase))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
334 (pgg-process-when-success)))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
335
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
336 (defun pgg-gpg-verify-region (start end &optional signature)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
337 "Verify region between START and END as the detached signature SIGNATURE."
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
338 (let ((args '("--batch" "--verify")))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
339 (when (stringp signature)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
340 (setq args (append args (list signature))))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
341 (setq args (append args '("-")))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
342 (pgg-gpg-process-region start end nil pgg-gpg-program args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
343 (with-current-buffer pgg-errors-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
344 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
345 (while (re-search-forward "^gpg: \\(.*\\)\n" nil t)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
346 (with-current-buffer pgg-output-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
347 (insert-buffer-substring pgg-errors-buffer
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
348 (match-beginning 1) (match-end 0)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
349 (delete-region (match-beginning 0) (match-end 0)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
350 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
351 (re-search-forward "^\\[GNUPG:] GOODSIG\\>" nil t))))
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
352
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
353 (defun pgg-gpg-insert-key ()
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
354 "Insert public key at point."
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
355 (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
356 (args (list "--batch" "--export" "--armor"
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
357 pgg-gpg-user-id)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
358 (pgg-gpg-process-region (point)(point) nil pgg-gpg-program args)
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
359 (insert-buffer-substring pgg-output-buffer)))
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
360
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
361 (defun pgg-gpg-snarf-keys-region (start end)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
362 "Add all public keys in region between START and END to the keyring."
69819
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
363 (let ((args '("--import" "--batch" "-")) status)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
364 (pgg-gpg-process-region start end nil pgg-gpg-program args)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
365 (set-buffer pgg-errors-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
366 (goto-char (point-min))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
367 (when (re-search-forward "^\\[GNUPG:] IMPORT_RES\\>" nil t)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
368 (setq status (buffer-substring (match-end 0)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
369 (progn (end-of-line)(point)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
370 status (vconcat (mapcar #'string-to-number (split-string status))))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
371 (erase-buffer)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
372 (insert (format "Imported %d key(s).
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
373 \tArmor contains %d key(s) [%d bad, %d old].\n"
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
374 (+ (aref status 2)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
375 (aref status 10))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
376 (aref status 0)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
377 (aref status 1)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
378 (+ (aref status 4)
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
379 (aref status 11)))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
380 (if (zerop (aref status 9))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
381 ""
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
382 "\tSecret keys are imported.\n")))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
383 (append-to-buffer pgg-output-buffer (point-min)(point-max))
f5b96aac4371 2006-04-06 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 69805
diff changeset
384 (pgg-process-when-success)))
69631
77a585c555e6 2006-03-22 Simon Josefsson <jas@extundo.com>
Simon Josefsson <jas@extundo.com>
parents: 69627
diff changeset
385
69848
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
386 (defun pgg-gpg-update-agent ()
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
387 "Try to connet to gpg-agent and send UPDATESTARTUPTTY."
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
388 (if (fboundp 'make-network-process)
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
389 (let* ((agent-info (getenv "GPG_AGENT_INFO"))
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
390 (socket (and agent-info
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
391 (string-match "^\\([^:]*\\)" agent-info)
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
392 (match-string 1 agent-info)))
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
393 (conn (and socket
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
394 (make-network-process :name "gpg-agent-process"
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
395 :host 'local :family 'local
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
396 :service socket))))
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
397 (when (and conn (eq (process-status conn) 'open))
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
398 (process-send-string conn "UPDATESTARTUPTTY\n")
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
399 (delete-process conn)
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
400 t))
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
401 ;; We can't check, so assume gpg-agent is up.
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
402 t))
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
403
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
404 (defun pgg-gpg-use-agent-p ()
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
405 "Return t if `pgg-gpg-use-agent' is t and gpg-agent is available."
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
406 (and pgg-gpg-use-agent (pgg-gpg-update-agent)))
a80d40a59be6 Revert to revision 1.8 to allow the use of gpg-agent.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 69819
diff changeset
407
66383
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
408 (provide 'pgg-gpg)
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
409
c82982d6cbc4 Moved pgg*.el files from lisp/gnus to lisp.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
410 ;;; pgg-gpg.el ends here