1 ;;; mml-sec.el --- A package with security functions for MML documents
2 ;; Copyright (C) 2000 Free Software Foundation, Inc.
4 ;; Author: Simon Josefsson <simon@josefsson.org>
5 ;; This file is not part of GNU Emacs, but the same permissions apply.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
31 (defvar mml-sign-alist
32 '(("smime" mml-smime-sign-buffer mml-smime-sign-query)
33 ("pgp" mml-pgp-sign-buffer list)
34 ("pgpmime" mml-pgpmime-sign-buffer list))
35 "Alist of MIME signer functions.")
37 (defvar mml-default-sign-method (caar mml-sign-alist)
38 "Default sign method.")
40 (defvar mml-encrypt-alist
41 '(("smime" mml-smime-encrypt-buffer mml-smime-encrypt-query)
42 ("pgp" mml-pgp-encrypt-buffer list)
43 ("pgpmime" mml-pgpmime-encrypt-buffer list))
44 "Alist of MIME encryption functions.")
46 (defvar mml-default-encrypt-method (caar mml-encrypt-alist)
47 "Default encryption method.")
49 ;;; Security functions
51 (defun mml-smime-sign-buffer (cont)
52 (or (mml-smime-sign cont)
53 (error "Signing failed... inspect message logs for errors")))
55 (defun mml-smime-encrypt-buffer (cont)
56 (or (mml-smime-encrypt cont)
57 (error "Encryption failed... inspect message logs for errors")))
59 (defun mml-pgp-sign-buffer (cont)
60 (or (mml1991-sign cont)
61 (error "Signing failed... inspect message logs for errors")))
63 (defun mml-pgp-encrypt-buffer (cont)
64 (or (mml1991-encrypt cont)
65 (error "Encryption failed... inspect message logs for errors")))
67 (defun mml-pgpmime-sign-buffer (cont)
68 (or (mml2015-sign cont)
69 (error "Signing failed... inspect message logs for errors")))
71 (defun mml-pgpmime-encrypt-buffer (cont)
72 (or (mml2015-encrypt cont)
73 (error "Encryption failed... inspect message logs for errors")))
75 (defun mml-secure-part (method &optional sign)
77 (let ((tags (funcall (nth 2 (assoc method (if sign mml-sign-alist
78 mml-encrypt-alist))))))
79 (cond ((re-search-backward
80 "<#\\(multipart\\|part\\|external\\|mml\\)" nil t)
81 (goto-char (match-end 0))
82 (insert (if sign " sign=" " encrypt=") method)
84 (let ((key (pop tags))
87 ;; Quote VALUE if it contains suspicious characters.
88 (when (string-match "[\"'\\~/*;() \t\n]" value)
89 (setq value (prin1-to-string value)))
90 (insert (format " %s=%s" key value))))))
91 ((or (re-search-backward
92 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
94 (concat "^" (regexp-quote mail-header-separator) "\n") nil t))
95 (goto-char (match-end 0))
96 (apply 'mml-insert-tag 'part (cons (if sign 'sign 'encrypt)
98 (t (error "The message is corrupted. No mail header separator"))))))
100 (defun mml-secure-sign-pgp ()
101 "Add MML tags to PGP sign this MML part."
103 (mml-secure-part "pgp" 'sign))
105 (defun mml-secure-sign-pgpmime ()
106 "Add MML tags to PGP/MIME sign this MML part."
108 (mml-secure-part "pgpmime" 'sign))
110 (defun mml-secure-sign-smime ()
111 "Add MML tags to S/MIME sign this MML part."
113 (mml-secure-part "smime" 'sign))
115 (defun mml-secure-encrypt-pgp ()
116 "Add MML tags to PGP encrypt this MML part."
118 (mml-secure-part "pgp"))
120 (defun mml-secure-encrypt-pgpmime ()
121 "Add MML tags to PGP/MIME encrypt this MML part."
123 (mml-secure-part "pgpmime"))
125 (defun mml-secure-encrypt-smime ()
126 "Add MML tags to S/MIME encrypt this MML part."
128 (mml-secure-part "smime"))
132 ;;; mml-sec.el ends here