annotate lisp/mailcrypt/mailcrypt.el @ 143:50e7fedfe353

Added tag r20-2b5 for changeset 1856695b1fa9
author cvs
date Mon, 13 Aug 2007 09:33:20 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; mailcrypt.el v3.4, mail encryption with PGP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1995 Jin Choi <jin@atype.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Patrick LoPresti <patl@lcs.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Any comments or suggestions welcome.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Inspired by pgp.el, by Gray Watson <gray@antaire.com>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;{{{ Licensing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is intended to be used with GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;}}}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;{{{ Load some required packages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (eval-when-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; Quiet warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (autoload 'start-itimer "itimer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (autoload 'cancel-itimer "itimer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (autoload 'delete-itimer "itimer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (require 'easymenu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (require 'comint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (eval-and-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (condition-case nil (require 'itimer) (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (if (not (featurep 'itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (condition-case nil (require 'timer) (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (if (not (fboundp 'buffer-substring-no-properties))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (fset 'buffer-substring-no-properties 'buffer-substring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defconst mc-xemacs-p (string-match "XEmacs" emacs-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (if (not mc-xemacs-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (autoload 'mc-decrypt "mc-toplev" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (autoload 'mc-verify "mc-toplev" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (autoload 'mc-snarf "mc-toplev" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (autoload 'mc-pgp-fetch-key "mc-pgp" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (autoload 'mc-encrypt "mc-toplev" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (autoload 'mc-sign "mc-toplev" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (autoload 'mc-insert-public-key "mc-toplev" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (autoload 'mc-remailer-encrypt-for-chain "mc-remail" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (autoload 'mc-remailer-insert-response-block "mc-remail" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (autoload 'mc-remailer-insert-pseudonym "mc-remail" nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;}}}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;{{{ Minor mode variables and functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (defvar mc-read-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 "Non-nil means Mailcrypt read mode key bindings are available.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (defvar mc-write-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 "Non-nil means Mailcrypt write mode key bindings are available.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (make-variable-buffer-local 'mc-read-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (make-variable-buffer-local 'mc-write-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defvar mc-read-mode-string " MC-r"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 "*String to put in mode line when Mailcrypt read mode is active.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (defvar mc-write-mode-string " MC-w"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 "*String to put in mode line when Mailcrypt write mode is active.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (defvar mc-read-mode-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 "Keymap for Mailcrypt read mode bindings.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (defvar mc-write-mode-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 "Keymap for Mailcrypt write mode bindings.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (or mc-read-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (setq mc-read-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (define-key mc-read-mode-map "\C-c/f" 'mc-deactivate-passwd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (define-key mc-read-mode-map "\C-c/d" 'mc-decrypt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (define-key mc-read-mode-map "\C-c/v" 'mc-verify)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (define-key mc-read-mode-map "\C-c/a" 'mc-snarf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (define-key mc-read-mode-map "\C-c/k" 'mc-pgp-fetch-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (or mc-write-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (setq mc-write-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (define-key mc-write-mode-map "\C-c/f" 'mc-deactivate-passwd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (define-key mc-write-mode-map "\C-c/e" 'mc-encrypt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (define-key mc-write-mode-map "\C-c/s" 'mc-sign)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (define-key mc-write-mode-map "\C-c/x" 'mc-insert-public-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (define-key mc-write-mode-map "\C-c/k" 'mc-pgp-fetch-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (define-key mc-write-mode-map "\C-c/r"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 'mc-remailer-encrypt-for-chain)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (define-key mc-write-mode-map "\C-c/b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 'mc-remailer-insert-response-block)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (define-key mc-write-mode-map "\C-c/p"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 'mc-remailer-insert-pseudonym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (easy-menu-define
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 mc-read-mode-menu (if mc-xemacs-p nil (list mc-read-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 "Mailcrypt read mode menu."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 '("Mailcrypt"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ["Decrypt Message" mc-decrypt t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ["Verify Signature" mc-verify t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ["Snarf Keys" mc-snarf t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ["Fetch Key" mc-pgp-fetch-key t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ["Forget Passphrase(s)" mc-deactivate-passwd t]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (easy-menu-define
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 mc-write-mode-menu (if mc-xemacs-p nil (list mc-write-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 "Mailcrypt write mode menu."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 '("Mailcrypt"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ["Encrypt Message" mc-encrypt t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ["Sign Message" mc-sign t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ["Insert Public Key" mc-insert-public-key t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ["Fetch Key" mc-pgp-fetch-key t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ["Encrypt for Remailer(s)" mc-remailer-encrypt-for-chain t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ["Insert Pseudonym" mc-remailer-insert-pseudonym t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ["Insert Response Block" mc-remailer-insert-response-block t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ["Forget Passphrase(s)" mc-deactivate-passwd t]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (or (assq 'mc-read-mode minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (setq minor-mode-map-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (cons (cons 'mc-read-mode mc-read-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 minor-mode-map-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (or (assq 'mc-write-mode minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (setq minor-mode-map-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (cons (cons 'mc-write-mode mc-write-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 minor-mode-map-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (or (assq 'mc-read-mode minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (cons '(mc-read-mode mc-read-mode-string) minor-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (or (assq 'mc-write-mode minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (cons '(mc-write-mode mc-write-mode-string) minor-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (defun mc-read-mode (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 "\nMinor mode for interfacing with cryptographic functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 \\<mc-read-mode-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 \\[mc-decrypt]\t\tDecrypt an encrypted message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 \\[mc-verify]\t\tVerify signature on a clearsigned message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 \\[mc-snarf]\t\tAdd public key(s) to keyring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 \\[mc-pgp-fetch-key]\t\tFetch a PGP key via finger or HTTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 \\[mc-deactivate-passwd]\t\tForget passphrase(s)\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (setq mc-read-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (if (null arg) (not mc-read-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (> (prefix-numeric-value arg) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (and mc-read-mode mc-write-mode (mc-write-mode nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (if mc-read-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (easy-menu-add mc-read-mode-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (easy-menu-remove mc-read-mode-menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (defun mc-write-mode (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 "\nMinor mode for interfacing with cryptographic functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 \\<mc-write-mode-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 \\[mc-encrypt]\t\tEncrypt (and optionally sign) message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 \\[mc-sign]\t\tClearsign message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 \\[mc-insert-public-key]\t\tExtract public key from keyring and insert into message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 \\[mc-pgp-fetch-key]\t\tFetch a PGP key via finger or HTTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 \\[mc-remailer-encrypt-for-chain]\t\tEncrypt message for remailing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 \\[mc-remailer-insert-pseudonym]\t\tInsert a pseudonym (for remailing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 \\[mc-remailer-insert-response-block]\t\tInsert a response block (for remailing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 \\[mc-deactivate-passwd]\t\tForget passphrase(s)\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (setq mc-write-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (if (null arg) (not mc-write-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (> (prefix-numeric-value arg) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (and mc-write-mode mc-read-mode (mc-read-mode nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (if mc-write-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (easy-menu-add mc-write-mode-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (easy-menu-remove mc-write-mode-menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (defun mc-install-read-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (mc-read-mode 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (defun mc-install-write-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (mc-write-mode 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;;}}}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;;{{{ Note:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;; The funny triple braces you see are used by `folding-mode', a minor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;; mode by Jamie Lokier, available from the elisp archive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;;}}}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;;{{{ User variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (defconst mc-version "3.4")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (defvar mc-default-scheme 'mc-scheme-pgp "*Default encryption scheme to use.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (defvar mc-passwd-timeout 60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 "*Time to deactivate password in seconds after a use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 nil or 0 means deactivate immediately. If the only timer package available
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 is the 'timer' package, then this can be a string in timer format.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (defvar mc-ripem-user-id (or (getenv "RIPEM_USER_NAME")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (user-full-name) "*Your RIPEM user ID."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (defvar mc-always-replace nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 "*If t, decrypt mail messages in place without prompting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 If 'never, always use a viewer instead of replacing.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (defvar mc-use-default-recipients nil "*Assume that the message should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 be encoded for everyone listed in the To, Cc, and Bcc fields.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (defvar mc-encrypt-for-me nil "*Encrypt all outgoing messages with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 user's public key.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (defvar mc-pre-signature-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 "*List of hook functions to run immediately before signing.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (defvar mc-post-signature-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 "*List of hook functions to run immediately after signing.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (defvar mc-pre-encryption-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 "*List of hook functions to run immediately before encrypting.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (defvar mc-post-encryption-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 "*List of hook functions to run after encrypting.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (defvar mc-pre-decryption-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 "*List of hook functions to run immediately before decrypting.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (defvar mc-post-decryption-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 "*List of hook functions to run after decrypting.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (defconst mc-buffer-name "*MailCrypt*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 "Name of temporary buffer for mailcrypt")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (defvar mc-modes-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 '((rmail-mode (decrypt . mc-rmail-decrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (verify . mc-rmail-verify-signature))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (rmail-summary-mode (decrypt . mc-rmail-summary-decrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (verify . mc-rmail-summary-verify-signature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (snarf . mc-rmail-summary-snarf-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (vm-mode (decrypt . mc-vm-decrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (verify . mc-vm-verify-signature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (snarf . mc-vm-snarf-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (vm-virtual-mode (decrypt . mc-vm-decrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (verify . mc-vm-verify-signature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (snarf . mc-vm-snarf-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (vm-summary-mode (decrypt . mc-vm-decrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (verify . mc-vm-verify-signature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (snarf . mc-vm-snarf-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (mh-folder-mode (decrypt . mc-mh-decrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (verify . mc-mh-verify-signature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (snarf . mc-mh-snarf-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ;; September Gnus (5.2) has a new message editing mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (message-mode (encrypt . mc-encrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (sign . mc-sign-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (gnus-summary-mode (decrypt . mc-gnus-decrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (verify . mc-gnus-verify-signature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (snarf . mc-gnus-snarf-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (gnus-article-mode (decrypt . mc-gnus-decrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (verify . mc-gnus-verify-signature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (snarf . mc-gnus-snarf-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (mail-mode (encrypt . mc-encrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (sign . mc-sign-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (vm-mail-mode (encrypt . mc-encrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (sign . mc-sign-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (mh-letter-mode (encrypt . mc-encrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (sign . mc-sign-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (news-reply-mode (encrypt . mc-encrypt-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (sign . mc-sign-message)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 "Association list (indexed by major mode) of association lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (indexed by operation) of functions to call for each major mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;;}}}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;;{{{ Program variables and constants.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (defvar mc-timer nil "Timer object for password deactivation.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (defvar mc-passwd-cache nil "Cache for passphrases.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (defvar mc-schemes '(("pgp" . mc-scheme-pgp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 ;;}}}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ;;{{{ Utility functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (defun mc-message-delimiter-positions (start-re end-re &optional begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 ;; Returns pair of integers (START . END) that delimit message marked off
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ;; by the regular expressions start-re and end-re. Optional argument BEGIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ;; determines where we should start looking from.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (setq begin (or begin (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (let (start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (and (re-search-forward start-re nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (setq start (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (re-search-forward end-re nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (cons start (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (defun mc-split (regexp str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 "Splits STR into a list of elements which were separated by REGEXP,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 stripping initial and trailing whitespace."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (let ((data (match-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (retval '())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (string-match "[ \t\n]*" str) ; Will always match at 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (setq beg (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (setq end (string-match "[ \t\n]*\\'" str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (while (string-match regexp str beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (setq retval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (cons (substring str beg (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (setq beg (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (if (not (= (length str) beg)) ; Not end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (setq retval (cons (substring str beg end) retval)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (nreverse retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (store-match-data data))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ;;; FIXME - Function never called?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ;(defun mc-temp-display (beg end &optional name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ; (let (tmp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 ; (if (not name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 ; (setq name mc-buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ; (if (string-match name "*ERROR*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 ; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 ; (message "mailcrypt: An error occured! See *ERROR* buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 ; (beep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 ; (setq tmp (buffer-substring beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 ; (delete-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 ; (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ; (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ; (with-output-to-temp-buffer name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ; (princ tmp))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 ;; In case I ever decide to do this right.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (defconst mc-field-name-regexp "^\\(.+\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (defconst mc-field-body-regexp "\\(.*\\(\n[ \t].*\\)*\n\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (defun mc-get-fields (&optional matching bounds nuke)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 "Get all header fields within BOUNDS. Return as an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 alist ((FIELD-NAME . FIELD-BODY) (FIELD-NAME . FIELD-BODY) ...).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 Argument MATCHING, if present, is a regexp which each FIELD-NAME
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 must match exactly. Matching is case-insensitive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 Optional arg NUKE, if non-nil, means eliminate all fields returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (let ((case-fold-search t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (header-field-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (concat mc-field-name-regexp ":" mc-field-body-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 ret name body field-start field-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 ;; Ensure exact match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (if matching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (setq matching (concat "^\\(" matching "\\)$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (if bounds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (narrow-to-region (car bounds) (cdr bounds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (while (re-search-backward header-field-regexp nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (setq field-start (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (setq field-end (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (setq name (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (match-beginning 1) (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (setq body (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (match-beginning 2) (match-end 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (if (or (null matching) (string-match matching name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (setq ret (cons (cons name body) ret))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (if nuke
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (delete-region field-start field-end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 ret))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (defsubst mc-strip-address (addr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 "Strip everything from ADDR except the basic Email address."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (car (cdr (mail-extract-address-components addr))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (defun mc-strip-addresses (addr-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 "Strip everything from the addresses in ADDR-LIST except the basic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 Email address. ADDR-LIST may be a single string or a list of strings."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (if (not (listp addr-list)) (setq addr-list (list addr-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (setq addr-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (function (lambda (s) (mc-split "\\([ \t\n]*,[ \t\n]*\\)" s)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 addr-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (setq addr-list (apply 'append addr-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (mapconcat 'mc-strip-address addr-list ", "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (defun mc-display-buffer (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 "Like display-buffer, but always display top of the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (display-buffer buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (defun mc-message (msg &optional buffer default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 ;; returns t if we used msg, nil if we used default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (let ((retval t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (if buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (setq msg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (if (re-search-forward msg nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (setq retval nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 default))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (if msg (message "%s" msg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (defun mc-process-region (beg end passwd program args parser &optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (let ((obuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (process-connection-type nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 mybuf result rgn proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (set-buffer mybuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (set-buffer obuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (buffer-disable-undo mybuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (setq proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (apply 'start-process "*PGP*" mybuf program args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (if passwd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (process-send-string proc (concat passwd "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (or mc-passwd-timeout (mc-deactivate-passwd t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (process-send-region proc beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (process-send-eof proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (while (eq 'run (process-status proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (accept-process-output proc 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (setq result (process-exit-status proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 ;; Hack to force a status_notify() in Emacs 19.29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (delete-process proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (set-buffer mybuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (delete-region (match-beginning 0) (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 ;; CRNL -> NL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (while (search-forward "\r\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (replace-match "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 ;; Hurm. FIXME; must get better result codes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (if (stringp result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (error "%s exited abnormally: '%s'" program result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (setq rgn (funcall parser result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 ;; If the parser found something, migrate it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (if (consp rgn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (set-buffer obuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (delete-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (set-buffer mybuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (delete-region (car rgn) (cdr rgn)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 ;; Return nil on failure and exit code on success
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (if rgn result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ;; Cleanup even on nonlocal exit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (if (and proc (eq 'run (process-status proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (interrupt-process proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (set-buffer obuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (or buffer (null mybuf) (kill-buffer mybuf)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 ;;}}}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ;;{{{ Passphrase management
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (defun mc-activate-passwd (id &optional prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 "Activate the passphrase matching ID, using PROMPT for a prompt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 Return the passphrase. If PROMPT is nil, only return value if cached."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (cond ((featurep 'itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (if mc-timer (delete-itimer mc-timer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (setq mc-timer (if mc-passwd-timeout
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (start-itimer "mc-itimer"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 'mc-deactivate-passwd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 mc-passwd-timeout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ((featurep 'timer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (let ((string-time (if (integerp mc-passwd-timeout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (format "%d sec" mc-passwd-timeout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 mc-passwd-timeout)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (if mc-timer (cancel-timer mc-timer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (setq mc-timer (if string-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (run-at-time string-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 nil 'mc-deactivate-passwd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (let ((cell (assoc id mc-passwd-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 passwd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (setq passwd (cdr-safe cell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (if (and (not passwd) prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (setq passwd (comint-read-noecho prompt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (if cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (setcdr cell passwd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (setq mc-passwd-cache (cons (cons id passwd) mc-passwd-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 passwd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (defun mc-deactivate-passwd (&optional inhibit-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 "*Deactivate the passphrase cache."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (if mc-timer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (cond ((featurep 'itimer) (delete-itimer mc-timer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ((featurep 'timer) (cancel-timer mc-timer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (lambda (cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (if (stringp (cdr-safe cell)) (fillarray (cdr cell) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (setcdr cell nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 mc-passwd-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (or inhibit-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (not (interactive-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (message "Passphrase%s deactivated"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (if (> (length mc-passwd-cache) 1) "s" ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 ;;}}}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ;;{{{ Define several aliases so that an apropos on `mailcrypt' will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 ;; return something.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (defalias 'mailcrypt-encrypt 'mc-encrypt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (defalias 'mailcrypt-decrypt 'mc-decrypt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (defalias 'mailcrypt-sign 'mc-sign)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (defalias 'mailcrypt-verify 'mc-verify)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (defalias 'mailcrypt-insert-public-key 'mc-insert-public-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (defalias 'mailcrypt-snarf 'mc-snarf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 ;;}}}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (provide 'mailcrypt)