1 ;;; mml1991.el --- Old PGP message format (RFC 1991) support for MML
2 ;; Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
4 ;; Author: Sascha Lüdecke <sascha@meta-x.de>,
5 ;; Simon Josefsson <simon@josefsson.org> (Mailcrypt interface, Gnus glue)
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
33 (autoload 'quoted-printable-decode-region
"qp")
34 (autoload 'quoted-printable-encode-region
"qp")
36 (defvar mml1991-use mml2015-use
37 "The package used for PGP.")
39 (defvar mml1991-function-alist
40 '((mailcrypt mml1991-mailcrypt-sign
41 mml1991-mailcrypt-encrypt
)
46 "Alist of PGP functions.")
51 (autoload 'mc-sign-generic
"mc-toplev"))
53 (defvar mml1991-decrypt-function
'mailcrypt-decrypt
)
54 (defvar mml1991-verify-function
'mailcrypt-verify
)
56 (defun mml1991-mailcrypt-sign (cont)
57 (let ((text (current-buffer))
59 (result-buffer (get-buffer-create "*GPG Result*")))
60 ;; Save MIME Content[^ ]+: headers from signing
61 (goto-char (point-min))
62 (while (looking-at "^Content[^ ]+:") (forward-line))
64 (setq headers
(buffer-string))
65 (delete-region (point-min) (point)))
66 (goto-char (point-max))
69 (quoted-printable-decode-region (point-min) (point-max))
71 (setq signature
(current-buffer))
72 (insert-buffer-substring text
)
73 (unless (mc-sign-generic (message-options-get 'message-sender
)
75 (unless (> (point-max) (point-min))
76 (pop-to-buffer result-buffer
)
77 (error "Sign error")))
78 (goto-char (point-min))
79 (while (re-search-forward "\r+$" nil t
)
80 (replace-match "" t t
))
81 (quoted-printable-encode-region (point-min) (point-max))
83 (delete-region (point-min) (point-max))
84 (if headers
(insert headers
))
86 (insert-buffer-substring signature
)
87 (goto-char (point-max)))))
89 (defun mml1991-mailcrypt-encrypt (cont &optional sign
)
90 (let ((text (current-buffer))
92 (or mc-pgp-always-sign
94 (eq t
(or (message-options-get 'message-sign-encrypt
)
97 (or (y-or-n-p "Sign the message? ")
101 (result-buffer (get-buffer-create "*GPG Result*")))
102 ;; Strip MIME Content[^ ]: headers since it will be ASCII ARMOURED
103 (goto-char (point-min))
104 (while (looking-at "^Content[^ ]+:") (forward-line))
106 (delete-region (point-min) (point)))
107 (mm-with-unibyte-current-buffer
109 (setq cipher
(current-buffer))
110 (insert-buffer-substring text
)
111 (unless (mc-encrypt-generic
113 (message-options-get 'message-recipients
)
114 (message-options-set 'message-recipients
115 (read-string "Recipients: ")))
117 (point-min) (point-max)
118 (message-options-get 'message-sender
)
120 (unless (> (point-max) (point-min))
121 (pop-to-buffer result-buffer
)
122 (error "Encrypt error")))
123 (goto-char (point-min))
124 (while (re-search-forward "\r+$" nil t
)
125 (replace-match "" t t
))
127 (delete-region (point-min) (point-max))
128 ;;(insert "Content-Type: application/pgp-encrypted\n\n")
129 ;;(insert "Version: 1\n\n")
131 (insert-buffer-substring cipher
)
132 (goto-char (point-max))))))
137 (autoload 'gpg-sign-cleartext
"gpg"))
139 (defun mml1991-gpg-sign (cont)
140 (let ((text (current-buffer))
142 (result-buffer (get-buffer-create "*GPG Result*")))
143 ;; Save MIME Content[^ ]+: headers from signing
144 (goto-char (point-min))
145 (while (looking-at "^Content[^ ]+:") (forward-line))
147 (setq headers
(buffer-string))
148 (delete-region (point-min) (point)))
149 (goto-char (point-max))
152 (quoted-printable-decode-region (point-min) (point-max))
154 (unless (gpg-sign-cleartext text
(setq signature
(current-buffer))
157 (message-options-get 'message-sender
))
158 (unless (> (point-max) (point-min))
159 (pop-to-buffer result-buffer
)
160 (error "Sign error")))
161 (goto-char (point-min))
162 (while (re-search-forward "\r+$" nil t
)
163 (replace-match "" t t
))
164 (quoted-printable-encode-region (point-min) (point-max))
166 (delete-region (point-min) (point-max))
167 (if headers
(insert headers
))
169 (insert-buffer-substring signature
)
170 (goto-char (point-max)))))
172 (defun mml1991-gpg-encrypt (cont &optional sign
)
173 (let ((text (current-buffer))
175 (result-buffer (get-buffer-create "*GPG Result*")))
176 ;; Strip MIME Content[^ ]: headers since it will be ASCII ARMOURED
177 (goto-char (point-min))
178 (while (looking-at "^Content[^ ]+:") (forward-line))
180 (delete-region (point-min) (point)))
181 (mm-with-unibyte-current-buffer
183 (flet ((gpg-encrypt-func
184 (sign plaintext ciphertext result recipients
&optional
185 passphrase sign-with-key armor textmode
)
188 plaintext ciphertext result recipients passphrase
189 sign-with-key armor textmode
)
191 plaintext ciphertext result recipients passphrase
193 (unless (gpg-encrypt-func
195 text
(setq cipher
(current-buffer))
199 (message-options-get 'message-recipients
)
200 (message-options-set 'message-recipients
201 (read-string "Recipients: ")))
204 (message-options-get 'message-sender
)
205 t t
) ; armor & textmode
206 (unless (> (point-max) (point-min))
207 (pop-to-buffer result-buffer
)
208 (error "Encrypt error"))))
209 (goto-char (point-min))
210 (while (re-search-forward "\r+$" nil t
)
211 (replace-match "" t t
))
213 (delete-region (point-min) (point-max))
214 ;;(insert "Content-Type: application/pgp-encrypted\n\n")
215 ;;(insert "Version: 1\n\n")
217 (insert-buffer-substring cipher
)
218 (goto-char (point-max))))))
222 (defvar pgg-output-buffer
)
223 (defvar pgg-errors-buffer
)
225 (defun mml1991-pgg-sign (cont)
227 ;; Don't sign headers.
228 (goto-char (point-min))
229 (while (not (looking-at "^$"))
231 (unless (eobp) ;; no headers?
232 (setq headers
(buffer-substring (point-min) (point)))
233 (forward-line) ;; skip header/body separator
234 (delete-region (point-min) (point)))
235 (when (string-match "^Content-Transfer-Encoding: \\(.+\\)" headers
)
236 (setq cte
(intern (match-string 1 headers
))))
237 (mm-decode-content-transfer-encoding cte
)
238 (unless (let ((pgg-default-user-id
239 (or (message-options-get 'mml-sender
)
240 pgg-default-user-id
)))
241 (pgg-sign-region (point-min) (point-max) t
))
242 (pop-to-buffer pgg-errors-buffer
)
243 (error "Encrypt error"))
244 (delete-region (point-min) (point-max))
245 (mm-with-unibyte-current-buffer
246 (insert-buffer-substring pgg-output-buffer
)
247 (goto-char (point-min))
248 (while (re-search-forward "\r+$" nil t
)
249 (replace-match "" t t
))
250 (mm-encode-content-transfer-encoding cte
)
251 (goto-char (point-min))
257 (defun mml1991-pgg-encrypt (cont &optional sign
)
259 ;; Strip MIME Content[^ ]: headers since it will be ASCII ARMOURED
260 (goto-char (point-min))
261 (while (looking-at "^Content[^ ]+:")
262 (when (looking-at "^Content-Transfer-Encoding: \\(.+\\)")
263 (setq cte
(intern (match-string 1))))
266 (delete-region (point-min) (point)))
267 (mm-decode-content-transfer-encoding cte
)
268 (unless (pgg-encrypt-region
269 (point-min) (point-max)
272 (message-options-get 'message-recipients
)
273 (message-options-set 'message-recipients
274 (read-string "Recipients: ")))
277 (pop-to-buffer pgg-errors-buffer
)
278 (error "Encrypt error"))
279 (delete-region (point-min) (point-max))
280 ;;(insert "Content-Type: application/pgp-encrypted\n\n")
281 ;;(insert "Version: 1\n\n")
283 (insert-buffer-substring pgg-output-buffer
)
287 (defun mml1991-encrypt (cont &optional sign
)
288 (let ((func (nth 2 (assq mml1991-use mml1991-function-alist
))))
290 (funcall func cont sign
)
291 (error "Cannot find encrypt function"))))
294 (defun mml1991-sign (cont)
295 (let ((func (nth 1 (assq mml1991-use mml1991-function-alist
))))
298 (error "Cannot find sign function"))))
303 ;; coding: iso-8859-1
306 ;;; arch-tag: e542be18-ab28-4393-9b33-97fe9cf30706
307 ;;; mml1991.el ends here