1 ;;; mml-gpg-old.el --- Old PGP message format (RFC 1991) support for MML
2 ;; Copyright (C) 1998, 1999, 2000, 2001 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 (not yet) 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.
27 ;; RCS: $Id: mml1991.el,v 6.11 2002/10/05 05:31:37 jas Exp $
31 (defvar mml1991-use mml2015-use
32 "The package used for PGP.")
34 (defvar mml1991-function-alist
35 '((mailcrypt mml1991-mailcrypt-sign
36 mml1991-mailcrypt-encrypt)
41 "Alist of PGP functions.")
46 (autoload 'mc-sign-generic "mc-toplev"))
48 (defvar mml1991-decrypt-function 'mailcrypt-decrypt)
49 (defvar mml1991-verify-function 'mailcrypt-verify)
51 (defun mml1991-mailcrypt-sign (cont)
52 (let ((text (current-buffer))
54 (result-buffer (get-buffer-create "*GPG Result*")))
55 ;; Save MIME Content[^ ]+: headers from signing
56 (goto-char (point-min))
57 (while (looking-at "^Content[^ ]+:") (forward-line))
58 (if (> (point) (point-min))
60 (setq headers (buffer-substring (point-min) (point)))
61 (kill-region (point-min) (point))))
62 (goto-char (point-max))
65 (quoted-printable-decode-region (point-min) (point-max))
67 (setq signature (current-buffer))
69 (unless (mc-sign-generic (message-options-get 'message-sender)
71 (unless (> (point-max) (point-min))
72 (pop-to-buffer result-buffer)
73 (error "Sign error")))
74 (goto-char (point-min))
75 (while (re-search-forward "\r+$" nil t)
76 (replace-match "" t t))
77 (quoted-printable-encode-region (point-min) (point-max))
79 (kill-region (point-min) (point-max))
80 (if headers (insert headers))
82 (insert-buffer signature)
83 (goto-char (point-max)))))
85 (defun mml1991-mailcrypt-encrypt (cont)
86 (let ((text (current-buffer))
88 (result-buffer (get-buffer-create "*GPG Result*")))
89 ;; Strip MIME Content[^ ]: headers since it will be ASCII ARMOURED
90 (goto-char (point-min))
91 (while (looking-at "^Content[^ ]+:") (forward-line))
92 (if (> (point) (point-min))
94 (kill-region (point-min) (point))))
95 (mm-with-unibyte-current-buffer-mule4
97 (setq cipher (current-buffer))
99 (unless (mc-encrypt-generic
101 (message-options-get 'message-recipients)
102 (message-options-set 'message-recipients
103 (read-string "Recipients: ")))
105 (point-min) (point-max)
106 (message-options-get 'message-sender)
108 (unless (> (point-max) (point-min))
109 (pop-to-buffer result-buffer)
110 (error "Encrypt error")))
111 (goto-char (point-min))
112 (while (re-search-forward "\r+$" nil t)
113 (replace-match "" t t))
115 (kill-region (point-min) (point-max))
116 ;;(insert "Content-Type: application/pgp-encrypted\n\n")
117 ;;(insert "Version: 1\n\n")
119 (insert-buffer cipher)
120 (goto-char (point-max))))))
125 (autoload 'gpg-sign-cleartext "gpg"))
127 (defun mml1991-gpg-sign (cont)
128 (let ((text (current-buffer))
130 (result-buffer (get-buffer-create "*GPG Result*")))
131 ;; Save MIME Content[^ ]+: headers from signing
132 (goto-char (point-min))
133 (while (looking-at "^Content[^ ]+:") (forward-line))
134 (if (> (point) (point-min))
136 (setq headers (buffer-substring (point-min) (point)))
137 (kill-region (point-min) (point))))
138 (goto-char (point-max))
141 (quoted-printable-decode-region (point-min) (point-max))
143 (unless (gpg-sign-cleartext text (setq signature (current-buffer))
146 (message-options-get 'message-sender))
147 (unless (> (point-max) (point-min))
148 (pop-to-buffer result-buffer)
149 (error "Sign error")))
150 (goto-char (point-min))
151 (while (re-search-forward "\r+$" nil t)
152 (replace-match "" t t))
153 (quoted-printable-encode-region (point-min) (point-max))
155 (kill-region (point-min) (point-max))
156 (if headers (insert headers))
158 (insert-buffer signature)
159 (goto-char (point-max)))))
161 (defun mml1991-gpg-encrypt (cont)
162 (let ((text (current-buffer))
164 (result-buffer (get-buffer-create "*GPG Result*")))
165 ;; Strip MIME Content[^ ]: headers since it will be ASCII ARMOURED
166 (goto-char (point-min))
167 (while (looking-at "^Content[^ ]+:") (forward-line))
168 (if (> (point) (point-min))
170 (kill-region (point-min) (point))))
171 (mm-with-unibyte-current-buffer-mule4
173 (unless (gpg-sign-encrypt
174 text (setq cipher (current-buffer))
178 (message-options-get 'message-recipients)
179 (message-options-set 'message-recipients
180 (read-string "Recipients: ")))
183 (message-options-get 'message-sender)
184 t t) ; armor & textmode
185 (unless (> (point-max) (point-min))
186 (pop-to-buffer result-buffer)
187 (error "Encrypt error")))
188 (goto-char (point-min))
189 (while (re-search-forward "\r+$" nil t)
190 (replace-match "" t t))
192 (kill-region (point-min) (point-max))
193 ;;(insert "Content-Type: application/pgp-encrypted\n\n")
194 ;;(insert "Version: 1\n\n")
196 (insert-buffer cipher)
197 (goto-char (point-max))))))
201 (defvar pgg-output-buffer)
202 (defvar pgg-errors-buffer)
204 (defun mml1991-pgg-sign (cont)
206 ;; Don't sign headers.
207 (goto-char (point-min))
208 (while (not (looking-at "^$"))
210 (unless (eobp) ;; no headers?
211 (setq headers (buffer-substring (point-min) (point)))
212 (forward-line) ;; skip header/body separator
213 (kill-region (point-min) (point)))
214 (quoted-printable-decode-region (point-min) (point-max))
215 (unless (let ((pgg-default-user-id (message-options-get 'message-sender)))
216 (pgg-sign-region (point-min) (point-max) t))
217 (pop-to-buffer pgg-errors-buffer)
218 (error "Encrypt error"))
219 (kill-region (point-min) (point-max))
220 (insert-buffer pgg-output-buffer)
221 (quoted-printable-encode-region (point-min) (point-max))
222 (goto-char (point-min))
223 (if headers (insert headers))
227 (defun mml1991-pgg-encrypt (cont)
229 ;; Don't sign headers.
230 (goto-char (point-min))
231 (while (not (looking-at "^$"))
233 (unless (eobp) ;; no headers?
234 (setq headers (buffer-substring (point-min) (point)))
235 (forward-line) ;; skip header/body separator
236 (kill-region (point-min) (point)))
237 (unless (pgg-encrypt-region
238 (point-min) (point-max)
241 (message-options-get 'message-recipients)
242 (message-options-set 'message-recipients
243 (read-string "Recipients: ")))
245 (pop-to-buffer pgg-errors-buffer)
246 (error "Encrypt error"))
247 (kill-region (point-min) (point-max))
248 (if headers (insert headers))
250 (insert-buffer pgg-output-buffer)
254 (defun mml1991-encrypt (cont)
255 (let ((func (nth 2 (assq mml1991-use mml1991-function-alist))))
258 (error "Cannot find encrypt function"))))
261 (defun mml1991-sign (cont)
262 (let ((func (nth 1 (assq mml1991-use mml1991-function-alist))))
265 (error "Cannot find sign function"))))
270 ;; coding: iso-8859-1
273 ;;; mml1991.el ends here