2 ;;; tm-pgp.el --- tm-view internal methods for PGP.
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1995 MORIOKA Tomohiko
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
11 ;;; $Id: tm-pgp.el,v 7.6 1995/12/23 10:16:40 morioka Exp $
12 ;;; Keywords: mail, news, MIME, multimedia, PGP, security
14 ;;; This file is part of tm (Tools for MIME).
16 ;;; This program is free software; you can redistribute it and/or
17 ;;; modify it under the terms of the GNU General Public License as
18 ;;; published by the Free Software Foundation; either version 2, or
19 ;;; (at your option) any later version.
21 ;;; This program is distributed in the hope that it will be useful,
22 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 ;;; General Public License for more details.
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with This program. If not, write to the Free Software
28 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
31 ;;; This module is based on 2 drafts about PGP MIME integration:
32 ;;; - draft-elkins-pem-pgp-02.txt
33 ;;; ``MIME Security with Pretty Good Privacy (PGP)''
34 ;;; by Michael Elkins <elkins@aero.org> (1995/11)
35 ;;; - draft-kazu-pgp-mime-00.txt
36 ;;; ``PGP MIME Integration''
37 ;;; by Kazuhiko Yamamoto <kazu@is.aist-nara.ac.jp> (1995/10)
38 ;;; These drafts may be contrary to each other. You should decide
39 ;;; which you support.
47 ;;; @ internal method for application/pgp
49 ;;; It is based on draft-kazu-pgp-mime-00.txt
51 (defun mime-article/view-application/pgp (beg end cal)
52 (let* ((cnum (mime-article/point-content-number beg))
53 (cur-buf (current-buffer))
54 (new-name (format "%s-%s" (buffer-name) cnum))
55 (mother mime::article/preview-buffer)
57 (or (cdr (assq major-mode mime-viewer/code-converter-alist))
58 'mime-viewer/default-code-convert-region))
60 (setq str (buffer-substring beg end))
61 (switch-to-buffer new-name)
65 (goto-char (point-min))
66 (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t)
69 (goto-char (point-min))
73 (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+\n\n")
77 (and (re-search-forward "^-+BEGIN PGP SIGNATURE-+")
81 (goto-char (point-min))
82 (while (re-search-forward "^- -" nil t)
87 (goto-char (point-min))
88 (re-search-forward "^-+BEGIN PGP MESSAGE-+$" nil t)
91 (goto-char (point-min))
92 (delete-region (point-min)
94 (search-forward "\n\n")
97 (setq major-mode 'mime/show-message-mode)
98 (setq mime::article/code-converter code-converter)
99 (mime/viewer-mode mother)
102 (set-atype 'mime/content-decoding-condition
103 '((type . "application/pgp")
104 (method . mime-article/view-application/pgp)
107 (set-atype 'mime/content-decoding-condition
108 '((type . "text/x-pgp")
109 (method . mime-article/view-application/pgp)
113 ;;; @ Internal method for application/pgp-signature
115 ;;; It is based on draft-elkins-pem-pgp-02.txt
117 (defun mime-article/check-pgp-signature (beg end cal)
118 (let* ((encoding (cdr (assq 'encoding cal)))
119 (cnum (mime-article/point-content-number beg))
120 (rcnum (reverse cnum))
126 (oinfo (mime-article/rcnum-to-cinfo (cons onum rmcnum)
127 mime::article/content-info))
129 (basename (expand-file-name "tm" mime/tmp-dir))
130 (orig-file (make-temp-name basename))
131 (sig-file (concat orig-file ".sig"))
134 (setq str (buffer-substring
135 (mime::content-info/point-min oinfo)
136 (mime::content-info/point-max oinfo)
138 (set-buffer (get-buffer-create mime/temp-buffer-name))
140 (goto-char (point-min))
141 (while (re-search-forward "\n" nil t)
142 (replace-match "\r\n")
144 (let ((mc-flag nil) ; for Mule
146 (if (featurep 'mule) *noconv*))
147 kanji-flag ; for NEmacs
148 (emx-binary-mode t) ; for OS/2
149 jka-compr-compression-info-list ; for jka-compr
150 jam-zcat-filename-list ; for jam-zcat
151 require-final-newline)
152 (write-file orig-file)
154 (kill-buffer (current-buffer))
157 (setq str (buffer-substring
160 (and (search-forward "\n\n")
163 (set-buffer (setq kbuf (get-buffer-create mime/temp-buffer-name)))
165 (mime/decode-region encoding (point-min)(point-max))
166 (let ((mc-flag nil) ; for Mule
168 (if (featurep 'mule) *noconv*))
169 kanji-flag ; for NEmacs
170 (emx-binary-mode t) ; for OS/2
171 jka-compr-compression-info-list ; for jka-compr
172 jam-zcat-filename-list ; for jam-zcat
173 require-final-newline)
174 (write-file sig-file)
176 ;;(define-program-coding-system (current-buffer) "pgp" *noconv*)
177 (mime-article/show-output-buffer)
179 (call-process-region (point-min)(point-max)
181 nil mime/output-buffer-name nil
184 (let ((other-window-scroll-buffer mime/output-buffer-name))
185 (scroll-other-window 8)
188 ;; (message "Good signature!")
189 ;; (message "Bad signature!")
191 (delete-file orig-file)
192 (delete-file sig-file)
195 (set-atype 'mime/content-decoding-condition
196 '((type . "application/pgp-signature")
197 (method . mime-article/check-pgp-signature)
201 ;;; @ Internal method for application/pgp-encrypted
203 ;;; It is based on draft-elkins-pem-pgp-02.txt
205 (defun mime-article/decrypt-pgp (beg end cal)
206 (let* ((cnum (mime-article/point-content-number beg))
207 (rcnum (reverse cnum))
213 (oinfo (mime-article/rcnum-to-cinfo (cons onum rmcnum)
214 mime::article/content-info))
215 (obeg (mime::content-info/point-min oinfo))
216 (oend (mime::content-info/point-max oinfo))
218 (mime-article/view-application/pgp obeg oend cal)
221 (set-atype 'mime/content-decoding-condition
222 '((type . "application/pgp-encrypted")
223 (method . mime-article/decrypt-pgp)
227 ;;; @ Internal method for application/pgp-keys
229 ;;; It is based on draft-elkins-pem-pgp-02.txt
231 (autoload 'mc-snarf-keys "mc-toplev")
233 (defun mime-article/add-pgp-keys (beg end cal)
234 (let* ((cnum (mime-article/point-content-number beg))
235 (cur-buf (current-buffer))
236 (new-name (format "%s-%s" (buffer-name) cnum))
237 (mother mime::article/preview-buffer)
238 (charset (cdr (assoc "charset" cal)))
239 (encoding (cdr (assq 'encoding cal)))
242 (setq str (buffer-substring beg end))
243 (switch-to-buffer new-name)
244 (setq buffer-read-only nil)
247 (goto-char (point-min))
248 (if (re-search-forward "^\n" nil t)
249 (delete-region (point-min) (match-end 0))
251 (mime/decode-region encoding (point-min)(point-max))
253 (kill-buffer (current-buffer))
256 (set-atype 'mime/content-decoding-condition
257 '((type . "application/pgp-keys")
258 (method . mime-article/add-pgp-keys)