unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH v2 0/2] add postpone support
Date: Thu,  3 Nov 2016 18:09:06 +0000	[thread overview]
Message-ID: <1478196548-19596-1-git-send-email-markwalters1009@gmail.com> (raw)

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))

             reply	other threads:[~2016-11-03 18:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-03 18:09 Mark Walters [this message]
2016-11-03 18:09 ` [PATCH v2 1/2] emacs: tree: remove binding for pressing button in message pane Mark Walters
2016-11-05  1:26   ` David Bremner
2016-11-03 18:09 ` [PATCH v2 2/2] emacs: postpone/resume support Mark Walters
2016-11-05  1:29   ` [PATCH] emacs: add check for encryption before saving David Bremner
2016-11-05  8:56     ` Mark Walters
2016-11-05 10:41       ` David Bremner
2016-11-05 12:20         ` Mark Walters

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1478196548-19596-1-git-send-email-markwalters1009@gmail.com \
    --to=markwalters1009@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).