Wanderlust: easily decrypt an inline-encrypted GPG/PGP message

Christian Kruse,

As I recently switched to Emacs, I noticed that there seems to be no easy way to decrypt an inline-encrypted message. You basically have to switch to the message buffer, select the encryption block and call (manually) wl-message-decrypt-pgp-nonmime. This makes sense as one can encrypt only parts (plural, yes – a message may contain multiple encrypted blocks) of the message. But the default case for me is that the whole message is encrypted. Thus I created a small snippet for exactly this task:

(defun ck-message-decrypt-pgp-nonmime()
  (interactive)

  (if (and wl-message-buffer (get-buffer-window wl-message-buffer))
      (let ((start) (ends))
        (wl-summary-toggle-disp-msg 'on)
        (save-excursion
          (set-buffer wl-message-buffer)
          (goto-char (point-min))
          (re-search-forward "^-----BEGIN PGP MESSAGE-----$")
          (setq start (point))

          (goto-char (point-min))
          (re-search-forward "^-----END PGP MESSAGE-----$")
          (setq ends (point))

          (goto-char start)
          (set-mark-command nil)
          (goto-char ends)

          (wl-message-decrypt-pgp-nonmime)))

    (message "no message to decrypt")))

(define-key wl-summary-mode-map (kbd "C-c d") 'ck-message-decrypt-pgp-nonmime)

This opens a message (if not yet opened), searches for the first PGP block, marks it and decrypts it.