plstore.el (plstore-passphrase-callback-function): Use plstore-get-file
[gnus] / lisp / mml2015.el
1 ;;; mml2015.el --- MIME Security with Pretty Good Privacy (PGP)
2
3 ;; Copyright (C) 2000-2012 Free Software Foundation, Inc.
4
5 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
6 ;; Keywords: PGP MIME MML
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;; RFC 2015 is updated by RFC 3156, this file should be compatible
26 ;; with both.
27
28 ;;; Code:
29
30 (eval-and-compile
31   ;; For Emacs <22.2 and XEmacs.
32   (unless (fboundp 'declare-function) (defmacro declare-function (&rest r)))
33
34   (if (locate-library "password-cache")
35       (require 'password-cache)
36     (require 'password)))
37
38 (eval-when-compile (require 'cl))
39 (require 'mm-decode)
40 (require 'mm-util)
41 (require 'mml)
42 (require 'mml-sec)
43
44 (defvar mc-pgp-always-sign)
45
46 (declare-function epg-check-configuration "ext:epg-config"
47                   (config &optional minimum-version))
48 (declare-function epg-configuration "ext:epg-config" ())
49
50 (defvar mml2015-use (or
51                      (condition-case nil
52                          (progn
53                            (require 'epg-config)
54                            (epg-check-configuration (epg-configuration))
55                            'epg)
56                        (error))
57                      (progn
58                        (let ((abs-file (locate-library "pgg")))
59                          ;; Don't load PGG if it is marked as obsolete
60                          ;; (Emacs 24).
61                          (when (and abs-file
62                                     (not (string-match "/obsolete/[^/]*\\'"
63                                                        abs-file)))
64                            (ignore-errors (require 'pgg))
65                            (and (fboundp 'pgg-sign-region)
66                                 'pgg))))
67                      (progn (ignore-errors
68                               (load "mc-toplev"))
69                             (and (fboundp 'mc-encrypt-generic)
70                                  (fboundp 'mc-sign-generic)
71                                  (fboundp 'mc-cleanup-recipient-headers)
72                                  'mailcrypt)))
73   "The package used for PGP/MIME.
74 Valid packages include `epg', `pgg' and `mailcrypt'.")
75
76 ;; Something is not RFC2015.
77 (defvar mml2015-function-alist
78   '((mailcrypt mml2015-mailcrypt-sign
79                mml2015-mailcrypt-encrypt
80                mml2015-mailcrypt-verify
81                mml2015-mailcrypt-decrypt
82                mml2015-mailcrypt-clear-verify
83                mml2015-mailcrypt-clear-decrypt)
84     (pgg mml2015-pgg-sign
85          mml2015-pgg-encrypt
86          mml2015-pgg-verify
87          mml2015-pgg-decrypt
88          mml2015-pgg-clear-verify
89          mml2015-pgg-clear-decrypt)
90     (epg mml2015-epg-sign
91          mml2015-epg-encrypt
92          mml2015-epg-verify
93          mml2015-epg-decrypt
94          mml2015-epg-clear-verify
95          mml2015-epg-clear-decrypt))
96   "Alist of PGP/MIME functions.")
97
98 (defvar mml2015-result-buffer nil)
99
100 (defcustom mml2015-unabbrev-trust-alist
101   '(("TRUST_UNDEFINED" . nil)
102     ("TRUST_NEVER"     . nil)
103     ("TRUST_MARGINAL"  . t)
104     ("TRUST_FULLY"     . t)
105     ("TRUST_ULTIMATE"  . t))
106   "Map GnuPG trust output values to a boolean saying if you trust the key."
107   :version "22.1"
108   :group 'mime-security
109   :type '(repeat (cons (regexp :tag "GnuPG output regexp")
110                        (boolean :tag "Trust key"))))
111
112 (defcustom mml2015-cache-passphrase mml-secure-cache-passphrase
113   "If t, cache passphrase."
114   :group 'mime-security
115   :type 'boolean)
116
117 (defcustom mml2015-passphrase-cache-expiry mml-secure-passphrase-cache-expiry
118   "How many seconds the passphrase is cached.
119 Whether the passphrase is cached at all is controlled by
120 `mml2015-cache-passphrase'."
121   :group 'mime-security
122   :type 'integer)
123
124 (defcustom mml2015-signers nil
125   "A list of your own key ID(s) which will be used to sign a message.
126 If set, it overrides the setting of `mml2015-sign-with-sender'."
127   :group 'mime-security
128   :type '(repeat (string :tag "Key ID")))
129
130 (defcustom mml2015-sign-with-sender nil
131   "If t, use message sender so find a key to sign with."
132   :group 'mime-security
133   :type 'boolean
134   :version "24.1")
135
136 (defcustom mml2015-encrypt-to-self nil
137   "If t, add your own key ID to recipient list when encryption."
138   :group 'mime-security
139   :type 'boolean)
140
141 (defcustom mml2015-always-trust t
142   "If t, GnuPG skip key validation on encryption."
143   :group 'mime-security
144   :type 'boolean)