-;;; notmuch-draft.el --- functions for postponing and editing drafts
+;;; notmuch-draft.el --- functions for postponing and editing drafts -*- lexical-binding: t -*-
;;
;; Copyright © Mark Walters
;; Copyright © David Bremner
(declare-function notmuch-show-get-message-id "notmuch-show" (&optional bare))
(declare-function notmuch-message-mode "notmuch-mua")
+;;; Options
+
(defgroup notmuch-draft nil
"Saving and editing drafts in Notmuch."
:group 'notmuch)
:group 'notmuch-send)
(defcustom notmuch-draft-save-plaintext 'ask
- "Should notmuch save/postpone in plaintext messages that seem
-like they are intended to be sent encrypted
-(i.e with an mml encryption tag in it)."
+ "Whether to allow saving plaintext when it seems encryption is intended.
+When a message contains mml tags, then that suggest it is
+intended to be encrypted. If the user requests that such a
+message is saved locally, then this option controls whether
+that is allowed. Beside a boolean, this can also be `ask'."
:type '(radio
(const :tag "Never" nil)
(const :tag "Ask every time" ask)
:group 'notmuch-draft
:group 'notmuch-crypto)
+;;; Internal
+
(defvar notmuch-draft-encryption-tag-regex
"<#\\(part encrypt\\|secure.*mode=.*encrypt>\\)"
"Regular expression matching mml tags indicating encryption of part or message.")
-(defvar notmuch-draft-id nil
+(defvar-local notmuch-draft-id nil
"Message-id of the most recent saved draft of this message.")
-(make-variable-buffer-local 'notmuch-draft-id)
(defun notmuch-draft--mark-deleted ()
"Tag the last saved draft deleted.
(let (secure-tag)
(save-restriction
(message-narrow-to-headers)
- (setq secure-tag (message-fetch-field "X-Notmuch-Emacs-Secure" 't))
+ (setq secure-tag (message-fetch-field "X-Notmuch-Emacs-Secure" t))
(message-remove-header "X-Notmuch-Emacs-Secure"))
(message-goto-body)
(when secure-tag
(insert secure-tag "\n")))))
(defun notmuch-draft--has-encryption-tag ()
- "Returns t if there is an mml secure tag."
+ "Return non-nil if there is an mml secure tag."
(save-excursion
(message-goto-body)
- (re-search-forward notmuch-draft-encryption-tag-regex nil 't)))
+ (re-search-forward notmuch-draft-encryption-tag-regex nil t)))
(defun notmuch-draft--query-encryption ()
- "Checks if we should save a message that should be encrypted.
+ "Return non-nil if we should save a message that should be encrypted.
`notmuch-draft-save-plaintext' controls the behaviour."
(cl-case notmuch-draft-save-plaintext
;; but notmuch doesn't want that form, so remove them.
(concat "draft-" (substring (message-make-message-id) 1 -1)))
+;;; Commands
+
(defun notmuch-draft-save ()
"Save the current draft message in the notmuch database.
(notmuch-draft-quote-some-mml)
(notmuch-maildir-setup-message-for-saving)
(notmuch-maildir-notmuch-insert-current-buffer
- notmuch-draft-folder 't notmuch-draft-tags))
+ notmuch-draft-folder t notmuch-draft-tags))
;; We are now back in the original compose buffer. Note the
;; function notmuch-call-notmuch-process (called by
;; notmuch-maildir-notmuch-insert-current-buffer) signals an error
(defun notmuch-draft-resume (id)
"Resume editing of message with id ID."
+ ;; Used by command `notmuch-show-resume-message'.
(let* ((tags (process-lines notmuch-command "search" "--output=tags"
"--exclude=false" id))
(draft (equal tags (notmuch-update-tags tags notmuch-draft-tags))))
;; message is resaved or sent.
(setq notmuch-draft-id (and draft id)))))
+;;; _
(add-hook 'message-send-hook 'notmuch-draft--mark-deleted)
-
(provide 'notmuch-draft)
;;; notmuch-draft.el ends here