[PATCH v6 0/4] emacs postpone/resume patches

Subject: [PATCH v6 0/4] emacs postpone/resume patches

Date: Sun, 13 Nov 2016 11:21:42 +0000

To: notmuch@notmuchmail.org

Cc:

From: Mark Walters


This version 6 of this series. The previous version is at
id:20161107125211.23405-1-david@tethera.net

This addresses the review comments on the previous version, adds a
couple of "requires" to fix some compile warnings, and1 updates on
function name which was missed previously.

I also rejigged Patch 3 (the secure tag checks). I think I like this
version but i am happy to revert to the previous one if preferred.

The diff from the previous version is below.

Best wishes

Mark

David Bremner (2):
  emacs: check drafts for encryption tags before saving
  emacs: resume messages

Mark Walters (2):
  emacs: tree: remove binding for pressing button in message pane
  emacs: postpone a message

 emacs/Makefile.local     |   3 +-
 emacs/notmuch-draft.el   | 268 +++++++++++++++++++++++++++++++++++++++++++++++
 emacs/notmuch-mua.el     |   4 +
 emacs/notmuch-show.el    |  10 ++
 emacs/notmuch-tree.el    |   2 +-
 test/T630-emacs-draft.sh |  70 +++++++++++++
 6 files changed, 355 insertions(+), 2 deletions(-)
 create mode 100644 emacs/notmuch-draft.el
 create mode 100755 test/T630-emacs-draft.sh

diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index 1528d79..496e11f 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -24,6 +24,8 @@
 ;;; Code:
 
 (require 'notmuch-maildir-fcc)
+(require 'notmuch-tag)
+(require 'notmuch-mua)
 
 (declare-function notmuch-show-get-message-id "notmuch-show" (&optional bare))
 
@@ -109,7 +111,7 @@ Used when a new version is saved, or the message is sent."
     ;; specified tags.
     (when notmuch-draft-quoted-tags
       (let ((re (concat "<#!*/?\\("
-			(mapconcat 'identity notmuch-draft-quoted-tags "\\|")
+			(mapconcat 'regexp-quote notmuch-draft-quoted-tags "\\|")
 			"\\)")))
 	(message-goto-body)
 	(while (re-search-forward re nil t)
@@ -122,7 +124,7 @@ Used when a new version is saved, or the message is sent."
   (save-excursion
     (when notmuch-draft-quoted-tags
       (let ((re (concat "<#!+/?\\("
-			(mapconcat 'identity notmuch-draft-quoted-tags "\\|")
+			(mapconcat 'regexp-quote notmuch-draft-quoted-tags "\\|")
 			"\\)")))
 	(message-goto-body)
 	(while (re-search-forward re nil t)
@@ -138,21 +140,32 @@ Used when a new version is saved, or the message is sent."
       (when secure-tag
 	(insert secure-tag "\n")))))
 
-(defun notmuch-draft--check-encryption-tag (&optional ask)
-  "Query user if there an mml tag that looks like it might indicate encryption.
-
-Returns t if there is no such tag, or the user confirms they mean
-it."
+(defun notmuch-draft--has-encryption-tag ()
+  "Returns t if there is an mml secure tag."
   (save-excursion
     (message-goto-body)
-      (or
-       ;; We are fine if no relevant tag is found, or
-       (not (re-search-forward notmuch-draft-encryption-tag-regex nil 't))
-       ;; The user confirms they means it.
-       (and ask
-	    (yes-or-no-p "(Customize `notmuch-draft-save-plaintext' to avoid this warning)
+    (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.
+
+`notmuch-draft-save-plaintext' controls the behaviour."
+  (case notmuch-draft-save-plaintext
+	((ask)
+	 (notmuch-draft--query-encryption)
+	 (unless (yes-or-no-p "(Customize `notmuch-draft-save-plaintext' to avoid this warning)
 This message contains mml tags that suggest it is intended to be encrypted.
-Really save and index an unencrypted copy? ")))))
+Really save and index an unencrypted copy? ")
+	   (error "Save aborted")))
+	((nil)
+	 (error "Refusing to save draft with encryption tags (see `notmuch-draft-save-plaintext')"))
+	((t)
+	 (ignore))))
+
+(defun notmuch-draft--make-message-id ()
+  ;; message-make-message-id gives the id inside a "<" ">" pair,
+  ;; but notmuch doesn't want that form, so remove them.
+  (concat "draft-" (substring (message-make-message-id) 1 -1)))
 
 (defun notmuch-draft-save ()
   "Save the current draft message in the notmuch database.
@@ -161,19 +174,9 @@ This saves the current message in the database with tags
 `notmuch-draft-tags` (in addition to any default tags
 applied to newly inserted messages)."
   (interactive)
-  (case notmuch-draft-save-plaintext
-    ((ask)
-     (unless (notmuch-draft--check-encryption-tag t)
-       (error "Save aborted")))
-    ((t)
-     (ignore))
-    ((nil)
-     (unless (notmuch-draft--check-encryption-tag nil)
-       (error "Refusing to save draft with encryption tags (see `notmuch-draft-save-plaintext')"))))
-  (let (;; We need the message id as we need it for tagging. Note
-	;; message-make-message-id gives the id inside a "<" ">" pair,
-	;; but notmuch doesn't want that form, so remove them.
-	(id (concat "draft-" (substring (message-make-message-id) 1 -1))))
+  (when (notmuch-draft--has-encryption-tag)
+    (notmuch-draft--query-encryption))
+  (let ((id (notmuch-draft--make-message-id)))
     (with-temporary-notmuch-message-buffer
      ;; We insert a Date header and a Message-ID header, the former
      ;; so that it is easier to search for the message, and the
@@ -183,17 +186,19 @@ applied to newly inserted messages)."
      ;; 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.
-     (if (member 'Message-ID message-deletable-headers)
-	 (progn
-	   (message-remove-header "Message-ID")
-	   (message-add-header (concat "Message-ID: <" id ">")))
+     (cond
+      ((member 'Message-ID message-deletable-headers)
+       (message-remove-header "Message-ID")
+       (message-add-header (concat "Message-ID: <" id ">")))
+      (t
        (message "You have customized emacs so Message-ID is not a deletable header, so not changing it")
-       (setq id nil))
-     (if (member 'Date message-deletable-headers)
-	 (progn
-	   (message-remove-header "Date")
-	   (message-add-header (concat "Date: " (message-make-date))))
-       (message "You have customized emacs so Date is not a deletable header, so not changing it"))
+       (setq id nil)))
+     (cond
+      ((member 'Date message-deletable-headers)
+       (message-remove-header "Date")
+       (message-add-header (concat "Date: " (message-make-date))))
+      (t
+       (message "You have customized emacs so Date is not a deletable header, so not changing it")))
      (message-add-header "X-Notmuch-Emacs-Draft: True")
      (notmuch-draft-quote-some-mml)
      (notmuch-maildir-setup-message-for-saving)
@@ -212,7 +217,7 @@ applied to newly inserted messages)."
 (defun notmuch-draft-postpone ()
   "Save the draft message in the notmuch database and exit buffer."
   (interactive)
-  (notmuch-draft-save-draft)
+  (notmuch-draft-save)
   (kill-buffer))
 
 (defun notmuch-draft-resume (id)

Thread: