chore(emacs): added better encryption support for mu4e
a7fc46b1
2 file(s) · +56 −0
| 65 | 65 | "oT" '(ghostel-project :wk "project terminal") |
|
| 66 | 66 | "os" '(eshell :wk "eshell") |
|
| 67 | 67 | ||
| 68 | + | "m" '(:ignore t :wk "mail") |
|
| 69 | + | "mc" '(mu4e-compose-new :wk "compose") |
|
| 70 | + | "ms" '(mml-secure-message-sign-pgpmime :wk "sign") |
|
| 71 | + | "me" '(mml-secure-message-encrypt-pgpmime :wk "sign+encrypt") |
|
| 72 | + | "mE" '((lambda () (interactive) (mml-secure-message-encrypt-pgpmime t)) |
|
| 73 | + | :wk "encrypt only") |
|
| 74 | + | "md" '(my/mail-decrypt-bridge :wk "decrypt (bridge)") |
|
| 75 | + | "mn" '(mml-unsecure-message :wk "remove sign/encrypt") |
|
| 76 | + | ||
| 68 | 77 | "u" '(:ignore t :wk "upload") |
|
| 69 | 78 | "uu" '(uguu-upload-file :wk "upload file") |
|
| 70 | 79 | "uc" '(uguu-upload-clipboard :wk "upload clipboard") |
| 26 | 26 | message-sendmail-envelope-from 'header |
|
| 27 | 27 | message-kill-buffer-on-exit t |
|
| 28 | 28 | ||
| 29 | + | ;; GPG |
|
| 30 | + | mml-secure-openpgp-sign-with-sender t ; pick key by From address |
|
| 31 | + | mml-secure-openpgp-encrypt-to-self t ; keep Sent copies readable |
|
| 32 | + | mm-verify-option 'always ; verify signatures on view |
|
| 33 | + | mm-decrypt-option 'always ; auto-decrypt on view |
|
| 34 | + | ||
| 29 | 35 | mu4e-maildir-shortcuts |
|
| 30 | 36 | '((:maildir "/local/Inbox" :key ?i) |
|
| 31 | 37 | (:maildir "/local/Sent" :key ?s) |
|
| 32 | 38 | (:maildir "/local/Drafts" :key ?d) |
|
| 33 | 39 | (:maildir "/local/Archive" :key ?a) |
|
| 34 | 40 | (:maildir "/local/Trash" :key ?t)))) |
|
| 41 | + | ||
| 42 | + | ;; Proton Bridge rewrites PGP/MIME into multipart/mixed with the armored |
|
| 43 | + | ;; block as an attachment, so Emacs won't auto-decrypt. Pull the block out |
|
| 44 | + | ;; of the raw message and decrypt it by hand. |
|
| 45 | + | (require 'mm-decode) |
|
| 46 | + | (require 'epg) |
|
| 47 | + | (require 'cl-lib) |
|
| 48 | + | ||
| 49 | + | (defun my/mail--pgp-blocks (path) |
|
| 50 | + | "Return armored PGP message strings found in the parts of PATH." |
|
| 51 | + | (with-temp-buffer |
|
| 52 | + | (insert-file-contents-literally path) |
|
| 53 | + | (let (blocks) |
|
| 54 | + | (cl-labels ((walk (h) |
|
| 55 | + | (cond ((and (consp h) (stringp (car h))) |
|
| 56 | + | (mapc #'walk (cdr h))) |
|
| 57 | + | ((and (consp h) (bufferp (car h))) |
|
| 58 | + | (let ((s (mm-get-part h))) |
|
| 59 | + | (when (string-match "-----BEGIN PGP MESSAGE-----" s) |
|
| 60 | + | (push (substring s (match-beginning 0)) blocks))))))) |
|
| 61 | + | (walk (mm-dissect-buffer t t))) |
|
| 62 | + | (nreverse blocks)))) |
|
| 63 | + | ||
| 64 | + | (defun my/mail-decrypt-bridge () |
|
| 65 | + | "Decrypt the PGP block of the mu4e message at point into a buffer." |
|
| 66 | + | (interactive) |
|
| 67 | + | (let* ((msg (mu4e-message-at-point)) |
|
| 68 | + | (blocks (or (my/mail--pgp-blocks (mu4e-message-field msg :path)) |
|
| 69 | + | (user-error "No PGP block in message"))) |
|
| 70 | + | (ctx (epg-make-context 'OpenPGP)) |
|
| 71 | + | (buf (get-buffer-create "*mail-decrypted*"))) |
|
| 72 | + | (with-current-buffer buf |
|
| 73 | + | (let ((inhibit-read-only t)) |
|
| 74 | + | (erase-buffer) |
|
| 75 | + | (dolist (b blocks) |
|
| 76 | + | (insert (decode-coding-string |
|
| 77 | + | (epg-decrypt-string ctx b) 'utf-8) |
|
| 78 | + | "\n")) |
|
| 79 | + | (goto-char (point-min)) |
|
| 80 | + | (special-mode))) |
|
| 81 | + | (pop-to-buffer buf))) |
|
| 35 | 82 | ||
| 36 | 83 | (provide 'init-mail) |