1 ;;; mml1991.el --- Old PGP message format (RFC 1991) support for MML
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; Author: Sascha Ldecke <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 2, 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)
233 ;; Don't sign headers.
234 (goto-char (point-min))
235 (while (not (looking-at "^$"))
237 (unless (eobp) ;; no headers?
238 (setq headers (buffer-substring (point-min) (point)))
239 (forward-line) ;; skip header/body separator
240 (delete-region (point-min) (point)))
241 (when (string-match "^Content-Transfer-Encoding: \\(.+\\)" headers)
242 (setq cte (intern (match-string 1 headers))))
243 (mm-decode-content-transfer-encoding cte)
244 (unless (let ((pgg-default-user-id
245 (or (message-options-get 'mml-sender)
246 pgg-default-user-id)))
247 (pgg-sign-region (point-min) (point-max) t))
248 (pop-to-buffer pgg-errors-buffer)
249 (error "Encrypt error"))
250 (delete-region (point-min) (point-max))
251 (mm-with-unibyte-current-buffer
252 (insert-buffer-substring pgg-output-buffer)
253 (goto-char (point-min))
254 (while (re-search-forward "\r+$" nil t)
255 (replace-match "" t t))
256 (mm-encode-content-transfer-encoding cte)
257 (goto-char (point-min))
263 (defun mml1991-pgg-encrypt (cont &optional sign)
265 ;; Strip MIME Content[^ ]: headers since it will be ASCII ARMOURED
266 (goto-char (point-min))
267 (while (looking-at "^Content[^ ]+:")
268 (when (looking-at "^Content-Transfer-Encoding: \\(.+\\)")
269 (setq cte (intern (match-string 1))))
272 (delete-region (point-min) (point)))
273 (mm-decode-content-transfer-encoding cte)
274 (unless (pgg-encrypt-region
275 (point-min) (point-max)
278 (message-options-get 'message-recipients)
279 (message-options-set 'message-recipients
280 (read-string "Recipients: ")))
283 (pop-to-buffer pgg-errors-buffer)
284 (error "Encrypt error"))
285 (delete-region (point-min) (point-max))
286 ;;(insert "Content-Type: application/pgp-encrypted\n\n")
287 ;;(insert "Version: 1\n\n")
289 (insert-buffer-substring pgg-output-buffer)
293 (defun mml1991-encrypt (cont &optional sign)
294 (let ((func (nth 2 (assq mml1991-use mml1991-function-alist))))
296 (funcall func cont sign)
297 (error "Cannot find encrypt function"))))
300 (defun mml1991-sign (cont)
301 (let ((func (nth 1 (assq mml1991-use mml1991-function-alist))))
304 (error "Cannot find sign function"))))
309 ;; coding: iso-8859-1
312 ;;; mml1991.el ends here