[PATCH v2 0/2] add postpone support

Subject: [PATCH v2 0/2] add postpone support

Date: Thu, 3 Nov 2016 18:09:06 +0000

To: notmuch@notmuchmail.org

Cc:

From: Mark Walters


This is version 2 of this set. The previous version is at
id:1473004582-19396-1-git-send-email-markwalters1009@gmail.com

The diff between v1 and v2 is below. The main change is that we store
the secure tag in a temporary header and restore it afterwards. This
avoids a bug in the way emacs deals with secure tags not at the top of
the message. 

Other comments:

I haven't tested this version heavily: I have been running something
similar in my tree but I just don't postpone enough messages to test
it thoroughly.

It unbinds rather than rebinds the press button in message pane option
in tree-view (currently bound to "e"). I have some thoughts on how to
deal better with attachment handling in tree-view but that can follow later.

It uses message-send-hook -- we really shouldn't do that, but as we
already do for tagging replies "replied" it is probably OK to do so
for now. (Fixing this properly is a little tricky -- avoiding the use
of message-send-hook is easy but we currently mark a message replied
even if the user aborts sending the message.)

Best wishes

Mark








Mark Walters (2):
  emacs: tree: move binding for pressing button in message pane to u
  emacs:  postpone/resume support

 emacs/notmuch-message.el | 187 +++++++++++++++++++++++++++++++++++++++++++++++
 emacs/notmuch-mua.el     |   4 +
 emacs/notmuch-show.el    |   9 +++
 emacs/notmuch-tree.el    |   2 +-
 4 files changed, 201 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index b8d6d07..a503296 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -63,11 +63,11 @@ database. It will be created if necessary."
   :type 'string
   :group 'notmuch-send)
 
-(defcustom notmuch-message-quoted-tags '("secure")
+(defcustom notmuch-message-quoted-tags '()
   "Mml tags to quote.
 
-This should be a list of mml tags to quote before saving. It is
-recommended that the list includes \"secure\".
+This should be a list of mml tags to quote before saving. You do
+not need to include \"secure\" as that is handled separately.
 
 If you include \"part\" then attachments will not be saved with
 the draft -- if not then they will be saved with the draft. The
@@ -100,10 +100,16 @@ Used when a new version is saved, or the message is sent."
 
 (defun notmuch-message-quote-some-mml ()
   "Quote the mml tags in `notmuch-message-quoted-tags`."
+  (save-excursion
+    ;; First we deal with any secure tag separately.
+    (message-goto-body)
+    (when (looking-at "<#secure[^\n]*>\n")
+      (let ((secure-tag (match-string 0)))
+	(delete-region (match-beginning 0) (match-end 0))
+	(message-add-header (concat "X-Notmuch-Emacs-Secure: " secure-tag))))
     ;; This is copied from mml-quote-region but only quotes the
     ;; specified tags.
     (when notmuch-message-quoted-tags
-    (save-excursion
       (let ((re (concat "<#!*/?\\("
 			(mapconcat 'identity notmuch-message-quoted-tags "\\|")
 			"\\)")))
@@ -115,8 +121,8 @@ Used when a new version is saved, or the message is sent."
 
 (defun notmuch-message-unquote-some-mml ()
   "Unquote the mml tags in `notmuch-message-quoted-tags`."
-  (when notmuch-message-quoted-tags
   (save-excursion
+    (when notmuch-message-quoted-tags
       (let ((re (concat "<#!+/?\\("
 			(mapconcat 'identity notmuch-message-quoted-tags "\\|")
 			"\\)")))
@@ -124,7 +130,15 @@ Used when a new version is saved, or the message is sent."
 	(while (re-search-forward re nil t)
 	  ;; Remove one ! from after the #.
 	  (goto-char (+ (match-beginning 0) 2))
-	  (delete-char 1))))))
+	  (delete-char 1))))
+    (let (secure-tag)
+      (save-restriction
+	(message-narrow-to-headers)
+	(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-message-save-draft ()
   "Save the current draft message in the notmuch database.
@@ -157,6 +171,7 @@ applied to newly inserted messages)."
 	   (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"))
+     (message-add-header "X-Notmuch-Emacs-Draft: True")
      (notmuch-message-quote-some-mml)
      (notmuch-maildir-setup-message-for-saving)
      (notmuch-maildir-notmuch-insert-current-buffer
@@ -201,10 +216,11 @@ applied to newly inserted messages)."
 	(when (member 'Message-ID message-deletable-headers)
 	  (message-remove-header "Message-ID"))
 	(when (member 'Date message-deletable-headers)
-	  (message-remove-header "Date")))
-      ;; If the message does not appear to be a draft, the postpone
-      ;; code probably didn't write it, so we should not unquote any
-      ;; mml.
+	  (message-remove-header "Date"))
+	;; The X-Notmuch-Emacs-Draft header is a more reliable
+	;; indication of whether the message really is a draft.
+	(setq draft (> (message-remove-header "X-Notmuch-Emacs-Draft") 0)))
+      ;; If the message is not a draft we should not unquote any mml.
       (when draft
 	(notmuch-message-unquote-some-mml))
       (notmuch-message-mode)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index a96ee4e..d4f5d30 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -51,8 +51,6 @@
 (declare-function notmuch-tree-get-message-properties "notmuch-tree" nil)
 (declare-function notmuch-read-query "notmuch" (prompt))
 (declare-function notmuch-message-resume "notmuch-message" (id))
-(declare-function notmuch-maildir-notmuch-insert-current-buffer
-		  "notmuch-maildir-fcc" (folder &optional create tags))
 
 (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")
   "Headers that should be shown in a message, in this order.
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index a74d45c..6c93bf9 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -257,7 +257,6 @@ FUNC."
     (define-key map (kbd "M-TAB") (notmuch-tree-to-message-pane #'notmuch-show-previous-button))
     (define-key map (kbd "<backtab>")  (notmuch-tree-to-message-pane #'notmuch-show-previous-button))
     (define-key map (kbd "TAB") (notmuch-tree-to-message-pane #'notmuch-show-next-button))
-    (define-key map "u" (notmuch-tree-to-message-pane #'notmuch-tree-button-activate))
 
     ;; bindings from show (or elsewhere) but we close the message pane first.
     (define-key map "f" (notmuch-tree-close-message-pane-and #'notmuch-show-forward-message))


Thread: