annotate lisp/tm/tm-edit-mc.el @ 76:c0c698873ce1 r20-0b33

Import from CVS: tag r20-0b33
author cvs
date Mon, 13 Aug 2007 09:05:10 +0200
parents 131b0175ea99
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-edit-mc.el --- Mailcrypt interface for tm-edit
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
2
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996 MORIOKA Tomohiko
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>
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 70
diff changeset
6 ;; Version: $Id: tm-edit-mc.el,v 1.2 1996/12/28 21:03:13 steve Exp $
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
7 ;; Keywords: mail, news, MIME, multimedia, multilingual, security, PGP
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
8
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
9 ;; This file is part of tm (Tools for MIME).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
10
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
11 ;; This program is free software; you can redistribute it and/or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
12 ;; modify it under the terms of the GNU General Public License as
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
13 ;; published by the Free Software Foundation; either version 2, or (at
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
14 ;; your option) any later version.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
15
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
16 ;; This program is distributed in the hope that it will be useful, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
19 ;; General Public License for more details.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
20
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
25
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
26 ;;; Code:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
27
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
28 (require 'mailcrypt)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
29 (load "mc-pgp")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
30
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
31 (defun tm:mc-pgp-generic-parser (result)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
32 (let ((ret (mc-pgp-generic-parser result)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
33 (if (consp ret)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
34 (vector (car ret)(cdr ret))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
35 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
36
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
37 (defun tm:mc-process-region
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
38 (beg end passwd program args parser &optional buffer boundary)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
39 (let ((obuf (current-buffer))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
40 (process-connection-type nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
41 mybuf result rgn proc)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
42 (unwind-protect
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
43 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
44 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
45 (set-buffer mybuf)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
46 (erase-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
47 (set-buffer obuf)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
48 (buffer-disable-undo mybuf)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
49 (setq proc
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
50 (apply 'start-process "*PGP*" mybuf program args))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
51 (if passwd
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
52 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
53 (process-send-string proc (concat passwd "\n"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
54 (or mc-passwd-timeout (mc-deactivate-passwd t))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
55 (process-send-region proc beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
56 (process-send-eof proc)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
57 (while (eq 'run (process-status proc))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
58 (accept-process-output proc 5))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
59 (setq result (process-exit-status proc))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
60 ;; Hack to force a status_notify() in Emacs 19.29
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
61 (delete-process proc)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
62 (set-buffer mybuf)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
63 (goto-char (point-max))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
64 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
65 (delete-region (match-beginning 0) (match-end 0)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
66 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
67 ;; CRNL -> NL
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
68 (while (search-forward "\r\n" nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
69 (replace-match "\n"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
70 ;; Hurm. FIXME; must get better result codes.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
71 (if (stringp result)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
72 (error "%s exited abnormally: '%s'" program result)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
73 (setq rgn (funcall parser result))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
74 ;; If the parser found something, migrate it
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
75 (if (consp rgn)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
76 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
77 (set-buffer obuf)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
78 (if boundary
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
79 (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
80 (narrow-to-region beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
81 (goto-char beg)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
82 (insert (format "--%s\n" boundary))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
83 (goto-char (point-max))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
84 (insert (format "\n--%s
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
85 Content-Type: application/pgp-signature
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
86 Content-Transfer-Encoding: 7bit
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
87
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
88 " boundary))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
89 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
90 (goto-char (point-max))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
91 (insert (format "\n--%s--\n" boundary))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
92 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
93 (delete-region beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
94 (goto-char beg)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
95 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
96 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
97 (set-buffer mybuf)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
98 (delete-region (car rgn) (cdr rgn)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
99 ;; Return nil on failure and exit code on success
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
100 (if rgn result))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
101 ;; Cleanup even on nonlocal exit
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
102 (if (and proc (eq 'run (process-status proc)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
103 (interrupt-process proc))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
104 (set-buffer obuf)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
105 (or buffer (null mybuf) (kill-buffer mybuf)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
106
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
107 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
108 ;; (if (not (boundp 'mc-pgp-user-id))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
109 ;; (load "mc-pgp")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
110 ;; )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
111 (let ((process-environment process-environment)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
112 (buffer (get-buffer-create mc-buffer-name))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
113 passwd args key
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
114 (parser (function mc-pgp-generic-parser))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
115 (pgp-path mc-pgp-path)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
116 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
117 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
118 (setq passwd
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
119 (mc-activate-passwd
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
120 (cdr key)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
121 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
122 (setenv "PGPPASSFD" "0")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
123 (setq args
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
124 (cons
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
125 (if boundary
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
126 "-fbast"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
127 "-fast")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
128 (list "+verbose=1" "+language=en"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
129 (format "+clearsig=%s" (if unclear "off" "on"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
130 "+batchmode" "-u" (cdr key))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
131 (if mc-pgp-comment
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
132 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
133 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
134 (message "Signing as %s ..." (car key))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
135 (if (tm:mc-process-region
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
136 start end passwd pgp-path args parser buffer boundary)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
137 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
138 (if boundary
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
139 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
140 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
141 (insert
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
142 (format "\
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
143 --[[multipart/signed; protocol=\"application/pgp-signature\";
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
144 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
145 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
146 (message "Signing as %s ... Done." (car key))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
147 t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
148 nil)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
149
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
150 (defun tm:mc-pgp-encrypt-region (recipients start end &optional id sign)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
151 (let ((mc-pgp-always-sign (if (eq sign 'maybe)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
152 mc-pgp-always-sign
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
153 'never)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
154 (mc-pgp-encrypt-region
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
155 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
156 start end id nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
157 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
158
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
159
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
160 ;;; @ end
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 (provide 'tm-edit-mc)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
164
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
165 ;;; tm-edit-mc.el ends here