*** empty log message ***
[gnus] / lisp / pgg.el
1 ;;; pgg.el --- glue for the various PGP implementations.
2
3 ;; Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
4
5 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; Created: 1999/10/28
7 ;; Keywords: PGP
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (require 'pgg-def)
31 (require 'pgg-parse)
32 (autoload 'run-at-time "timer")
33
34 ;; Don't merge these two `eval-when-compile's.
35 (eval-when-compile
36   (require 'cl))
37 ;; Fixme: This would be better done with an autoload for
38 ;; `url-insert-file-contents', and the url stuff rationalized.
39 ;; (`locate-library' can say whether the url code is available.)
40 (eval-when-compile
41   (ignore-errors
42     (require 'w3)
43     (require 'url)))
44
45 ;; Fixme: Avoid this and use mm-make-temp-file (especially for
46 ;; something sensitive like pgp).
47 (defvar pgg-temporary-file-directory
48   (cond ((fboundp 'temp-directory) (temp-directory))
49         ((boundp 'temporary-file-directory) temporary-file-directory)
50         ("/tmp/")))
51
52 ;;; @ utility functions
53 ;;;
54
55 (defvar pgg-fetch-key-function (if (fboundp 'url-insert-file-contents)
56                                    (function pgg-fetch-key-with-w3)))
57
58 (defun pgg-invoke (func scheme &rest args)
59   (progn
60     (require (intern (format "pgg-%s" scheme)))
61     (apply 'funcall (intern (format "pgg-%s-%s" scheme func)) args)))
62
63 (put 'pgg-save-coding-system 'lisp-indent-function 2)
64
65 (defmacro pgg-save-coding-system (start end &rest body)
66   `(if (interactive-p)
67        (let ((buffer (current-buffer)))
68          (with-temp-buffer
69            (let (buffer-undo-list)
70              (insert-buffer-substring buffer ,start ,end)
71              (encode-coding-region (point-min)(point-max)
72                                    buffer-file-coding-system)
73              (prog1 (save-excursion ,@body)
74                (push nil buffer-undo-list)
75                (ignore-errors (undo))))))
76      (save-restriction
77        (narrow-to-region ,start ,end)
78        ,@body)))
79
80 (defun pgg-temp-buffer-show-function (buffer)
81   (let ((window (split-window-vertically)))
82     (set-window-buffer window buffer)
83     (shrink-window-if-larger-than-buffer window)))
84
85 (defun pgg-display-output-buffer (start end status)
86   (if status
87       (progn
88         (delete-region start end)
89         (insert-buffer-substring pgg-output-buffer)
90         (decode-coding-region start (point) buffer-file-coding-system))
91     (let ((temp-buffer-show-function
92            (function pgg-temp-buffer-show-function)))