X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=emacs%2Fnotmuch-draft.el;h=a68b7d8da002a7f3f76b2ccded426bb465724de7;hp=283830ad0d0097c2aa529cc754ea41cd90002281;hb=HEAD;hpb=88ae4f02511c4dd61ea90b28794f469819d543be diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el index 283830ad..fcc45503 100644 --- a/emacs/notmuch-draft.el +++ b/emacs/notmuch-draft.el @@ -1,4 +1,4 @@ -;;; 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 @@ -25,18 +25,24 @@ ;;; Code: +(require 'cl-lib) +(require 'pcase) +(require 'subr-x) + (require 'notmuch-maildir-fcc) (require 'notmuch-tag) (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) (defcustom notmuch-draft-tags '("+draft") - "List of tags changes to apply to a draft message when it is saved in the database. + "List of tag changes to apply when saving a draft message in the database. Tags starting with \"+\" (or not starting with either \"+\" or \"-\") in the list will be added, and tags starting with \"-\" @@ -75,9 +81,11 @@ postponing and resuming a message." :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) @@ -85,13 +93,14 @@ like they are intended to be sent encrypted :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. @@ -101,7 +110,7 @@ Used when a new version is saved, or the message is sent." (notmuch-tag notmuch-draft-id '("+deleted")))) (defun notmuch-draft-quote-some-mml () - "Quote the mml tags in `notmuch-draft-quoted-tags`." + "Quote the mml tags in `notmuch-draft-quoted-tags'." (save-excursion ;; First we deal with any secure tag separately. (message-goto-body) @@ -122,7 +131,7 @@ Used when a new version is saved, or the message is sent." (insert "!")))))) (defun notmuch-draft-unquote-some-mml () - "Unquote the mml tags in `notmuch-draft-quoted-tags`." + "Unquote the mml tags in `notmuch-draft-quoted-tags'." (save-excursion (when notmuch-draft-quoted-tags (let ((re (concat "<#!+/?\\(" @@ -136,20 +145,20 @@ Used when a new version is saved, or the message is sent." (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 @@ -170,11 +179,13 @@ Really save and index an unencrypted copy? ") ;; 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. This saves the current message in the database with tags -`notmuch-draft-tags` (in addition to any default tags +`notmuch-draft-tags' (in addition to any default tags applied to newly inserted messages)." (interactive) (when (notmuch-draft--has-encryption-tag) @@ -185,7 +196,7 @@ applied to newly inserted messages)." ;; so that it is easier to search for the message, and the ;; latter so we have a way of accessing the saved message (for ;; example to delete it at a later time). We check that the - ;; user has these in `message-deletable-headers` (the default) + ;; user has these in `message-deletable-headers' (the default) ;; as otherwise they are doing something strange and we ;; shouldn't interfere. Note, since we are doing this in a new ;; buffer we don't change the version in the compose buffer. @@ -208,7 +219,7 @@ applied to newly inserted messages)." (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 @@ -227,7 +238,8 @@ applied to newly inserted messages)." (defun notmuch-draft-resume (id) "Resume editing of message with id ID." - (let* ((tags (process-lines notmuch-command "search" "--output=tags" + ;; Used by command `notmuch-show-resume-message'. + (let* ((tags (notmuch--process-lines notmuch-command "search" "--output=tags" "--exclude=false" id)) (draft (equal tags (notmuch-update-tags tags notmuch-draft-tags)))) (when (or draft @@ -237,7 +249,7 @@ applied to newly inserted messages)." (setq buffer-read-only nil) (erase-buffer) (let ((coding-system-for-read 'no-conversion)) - (call-process notmuch-command nil t nil "show" "--format=raw" id)) + (notmuch--call-process notmuch-command nil t nil "show" "--format=raw" id)) (mime-to-mml) (goto-char (point-min)) (when (re-search-forward "^$" nil t) @@ -266,10 +278,10 @@ applied to newly inserted messages)." ;; 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