1 ;;; mml1991.el --- Old PGP message format (RFC 1991) support for MML
3 ;; Copyright (C) 1998-2017 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))
200 (set-buffer-multibyte nil
)
201 (insert-buffer-substring pgg-output-buffer
)
202 (goto-char (point-min))
203 (while (re-search-forward "\r+$" nil t
)
204 (replace-match "" t t
))
206 (mm-encode-content-transfer-encoding cte
))
207 (goto-char (point-min))
214 (defun mml1991-pgg-encrypt (cont &optional sign
)
215 (goto-char (point-min))
216 (when (re-search-forward "^$" nil t
)
217 (let ((cte (save-restriction
218 (narrow-to-region (point-min) (point))
219 (mail-fetch-field "content-transfer-encoding"))))
220 ;; Strip MIME headers since it will be ASCII armored.
222 (delete-region (point-min) (point))
224 (mm-decode-content-transfer-encoding (intern (downcase cte
))))))
225 (unless (let ((pgg-text-mode t
))
227 (point-min) (point-max)
230 (message-options-get 'message-recipients
)
231 (message-options-set 'message-recipients
232 (read-string "Recipients: ")))
235 (pop-to-buffer pgg-errors-buffer
)
236 (error "Encrypt error"))
237 (delete-region (point-min) (point-max))
239 (insert-buffer-substring pgg-output-buffer
)
244 (defvar epg-user-id-alist
)
246 (autoload 'epg-make-context
"epg")
247 (autoload 'epg-passphrase-callback-function
"epg")
248 (autoload 'epa-select-keys
"epa")
249 (autoload 'epg-list-keys
"epg")
250 (autoload 'epg-context-set-armor
"epg")
251 (autoload 'epg-context-set-textmode
"epg")
252 (autoload 'epg-context-set-signers
"epg")
253 (autoload 'epg-context-set-passphrase-callback
"epg")
254 (autoload 'epg-key-sub-key-list
"epg")
255 (autoload 'epg-sub-key-capability
"epg")
256 (autoload 'epg-sub-key-validity
"epg")
257 (autoload 'epg-sub-key-fingerprint
"epg")
258 (autoload 'epg-sign-string
"epg")
259 (autoload 'epg-encrypt-string
"epg")
260 (autoload 'epg-configuration
"epg-config")
261 (autoload 'epg-expand-group
"epg-config")
263 (defun mml1991-epg-sign (cont)
264 (let ((inhibit-redisplay t
)
266 ;; Don't sign headers.
267 (goto-char (point-min))
268 (when (re-search-forward "^$" nil t
)
269 (setq headers
(buffer-substring (point-min) (point)))
271 (narrow-to-region (point-min) (point))
272 (setq cte
(mail-fetch-field "content-transfer-encoding")))
274 (delete-region (point-min) (point))
276 (setq cte
(intern (downcase cte
)))
277 (mm-decode-content-transfer-encoding cte
)))
278 (let* ((pair (mml-secure-epg-sign 'OpenPGP
'clear
))
279 (signature (car pair
)))
280 (delete-region (point-min) (point-max))
283 (set-buffer-multibyte nil
)
285 (goto-char (point-min))
286 (while (re-search-forward "\r+$" nil t
)
287 (replace-match "" t t
))
289 (mm-encode-content-transfer-encoding cte
))
290 (goto-char (point-min))
297 (defun mml1991-epg-encrypt (cont &optional sign
)
298 (goto-char (point-min))
299 (when (re-search-forward "^$" nil t
)
300 (let ((cte (save-restriction
301 (narrow-to-region (point-min) (point))
302 (mail-fetch-field "content-transfer-encoding"))))
303 ;; Strip MIME headers since it will be ASCII armored.
305 (delete-region (point-min) (point))
307 (mm-decode-content-transfer-encoding (intern (downcase cte
))))))
308 (let ((cipher (mml-secure-epg-encrypt 'OpenPGP cont sign
)))
309 (delete-region (point-min) (point-max))
310 (insert "\n" cipher
))
314 (defun mml1991-encrypt (cont &optional sign
)
315 (let ((func (nth 2 (assq mml1991-use mml1991-function-alist
))))
317 (funcall func cont sign
)
318 (error "Cannot find encrypt function"))))
321 (defun mml1991-sign (cont)
322 (let ((func (nth 1 (assq mml1991-use mml1991-function-alist
))))
325 (error "Cannot find sign function"))))
333 ;;; mml1991.el ends here