all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philip K <philip@warpmail.net>
To: 39964@debbugs.gnu.org
Cc: Philip K <philip.kaludercic@fau.de>
Subject: bug#39964: [PATCH] Add support for creating OpenPGP header
Date: Sat,  7 Mar 2020 01:11:28 +0100	[thread overview]
Message-ID: <20200307001128.10698-1-philip@warpmail.net> (raw)

From: Philip K <philip.kaludercic@fau.de>

See [0] for more details on it's usage and interpretation.

[0]: https://tools.ietf.org/html/draft-josefsson-openpgp-mailnews-header
---
 lisp/gnus/message.el | 57 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index adefa0efd6..1c9c99afbe 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -2730,6 +2730,63 @@ message-sign-encrypt-if-all-keys-available
   (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")))))
+
+(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)))))
+
 \f
 
 ;;;
-- 
2.20.1






             reply	other threads:[~2020-03-07  0:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-07  0:11 Philip K [this message]
2020-03-07  7:53 ` bug#39964: [PATCH] Add support for creating OpenPGP header Eli Zaretskii
2020-08-08 13:50 ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200307001128.10698-1-philip@warpmail.net \
    --to=philip@warpmail.net \
    --cc=39964@debbugs.gnu.org \
    --cc=philip.kaludercic@fau.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.