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

Antoine Beaupré anarcat at koumbit.org
Mon Aug 8 07:52:06 PDT 2011


On Thu, 21 Jul 2011 14:58:22 -0700, Jameson Graef Rollins <jrollins at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20110808/a2b8dfc9/attachment.pgp>


More information about the notmuch mailing list