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 ("pgpmime" mml-pgpmime-sign-buffer list))
34 "Alist of MIME signer functions.")
36 (defvar mml-default-sign-method (caar mml-sign-alist)
37 "Default sign method.")
39 (defvar mml-encrypt-alist
40 '(("smime" mml-smime-encrypt-buffer mml-smime-encrypt-query)
41 ("pgpmime" mml-pgpmime-encrypt-buffer list))
42 "Alist of MIME encryption functions.")
44 (defvar mml-default-encrypt-method (caar mml-encrypt-alist)
45 "Default encryption method.")
47 ;;; Security functions
49 (defun mml-smime-sign-buffer (cont)
50 (or (mml-smime-sign cont)
51 (error "Signing failed... inspect message logs for errors")))
53 (defun mml-smime-encrypt-buffer (cont)
54 (or (mml-smime-encrypt cont)
55 (error "Encryption failed... inspect message logs for errors")))
57 (defun mml-pgpmime-sign-buffer (cont)
58 (or (mml2015-sign cont)
59 (error "Signing failed... inspect message logs for errors")))
61 (defun mml-pgpmime-encrypt-buffer (cont)
62 (or (mml2015-encrypt cont)
63 (error "Encryption failed... inspect message logs for errors")))
65 (defun mml-secure-part (method &optional sign)
67 (let ((tags (funcall (nth 2 (assoc method (if sign mml-sign-alist
68 mml-encrypt-alist))))))
69 (cond ((re-search-backward
70 "<#\\(multipart\\|part\\|external\\|mml\\)" nil t)
71 (goto-char (match-end 0))
72 (insert (if sign " sign=" " encrypt=") method)
74 (let ((key (pop tags))
77 ;; Quote VALUE if it contains suspicious characters.
78 (when (string-match "[\"'\\~/*;() \t\n]" value)
79 (setq value (prin1-to-string value)))
80 (insert (format " %s=%s" key value))))))
81 ((or (re-search-backward
82 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
84 (concat "^" (regexp-quote mail-header-separator) "\n") nil t))
85 (goto-char (match-end 0))
86 (apply 'mml-insert-tag 'part (cons (if sign 'sign 'encrypt)
88 (t (error "The message is corrupted. No mail header separator."))))))
90 (defun mml-secure-sign-pgpmime ()
91 "Add MML tags to PGP/MIME sign this MML part."
93 (mml-secure-part "pgpmime" 'sign))
95 (defun mml-secure-sign-smime ()
96 "Add MML tags to S/MIME sign this MML part."
98 (mml-secure-part "smime" 'sign))
100 (defun mml-secure-encrypt-pgpmime ()
101 "Add MML tags to PGP/MIME encrypt this MML part."
103 (mml-secure-part "pgpmime"))
105 (defun mml-secure-encrypt-smime ()
106 "Add MML tags to S/MIME encrypt this MML part."
108 (mml-secure-part "smime"))
112 ;;; mml-sec.el ends here