1 ;;; mml1991.el --- Old PGP message format (RFC 1991) support for MML
3 ;; Copyright (C) 1998-2018 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 <https://www.gnu.org/licenses/>.
28 (eval-when-compile (require 'mm-util
))
33 (defvar mc-pgp-always-sign
)
35 (autoload 'quoted-printable-decode-region
"qp")
36 (autoload 'quoted-printable-encode-region
"qp")
38 (autoload 'mm-decode-content-transfer-encoding
"mm-bodies")
39 (autoload 'mm-encode-content-transfer-encoding
"mm-bodies")
40 (autoload 'message-options-get
"message")
41 (autoload 'message-options-set
"message")
45 (defvar mml1991-use mml2015-use
46 "The package used for PGP.")
48 (defvar mml1991-function-alist
49 '((mailcrypt mml1991-mailcrypt-sign
50 mml1991-mailcrypt-encrypt
)
55 "Alist of PGP functions.")
57 (defvar mml1991-cache-passphrase mml-secure-cache-passphrase
58 "If t, cache passphrase.")
59 (make-obsolete-variable 'mml1991-cache-passphrase
60 'mml-secure-cache-passphrase
63 (defvar mml1991-passphrase-cache-expiry mml-secure-passphrase-cache-expiry
64 "How many seconds the passphrase is cached.
65 Whether the passphrase is cached at all is controlled by
66 `mml1991-cache-passphrase'.")
67 (make-obsolete-variable 'mml1991-passphrase-cache-expiry
68 'mml-secure-passphrase-cache-expiry
71 (defvar mml1991-signers nil
72 "A list of your own key ID which will be used to sign a message.")
74 (defvar mml1991-encrypt-to-self nil
75 "If t, add your own key ID to recipient list when encryption.")
80 (autoload 'mc-sign-generic
"mc-toplev")
82 (defvar mml1991-decrypt-function
'mailcrypt-decrypt
)
83 (defvar mml1991-verify-function
'mailcrypt-verify
)
85 (defun mml1991-mailcrypt-sign (cont)
86 (let ((text (current-buffer))
88 (result-buffer (get-buffer-create "*GPG Result*")))
89 ;; Save MIME Content[^ ]+: headers from signing
90 (goto-char (point-min))
91 (while (looking-at "^Content[^ ]+:") (forward-line))
93 (setq headers
(buffer-string))
94 (delete-region (point-min) (point)))
95 (goto-char (point-max))
98 (quoted-printable-decode-region (point-min) (point-max))
100 (setq signature
(current-buffer))
101 (insert-buffer-substring text
)
102 (unless (mc-sign-generic (message-options-get 'message-sender
)
104 (unless (> (point-max) (point-min))
105 (pop-to-buffer result-buffer
)
106 (error "Sign error")))
107 (goto-char (point-min))
108 (while (re-search-forward "\r+$" nil t
)
109 (replace-match "" t t
))
110 (quoted-printable-encode-region (point-min) (point-max))
112 (delete-region (point-min) (point-max))
113 (if headers
(insert headers
))
115 (insert-buffer-substring signature
)
116 (goto-char (point-max)))))
118 (declare-function mc-encrypt-generic
"ext:mc-toplev"
119 (&optional recipients scheme start end from sign
))
121 (defun mml1991-mailcrypt-encrypt (cont &optional sign
)
122 (let ((text (current-buffer))
124 (or mc-pgp-always-sign
126 (eq t
(or (message-options-get 'message-sign-encrypt
)
128 'message-sign-encrypt
129 (or (y-or-n-p "Sign the message? ")
133 (result-buffer (get-buffer-create "*GPG Result*")))
134 ;; Strip MIME Content[^ ]: headers since it will be ASCII ARMORED
135 (goto-char (point-min))
136 (while (looking-at "^Content[^ ]+:") (forward-line))
138 (delete-region (point-min) (point)))
140 (inline (mm-disable-multibyte))
141 (setq cipher
(current-buffer))
142 (insert-buffer-substring text
)
143 (unless (mc-encrypt-generic
145 (message-options-get 'message-recipients
)
146 (message-options-set 'message-recipients
147 (read-string "Recipients: ")))
149 (point-min) (point-max)
150 (message-options-get 'message-sender
)
152 (unless (> (point-max) (point-min))
153 (pop-to-buffer result-buffer
)
154 (error "Encrypt error")))
155 (goto-char (point-min))
156 (while (re-search-forward "\r+$" nil t
)
157 (replace-match "" t t
))
159 (delete-region (point-min) (point-max))
160 ;;(insert "Content-Type: application/pgp-encrypted\n\n")
161 ;;(insert "Version: 1\n\n")
163 (insert-buffer-substring cipher
)
164 (goto-char (point-max)))))
168 (autoload 'pgg-sign-region
"pgg")
169 (autoload 'pgg-encrypt-region
"pgg")
171 (defvar pgg-default-user-id
)
172 (defvar pgg-errors-buffer
)
173 (defvar pgg-output-buffer
)
175 (defun mml1991-pgg-sign (cont)
176 (let ((pgg-text-mode t
)
177 (pgg-default-user-id (or (message-options-get 'mml-sender
)
178 pgg-default-user-id
))
180 ;; Don't sign headers.
181 (goto-char (point-min))
182 (when (re-search-forward "^$" nil t
)
183 (setq headers
(buffer-substring (point-min) (point)))
185 (narrow-to-region (point-min) (point))
186 (setq cte
(mail-fetch-field "content-transfer-encoding")))
188 (delete-region (point-min) (point))
190 (setq cte
(intern (downcase cte
)))
191 (mm-decode-content-transfer-encoding cte
)))
192 (unless (pgg-sign-region (point-min) (point-max) t
)
193 (pop-to-buffer pgg-errors-buffer
)
194 (error "Encrypt error"))
195 (delete-region (point-min) (point-max))
198 (set-buffer-multibyte nil
)
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))
212 (defun mml1991-pgg-encrypt (cont &optional sign
)
213 (goto-char (point-min))
214 (when (re-search-forward "^$" nil t
)
215 (let ((cte (save-restriction
216 (narrow-to-region (point-min) (point))
217 (mail-fetch-field "content-transfer-encoding"))))
218 ;; Strip MIME headers since it will be ASCII armored.
220 (delete-region (point-min) (point))
222 (mm-decode-content-transfer-encoding (intern (downcase cte
))))))
223 (unless (let ((pgg-text-mode t
))
225 (point-min) (point-max)
228 (message-options-get 'message-recipients
)
229 (message-options-set 'message-recipients
230 (read-string "Recipients: ")))
233 (pop-to-buffer pgg-errors-buffer
)
234 (error "Encrypt error"))
235 (delete-region (point-min) (point-max))
237 (insert-buffer-substring pgg-output-buffer
)
242 (defvar epg-user-id-alist
)
244 (autoload 'epg-make-context
"epg")
245 (autoload 'epg-passphrase-callback-function
"epg")
246 (autoload 'epa-select-keys
"epa")
247 (autoload 'epg-list-keys
"epg")
248 (autoload 'epg-context-set-armor
"epg")
249 (autoload 'epg-context-set-textmode
"epg")
250 (autoload 'epg-context-set-signers
"epg")
251 (autoload 'epg-context-set-passphrase-callback
"epg")
252 (autoload 'epg-key-sub-key-list
"epg")
253 (autoload 'epg-sub-key-capability
"epg")
254 (autoload 'epg-sub-key-validity
"epg")
255 (autoload 'epg-sub-key-fingerprint
"epg")
256 (autoload 'epg-sign-string
"epg")
257 (autoload 'epg-encrypt-string
"epg")
258 (autoload 'epg-configuration
"epg-config")
259 (autoload 'epg-expand-group
"epg-config")
261 (defun mml1991-epg-sign (cont)
262 (let ((inhibit-redisplay t
)
264 ;; Don't sign headers.
265 (goto-char (point-min))
266 (when (re-search-forward "^$" nil t
)
267 (setq headers
(buffer-substring (point-min) (point)))
269 (narrow-to-region (point-min) (point))
270 (setq cte
(mail-fetch-field "content-transfer-encoding")))
272 (delete-region (point-min) (point))
274 (setq cte
(intern (downcase cte
)))
275 (mm-decode-content-transfer-encoding cte
)))
276 (let* ((pair (mml-secure-epg-sign 'OpenPGP
'clear
))
277 (signature (car pair
)))
278 (unless (stringp signature
)
279 (error "Signature failed"))
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