annotate lisp/tm/tm-pgp.el @ 114:8619ce7e4c50 r20-1b9

Import from CVS: tag r20-1b9
author cvs
date Mon, 13 Aug 2007 09:21:54 +0200
parents 0d2f883870bc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1 ;;; tm-pgp.el --- tm-view internal methods for PGP.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
2
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
3 ;; Copyright (C) 1995,1996,1997 MORIOKA Tomohiko
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
6 ;; Created: 1995/12/7
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
7 ;; Version: $Id: tm-pgp.el,v 1.3 1997/02/15 22:21:29 steve Exp $
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
8 ;; Keywords: mail, news, MIME, multimedia, PGP, security
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
9
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
10 ;; This file is part of tm (Tools for MIME).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
11
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
12 ;; This program is free software; you can redistribute it and/or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
13 ;; modify it under the terms of the GNU General Public License as
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
14 ;; published by the Free Software Foundation; either version 2, or (at
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
15 ;; your option) any later version.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
16
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
17 ;; This program is distributed in the hope that it will be useful, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
20 ;; General Public License for more details.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
21
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
26
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
27 ;;; Commentary:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
28
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
29 ;; This module is based on 2 drafts about PGP MIME integration:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
30
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
31 ;; - RFC 2015: "MIME Security with Pretty Good Privacy (PGP)"
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
32 ;; by Michael Elkins <elkins@aero.org> (1996/6)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
33 ;;
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
34 ;; - draft-kazu-pgp-mime-00.txt: "PGP MIME Integration"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
35 ;; by Kazuhiko Yamamoto <kazu@is.aist-nara.ac.jp>
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
36 ;; (1995/10; expired)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
37 ;;
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
38 ;; These drafts may be contrary to each other. You should decide
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
39 ;; which you support. (Maybe you should use PGP/MIME)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
40
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
41 ;;; Code:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
42
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
43 (require 'tm-play)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
44
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
45
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
46 ;;; @ internal method for application/pgp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
47 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
48 ;;; It is based on draft-kazu-pgp-mime-00.txt
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
49
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
50 (defun mime-article/view-application/pgp (beg end cal)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
51 (let* ((cnum (mime-article/point-content-number beg))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
52 (cur-buf (current-buffer))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
53 (p-win (or (get-buffer-window mime::article/preview-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
54 (get-largest-window)))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
55 (new-name (format "%s-%s" (buffer-name) cnum))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
56 (mother mime::article/preview-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
57 (mode major-mode)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
58 code-converter
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
59 (str (buffer-substring beg end))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
60 )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
61 (set-buffer (get-buffer-create new-name))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
62 (erase-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
63 (insert str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
64 (cond ((progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
65 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
66 (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
67 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
68 (funcall (pgp-function 'verify))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
69 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
70 (delete-region
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
71 (point-min)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
72 (and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
73 (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+\n\n")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
74 (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
75 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
76 (delete-region
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
77 (and (re-search-forward "^-+BEGIN PGP SIGNATURE-+")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
78 (match-beginning 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
79 (point-max)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
80 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
81 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
82 (while (re-search-forward "^- -" nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
83 (replace-match "-")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
84 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
85 (setq code-converter
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
86 (or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
87 (cdr (assq mode mime-viewer/code-converter-alist))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
88 (function mime-viewer/default-code-convert-region)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
89 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
90 ((progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
91 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
92 (re-search-forward "^-+BEGIN PGP MESSAGE-+$" nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
93 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
94 (as-binary-process (funcall (pgp-function 'decrypt)))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
95 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
96 (delete-region (point-min)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
97 (and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
98 (search-forward "\n\n")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
99 (match-end 0)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
100 (setq code-converter (function mime-charset/decode-buffer))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
101 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
102 (setq major-mode 'mime/show-message-mode)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
103 (setq mime::article/code-converter code-converter)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
104 (save-window-excursion (mime/viewer-mode mother))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
105 (set-window-buffer p-win mime::article/preview-buffer)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
106 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
107
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
108 (set-atype 'mime/content-decoding-condition
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
109 '((type . "application/pgp")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
110 (method . mime-article/view-application/pgp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
111 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
112
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
113 (set-atype 'mime/content-decoding-condition
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
114 '((type . "text/x-pgp")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
115 (method . mime-article/view-application/pgp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
116 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
117
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
118
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
119 ;;; @ Internal method for application/pgp-signature
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
120 ;;;
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
121 ;;; It is based on RFC 2015.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
122
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
123 (defvar tm-pgp::default-language 'en
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
124 "*Symbol of language for pgp.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
125 It should be ISO 639 2 letter language code such as en, ja, ...")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
126
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
127 (defvar tm-pgp::good-signature-regexp-alist
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
128 '((en . "Good signature from user.*$"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
129 "Alist of language vs regexp to detect ``Good signature''.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
130
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
131 (defvar tm-pgp::key-expected-regexp-alist
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
132 '((en . "Key matching expected Key ID \\(\\S +\\) not found"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
133 "Alist of language vs regexp to detect ``Key expected''.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
134
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
135 (defun mime::article/call-pgp-to-check-signature (output-buffer orig-file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
136 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
137 (set-buffer output-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
138 (erase-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
139 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
140 (let* ((lang (or tm-pgp::default-language 'en))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
141 (status
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
142 (call-process-region (point-min)(point-max)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
143 "pgp" nil output-buffer nil orig-file
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
144 (format "+language=%s" lang)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
145 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
146 (regexp (cdr (assq lang tm-pgp::good-signature-regexp-alist)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
147 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
148 (if (= status 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
149 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
150 (set-buffer output-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
151 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
152 (message
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
153 (cond ((not (stringp regexp))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
154 "Please specify right regexp for specified language")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
155 ((re-search-forward regexp nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
156 (buffer-substring (match-beginning 0) (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
157 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
158 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
159 "Bad signature"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
160 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
161 ))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
162
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
163 (defun mime-article/check-pgp-signature (beg end cal)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
164 (let* ((encoding (cdr (assq 'encoding cal)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
165 (cnum (mime-article/point-content-number beg))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
166 (rcnum (reverse cnum))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
167 (rmcnum (cdr rcnum))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
168 (knum (car rcnum))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
169 (onum (if (> knum 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
170 (1- knum)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
171 (1+ knum)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
172 (oinfo (mime-article/rcnum-to-cinfo (cons onum rmcnum)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
173 mime::article/content-info))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
174 status str kbuf
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
175 (basename (expand-file-name "tm" mime/tmp-dir))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
176 (orig-file (make-temp-name basename))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
177 (sig-file (concat orig-file ".sig"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
178 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
179 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
180 (setq str (buffer-substring
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
181 (mime::content-info/point-min oinfo)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
182 (mime::content-info/point-max oinfo)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
183 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
184 (set-buffer (get-buffer-create mime/temp-buffer-name))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
185 (insert str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
186 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
187 (while (re-search-forward "\n" nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
188 (replace-match "\r\n")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
189 )
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
190 (as-binary-output-file (write-file orig-file))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
191 (kill-buffer (current-buffer))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
192 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
193 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
194 (mime-article/show-output-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
195 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
196 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
197 (setq str (buffer-substring
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
198 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
199 (goto-char beg)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
200 (and (search-forward "\n\n")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
201 (match-end 0)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
202 end))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
203 (set-buffer (setq kbuf (get-buffer-create mime/temp-buffer-name)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
204 (insert str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
205 (mime-decode-region (point-min)(point-max) encoding)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
206 (as-binary-output-file (write-file sig-file))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
207 (or (mime::article/call-pgp-to-check-signature
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
208 mime/output-buffer-name orig-file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
209 (let (pgp-id)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
210 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
211 (set-buffer mime/output-buffer-name)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
212 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
213 (let ((regexp (cdr (assq (or tm-pgp::default-language 'en)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
214 tm-pgp::key-expected-regexp-alist))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
215 (cond ((not (stringp regexp))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
216 (message
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
217 "Please specify right regexp for specified language")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
218 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
219 ((re-search-forward regexp nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
220 (setq pgp-id
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
221 (concat "0x" (buffer-substring-no-properties
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
222 (match-beginning 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
223 (match-end 1))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
224 ))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
225 (if (and pgp-id
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
226 (y-or-n-p
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
227 (format "Key %s not found; attempt to fetch? " pgp-id))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
228 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
229 (progn
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
230 (funcall (pgp-function 'fetch-key) (cons nil pgp-id))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
231 (mime::article/call-pgp-to-check-signature
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
232 mime/output-buffer-name orig-file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
233 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
234 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
235 (let ((other-window-scroll-buffer mime/output-buffer-name))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
236 (scroll-other-window 8)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
237 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
238 (kill-buffer kbuf)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
239 (delete-file orig-file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
240 (delete-file sig-file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
241 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
242
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
243 (set-atype 'mime/content-decoding-condition
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
244 '((type . "application/pgp-signature")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
245 (method . mime-article/check-pgp-signature)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
246 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
247
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
248
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
249 ;;; @ Internal method for application/pgp-encrypted
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
250 ;;;
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
251 ;;; It is based on RFC 2015.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
252
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
253 (defun mime-article/decrypt-pgp (beg end cal)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
254 (let* ((cnum (mime-article/point-content-number beg))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
255 (rcnum (reverse cnum))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
256 (rmcnum (cdr rcnum))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
257 (knum (car rcnum))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
258 (onum (if (> knum 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
259 (1- knum)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
260 (1+ knum)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
261 (oinfo (mime-article/rcnum-to-cinfo (cons onum rmcnum)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
262 mime::article/content-info))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
263 (obeg (mime::content-info/point-min oinfo))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
264 (oend (mime::content-info/point-max oinfo))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
265 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
266 (mime-article/view-application/pgp obeg oend cal)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
267 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
268
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
269 (set-atype 'mime/content-decoding-condition
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
270 '((type . "application/pgp-encrypted")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
271 (method . mime-article/decrypt-pgp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
272 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
273
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
274
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
275 ;;; @ Internal method for application/pgp-keys
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
276 ;;;
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
277 ;;; It is based on RFC 2015.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
278
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
279 (defun mime-article/add-pgp-keys (beg end cal)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
280 (let* ((cnum (mime-article/point-content-number beg))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
281 (cur-buf (current-buffer))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
282 (new-name (format "%s-%s" (buffer-name) cnum))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
283 (mother mime::article/preview-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
284 (charset (cdr (assoc "charset" cal)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
285 (encoding (cdr (assq 'encoding cal)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
286 (mode major-mode)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
287 str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
288 (setq str (buffer-substring beg end))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
289 (switch-to-buffer new-name)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
290 (setq buffer-read-only nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
291 (erase-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
292 (insert str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
293 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
294 (if (re-search-forward "^\n" nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
295 (delete-region (point-min) (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
296 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
297 (mime-decode-region (point-min)(point-max) encoding)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 76
diff changeset
298 (funcall (pgp-function 'snarf-keys))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
299 (kill-buffer (current-buffer))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
300 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
301
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
302 (set-atype 'mime/content-decoding-condition
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
303 '((type . "application/pgp-keys")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
304 (method . mime-article/add-pgp-keys)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
305 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
306
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
307
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
308 ;;; @ end
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
309 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
310
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
311 (provide 'tm-pgp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
312
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
313 (run-hooks 'tm-pgp-load-hook)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
314
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
315 ;;; tm-pgp.el ends here