summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip K <philip.kaludercic@fau.de>2020-08-08 15:40:32 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2020-08-08 15:40:32 +0200
commitb799cc271d69fc494da1fe04ca8ec6c529a19a19 (patch)
tree9921dcc166e5198126beb527ab0dc4af45f45ab5
parent289d6b2265e19822ed5ad44e5c62e9bf3750f606 (diff)
downloademacs-b799cc271d69fc494da1fe04ca8ec6c529a19a19.tar.gz
emacs-b799cc271d69fc494da1fe04ca8ec6c529a19a19.tar.bz2
emacs-b799cc271d69fc494da1fe04ca8ec6c529a19a19.zip
Add support for the OpenPGP header to Emacs
* lisp/gnus/message.el (message-openpgp-header): New variable (bug#39964). (messasge-add-openpgp-header): New function to use it.
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/gnus/message.el58
2 files changed, 63 insertions, 0 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 5cef0eb4c87..d2903449bed 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -246,6 +246,11 @@ not.
** Message
+*** Message now supports the OpenPGP header.
+To generate these headers, add the new function
+'messasge-add-openpgp-header' to 'message-send-hook'. The header will
+be generated according to the new 'message-openpgp-header' variable.
+
---
*** A change to how Mail-Copies-To: never is handled.
If a user has specified Mail-Copies-To: never, and Message was asked
diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index 819f3e41d3d..e5ddfcffffc 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -2737,6 +2737,64 @@ systematically send encrypted emails when possible."
(when (message-all-epg-keys-available-p)
(mml-secure-message-sign-encrypt)))
+(defcustom message-openpgp-header nil
+ "Specification for \"OpenPGP\" header.
+
+Otherwise, the variable must be a
+list with three elements, all strings:
+- Key ID, in hexadecimal form
+- Key URL or ASCII armoured key.
+- Protection preference, one of: \"unprotected\", \"sign\",
+ \"encrypt\" or \"signencrypt\".
+
+Each value may be nil, in which case it won't be inserted. If all
+the values are nil, or `message-openpgp-header' is nil itself,
+don't insert any header."
+ :type '(choice
+ (const nil :tag "Don't add OpenPGP header")
+ (list (choice (string :tag "ID")
+ (const nil :tag "No ID"))
+ (choice (string :tag "Key")
+ (const nil :tag "No Key"))
+ (choice (other nil :tag "None")
+ (const "unprotected" :tag "Unprotected")
+ (const "sign" :tag "Sign")
+ (const "encrypt" :tag "Encrypt")
+ (const "signencrypt" :tag "Sign and Encrypt"))))
+ :version "28.1")
+
+(defun messasge-add-openpgp-header ()
+ "Add OpenPGP header to point to public key.
+
+Header will be constructed as specified in `message-openpgp-header'.
+
+Consider adding this function to `message-send-hook'."
+ ;; See https://tools.ietf.org/html/draft-josefsson-openpgp-mailnews-header
+ (when (and message-openpgp-header
+ (or (nth 0 message-openpgp-header)
+ (nth 1 message-openpgp-header)
+ (nth 2 message-openpgp-header)))
+ (with-temp-buffer
+ (insert "OpenPGP: ")
+ ;; add ID
+ (let (need-sep)
+ (when (nth 0 message-openpgp-header)
+ (insert "id=" (nth 0 message-openpgp-header))
+ (setq need-sep t))
+ ;; add URL
+ (when (nth 1 message-openpgp-header)
+ (when need-sep (insert "; "))
+ (if (string-match-p ";")
+ (insert "url=\"" (nth 1 message-openpgp-header) "\"")
+ (insert "url=\"" (nth 1 message-openpgp-header) "\""))
+ (setq need-sep t))
+ ;; add preference
+ (when (nth 2 message-openpgp-header)
+ (when need-sep (insert "; "))
+ (insert "preference=" (nth 2 message-openpgp-header))))
+ ;; insert header
+ (message-add-header (buffer-string)))))
+
;;;