[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Gnus: Store message in PGP-decrypted form
From: |
Jamie Beardslee |
Subject: |
Re: Gnus: Store message in PGP-decrypted form |
Date: |
Wed, 10 Jun 2020 13:38:14 +1200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
It's not exactly what you want, but `epa-decrypt-region' usually works
for my needs. In any case, here's a little function to decrypt some
saved mail.
(defun decrypt-saved-message (file &optional save)
"Decrypt a plaintext mail FILE.
With prefix arg SAVE, save the decrypted contents."
(interactive "F\nP")
(require 'epa-mail)
(let ((buffer (get-buffer-create
(format "%s *decrypted*"
(file-name-nondirectory file)))))
(pop-to-buffer buffer)
(insert-file-contents file)
(while (re-search-forward "-----BEGIN PGP MESSAGE-----$" nil t)
(setq armor-start (match-beginning 0)
armor-end (re-search-forward "^-----END PGP MESSAGE-----$"
nil t))
(unless armor-end
(error "Encryption armor beginning has no matching end"))
(goto-char armor-start)
(let* ((context (epg-make-context 'OpenPGP))
(decrypted (epg-decrypt-string
context
(buffer-substring armor-start armor-end))))
(delete-region armor-start armor-end)
(insert decrypted)))
(when (or save (y-or-n-p "Save mail in decrypted form?"))
(write-file file))))
It can be used interactively, or if you want to decrypt a bunch of saved
mails you can call it from lisp with a second argument:
(dolist (f '("~/mail1" "~/mail2" ...))
(decrypt-saved-message f t))
Surely this can be hacked a bit to make gnus decrypt the mail before
saving...
--
Jamie
signature.asc
Description: PGP signature