New revision.
[gnus] / lisp / mml-smime.el
1 ;;; mml-smime.el --- S/MIME support for MML
2 ;; Copyright (c) 2000 Free Software Foundation, Inc.
3
4 ;; Author: Simon Josefsson <simon@josefsson.org>
5 ;; Keywords: Gnus, MIME, SMIME, MML
6
7 ;; This file is a part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 ;; General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;; This support creation of S/MIME parts in MML.
27
28 ;; Usage:
29 ;;    (mml-smime-setup)
30 ;; 
31 ;; Insert an attribute, postprocess=smime-sign (or smime-encrypt), into
32 ;; the mml tag to be signed (or encrypted).
33 ;;
34 ;; It is based on rfc2015.el by Shenghuo Zhu.
35
36 ;;; Code:
37
38 (require 'smime)
39
40 (defun mml-smime-sign (cont)
41   ;; FIXME: You have to input the sender.
42   (when (null smime-keys)
43     (error "Please use M-x customize RET smime RET to configure SMIME"))
44   (smime-sign-buffer)
45   (goto-char (point-min))
46   (when (looking-at "^MIME-Version: 1.0")
47     (forward-line 1)
48     (delete-region (point-min) (point)))
49   (goto-char (point-max)))
50   
51 (defun mml-smime-encrypt (cont)
52   ;; FIXME: You have to input the receiptant.
53   ;; FIXME: Should encrypt to myself so I can read it??
54   (smime-encrypt-buffer)
55   (goto-char (point-min))
56   (when (looking-at "^MIME-Version: 1.0")
57     (forward-line 1)
58     (delete-region (point-min) (point)))
59   (goto-char (point-max)))
60
61 ;; The following code might be moved into mml.el or gnus-art.el.
62
63 (defvar mml-postprocess-alist
64   '(("smime-sign" . mml-smime-sign)
65     ("smime-encrypt" . mml-smime-encrypt))
66   "Alist of postprocess functions.")
67
68 (defun mml-postprocess (cont)
69   (let ((pp (cdr (or (assq 'postprocess cont)
70                      (assq 'pp cont))))
71         item)
72     (if (and pp (setq item (assoc pp mml-postprocess-alist)))
73         (funcall (cdr item) cont))))
74
75 (defun mml-smime-setup ()
76   (setq mml-generate-mime-postprocess-function 'mml-postprocess))
77
78 (provide 'mml-smime)
79
80 ;;; mml-smime.el ends here