[PATCH 2/2] add edit function to resume postponed emails

2011-08-08 Thread Antoine Beaupré
On Thu, 21 Jul 2011 14:58:22 -0700, Jameson Graef Rollins  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
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 



Re: [PATCH 2/2] add edit function to resume postponed emails

2011-08-08 Thread Antoine Beaupré
On Thu, 21 Jul 2011 14:58:22 -0700, Jameson Graef Rollins 
jroll...@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


pgp3ot1ZRpvIe.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 2/2] add edit function to resume postponed emails

2011-07-22 Thread Xavier Maillard
On Thu, 21 Jul 2011 14:58:22 -0700, Jameson Graef Rollins  wrote:
> On Thu, 21 Jul 2011 23:32:58 +0200, Xavier Maillard  
> 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


[PATCH 2/2] add edit function to resume postponed emails

2011-07-22 Thread Xavier Maillard
Hi Jameson,

On Wed, 20 Jul 2011 14:40:44 -0700, Jameson Graef Rollins  wrote:
> On Wed, 20 Jul 2011 17:36:43 -0400, Antoine Beaupr?  
> 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


Re: [PATCH 2/2] add edit function to resume postponed emails

2011-07-22 Thread Xavier Maillard
On Thu, 21 Jul 2011 14:58:22 -0700, Jameson Graef Rollins 
jroll...@finestructure.net wrote:
 On Thu, 21 Jul 2011 23:32:58 +0200, Xavier Maillard xav...@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
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 2/2] add edit function to resume postponed emails

2011-07-21 Thread Antoine Beaupré
On Thu, 21 Jul 2011 14:58:22 -0700, Jameson Graef Rollins  wrote:
> On Thu, 21 Jul 2011 23:32:58 +0200, Xavier Maillard  
> 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"
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 



[PATCH 2/2] add edit function to resume postponed emails

2011-07-21 Thread Jameson Graef Rollins
On Thu, 21 Jul 2011 20:00:45 -0400, Antoine Beaupr?  
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.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 



[PATCH 2/2] add edit function to resume postponed emails

2011-07-21 Thread Jameson Graef Rollins
On Thu, 21 Jul 2011 23:32:58 +0200, Xavier Maillard  
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.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 



Re: [PATCH 2/2] add edit function to resume postponed emails

2011-07-21 Thread Xavier Maillard
Hi Jameson,

On Wed, 20 Jul 2011 14:40:44 -0700, Jameson Graef Rollins 
jroll...@finestructure.net wrote:
 On Wed, 20 Jul 2011 17:36:43 -0400, Antoine Beaupré anar...@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
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 2/2] add edit function to resume postponed emails

2011-07-21 Thread Jameson Graef Rollins
On Thu, 21 Jul 2011 23:32:58 +0200, Xavier Maillard xav...@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.


pgpAU9hOiK7Km.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 2/2] add edit function to resume postponed emails

2011-07-21 Thread Antoine Beaupré
On Thu, 21 Jul 2011 14:58:22 -0700, Jameson Graef Rollins 
jroll...@finestructure.net wrote:
 On Thu, 21 Jul 2011 23:32:58 +0200, Xavier Maillard xav...@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


pgpL6Mll8rQsq.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 2/2] add edit function to resume postponed emails

2011-07-21 Thread Jameson Graef Rollins
On Thu, 21 Jul 2011 20:00:45 -0400, Antoine Beaupré anar...@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.


pgpdEmkW7eIN8.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 2/2] add edit function to resume postponed emails

2011-07-20 Thread Antoine Beaupré
On Sat, 16 Jul 2011 15:31:31 -0400, Austin Clements  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
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 



[PATCH 2/2] add edit function to resume postponed emails

2011-07-20 Thread Jameson Graef Rollins
On Wed, 20 Jul 2011 17:36:43 -0400, Antoine Beaupr?  
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.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 



Re: [PATCH 2/2] add edit function to resume postponed emails

2011-07-20 Thread Antoine Beaupré
On Sat, 16 Jul 2011 15:31:31 -0400, Austin Clements amdra...@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


pgp2pNs2TFrvJ.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 2/2] add edit function to resume postponed emails

2011-07-20 Thread Jameson Graef Rollins
On Wed, 20 Jul 2011 17:36:43 -0400, Antoine Beaupré anar...@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.


pgp76syaqAt9B.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 2/2] add edit function to resume postponed emails

2011-07-16 Thread Austin Clements
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? :
> 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 ( 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 

Re: [PATCH 2/2] add edit function to resume postponed emails

2011-07-16 Thread Austin Clements
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é anar...@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é anar...@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