unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] add edit function to resume postponed emails
@ 2011-07-16  9:12 Antoine Beaupré
  2011-07-16 18:41 ` [PATCH 2/2] " Antoine Beaupré
  0 siblings, 1 reply; 11+ messages in thread
From: Antoine Beaupré @ 2011-07-16  9:12 UTC (permalink / raw)
  To: notmuch; +Cc: Antoine Beaupré

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é <anarcat@koumbit.org>
---
 emacs/notmuch-mua.el  |   51 +++++++++++++++++++++++++++++++++++++++++++++++++
 emacs/notmuch-show.el |    6 +++++
 emacs/notmuch.el      |    7 ++++++
 3 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 274c5da..83d7d2b 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -201,6 +201,57 @@ 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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/2] add edit function to resume postponed emails
  2011-07-16  9:12 [PATCH] add edit function to resume postponed emails Antoine Beaupré
@ 2011-07-16 18:41 ` Antoine Beaupré
  2011-07-16 19:31   ` Austin Clements
  0 siblings, 1 reply; 11+ messages in thread
From: Antoine Beaupré @ 2011-07-16 18:41 UTC (permalink / raw)
  To: notmuch; +Cc: Antoine Beaupré

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é <anarcat@koumbit.org>
---
 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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] add edit function to resume postponed emails
  2011-07-16 18:41 ` [PATCH 2/2] " Antoine Beaupré
@ 2011-07-16 19:31   ` Austin Clements
  2011-07-20 21:36     ` Antoine Beaupré
  0 siblings, 1 reply; 11+ messages in thread
From: Austin Clements @ 2011-07-16 19:31 UTC (permalink / raw)
  To: Antoine Beaupré; +Cc: notmuch

I think this could be simplified a lot and many of the known issues
addressed if this were narrowed to *only* resuming from drafts.
message-mode draft files aren't MIME messages (or, at least, they're
never multipart, and message-mode has its own special annotations over
basic RFC 822), so rather than treating the draft as a MIME message
and trying to transform it back into a message-mode-compatible draft
(which, in full generality, would be somewhere between hard and
impossible), what about just dumping the raw contents of the draft
file into a buffer and pointing message-mode at it?  If the draft file
is available, you could even open it directly (this wouldn't work for
remote usage, but remote drafts introduce many other problems, too).

2011/7/16 Antoine Beaupré <anarcat@koumbit.org>:
> 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é <anarcat@koumbit.org>
> ---
>  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
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] add edit function to resume postponed emails
  2011-07-16 19:31   ` Austin Clements
@ 2011-07-20 21:36     ` Antoine Beaupré
  2011-07-20 21:40       ` Jameson Graef Rollins
  0 siblings, 1 reply; 11+ messages in thread
From: Antoine Beaupré @ 2011-07-20 21:36 UTC (permalink / raw)
  To: Austin Clements; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 1515 bytes --]

On Sat, 16 Jul 2011 15:31:31 -0400, Austin Clements <amdragon@mit.edu> wrote:
> I think this could be simplified a lot and many of the known issues
> addressed if this were narrowed to *only* resuming from drafts.
> message-mode draft files aren't MIME messages (or, at least, they're
> never multipart, and message-mode has its own special annotations over
> basic RFC 822), so rather than treating the draft as a MIME message
> and trying to transform it back into a message-mode-compatible draft
> (which, in full generality, would be somewhere between hard and
> impossible), what about just dumping the raw contents of the draft
> file into a buffer and pointing message-mode at it?  If the draft file
> is available, you could even open it directly (this wouldn't work for
> remote usage, but remote drafts introduce many other problems, too).

I think this is a great idea. Unfortunately, I had a lot of trouble
making message-mode digest an existing buffer. For example, if you take
any existing buffer and call (message-mode) on it, you will notice it
will clear the buffer completely.

I guess I would need to look at how (notmuch-mua-edit-mail) does it but
it was the blocker i had when i tried to figure this out..

Any suggestions?

A.

-- 
To be naive and easily deceived is impermissible, today more than
ever, when the prevailing untruths may lead to a catastrophe because
they blind people to real dangers and real possibilities.
                        - Erich Fromm

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] add edit function to resume postponed emails
  2011-07-20 21:36     ` Antoine Beaupré
@ 2011-07-20 21:40       ` Jameson Graef Rollins
  2011-07-21 21:32         ` Xavier Maillard
  0 siblings, 1 reply; 11+ messages in thread
From: Jameson Graef Rollins @ 2011-07-20 21:40 UTC (permalink / raw)
  To: Antoine Beaupré, Austin Clements; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 593 bytes --]

On Wed, 20 Jul 2011 17:36:43 -0400, Antoine Beaupré <anarcat@koumbit.org> wrote:
> I think this is a great idea. Unfortunately, I had a lot of trouble
> making message-mode digest an existing buffer. For example, if you take
> any existing buffer and call (message-mode) on it, you will notice it
> will clear the buffer completely.

Hey, Antoine.  Is this really true?  It seems to work for me.  For
instance, if I view a received message raw ('V') I can then "C-x
message-mode" on that buffer and it creates a partially filled, although
not properly formatted, message.

jamie.

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] add edit function to resume postponed emails
  2011-07-20 21:40       ` Jameson Graef Rollins
@ 2011-07-21 21:32         ` Xavier Maillard
  2011-07-21 21:58           ` Jameson Graef Rollins
  0 siblings, 1 reply; 11+ messages in thread
From: Xavier Maillard @ 2011-07-21 21:32 UTC (permalink / raw)
  To: Jameson Graef Rollins, Antoine Beaupré, Austin Clements; +Cc: notmuch

Hi Jameson,

On Wed, 20 Jul 2011 14:40:44 -0700, Jameson Graef Rollins <jrollins@finestructure.net> wrote:
> On Wed, 20 Jul 2011 17:36:43 -0400, Antoine Beaupré <anarcat@koumbit.org> wrote:
> > I think this is a great idea. Unfortunately, I had a lot of trouble
> > making message-mode digest an existing buffer. For example, if you take
> > any existing buffer and call (message-mode) on it, you will notice it
> > will clear the buffer completely.
> 
> Hey, Antoine.  Is this really true?  It seems to work for me.  For
> instance, if I view a received message raw ('V') I can then "C-x
> message-mode" on that buffer and it creates a partially filled, although
> not properly formatted, message.

Maybe I misunderstood original goal but what I had in mind reading this
is certainly not editing a priviously received message in order to
(re)send it again but sending a postponed/draft message which, I guess,
means no full header(s) (no received header and such and probably
partially filled header, if any).

On the other hand, doing just something like:

C-x mail RET M-x text-mode RET M-x message-mode RET

does no harm to the buffer content as far as I can tell thus, I guess
amdragon suggestion is by far, the best compromise.

/Xavier

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] add edit function to resume postponed emails
  2011-07-21 21:32         ` Xavier Maillard
@ 2011-07-21 21:58           ` Jameson Graef Rollins
  2011-07-22  0:00             ` Antoine Beaupré
                               ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Jameson Graef Rollins @ 2011-07-21 21:58 UTC (permalink / raw)
  To: Xavier Maillard, Antoine Beaupré, Austin Clements; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 841 bytes --]

On Thu, 21 Jul 2011 23:32:58 +0200, Xavier Maillard <xavier@maillard.im> wrote:
> Maybe I misunderstood original goal but what I had in mind reading this
> is certainly not editing a priviously received message in order to
> (re)send it again but sending a postponed/draft message which, I guess,
> means no full header(s) (no received header and such and probably
> partially filled header, if any).

Hey, Xavier.  I was just responding to Antoine's comment that he had
"trouble making message-mode digest an existing buffer".

As for resuming postponed messages, I have defined the following key
binding, which I use on draft messages that have been indexed by
notmuch:

(define-key notmuch-show-mode-map "R"
  (lambda ()
    "Resume a postponed message."
    (interactive)
    (notmuch-show-view-raw-message)
    (message-mode)))

jamie.

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] add edit function to resume postponed emails
  2011-07-21 21:58           ` Jameson Graef Rollins
@ 2011-07-22  0:00             ` Antoine Beaupré
  2011-07-22  0:14               ` Jameson Graef Rollins
  2011-07-22 20:17             ` Xavier Maillard
  2011-08-08 14:52             ` Antoine Beaupré
  2 siblings, 1 reply; 11+ messages in thread
From: Antoine Beaupré @ 2011-07-22  0:00 UTC (permalink / raw)
  To: Jameson Graef Rollins, Xavier Maillard, Austin Clements; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 1323 bytes --]

On Thu, 21 Jul 2011 14:58:22 -0700, Jameson Graef Rollins <jrollins@finestructure.net> wrote:
> On Thu, 21 Jul 2011 23:32:58 +0200, Xavier Maillard <xavier@maillard.im> wrote:
> > Maybe I misunderstood original goal but what I had in mind reading this
> > is certainly not editing a priviously received message in order to
> > (re)send it again but sending a postponed/draft message which, I guess,
> > means no full header(s) (no received header and such and probably
> > partially filled header, if any).
> 
> Hey, Xavier.  I was just responding to Antoine's comment that he had
> "trouble making message-mode digest an existing buffer".
> 
> As for resuming postponed messages, I have defined the following key
> binding, which I use on draft messages that have been indexed by
> notmuch:
> 
> (define-key notmuch-show-mode-map "R"
>   (lambda ()
>     "Resume a postponed message."
>     (interactive)
>     (notmuch-show-view-raw-message)
>     (message-mode)))

Now that's a pretty good start!

It will not work to edit sent mails (which are QP-encoded, for example),
but it should work for postponed messages..

How about we patch that in? Seems like a major feature missing...

A.

-- 
L'art n'est pas un bureau d'anthropométrie.
                        - Léo Ferré, "Préface"

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] add edit function to resume postponed emails
  2011-07-22  0:00             ` Antoine Beaupré
@ 2011-07-22  0:14               ` Jameson Graef Rollins
  0 siblings, 0 replies; 11+ messages in thread
From: Jameson Graef Rollins @ 2011-07-22  0:14 UTC (permalink / raw)
  To: Antoine Beaupré, Xavier Maillard, Austin Clements; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 491 bytes --]

On Thu, 21 Jul 2011 20:00:45 -0400, Antoine Beaupré <anarcat@koumbit.org> wrote:
> How about we patch that in? Seems like a major feature missing...

Handling postponed messages is definitely something that's missing.
It's a little tricky, though, because notmuch-show.el doesn't handle
display of message-mode formatted save files very well, as Austin
previously pointed out.  I think we need to make a new notmuch-drafts.el
or something like that, to make the UI clean.

jamie.

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] add edit function to resume postponed emails
  2011-07-21 21:58           ` Jameson Graef Rollins
  2011-07-22  0:00             ` Antoine Beaupré
@ 2011-07-22 20:17             ` Xavier Maillard
  2011-08-08 14:52             ` Antoine Beaupré
  2 siblings, 0 replies; 11+ messages in thread
From: Xavier Maillard @ 2011-07-22 20:17 UTC (permalink / raw)
  To: Jameson Graef Rollins, Antoine Beaupré, Austin Clements; +Cc: notmuch

On Thu, 21 Jul 2011 14:58:22 -0700, Jameson Graef Rollins <jrollins@finestructure.net> wrote:
> On Thu, 21 Jul 2011 23:32:58 +0200, Xavier Maillard <xavier@maillard.im> wrote:
> > Maybe I misunderstood original goal but what I had in mind reading this
> > is certainly not editing a priviously received message in order to
> > (re)send it again but sending a postponed/draft message which, I guess,
> > means no full header(s) (no received header and such and probably
> > partially filled header, if any).
> 
> Hey, Xavier.  I was just responding to Antoine's comment that he had
> "trouble making message-mode digest an existing buffer".

Oh well, sorry then ;)
 
/Xavier

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] add edit function to resume postponed emails
  2011-07-21 21:58           ` Jameson Graef Rollins
  2011-07-22  0:00             ` Antoine Beaupré
  2011-07-22 20:17             ` Xavier Maillard
@ 2011-08-08 14:52             ` Antoine Beaupré
  2 siblings, 0 replies; 11+ messages in thread
From: Antoine Beaupré @ 2011-08-08 14:52 UTC (permalink / raw)
  To: Jameson Graef Rollins, Xavier Maillard, Austin Clements; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 3631 bytes --]

On Thu, 21 Jul 2011 14:58:22 -0700, Jameson Graef Rollins <jrollins@finestructure.net> wrote:
> As for resuming postponed messages, I have defined the following key
> binding, which I use on draft messages that have been indexed by
> notmuch:
[...]

So I have improved on this, I believe. I now have this in my .emacs as
test code for a new postpone workflow. I have completely ditched my
older patches in favor of this approach.

The general workflow is this:

 1. start writing an email
 2. postpone it with C-c C-d, as usual
   -> the mail gets saved to a (currently hardcoded) maildir mailbox
 using the notmuch's FCC routines
 3. notmuch new eventually happens (not ran automatically, maybe we should?)
 4. load the "tag:draft" search or the above mailbox in some way or
 another
 5. show the draft you want to resume and hit R
 6. finish editing the email and send it
   -> the mail gets deleted from the maildir

If instead of sending the mail the buffer is killed, the draft is left
alone.

I can already think of a few improvements:

 * make variable for the draft folder
 * automatically tag drafts with the draft tag (so notmuch new is not
   necessary)
 * hotkey for loading the draft search
 * kill or save a draft (after confirmation) when killing a buffer

It's still quite messy, but I wanted to share with the list here the
working code I had. I would welcome feedback on how to integrate this
into notmuch...

Thanks!

A.

(defun anarcat/notmuch-message-setup ()
  "Configures a bunch of hooks for notmuch message windows"
  (message-add-action `(message "debug: done exit actions") 'exit)
  (message-add-action `(message "debug: done postpone actions") 'postpone)
  (message-add-action `(message "debug: done kill actions") 'kill)
  (message-add-action 'notmuch-message-postpone-keep 'postpone)
  (message-add-action 'notmuch-message-postpone-cleanup 'exit)
)
(add-hook 'message-mode-hook 'anarcat/notmuch-message-setup)

(defun notmuch-message-postpone-cleanup ()
  "Remove autosave and postponed messages for that buffer"
  (message "debug: postpone cleanup hook")
  (message "deleting draft file: %s" notmuch-draft-filename)
  (if (file-exists-p notmuch-draft-filename)
      (progn 
        (kill-buffer)
        (delete-file notmuch-draft-filename)
        (if (file-exists-p notmuch-draft-filename)
            (message "failed to delete file %s" notmuch-draft-filename)
          (message "debug: file deleted"))
        )
    (message "draft file %s doesn't exist" notmuch-draft-filename)))

(defun notmuch-message-postpone-keep ()
  "Moves the previous buffer into the postponed folder and then kill it"
  ;; shouldn't be necessary: why the heck aren't we in the right buffer?
  (save-excursion
    (set-buffer (last-buffer))
    (notmuch-maildir-fcc-write-buffer-to-maildir "~/Maildir/Anarcat/postponed/" t)
    (kill-buffer))
)

(defun notmuch-show-resume-message ()
  "Resume a postponed message."
  (interactive)
  (setq tmpfilename (notmuch-show-get-filename))
  (notmuch-show-view-raw-message)
  (setq buffer-file-name tmpfilename)
  (message "debug: set buffer file name to %s" buffer-file-name)
  (setq notmuch-draft-filename buffer-file-name)
  (make-local-variable 'notmuch-draft-filename)
  (message "debug: set draft file name to %s" notmuch-draft-filename)
  (message-mode))

(define-key notmuch-show-mode-map "R" 'notmuch-show-resume-message)

-- 
O gentilshommes, la vie est courte.
Si nous vivons, nous vivons 
pour marcher sur la tête des rois.
                        - William Shakespeare

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-08-08 14:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-16  9:12 [PATCH] add edit function to resume postponed emails Antoine Beaupré
2011-07-16 18:41 ` [PATCH 2/2] " Antoine Beaupré
2011-07-16 19:31   ` Austin Clements
2011-07-20 21:36     ` Antoine Beaupré
2011-07-20 21:40       ` Jameson Graef Rollins
2011-07-21 21:32         ` Xavier Maillard
2011-07-21 21:58           ` Jameson Graef Rollins
2011-07-22  0:00             ` Antoine Beaupré
2011-07-22  0:14               ` Jameson Graef Rollins
2011-07-22 20:17             ` Xavier Maillard
2011-08-08 14:52             ` Antoine Beaupré

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