Emacs: Crypto: How to get automatic encryption?

David Edmondson dme at dme.org
Wed Jan 4 00:36:39 PST 2012


On Tue, 03 Jan 2012 13:45:14 -0800, Jameson Graef Rollins <jrollins at finestructure.net> wrote:
> Any other suggestions?

In the function that I add to `message-send-hook' I do the following:

	(message-goto-body)
	;; If already set, don't override.
	(if (not (looking-at (regexp-quote "<#secure ")))
	    ;; If we can encrypt, do so, else just sign.
	    (if (and encrypt (dme:message-determine-encryption))
	        (insert "<#secure method=pgpmime mode=signencrypt>\n")
	      (insert "<#secure method=pgpmime mode=sign>\n"))))

Where `dme:message-determine-encryption' is:

(defun dme:message-determine-encryption ()
  "Return `t' if we have gpg public keys for all recipients of
this message."
  (require 'pgg)
  (if (not (message-news-p)) ; No encryption for news.
      (catch :exit
	(mapc
	 (lambda (addr)
	   (if (not (pgg-lookup-key (downcase (mail-strip-quoted-names addr))))
	       (throw :exit nil)))
	 (message-tokenize-header (concat
				   (message-fetch-field "to")
				   ","
				   (message-fetch-field "cc"))))
	t)
    nil))

(I'd probably re-write that to use a cl loop now - it's very old.)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20120104/afd87b4c/attachment-0001.pgp>


More information about the notmuch mailing list