From c44029af2121ccf834f38953f4eb1e0bb32f55a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Antoine=20Beaupr=C3=A9?= Date: Sun, 17 Jul 2011 14:41:25 +2000 Subject: [PATCH] [PATCH 2/2] add edit function to resume postponed emails --- e3/7a3b230b6ea8a19e69c7ec3ee65868ecfde923 | 193 ++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 e3/7a3b230b6ea8a19e69c7ec3ee65868ecfde923 diff --git a/e3/7a3b230b6ea8a19e69c7ec3ee65868ecfde923 b/e3/7a3b230b6ea8a19e69c7ec3ee65868ecfde923 new file mode 100644 index 000000000..0dc32178f --- /dev/null +++ b/e3/7a3b230b6ea8a19e69c7ec3ee65868ecfde923 @@ -0,0 +1,193 @@ +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 5503A431FD0 + for ; Sat, 16 Jul 2011 11:41:29 -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 0VQX-qLhOtZH for ; + Sat, 16 Jul 2011 11:41:28 -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 94C43431FB6 + for ; Sat, 16 Jul 2011 11:41:28 -0700 (PDT) +Received: by marcos.anarcat.ath.cx (Postfix, from userid 1000) + id 3E71F7621D; Sat, 16 Jul 2011 14:41:28 -0400 (EDT) +From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= +To: notmuch@notmuchmail.org +Subject: [PATCH 2/2] add edit function to resume postponed emails +Date: Sat, 16 Jul 2011 14:41:25 -0400 +Message-Id: <1310841685-29167-1-git-send-email-anarcat@koumbit.org> +X-Mailer: git-send-email 1.7.5.4 +In-Reply-To: <1310807540-29960-1-git-send-email-anarcat@koumbit.org> +References: <1310807540-29960-1-git-send-email-anarcat@koumbit.org> +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 18:41:29 -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. + +"draft" 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 + 3. encoding is broken when files are reloaded, because we don't parse + MIME back + 4. draft files are left around when mails are written, even if they + are not postponed + +Todo: + + 1. use the proper gnus hooks to resume emails: + https://www.gnu.org/software/emacs/manual/html_node/message/Message-Actions.html#index-message_002dpostpone_002dactions-334 + + 2. write tests + +Signed-off-by: Antoine Beaupré +--- + 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..11d014d 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 "+deleted") ++ (notmuch-tag query-string "-draft") ++) ++ ++(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 c83b992..1efde1c 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) +@@ -1165,6 +1166,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 f6fb07b..b522715 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) +@@ -449,6 +450,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 + -- 2.26.2