Re: [PATCH 2/2] add edit function to resume postponed emails
authorAustin Clements <amdragon@mit.edu>
Sat, 16 Jul 2011 19:31:31 +0000 (15:31 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:39:08 +0000 (09:39 -0800)
fb/6792dfa684b0c4a55db8fcaedb8783a7c85be4 [new file with mode: 0644]

diff --git a/fb/6792dfa684b0c4a55db8fcaedb8783a7c85be4 b/fb/6792dfa684b0c4a55db8fcaedb8783a7c85be4
new file mode 100644 (file)
index 0000000..858c7e9
--- /dev/null
@@ -0,0 +1,237 @@
+Return-Path: <amdragon@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 150F8431FD0\r
+       for <notmuch@notmuchmail.org>; Sat, 16 Jul 2011 12:31:36 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.699\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001,\r
+       RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id z7BeW0-8hQ2j for <notmuch@notmuchmail.org>;\r
+       Sat, 16 Jul 2011 12:31:34 -0700 (PDT)\r
+Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com\r
+       [209.85.216.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 0F3C8431FB6\r
+       for <notmuch@notmuchmail.org>; Sat, 16 Jul 2011 12:31:34 -0700 (PDT)\r
+Received: by qyk9 with SMTP id 9so1416290qyk.5\r
+       for <notmuch@notmuchmail.org>; Sat, 16 Jul 2011 12:31:33 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=mime-version:sender:in-reply-to:references:date\r
+       :x-google-sender-auth:message-id:subject:from:to:cc:content-type\r
+       :content-transfer-encoding;\r
+       bh=mp84a5lCy+y0LfMQvD0KCKrwd/QKyw6kpmKcgxOXP3M=;\r
+       b=Tn8odq3+esV+k4yJL11ko7u89pwZUDL1m/U1AhYPXPpr1PPb5KA6RYcJSGimau/GQu\r
+       Qyt8MOTscKcL/9UhshOD9feKXvpCXrrjhNhGfnc+Xqq7LFexJGp2LZE07iG28GODBqNX\r
+       dUy3YohcjajxB6NfOsLSbN97PmkeKxZcCD21k=\r
+MIME-Version: 1.0\r
+Received: by 10.229.27.198 with SMTP id j6mr3708789qcc.10.1310844691654; Sat,\r
+       16 Jul 2011 12:31:31 -0700 (PDT)\r
+Sender: amdragon@gmail.com\r
+Received: by 10.229.250.208 with HTTP; Sat, 16 Jul 2011 12:31:31 -0700 (PDT)\r
+In-Reply-To: <1310841685-29167-1-git-send-email-anarcat@koumbit.org>\r
+References: <1310807540-29960-1-git-send-email-anarcat@koumbit.org>\r
+       <1310841685-29167-1-git-send-email-anarcat@koumbit.org>\r
+Date: Sat, 16 Jul 2011 15:31:31 -0400\r
+X-Google-Sender-Auth: PO4J04y2Ix-Ob6Dy6yP9n_VHI34\r
+Message-ID:\r
+ <CAH-f9Wtff0noP2-jxSmmhMRDWebt6G10Pe+3r-m6WvhDm_--ow@mail.gmail.com>\r
+Subject: Re: [PATCH 2/2] add edit function to resume postponed emails\r
+From: Austin Clements <amdragon@mit.edu>\r
+To: =?ISO-8859-1?Q?Antoine_Beaupr=E9?= <anarcat@koumbit.org>\r
+Content-Type: text/plain; charset=ISO-8859-1\r
+Content-Transfer-Encoding: quoted-printable\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 16 Jul 2011 19:31:36 -0000\r
+\r
+I think this could be simplified a lot and many of the known issues\r
+addressed if this were narrowed to *only* resuming from drafts.\r
+message-mode draft files aren't MIME messages (or, at least, they're\r
+never multipart, and message-mode has its own special annotations over\r
+basic RFC 822), so rather than treating the draft as a MIME message\r
+and trying to transform it back into a message-mode-compatible draft\r
+(which, in full generality, would be somewhere between hard and\r
+impossible), what about just dumping the raw contents of the draft\r
+file into a buffer and pointing message-mode at it?  If the draft file\r
+is available, you could even open it directly (this wouldn't work for\r
+remote usage, but remote drafts introduce many other problems, too).\r
+\r
+2011/7/16 Antoine Beaupr=E9 <anarcat@koumbit.org>:\r
+> Add a new function to allow editing a new message starting from an\r
+> existing one, roughly the equivalent of Mutt's resend-message\r
+> functionality.\r
+>\r
+> Hooks into the search and show views through the "e" keybinding.\r
+>\r
+> "draft" tag is removed after the email is sent and the target thread\r
+> is marked as deleted.\r
+>\r
+> Known issues:\r
+>\r
+> =A01. only the first MIME part of the email is used\r
+> =A02. running this on a thread with more than one message has not been\r
+> =A0tested\r
+> =A03. encoding is broken when files are reloaded, because we don't parse\r
+> =A0MIME back\r
+> =A04. draft files are left around when mails are written, even if they\r
+> =A0are not postponed\r
+>\r
+> Todo:\r
+>\r
+> =A01. use the proper gnus hooks to resume emails:\r
+> =A0https://www.gnu.org/software/emacs/manual/html_node/message/Message-Ac=\r
+tions.html#index-message_002dpostpone_002dactions-334\r
+>\r
+> =A02. write tests\r
+>\r
+> Signed-off-by: Antoine Beaupr=E9 <anarcat@koumbit.org>\r
+> ---\r
+> =A0emacs/notmuch-mua.el =A0| =A0 50 +++++++++++++++++++++++++++++++++++++=\r
+++++++++++++\r
+> =A0emacs/notmuch-show.el | =A0 =A06 +++++\r
+> =A0emacs/notmuch.el =A0 =A0 =A0| =A0 =A07 ++++++\r
+> =A03 files changed, 63 insertions(+), 0 deletions(-)\r
+>\r
+> diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+> index 274c5da..11d014d 100644\r
+> --- a/emacs/notmuch-mua.el\r
+> +++ b/emacs/notmuch-mua.el\r
+> @@ -201,6 +201,56 @@ the From: address first."\r
+> =A0 =A0 =A0 =A0 =A0 (list (cons 'from (notmuch-mua-prompt-for-sender)))))=\r
+)\r
+> =A0 =A0 (notmuch-mua-mail nil nil other-headers)))\r
+>\r
+> +(defun notmuch-mua-delete-postponed (query-string)\r
+> + =A0"Delete postponed mail after sending."\r
+> + =A0(notmuch-tag query-string "+deleted")\r
+> + =A0(notmuch-tag query-string "-draft")\r
+> +)\r
+> +\r
+> +(defun notmuch-mua-edit-mail (query-string)\r
+> + =A0"Create a new mail composition window based on the current mail."\r
+> + =A0(interactive)\r
+> + =A0(let (headers\r
+> + =A0 =A0 =A0 body\r
+> + =A0 =A0 =A0 (args '("show" "--format=3Draw")))\r
+> + =A0 =A0(if notmuch-show-process-crypto\r
+> + =A0 =A0 =A0 (setq args (append args '("--decrypt"))))\r
+> + =A0 =A0(setq args (append args (list query-string)))\r
+> + =A0 =A0;; This make assumptions about the output of `notmuch show', but\r
+> + =A0 =A0;; really only that the headers come first followed by a blank\r
+> + =A0 =A0;; line and then the body.\r
+> + =A0 =A0(with-temp-buffer\r
+> + =A0 =A0 =A0(apply 'call-process (append (list notmuch-command nil (list=\r
+ t t) nil) args))\r
+> + =A0 =A0 =A0(goto-char (point-min))\r
+> + =A0 =A0 =A0(if (re-search-forward "^$" nil t)\r
+> + =A0 =A0 =A0 =A0 (save-excursion\r
+> + =A0 =A0 =A0 =A0 =A0 (save-restriction\r
+> + =A0 =A0 =A0 =A0 =A0 =A0 (narrow-to-region (point-min) (point))\r
+> + =A0 =A0 =A0 =A0 =A0 =A0 (goto-char (point-min))\r
+> + =A0 =A0 =A0 =A0 =A0 =A0 (setq headers (mail-header-extract))))\r
+> + =A0 =A0 =A0 =A0 )\r
+> + =A0 =A0 =A0(forward-line 1)\r
+> + =A0 =A0 =A0(setq body (buffer-substring (point) (point-max)))\r
+> + =A0 =A0 =A0)\r
+> +\r
+> + =A0 =A0(let ((message-signature nil))\r
+> + =A0 =A0 =A0(notmuch-mua-mail (mail-header 'to headers)\r
+> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (mail-header 'subject heade=\r
+rs)\r
+> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (message-headers-to-generat=\r
+e headers t '(to subject))\r
+> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 t nil nil (notmuch-mua-dele=\r
+te-postponed query-string))\r
+> + =A0 =A0)\r
+> +\r
+> + =A0 =A0;; insert the message body - but put it in front of the signatur=\r
+e\r
+> + =A0 =A0;; if one is present\r
+> + =A0 =A0(goto-char (point-max))\r
+> + =A0 =A0(if (re-search-backward message-signature-separator nil t)\r
+> + =A0 =A0 =A0 =A0 (forward-line -1)\r
+> + =A0 =A0 =A0(goto-char (point-max)))\r
+> + =A0 =A0(insert body))\r
+> + =A0(set-buffer-modified-p nil)\r
+> +\r
+> + =A0(message-goto-body))\r
+> +\r
+> =A0(defun notmuch-mua-new-forward-message (&optional prompt-for-sender)\r
+> =A0 "Invoke the notmuch message forwarding window.\r
+>\r
+> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+> index c83b992..1efde1c 100644\r
+> --- a/emacs/notmuch-show.el\r
+> +++ b/emacs/notmuch-show.el\r
+> @@ -865,6 +865,7 @@ function is used. "\r
+> =A0 =A0 =A0 =A0(define-key map "m" 'notmuch-mua-new-mail)\r
+> =A0 =A0 =A0 =A0(define-key map "f" 'notmuch-show-forward-message)\r
+> =A0 =A0 =A0 =A0(define-key map "r" 'notmuch-show-reply)\r
+> + =A0 =A0 =A0 (define-key map "e" 'notmuch-show-edit)\r
+> =A0 =A0 =A0 =A0(define-key map "|" 'notmuch-show-pipe-message)\r
+> =A0 =A0 =A0 =A0(define-key map "w" 'notmuch-show-save-attachments)\r
+> =A0 =A0 =A0 =A0(define-key map "V" 'notmuch-show-view-raw-message)\r
+> @@ -1165,6 +1166,11 @@ any effects from previous calls to\r
+> =A0 (interactive "P")\r
+> =A0 (notmuch-mua-new-reply (notmuch-show-get-message-id) prompt-for-sende=\r
+r))\r
+>\r
+> +(defun notmuch-show-edit ()\r
+> + =A0"Edit the current message as new."\r
+> + =A0(interactive)\r
+> + =A0(notmuch-mua-edit-mail (notmuch-show-get-message-id)))\r
+> +\r
+> =A0(defun notmuch-show-forward-message (&optional prompt-for-sender)\r
+> =A0 "Forward the current message."\r
+> =A0 (interactive "P")\r
+> diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> index f6fb07b..b522715 100644\r
+> --- a/emacs/notmuch.el\r
+> +++ b/emacs/notmuch.el\r
+> @@ -204,6 +204,7 @@ For a mouse binding, return nil."\r
+> =A0 =A0 (define-key map "p" 'notmuch-search-previous-thread)\r
+> =A0 =A0 (define-key map "n" 'notmuch-search-next-thread)\r
+> =A0 =A0 (define-key map "r" 'notmuch-search-reply-to-thread)\r
+> + =A0 =A0(define-key map "e" 'notmuch-search-edit)\r
+> =A0 =A0 (define-key map "m" 'notmuch-mua-new-mail)\r
+> =A0 =A0 (define-key map "s" 'notmuch-search)\r
+> =A0 =A0 (define-key map "o" 'notmuch-search-toggle-order)\r
+> @@ -449,6 +450,12 @@ Complete list of currently available key bindings:\r
+> =A0 (let ((message-id (notmuch-search-find-thread-id)))\r
+> =A0 =A0 (notmuch-mua-new-reply message-id prompt-for-sender)))\r
+>\r
+> +(defun notmuch-search-edit ()\r
+> + =A0"Edit the current message as new."\r
+> + =A0(interactive)\r
+> + =A0(let ((message-id (notmuch-search-find-thread-id)))\r
+> + =A0 =A0(notmuch-mua-edit-mail message-id)))\r
+> +\r
+> =A0(defun notmuch-call-notmuch-process (&rest args)\r
+> =A0 "Synchronously invoke \"notmuch\" with the given list of arguments.\r
+>\r
+> --\r
+> 1.7.5.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r
+>\r