1 ;;; mml1991.el --- Old PGP message format (RFC 1991) support for MML
3 ;; Copyright (C) 1998-2016 Free Software Foundation, Inc.
5 ;; Author: Sascha Lüdecke <sascha@meta-x.de>,
6 ;; Simon Josefsson <simon@josefsson.org> (Mailcrypt interface, Gnus glue)
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
35 (defvar mc-pgp-always-sign
)
37 (autoload 'quoted-printable-decode-region
"qp")
38 (autoload 'quoted-printable-encode-region
"qp")
40 (autoload 'mm-decode-content-transfer-encoding
"mm-bodies")
41 (autoload 'mm-encode-content-transfer-encoding
"mm-bodies")
42 (autoload 'message-options-get
"message")
43 (autoload 'message-options-set
"message")
47 (defvar mml1991-use mml2015-use
48 "The package used for PGP.")
50 (defvar mml1991-function-alist
51 '((mailcrypt mml1991-mailcrypt-sign
52 mml1991-mailcrypt-encrypt
)
57 "Alist of PGP functions.")
59 (defvar mml1991-cache-passphrase mml-secure-cache-passphrase
60 "If t, cache passphrase.")
61 (make-obsolete-variable 'mml1991-cache-passphrase
62 'mml-secure-cache-passphrase
65 (defvar mml1991-passphrase-cache-expiry mml-secure-passphrase-cache-expiry
66 "How many seconds the passphrase is cached.
67 Whether the passphrase is cached at all is controlled by
68 `mml1991-cache-passphrase'.")
69 (make-obsolete-variable 'mml1991-passphrase-cache-expiry
70 'mml-secure-passphrase-cache-expiry
73 (defvar mml1991-signers nil
74 "A list of your own key ID which will be used to sign a message.")
76 (defvar mml1991-encrypt-to-self nil
77 "If t, add your own key ID to recipient list when encryption.")
82 (autoload 'mc-sign-generic
"mc-toplev")
84 (defvar mml1991-decrypt-function
'mailcrypt-decrypt
)
85 (defvar mml1991-verify-function
'mailcrypt-verify
)
87 (defun mml1991-mailcrypt-sign (cont)
88 (let ((text (current-buffer))
90 (result-buffer (get-buffer-create "*GPG Result*")))
91 ;; Save MIME Content[^ ]+: headers from signing
92 (goto-char (point-min))
93 (while (looking-at "^Content[^ ]+:") (forward-line))
95 (setq headers
(buffer-string))
96 (delete-region (point-min) (point)))
97 (goto-char (point-max))
100 (quoted-printable-decode-region (point-min) (point-max))
102 (setq signature
(current-buffer))
103 (insert-buffer-substring text
)
104 (unless (mc-sign-generic (message-options-get 'message-sender
)
106 (unless (> (point-max) (point-min))
107 (pop-to-buffer result-buffer
)
108 (error "Sign error")))
109 (goto-char (point-min))
110 (while (re-search-forward "\r+$" nil t
)
111 (replace-match "" t t
))
112 (quoted-printable-encode-region (point-min) (point-max))
114 (delete-region (point-min) (point-max))
115 (if headers
(insert headers
))
117 (insert-buffer-substring signature
)
118 (goto-char (point-max)))))
120 (declare-function mc-encrypt-generic
"ext:mc-toplev"
121 (&optional recipients scheme start end from sign
))
123 (defun mml1991-mailcrypt-encrypt (cont &optional sign
)
124 (let ((text (current-buffer))
126 (or mc-pgp-always-sign
128 (eq t
(or (message-options-get 'message-sign-encrypt
)
130 'message-sign-encrypt
131 (or (y-or-n-p "Sign the message? ")
135 (result-buffer (get-buffer-create "*GPG Result*")))
136 ;; Strip MIME Content[^ ]: headers since it will be ASCII ARMORED
137 (goto-char (point-min))
138 (while (looking-at "^Content[^ ]+:") (forward-line))
140 (delete-region (point-min) (point)))
142 (inline (mm-disable-multibyte))
143 (setq cipher
(current-buffer))
144 (insert-buffer-substring text
)
145 (unless (mc-encrypt-generic
147 (message-options-get 'message-recipients
)
148 (message-options-set 'message-recipients
149 (read-string "Recipients: ")))
151 (point-min) (point-max)
152 (message-options-get 'message-sender
)
154 (unless (> (point-max) (point-min))
155 (pop-to-buffer result-buffer
)
156 (error "Encrypt error")))
157 (goto-char (point-min))
158 (while (re-search-forward "\r+$" nil t
)
159 (replace-match "" t t
))
161 (delete-region (point-min) (point-max))
162 ;;(insert "Content-Type: application/pgp-encrypted\n\n")
163 ;;(insert "Version: 1\n\n")
165 (insert-buffer-substring cipher
)
166 (goto-char (point-max)))))
170 (autoload 'pgg-sign-region
"pgg")
171 (autoload 'pgg-encrypt-region
"pgg")
173 (defvar pgg-default-user-id
)
174 (defvar pgg-errors-buffer
)
175 (defvar pgg-output-buffer
)
177 (defun mml1991-pgg-sign (cont)
178 (let ((pgg-text-mode t
)
179 (pgg-default-user-id (or (message-options-get 'mml-sender
)
180 pgg-default-user-id
))
182 ;; Don't sign headers.
183 (goto-char (point-min))
184 (when (re-search-forward "^$" nil t
)
185 (setq headers
(buffer-substring (point-min) (point)))
187 (narrow-to-region (point-min) (point))
188 (setq cte
(mail-fetch-field "content-transfer-encoding")))
190 (delete-region (point-min) (point))
192 (setq cte
(intern (downcase cte
)))
193 (mm-decode-content-transfer-encoding cte
)))
194 (unless (pgg-sign-region (point-min) (point-max) t
)
195 (pop-to-buffer pgg-errors-buffer
)
196 (error "Encrypt error"))
197 (delete-region (point-min) (point-max))
198 (mm-with-unibyte-current-buffer
199 (insert-buffer-substring pgg-output-buffer
)
200 (goto-char (point-min))
201 (while (re-search-forward "\r+$" nil t
)
202 (replace-match "" t t
))
204 (mm-encode-content-transfer-encoding cte
))
205 (goto-char (point-min))
211 (defun mml1991-pgg-encrypt (cont &optional sign
)
212 (goto-char (point-min))
213 (when (re-search-forward "^$" nil t
)
214 (let ((cte (save-restriction
215 (narrow-to-region (point-min) (point))
216 (mail-fetch-field "content-transfer-encoding"))))
217 ;; Strip MIME headers since it will be ASCII armored.
219 (delete-region (point-min) (point))
221 (mm-decode-content-transfer-encoding (intern (downcase cte
))))))
222 (unless (let ((pgg-text-mode t
))
224 (point-min) (point-max)
227 (message-options-get 'message-recipients
)
228 (message-options-set 'message-recipients
229 (read-string "Recipients: ")))
232 (pop-to-buffer pgg-errors-buffer
)
233 (error "Encrypt error"))
234 (delete-region (point-min) (point-max))
236 (insert-buffer-substring pgg-output-buffer
)
241 (defvar epg-user-id-alist
)
243 (autoload 'epg-make-context
"epg")
244 (autoload 'epg-passphrase-callback-function
"epg")
245 (autoload 'epa-select-keys
"epa")
246 (autoload 'epg-list-keys
"epg")
247 (autoload 'epg-context-set-armor
"epg")
248 (autoload 'epg-context-set-textmode
"epg")
249 (autoload 'epg-context-set-signers
"epg")
250 (autoload 'epg-context-set-passphrase-callback
"epg")
251 (autoload 'epg-key-sub-key-list
"epg")
252 (autoload 'epg-sub-key-capability
"epg")
253 (autoload 'epg-sub-key-validity
"epg")
254 (autoload 'epg-sub-key-fingerprint
"epg")
255 (autoload 'epg-sign-string
"epg")
256 (autoload 'epg-encrypt-string
"epg")
257 (autoload 'epg-configuration
"epg-config")
258 (autoload 'epg-expand-group
"epg-config")
260 (defun mml1991-epg-sign (cont)
261 (let ((inhibit-redisplay t
)
263 ;; Don't sign headers.
264 (goto-char (point-min))
265 (when (re-search-forward "^$" nil t
)
266 (setq headers
(buffer-substring (point-min) (point)))
268 (narrow-to-region (point-min) (point))
269 (setq cte
(mail-fetch-field "content-transfer-encoding")))
271 (delete-region (point-min) (point))
273 (setq cte
(intern (downcase cte
)))
274 (mm-decode-content-transfer-encoding cte
)))
275 (let* ((pair (mml-secure-epg-sign 'OpenPGP
'clear
))
276 (signature (car pair
)))
277 (delete-region (point-min) (point-max))
278 (mm-with-unibyte-current-buffer
280 (goto-char (point-min))
281 (while (re-search-forward "\r+$" nil t
)
282 (replace-match "" t t
))
284 (mm-encode-content-transfer-encoding cte
))
285 (goto-char (point-min))
291 (defun mml1991-epg-encrypt (cont &optional sign
)
292 (goto-char (point-min))
293 (when (re-search-forward "^$" nil t
)
294 (let ((cte (save-restriction
295 (narrow-to-region (point-min) (point))
296 (mail-fetch-field "content-transfer-encoding"))))
297 ;; Strip MIME headers since it will be ASCII armored.
299 (delete-region (point-min) (point))
301 (mm-decode-content-transfer-encoding (intern (downcase cte
))))))
302 (let ((cipher (mml-secure-epg-encrypt 'OpenPGP cont sign
)))
303 (delete-region (point-min) (point-max))
304 (insert "\n" cipher
))
308 (defun mml1991-encrypt (cont &optional sign
)
309 (let ((func (nth 2 (assq mml1991-use mml1991-function-alist
))))
311 (funcall func cont sign
)
312 (error "Cannot find encrypt function"))))
315 (defun mml1991-sign (cont)
316 (let ((func (nth 1 (assq mml1991-use mml1991-function-alist
))))
319 (error "Cannot find sign function"))))
327 ;;; mml1991.el ends here