1 ;;; mml1991.el --- Old PGP message format (RFC 1991) support for MML
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Sascha Lüdecke <sascha@meta-x.de>,
7 ;; Simon Josefsson <simon@josefsson.org> (Mailcrypt interface, Gnus glue)
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
35 (defvar mc-pgp-always-sign
)
37 (autoload 'quoted-printable-decode-region
"qp")
38 (autoload 'quoted-printable-encode-region
"qp")
40 (defvar mml1991-use mml2015-use
41 "The package used for PGP.")
43 (defvar mml1991-function-alist
44 '((mailcrypt mml1991-mailcrypt-sign
45 mml1991-mailcrypt-encrypt
)
50 "Alist of PGP functions.")
55 (autoload 'mc-sign-generic
"mc-toplev"))
57 (defvar mml1991-decrypt-function
'mailcrypt-decrypt
)
58 (defvar mml1991-verify-function
'mailcrypt-verify
)
60 (defun mml1991-mailcrypt-sign (cont)
61 (let ((text (current-buffer))
63 (result-buffer (get-buffer-create "*GPG Result*")))
64 ;; Save MIME Content[^ ]+: headers from signing
65 (goto-char (point-min))
66 (while (looking-at "^Content[^ ]+:") (forward-line))
68 (setq headers
(buffer-string))
69 (delete-region (point-min) (point)))
70 (goto-char (point-max))
73 (quoted-printable-decode-region (point-min) (point-max))
75 (setq signature
(current-buffer))
76 (insert-buffer-substring text
)
77 (unless (mc-sign-generic (message-options-get 'message-sender
)
79 (unless (> (point-max) (point-min))
80 (pop-to-buffer result-buffer
)
81 (error "Sign error")))
82 (goto-char (point-min))
83 (while (re-search-forward "\r+$" nil t
)
84 (replace-match "" t t
))
85 (quoted-printable-encode-region (point-min) (point-max))
87 (delete-region (point-min) (point-max))
88 (if headers
(insert headers
))
90 (insert-buffer-substring signature
)
91 (goto-char (point-max)))))
93 (defun mml1991-mailcrypt-encrypt (cont &optional sign
)
94 (let ((text (current-buffer))
96 (or mc-pgp-always-sign
98 (eq t
(or (message-options-get 'message-sign-encrypt
)
100 'message-sign-encrypt
101 (or (y-or-n-p "Sign the message? ")
105 (result-buffer (get-buffer-create "*GPG Result*")))
106 ;; Strip MIME Content[^ ]: headers since it will be ASCII ARMOURED
107 (goto-char (point-min))
108 (while (looking-at "^Content[^ ]+:") (forward-line))
110 (delete-region (point-min) (point)))
111 (mm-with-unibyte-current-buffer
113 (setq cipher
(current-buffer))
114 (insert-buffer-substring text
)
115 (unless (mc-encrypt-generic
117 (message-options-get 'message-recipients
)
118 (message-options-set 'message-recipients
119 (read-string "Recipients: ")))
121 (point-min) (point-max)
122 (message-options-get 'message-sender
)
124 (unless (> (point-max) (point-min))
125 (pop-to-buffer result-buffer
)
126 (error "Encrypt error")))
127 (goto-char (point-min))
128 (while (re-search-forward "\r+$" nil t
)
129 (replace-match "" t t
))
131 (delete-region (point-min) (point-max))
132 ;;(insert "Content-Type: application/pgp-encrypted\n\n")
133 ;;(insert "Version: 1\n\n")
135 (insert-buffer-substring cipher
)
136 (goto-char (point-max))))))
141 (autoload 'gpg-sign-cleartext
"gpg"))
143 (defun mml1991-gpg-sign (cont)
144 (let ((text (current-buffer))
146 (result-buffer (get-buffer-create "*GPG Result*")))
147 ;; Save MIME Content[^ ]+: headers from signing
148 (goto-char (point-min))
149 (while (looking-at "^Content[^ ]+:") (forward-line))
151 (setq headers
(buffer-string))
152 (delete-region (point-min) (point)))
153 (goto-char (point-max))
156 (quoted-printable-decode-region (point-min) (point-max))
158 (unless (gpg-sign-cleartext text
(setq signature
(current-buffer))
161 (message-options-get 'message-sender
))
162 (unless (> (point-max) (point-min))
163 (pop-to-buffer result-buffer
)
164 (error "Sign error")))
165 (goto-char (point-min))
166 (while (re-search-forward "\r+$" nil t
)
167 (replace-match "" t t
))
168 (quoted-printable-encode-region (point-min) (point-max))
170 (delete-region (point-min) (point-max))
171 (if headers
(insert headers
))
173 (insert-buffer-substring signature
)
174 (goto-char (point-max)))))
176 (defun mml1991-gpg-encrypt (cont &optional sign
)
177 (let ((text (current-buffer))
179 (result-buffer (get-buffer-create "*GPG Result*")))
180 ;; Strip MIME Content[^ ]: headers since it will be ASCII ARMOURED
181 (goto-char (point-min))
182 (while (looking-at "^Content[^ ]+:") (forward-line))
184 (delete-region (point-min) (point)))
185 (mm-with-unibyte-current-buffer
187 (flet ((gpg-encrypt-func
188 (sign plaintext ciphertext result recipients
&optional
189 passphrase sign-with-key armor textmode
)
192 plaintext ciphertext result recipients passphrase
193 sign-with-key armor textmode
)
195 plaintext ciphertext result recipients passphrase
197 (unless (gpg-encrypt-func
199 text
(setq cipher
(current-buffer))
203 (message-options-get 'message-recipients
)
204 (message-options-set 'message-recipients
205 (read-string "Recipients: ")))
208 (message-options-get 'message-sender
)
209 t t
) ; armor & textmode
210 (unless (> (point-max) (point-min))
211 (pop-to-buffer result-buffer
)
212 (error "Encrypt error"))))
213 (goto-char (point-min))
214 (while (re-search-forward "\r+$" nil t
)
215 (replace-match "" t t
))
217 (delete-region (point-min) (point-max))
218 ;;(insert "Content-Type: application/pgp-encrypted\n\n")
219 ;;(insert "Version: 1\n\n")
221 (insert-buffer-substring cipher
)
222 (goto-char (point-max))))))
227 (defvar pgg-default-user-id
)
228 (defvar pgg-errors-buffer
)
229 (defvar pgg-output-buffer
))
231 (defun mml1991-pgg-sign (cont)
232 (let ((pgg-text-mode t
)
233 (pgg-default-user-id (or (message-options-get 'mml-sender
)
234 pgg-default-user-id
))
236 ;; Don't sign headers.
237 (goto-char (point-min))
238 (when (re-search-forward "^$" nil t
)
239 (setq headers
(buffer-substring (point-min) (point)))
241 (narrow-to-region (point-min) (point))
242 (setq cte
(mail-fetch-field "content-transfer-encoding")))
244 (delete-region (point-min) (point))
246 (setq cte
(intern (downcase cte
)))
247 (mm-decode-content-transfer-encoding cte
)))
248 (unless (pgg-sign-region (point-min) (point-max) t
)
249 (pop-to-buffer pgg-errors-buffer
)
250 (error "Encrypt error"))
251 (delete-region (point-min) (point-max))
252 (mm-with-unibyte-current-buffer
253 (insert-buffer-substring pgg-output-buffer
)
254 (goto-char (point-min))
255 (while (re-search-forward "\r+$" nil t
)
256 (replace-match "" t t
))
258 (mm-encode-content-transfer-encoding cte
))
259 (goto-char (point-min))
265 (defun mml1991-pgg-encrypt (cont &optional sign
)
266 (goto-char (point-min))
267 (when (re-search-forward "^$" nil t
)
268 (let ((cte (save-restriction
269 (narrow-to-region (point-min) (point))
270 (mail-fetch-field "content-transfer-encoding"))))
271 ;; Strip MIME headers since it will be ASCII armoured.
273 (delete-region (point-min) (point))
275 (mm-decode-content-transfer-encoding (intern (downcase cte
))))))
276 (unless (let ((pgg-text-mode t
))
278 (point-min) (point-max)
281 (message-options-get 'message-recipients
)
282 (message-options-set 'message-recipients
283 (read-string "Recipients: ")))
286 (pop-to-buffer pgg-errors-buffer
)
287 (error "Encrypt error"))
288 (delete-region (point-min) (point-max))
290 (insert-buffer-substring pgg-output-buffer
)
294 (defun mml1991-encrypt (cont &optional sign
)
295 (let ((func (nth 2 (assq mml1991-use mml1991-function-alist
))))
297 (funcall func cont sign
)
298 (error "Cannot find encrypt function"))))
301 (defun mml1991-sign (cont)
302 (let ((func (nth 1 (assq mml1991-use mml1991-function-alist
))))
305 (error "Cannot find sign function"))))
310 ;; coding: iso-8859-1
313 ;;; arch-tag: e542be18-ab28-4393-9b33-97fe9cf30706
314 ;;; mml1991.el ends here