~pkal/autocrypt

ref: c1ce4d74468ddf05c6fb893908a0858e7f98afbf autocrypt/autocrypt-message.el -rw-r--r-- 2.3 KiB
c1ce4d74Philip K Use eql specializers instead of derived-mode specializers 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
;;; autocrypt-message.el --- Autocrypt for message-mode -*- lexical-binding:t -*-

;; Author: Philip K. <philip@warpmail.net>
;; Version: 0.4.0
;; Keywords: comm
;; Package-Requires: ((emacs "25.1"))
;; URL: https://git.sr.ht/~zge/autocrypt

;; This file is NOT part of Emacs.
;;
;; This file is in the public domain, to the extent possible under law,
;; published under the CC0 1.0 Universal license.
;;
;; For a full copy of the CC0 license see
;; https://creativecommons.org/publicdomain/zero/1.0/legalcode

;;; Commentary:

;; MUA specific functions for `message-mode'
;;
;; Setup with (add-hook 'message-mode-hook #'autocrypt-mode)

;;; Code:

(require 'message)

(cl-defmethod autocrypt-install ((_mode (eql message)))
  "Install autocrypt hooks for message mode."
  (add-hook 'message-setup-hook #'autocrypt-compose-setup)
  (add-hook 'message-send-hook #'autocrypt-compose-pre-send)
  (unless (lookup-key message-mode-map (kbd "C-c RET C-a"))
    (define-key message-mode-map (kbd "C-c RET C-a") #'autocrypt-compose-setup)))

(defun autocrypt-message-uninstall ()
  "Remove autocrypt hooks for message mode."
  (remove-hook 'message-setup-hook #'autocrypt-compose-setup)
  (remove-hook 'message-send-hook #'autocrypt-compose-pre-send)
  (when (eq (lookup-key message-mode-map (kbd "C-c RET C-a"))
            #'autocrypt-compose-setup)
    (define-key message-mode-map (kbd "C-c RET C-a") nil)))

(cl-defmethod autocrypt-get-header ((_ (eql message)) header)
  "Return the value for HEADER."
  (message-fetch-field header))

(cl-defmethod autocrypt-add-header ((_mode (eql message)) header value)
  "Insert HEADER with VALUE into the message head."
  (message-add-header (concat header ": " value)))

(cl-defmethod autocrypt-sign-encrypt ((_mode (eql message)))
  "Sign and encrypt message."
  (mml-secure-message-sign-encrypt "pgpmime"))

(cl-defmethod autocrypt-sign-secure-attach ((_mode (eql message)) payload)
  "Attach and encrypt buffer PAYLOAD."
  (mml-attach-buffer payload)
  (mml-secure-part "pgpmime")
  (add-hook 'message-send-hook
            (lambda () (kill-buffer payload))
            nil t))

(cl-defmethod autocrypt-encrypted-p ((_mode (eql message)))
  "Check if the current message is encrypted."
  (mml-secure-is-encrypted-p))

(provide 'autocrypt-message)

;;; autocrypt-message.el ends here