Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 448C1431FD0 for ; Sat, 16 Jul 2011 02:21:20 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EiRu47M-L4s5 for ; Sat, 16 Jul 2011 02:21:19 -0700 (PDT) Received: from marcos.anarcat.ath.cx (H144.C72.B0.tor.eicat.ca [72.0.72.144]) by olra.theworths.org (Postfix) with ESMTP id 88B56431FB6 for ; Sat, 16 Jul 2011 02:21:19 -0700 (PDT) Received: by marcos.anarcat.ath.cx (Postfix, from userid 1000) id 26C267621C; Sat, 16 Jul 2011 05:21:18 -0400 (EDT) From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= To: notmuch@notmuchmail.org Subject: [PATCH] add edit function to resume postponed emails (v2) Date: Sat, 16 Jul 2011 05:21:15 -0400 Message-Id: <1310808075-787-1-git-send-email-anarcat@koumbit.org> X-Mailer: git-send-email 1.7.5.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Jul 2011 09:21:20 -0000 Add a new function to allow editing a new message starting from an existing one, roughly the equivalent of Mutt's resend-message functionality. Hooks into the search and show views through the "e" keybinding. "postponed" tag is removed after the email is sent and the target thread is marked as deleted. Known issues: 1. only the first MIME part of the email is used 2. running this on a thread with more than one message has not been tested Signed-off-by: Antoine Beaupré --- Previous patch actually had a parse error, thanks to eval-defun... emacs/notmuch-mua.el | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ emacs/notmuch-show.el | 6 +++++ emacs/notmuch.el | 7 ++++++ 3 files changed, 63 insertions(+), 0 deletions(-) diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el index 274c5da..cd32c55 100644 --- a/emacs/notmuch-mua.el +++ b/emacs/notmuch-mua.el @@ -201,6 +201,56 @@ the From: address first." (list (cons 'from (notmuch-mua-prompt-for-sender)))))) (notmuch-mua-mail nil nil other-headers))) +(defun notmuch-mua-delete-postponed (query-string) + "Delete postponed mail after sending." + (notmuch-tag query-string "+delete") + (notmuch-tag query-string "-postponed") +) + +(defun notmuch-mua-edit-mail (query-string) + "Create a new mail composition window based on the current mail." + (interactive) + (let (headers + body + (args '("show" "--format=raw"))) + (if notmuch-show-process-crypto + (setq args (append args '("--decrypt")))) + (setq args (append args (list query-string))) + ;; This make assumptions about the output of `notmuch show', but + ;; really only that the headers come first followed by a blank + ;; line and then the body. + (with-temp-buffer + (apply 'call-process (append (list notmuch-command nil (list t t) nil) args)) + (goto-char (point-min)) + (if (re-search-forward "^$" nil t) + (save-excursion + (save-restriction + (narrow-to-region (point-min) (point)) + (goto-char (point-min)) + (setq headers (mail-header-extract)))) + ) + (forward-line 1) + (setq body (buffer-substring (point) (point-max))) + ) + + (let ((message-signature nil)) + (notmuch-mua-mail (mail-header 'to headers) + (mail-header 'subject headers) + (message-headers-to-generate headers t '(to subject)) + t nil nil (notmuch-mua-delete-postponed query-string)) + ) + + ;; insert the message body - but put it in front of the signature + ;; if one is present + (goto-char (point-max)) + (if (re-search-backward message-signature-separator nil t) + (forward-line -1) + (goto-char (point-max))) + (insert body)) + (set-buffer-modified-p nil) + + (message-goto-body)) + (defun notmuch-mua-new-forward-message (&optional prompt-for-sender) "Invoke the notmuch message forwarding window. diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index f96743b..3698767 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -865,6 +865,7 @@ function is used. " (define-key map "m" 'notmuch-mua-new-mail) (define-key map "f" 'notmuch-show-forward-message) (define-key map "r" 'notmuch-show-reply) + (define-key map "e" 'notmuch-show-edit) (define-key map "|" 'notmuch-show-pipe-message) (define-key map "w" 'notmuch-show-save-attachments) (define-key map "V" 'notmuch-show-view-raw-message) @@ -1164,6 +1165,11 @@ any effects from previous calls to (interactive "P") (notmuch-mua-new-reply (notmuch-show-get-message-id) prompt-for-sender)) +(defun notmuch-show-edit () + "Edit the current message as new." + (interactive) + (notmuch-mua-edit-mail (notmuch-show-get-message-id))) + (defun notmuch-show-forward-message (&optional prompt-for-sender) "Forward the current message." (interactive "P") diff --git a/emacs/notmuch.el b/emacs/notmuch.el index f11ec24..f18b739 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -204,6 +204,7 @@ For a mouse binding, return nil." (define-key map "p" 'notmuch-search-previous-thread) (define-key map "n" 'notmuch-search-next-thread) (define-key map "r" 'notmuch-search-reply-to-thread) + (define-key map "e" 'notmuch-search-edit) (define-key map "m" 'notmuch-mua-new-mail) (define-key map "s" 'notmuch-search) (define-key map "o" 'notmuch-search-toggle-order) @@ -448,6 +449,12 @@ Complete list of currently available key bindings: (let ((message-id (notmuch-search-find-thread-id))) (notmuch-mua-new-reply message-id prompt-for-sender))) +(defun notmuch-search-edit () + "Edit the current message as new." + (interactive) + (let ((message-id (notmuch-search-find-thread-id))) + (notmuch-mua-edit-mail message-id))) + (defun notmuch-call-notmuch-process (&rest args) "Synchronously invoke \"notmuch\" with the given list of arguments. -- 1.7.5.4