[notmuch] Fcc, Maildir, and Emacs message-mode -- a bit of code

Dirk Hohndel hohndel at infradead.org
Thu Apr 22 16:17:36 PDT 2010


On Thu, 22 Apr 2010 11:06:04 +0200, "Sebastian Spaeth" <Sebastian at SSpaeth.de> wrote:
> As Carl stated that he would probably merge this one if someone tested
> it, here it comes: I tested it and it works great. When I define a
> non-existing directory as maildir it aborts with an error message that
> is visible to the user.
> 
> I put this in a branch based on cworth/master and with Jesse's
> permission, I renamed the functions and did some further cleanup (It's
> also integrated in the build system)
> 
> The git branch is here:
> http://github.com/spaetz/notmuch-all-feature/tree/feature/elisp-fcc
> 
> It's not enabled by default. Enable it with:
> 
> (setq message-fcc-handler-function 
>       '(lambda (destdir) 
>          (notmuch-maildir-fcc-write-buffer-to-maildir destdir t)))
> 
> (add-hook 'message-send-hook 
>           '(lambda ()
>              (message-add-header "Fcc: ~/mail/INBOX.Sent")))

I am now using this patch together with this little snippet in my .emacs
file to FCC into per-from-address specific sent folders

;; This is the list of alternatives that should be configurable as
;; defcustom (or simply set in .emacs for now)
(setq notmuch-fcc-dirs '(
      ("Dirk Hohndel <dirk.hohndel at intel.com>" . "Maildir/Sent Items")
      ("Dirk Hohndel <hohndel at infradead.org>" . "MaildirInfradead/Sent")))

;This constructs a path, concatenating the content of the variable
;"message-directory" and the second part in the alist:
(defun my-fcc-header-setup ()
(let ((subdir (cdr (assoc (message-fetch-field "from") notmuch-fcc-dirs))))
     (message-add-header (concat "Fcc: " message-directory subdir))))
(add-hook 'message-send-hook 'my-fcc-header-setup)

(setq message-fcc-handler-function
       '(lambda (destdir)
	   (notmuch-maildir-fcc-write-buffer-to-maildir destdir t)))

I am using the message-send-hook (instead of the
message-header-setup-hook as Sebastian initially suggested) because I
tend to edit the From line in my message buffer and want to make sure
that it uses the final From line. Also, this way the FCC also works
correctly with replies (the message-header-setup-hook doesn't get called
by our notmuch-reply function, it seems).

The disadvantage is that with the message-send-hook I don't get to see /
correct the FCC line in the message buffer - but since I trust the logic
here (and tested it quite a bit), I'm less concerned about this.

Finally, for other emacs-newbies like me - this concats the
message-directory variable with the path that you setup in the
notmuch-fcc-dirs associative array... so the path to the sent folder
needs to be relative to that.

Carl - I'd love to see this in 0.3

/D

-- 
Dirk Hohndel
Intel Open Source Technology Center


More information about the notmuch mailing list