From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [Patch v5 4/4] emacs: resume messages
Date: Mon, 7 Nov 2016 08:52:11 -0400 [thread overview]
Message-ID: <20161107125211.23405-5-david@tethera.net> (raw)
In-Reply-To: <20161107125211.23405-1-david@tethera.net>
Provide functionality to resume editing a mesage previously saved with
notmuch-draft-save, including decoding the X-Notmuch-Emacs-Secure
header.
Resume gets the raw file from notmuch and using the emacs function
mime-to-mml reconstructs the message (including attachments).
'e' is bound to resume a draft from show or tree mode.
---
emacs/notmuch-draft.el | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
emacs/notmuch-show.el | 10 ++++++++
emacs/notmuch-tree.el | 1 +
test/T630-emacs-draft.sh | 15 ++++++++++++
4 files changed, 87 insertions(+)
diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index 5a230e8..1528d79 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -117,6 +117,27 @@ Used when a new version is saved, or the message is sent."
(goto-char (+ (match-beginning 0) 2))
(insert "!"))))))
+(defun notmuch-draft-unquote-some-mml ()
+ "Unquote the mml tags in `notmuch-draft-quoted-tags`."
+ (save-excursion
+ (when notmuch-draft-quoted-tags
+ (let ((re (concat "<#!+/?\\("
+ (mapconcat 'identity notmuch-draft-quoted-tags "\\|")
+ "\\)")))
+ (message-goto-body)
+ (while (re-search-forward re nil t)
+ ;; Remove one ! from after the #.
+ (goto-char (+ (match-beginning 0) 2))
+ (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-draft--check-encryption-tag (&optional ask)
"Query user if there an mml tag that looks like it might indicate encryption.
@@ -194,6 +215,46 @@ applied to newly inserted messages)."
(notmuch-draft-save-draft)
(kill-buffer))
+(defun notmuch-draft-resume (id)
+ "Resume editing of message with id ID."
+ (let* ((tags (process-lines notmuch-command "search" "--output=tags"
+ "--exclude=false" id))
+ (draft (equal tags (notmuch-update-tags tags notmuch-draft-tags))))
+ (when (or draft
+ (yes-or-no-p "Message does not appear to be a draft: really resume? "))
+ (switch-to-buffer (get-buffer-create (concat "*notmuch-draft-" id "*")))
+ (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))
+ (mime-to-mml)
+ (goto-char (point-min))
+ (when (re-search-forward "^$" nil t)
+ (replace-match mail-header-separator t t))
+ ;; Remove the Date and Message-ID headers (unless the user has
+ ;; explicitly customized emacs to tell us not to) as they will
+ ;; be replaced when the message is sent.
+ (save-restriction
+ (message-narrow-to-headers)
+ (when (member 'Message-ID message-deletable-headers)
+ (message-remove-header "Message-ID"))
+ (when (member 'Date message-deletable-headers)
+ (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-draft-unquote-some-mml))
+ (notmuch-message-mode)
+ (message-goto-body)
+ (set-buffer-modified-p nil)
+ ;; If the resumed message was a draft then set the draft
+ ;; message-id so that we can delete the current saved draft if the
+ ;; message is resaved or sent.
+ (setq notmuch-draft-id (when draft id)))))
+
+
(add-hook 'message-send-hook 'notmuch-draft--mark-deleted)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index fcf7e6e..79e4435 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -38,6 +38,7 @@
(require 'notmuch-mua)
(require 'notmuch-crypto)
(require 'notmuch-print)
+(require 'notmuch-draft)
(declare-function notmuch-call-notmuch-process "notmuch" (&rest args))
(declare-function notmuch-search-next-thread "notmuch" nil)
@@ -50,6 +51,7 @@
(&optional query query-context target buffer-name open-target))
(declare-function notmuch-tree-get-message-properties "notmuch-tree" nil)
(declare-function notmuch-read-query "notmuch" (prompt))
+(declare-function notmuch-draft-resume "notmuch-draft" (id))
(defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")
"Headers that should be shown in a message, in this order.
@@ -1445,6 +1447,7 @@ reset based on the original query."
(define-key map "|" 'notmuch-show-pipe-message)
(define-key map "w" 'notmuch-show-save-attachments)
(define-key map "V" 'notmuch-show-view-raw-message)
+ (define-key map "e" 'notmuch-show-resume-message)
(define-key map "c" 'notmuch-show-stash-map)
(define-key map "h" 'notmuch-show-toggle-visibility-headers)
(define-key map "k" 'notmuch-tag-jump)
@@ -1982,6 +1985,13 @@ to show, nil otherwise."
(setq buffer-read-only t)
(view-buffer buf 'kill-buffer-if-not-modified)))
+(defun notmuch-show-resume-message ()
+ "Resume EDITING the current draft message."
+ (interactive)
+ (let ((id (notmuch-show-get-message-id)))
+ (when id
+ (notmuch-draft-resume id))))
+
(put 'notmuch-show-pipe-message 'notmuch-doc
"Pipe the contents of the current message to a command.")
(put 'notmuch-show-pipe-message 'notmuch-prefix-doc
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 8398eb1..4abcf60 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -273,6 +273,7 @@ FUNC."
(define-key map "r" (notmuch-tree-close-message-pane-and #'notmuch-show-reply-sender))
(define-key map "R" (notmuch-tree-close-message-pane-and #'notmuch-show-reply))
(define-key map "V" (notmuch-tree-close-message-pane-and #'notmuch-show-view-raw-message))
+ (define-key map "e" (notmuch-tree-close-message-pane-and #'notmuch-show-resume-message))
;; The main tree view bindings
(define-key map (kbd "RET") 'notmuch-tree-show-message)
diff --git a/test/T630-emacs-draft.sh b/test/T630-emacs-draft.sh
index 689ccfb..46fc356 100755
--- a/test/T630-emacs-draft.sh
+++ b/test/T630-emacs-draft.sh
@@ -52,4 +52,19 @@ count2=$(notmuch count subject:draft-test-0004)
test_expect_equal "$count1,$count2" "3,0"
+test_begin_subtest "Resuming a signed draft"
+
+test_emacs '(notmuch-show "subject:draft-test-0003")
+ (notmuch-show-resume-message)
+ (test-output)'
+notmuch_dir_sanitize OUTPUT > OUTPUT.clean
+cat <<EOF | notmuch_dir_sanitize >EXPECTED
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To:
+Subject: draft-test-0003
+Fcc: MAIL_DIR/sent
+--text follows this line--
+<#secure method=pgpmime mode=sign>
+EOF
+test_expect_equal_file EXPECTED OUTPUT.clean
test_done
--
2.10.2
next prev parent reply other threads:[~2016-11-07 12:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-07 12:52 v5 emacs postpone/resume patches David Bremner
2016-11-07 12:52 ` [Patch v5 1/4] emacs: tree: remove binding for pressing button in message pane David Bremner
2016-11-07 12:52 ` [Patch v5 2/4] emacs: postpone a message David Bremner
2016-11-12 12:30 ` David Bremner
2016-11-13 9:36 ` Mark Walters
2016-11-07 12:52 ` [Patch v5 3/4] emacs: check drafts for encryption tags before saving David Bremner
2016-11-07 19:47 ` Mark Walters
2016-11-12 12:48 ` David Bremner
2016-11-07 12:52 ` David Bremner [this message]
2016-11-12 13:10 ` [Patch v5 4/4] emacs: resume messages David Bremner
2016-11-13 9:41 ` Mark Walters
2016-11-13 13:13 ` David Bremner
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=20161107125211.23405-5-david@tethera.net \
--to=david@tethera.net \
--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).