[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ebdb a712f52 050/350: Update ebdb-pgp
From: |
Eric Abrahamsen |
Subject: |
[elpa] externals/ebdb a712f52 050/350: Update ebdb-pgp |
Date: |
Mon, 14 Aug 2017 11:46:00 -0400 (EDT) |
branch: externals/ebdb
commit a712f5273a707a510563ea17e153f4933619f60c
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>
Update ebdb-pgp
Closes #9
* ebdb-pgp.el (ebdb-field-pgp): New class holding the default
signing/encryption action for this record.
(ebdb-pgp): Update this function to use the class.
* ebdb.el: Provide a defclass autoload.
---
ebdb-pgp.el | 94 ++++++++++++++++++++++++++++++++++++-------------------------
ebdb.el | 6 ++++
2 files changed, 62 insertions(+), 38 deletions(-)
diff --git a/ebdb-pgp.el b/ebdb-pgp.el
index c6f6301..79282d7 100644
--- a/ebdb-pgp.el
+++ b/ebdb-pgp.el
@@ -28,21 +28,34 @@
(require 'message)
(require 'ebdb-com)
-(defcustom ebdb-pgp-field 'pgp-mail
- "EBDB xfield holding the PGP action.
-If the recipient of a message has this xfield in his/her EBDB record,
-its value determines whether `ebdb-pgp' signs or encrypts the message.
-The value of this xfield should be one of the following symbols:
- sign Sign the message
- sign-query Query whether to sign the message
- encrypt Encrypt the message
- encrypt-query Query whether to encrypt the message
-If the xfield is absent use `ebdb-pgp-default'.
-See also info node `(message)security'."
- :type '(symbol :tag "EBDB xfield")
- :group 'ebdb-utilities-pgp)
-
-(defcustom ebdb-pgp-default nil
+(defclass ebdb-field-pgp (ebdb-field-user)
+ ((action
+ :initarg :action
+ :type symbol
+ :custom (choice
+ (const :tag "Encrypt" encrypt)
+ (const :tag "Query encryption" encrypt-query)
+ (const :tag "Sign" sign)
+ (const :tag "Query signing" sign-query))
+ :documentation
+ "A symbol indicating what action to take when sending a
+ message to this contact."))
+ :documentation "A field defining a default signing/encryption
+ action for a record. This action is taken by calling
+ `ebdb-pgp' in a message/mail composition buffer, or by adding
+ that function to the message/mail-send-hook."
+ :human-readable "pgp action")
+
+(cl-defmethod ebdb-string ((field ebdb-field-pgp))
+ (symbol-name (slot-value field 'action)))
+
+(cl-defmethod ebdb-read ((class (subclass ebdb-field-pgp)) &optional slots obj)
+ (let ((val (intern (ebdb-read-string
+ "PGP action: " (when obj (slot-value obj 'action))
+ ebdb-pgp-ranked-actions t))))
+ (cl-call-next-method class (plist-put slots :action val) obj)))
+
+(defcustom ebdb-pgp-default-action nil
"Default action when sending a message and the recipients are not in EBDB.
This should be one of the following symbols:
nil Do nothing
@@ -79,7 +92,7 @@ This list should include the following four symbols:
:group 'ebdb-utilities-pgp)
(defcustom ebdb-pgp-method 'pgpmime
- "Method for signing and encrypting messages.
+ "Default method for signing and encrypting messages.
It should be one of the keys of `ebdb-pgp-method-alist'.
The default methods include
pgp Add MML tags for PGP format
@@ -122,29 +135,36 @@ See info node `(message)security'."
;;;###autoload
(defun ebdb-read-xfield-pgp-mail (&optional init)
"Set `ebdb-pgp-field', requiring match with `ebdb-pgp-ranked-actions'."
- (ebdb-read-string "PGP action: " init
- (mapcar 'list ebdb-pgp-ranked-actions) t))
+ )
;;;###autoload
(defun ebdb-pgp ()
"Add PGP MML tags to a message according to the recipients' EBDB records.
-For all message recipients in `ebdb-pgp-headers', this grabs the action
-in `ebdb-pgp-field' of their EBDB records. If this proposes multiple actions,
-perform the action which appears first in `ebdb-pgp-ranked-actions'.
-If this proposes no action at all, use `ebdb-pgp-default'.
-The variable `ebdb-pgp-method' defines the method which is actually used
-for signing and encrypting.
+
+Use it by adding a \"pgp action\" field to one or more records.
+
+When sending a message to those records (ie, the records appear
+in `ebdb-pgp-headers' headers), this grabs the action from their
+`ebdb-field-pgp' field. If multiple records propose different
+actions, perform the action which appears first in
+`ebdb-pgp-ranked-actions'. If this proposes no action at all,
+use `ebdb-pgp-default-action'. The variable `ebdb-pgp-method'
+defines the method which is actually used for signing and
+encrypting.
This command works with both `mail-mode' and `message-mode' to send
signed or encrypted mail.
-To run this command automatically when sending a message,
-use `ebdb-initialize' with arg `pgp' to add this function
-to `message-send-hook' and `mail-send-hook'.
-Yet see info node `(message)Signing and encryption' why you
-might not want to rely for encryption on a hook function
-which runs just before the message is sent, that is, you might want
-to call the command `ebdb-pgp' manually, then call `mml-preview'."
+This file does not automatically set up hooks for signing and
+encryption, see Info node `(message)Signing and encryption' for
+reasons why. Instead, you might want to call the command
+`ebdb-pgp' manually, then call `mml-preview'.
+
+If you do decide to set up automatic signing/encryption hooks,
+use one of the following, as appropriate:
+
+(add-hook 'message-send-hook 'ebdb-pgp)
+(add-hook 'mail-send-hook 'ebdb-pgp)"
(interactive)
(save-excursion
(save-restriction
@@ -158,7 +178,8 @@ to call the command `ebdb-pgp' manually, then call
`mml-preview'."
(delete-dups
(mapcar
(lambda (record)
- (ebdb-record-xfield-intern record ebdb-pgp-field))
+ (if-let ((field (car-safe (ebdb-record-field record
ebdb-field-pgp))))
+ (slot-value field 'action)))
(delete-dups
(apply 'nconc
(mapcar
@@ -168,11 +189,11 @@ to call the command `ebdb-pgp' manually, then call
`mml-preview'."
(ebdb-extract-address-components
(mapconcat
(lambda (header)
- (mail-fetch-field header nil t))
+ (ebdb-message-header header))
ebdb-pgp-headers ", ")
t)))))))
- (and ebdb-pgp-default
- (list ebdb-pgp-default)))))
+ (and ebdb-pgp-default-action
+ (list ebdb-pgp-default-action)))))
(when actions
(widen) ; after analyzing the headers
(let ((ranked-actions ebdb-pgp-ranked-actions)
@@ -192,8 +213,5 @@ to call the command `ebdb-pgp' manually, then call
`mml-preview'."
ebdb-pgp-method-alist)))
(setq ranked-actions nil)))))))))))
-(add-hook 'message-send-hook 'ebdb-pgp)
-(add-hook 'mail-send-hook 'ebdb-pgp)
-
(provide 'ebdb-pgp)
;;; ebdb-pgp.el ends here
diff --git a/ebdb.el b/ebdb.el
index 44d913e..b04e74f 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -4571,5 +4571,11 @@ but not allowing for regexps."
"ebdb-gnus"
"Gnus field holding private IMAP mailbox name.")
+(eieio-defclass-autoload
+ 'ebdb-field-pgp
+ 'ebdb-field-user
+ "ebdb-pgp"
+ "Field holding default pgp action when sending messages to this record.")
+
(provide 'ebdb)
;;; ebdb.el ends here
- [elpa] externals/ebdb a43e883 026/350: Move record initialization out of load process, (continued)
- [elpa] externals/ebdb a43e883 026/350: Move record initialization out of load process, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 77eb15b 037/350: Add keybinding for ebdb-search-database, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 8eb2262 036/350: Add object-print method for records, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 20785a1 029/350: Additions to README and manual, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 8537076 052/350: Improvements to the gnorb-ebdb-org-tags field, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 6568bbf 053/350: Straighten out ebdb-separator-alist, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 9791ed5 030/350: Merge branch 'buff', Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 49b422e 035/350: Remove mentions and bindings for ebdb-do-all-records, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 11fe701 047/350: Name classes now inherit from ebdb-field-user, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 784f45c 060/350: New function ebdb-prompt-for-mail, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb a712f52 050/350: Update ebdb-pgp,
Eric Abrahamsen <=
- [elpa] externals/ebdb 118f567 062/350: Add a "defunct" arg to ebdb-record-mail, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 90cb02a 068/350: Remove ebdb-mail-address, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb decfc94 073/350: Update company-ebdb to work, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 47ac653 066/350: Fix autoload for ebdb-org-field-tags definition, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb b2fdb42 064/350: Include record name when prompting for mail, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 41bc859 084/350: Still need to hash newly-added records, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb dc517a1 067/350: More fixes to merging logic in ebdb-db-load, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb b9d7727 087/350: Fill out the ebdb-parse process, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb a5b00bd 074/350: Re-init mail fields after moving them to a role, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 76621c7 091/350: Clean up keymap bindings, Eric Abrahamsen, 2017/08/14