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

2010-04-23 Thread Sebastian Spaeth
On 2010-04-22, Dirk Hohndel wrote:
> ;; 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 " . "Maildir/Sent Items")
>   ("Dirk Hohndel " . "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)

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

Another disadvantage is that this does not provide a fallback, so if you
type "dirk" rather than "Dirk" in your from, the fcc dir will be nil, so
it tries to deliver just to "message-directory". The user should be able
to configure a default FCC dir, I think.

Sebastian


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

2010-04-23 Thread Sebastian Spaeth
On 2010-04-22, Dirk Hohndel wrote:
 ;; 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.hohn...@intel.com . Maildir/Sent Items)
   (Dirk Hohndel hohn...@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)

 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.

Another disadvantage is that this does not provide a fallback, so if you
type dirk rather than Dirk in your from, the fcc dir will be nil, so
it tries to deliver just to message-directory. The user should be able
to configure a default FCC dir, I think.

Sebastian
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2010-04-22 Thread Dirk Hohndel
On Thu, 22 Apr 2010 11:06:04 +0200, "Sebastian Spaeth"  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 " . "Maildir/Sent Items")
  ("Dirk Hohndel " . "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


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

2010-04-22 Thread Sebastian Spaeth
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")))

in your .emacs for now.

I'll send the patch series by mail in a second.

I have the slight problem that offlineimap takes the message from
INBOX.Sent/cur and stuffs it in INBOX.Sent/new (but that cannot really
be related to this as the mail ends up correctly in /cur after sending
it).

Sebastian


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

2010-04-07 Thread Dirk Hohndel
On Wed, 27 Jan 2010 09:44:41 -0500, Jameson Rollins  wrote:
> Hey, folks.  Following up on this thread about better fcc handling,
> Jesse passed on a simple python script he wrote that uses the python
> "mailbox" module to deliver a message on stdin to a specified maildir
> directory.  It's very a simple, elegant and general purpose script
> (attached).
> 
> I then put the following in my notmuch .emacs to use the new script in
> message-mode to fcc sent mail to my ~/.mail/sent directory:
> 
> ;; fcc handler
> (defun maildir-deliver-region(destdir)
>   (shell-command-on-region
>(point-min) (point-max)
>(concat "maildir-deliver.py -c -s -d " destdir)))
> (setq message-fcc-handler-function 'maildir-deliver-region)
> (defun my-message-header-setup ()
>   (message-add-header "Fcc: ~/.mail/sent"))
> (add-hook 'message-send-hook 'my-message-header-setup)

This is really nice - just what I needed. Well, almost.

Instead of passing in destdir it would be even better if the lisp code
figured out which MailDir to use. So we'd have a configuration variable
that matched From addresses to MailDirs
"dirk at hohndel.org" "~/MailDirHohndel"
"dirk.hohndel at intel.com" "~/MailDirIntel"
etc.
And just for safety used the passed in destdir as fallback / default.

Anyone willing / able to add this? I can't lisp to save my life...

/D

-- 
Dirk Hohndel
Intel Open Source Technology Center


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

2010-01-29 Thread Sebastian Spaeth
First, I think this FCC method is phantastic and it works like a
charm. I agree that we should include the snippets at least in some
"contrib" directory (or doc/examples) to make it easier to find.

Jameson Rollins  wrote:
> (defun my-message-header-setup ()
>   (message-add-header "Fcc: ~/.mail/sent"))
> (add-hook 'message-send-hook 'my-message-header-setup)

I tried to replace that snippet with:

(setq message-default-mail-headers "Fcc:  ~/.mail/sent\n")

because I like to see the Fcc header when composing, but this only works
for new messages (via ctrl-x m) and not when invoked with "r"(eply) on
an existing message in notmuch.

Is message-default-mail-headers only invoked for completely new mails?
The message mode manual doesn't state anything about that.

And I agree with JRollins patch to not add the BCC to myself from
notmuch.el by default. Either make it a notmuch option, or specify how to
set up a default BCC in emacs in the docs.

Sebastian


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

2010-01-29 Thread Jesse Rosenthal
On Fri, 29 Jan 2010 14:21:56 +0100, Sebastian Spaeth  
wrote:
> First, I think this FCC method is phantastic and it works like a
> charm. I agree that we should include the snippets at least in some
> "contrib" directory (or doc/examples) to make it easier to find.

I'm glad it's proved useful. However, I should say that I'd be wary of
distributing it, or even recommending it, without at least rudimentary
error checking -- even if it's just the delivery function returning
either 0 or -1, and the emacs wrapper reporting failure back to the user
in a sensible fashion. As it is now, a failed delivery will either go
silently by, or muck everything up in a not-so-useful way.

Returning some sort of success/fail would just take a couple of
try/except lines. I would have put that in myself, but I just whipped it
up for personal use (and then never used it).

Best,
Jesse


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

2010-01-29 Thread Jameson Rollins
On Fri, 29 Jan 2010 14:21:56 +0100, "Sebastian Spaeth"  wrote:
> First, I think this FCC method is phantastic and it works like a
> charm. I agree that we should include the snippets at least in some
> "contrib" directory (or doc/examples) to make it easier to find.

I'm really glad this was useful.  Thanks of course to Jesse, who
initially figured all this out.

I'm pretty convinced that soon enough we'll have a new packages worth of
notmuch helper functions and scripts.

> Jameson Rollins  wrote:
> > (defun my-message-header-setup ()
> >   (message-add-header "Fcc: ~/.mail/sent"))
> > (add-hook 'message-send-hook 'my-message-header-setup)
> 
> I tried to replace that snippet with:
> 
> (setq message-default-mail-headers "Fcc:  ~/.mail/sent\n")
>
> because I like to see the Fcc header when composing, but this only works
> for new messages (via ctrl-x m) and not when invoked with "r"(eply) on
> an existing message in notmuch.
>
> Is message-default-mail-headers only invoked for completely new mails?
> The message mode manual doesn't state anything about that.

Yeah, I started out doing that as well, but I tried every permutation of
setup hooks I could think of and couldn't get consisten behavior when
doing replys or new messages.  I ended up just using the send-hook
because it was simple and consistent.

> And I agree with JRollins patch to not add the BCC to myself from
> notmuch.el by default. Either make it a notmuch option, or specify how to
> set up a default BCC in emacs in the docs.

I think this needs to just be done via a personal emacs config.  There's
really no need for the notmuch CLI to handle this, when it can easily
enough be handled by the reader UI.

jamie.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 



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

2010-01-29 Thread Sebastian Spaeth
First, I think this FCC method is phantastic and it works like a
charm. I agree that we should include the snippets at least in some
contrib directory (or doc/examples) to make it easier to find.

Jameson Rollins jroll...@finestructure.net wrote:
 (defun my-message-header-setup ()
   (message-add-header Fcc: ~/.mail/sent))
 (add-hook 'message-send-hook 'my-message-header-setup)

I tried to replace that snippet with:

(setq message-default-mail-headers Fcc:  ~/.mail/sent\n)

because I like to see the Fcc header when composing, but this only works
for new messages (via ctrl-x m) and not when invoked with r(eply) on
an existing message in notmuch.

Is message-default-mail-headers only invoked for completely new mails?
The message mode manual doesn't state anything about that.

And I agree with JRollins patch to not add the BCC to myself from
notmuch.el by default. Either make it a notmuch option, or specify how to
set up a default BCC in emacs in the docs.

Sebastian
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2010-01-29 Thread Jesse Rosenthal
On Fri, 29 Jan 2010 14:21:56 +0100, Sebastian Spaeth sebast...@sspaeth.de 
wrote:
 First, I think this FCC method is phantastic and it works like a
 charm. I agree that we should include the snippets at least in some
 contrib directory (or doc/examples) to make it easier to find.

I'm glad it's proved useful. However, I should say that I'd be wary of
distributing it, or even recommending it, without at least rudimentary
error checking -- even if it's just the delivery function returning
either 0 or -1, and the emacs wrapper reporting failure back to the user
in a sensible fashion. As it is now, a failed delivery will either go
silently by, or muck everything up in a not-so-useful way.

Returning some sort of success/fail would just take a couple of
try/except lines. I would have put that in myself, but I just whipped it
up for personal use (and then never used it).

Best,
Jesse
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2010-01-27 Thread Jameson Rollins
Hey, folks.  Following up on this thread about better fcc handling,
Jesse passed on a simple python script he wrote that uses the python
"mailbox" module to deliver a message on stdin to a specified maildir
directory.  It's very a simple, elegant and general purpose script
(attached).

I then put the following in my notmuch .emacs to use the new script in
message-mode to fcc sent mail to my ~/.mail/sent directory:

;; fcc handler
(defun maildir-deliver-region(destdir)
  (shell-command-on-region
   (point-min) (point-max)
   (concat "maildir-deliver.py -c -s -d " destdir)))
(setq message-fcc-handler-function 'maildir-deliver-region)
(defun my-message-header-setup ()
  (message-add-header "Fcc: ~/.mail/sent"))
(add-hook 'message-send-hook 'my-message-header-setup)

Works like a charm.  Thanks Jesse!

I think we should look at packaging this in a set of notmuch helper
scripts, hopefully including notmuchsync.

jamie.

-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 

-- next part --
A non-text attachment was scrubbed...
Name: maildir-deliver.py
Type: text/x-python
Size: 1090 bytes
Desc: python maildir delivery script
URL: 



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

2010-01-21 Thread Jesse Rosenthal

Dear all,

First of all, many thanks to Carl and others for writing notmuch.

Some folks on IRC were bemoaning message-mode's annoying inability to
save sent-mail to a Maildir using Fcc. I mentioned that I had written a
bit of Maildir elisp code for that purpose a while back, and it was
suggested that I share it with the list.

Some caveats:

- I've tested this a good number of times, but not very robustly, since
  I don't actually use it (I found that I prefer blind-copying
  myself). Please test it out somewhere safe, on a maildir you can
  afford to lose.

- The hardlinking performed by `add-name-to-file' might be platform and
  filesystem specific. I'm using linux/ext3, and it works here. I don't
  know what will happen anywhere else.

- I imagine there's a much better implementation inside of Wanderlust,
  if you can dig through all the libraries.

- It's not really commented, but I hope the function names are pretty
  self-explanatory.

- It requires that the directory in the `Fcc:' header already exist and
  be a maildir (i.e. have cur/, new/, and tmp/). It should be pretty
  simple to add in a prompt for creating a directory if it points to a
  nonexistent place.

Anyway, here it is:

http://jkr.acm.jhu.edu/jkr-maildir.el

To use it, set one of the following:

If you want Fcc'd messages to be marked as read:

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

If you want Fcc'd messages to be marked as new:

 (setq message-fcc-handler-function 
  '(lambda (destdir) 
 (jkr/maildir-write-buffer-to-maildir destdir nil)))


Best,
Jesse



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

2010-01-21 Thread Jesse Rosenthal

Dear all,

First of all, many thanks to Carl and others for writing notmuch.

Some folks on IRC were bemoaning message-mode's annoying inability to
save sent-mail to a Maildir using Fcc. I mentioned that I had written a
bit of Maildir elisp code for that purpose a while back, and it was
suggested that I share it with the list.

Some caveats:

- I've tested this a good number of times, but not very robustly, since
  I don't actually use it (I found that I prefer blind-copying
  myself). Please test it out somewhere safe, on a maildir you can
  afford to lose.

- The hardlinking performed by `add-name-to-file' might be platform and
  filesystem specific. I'm using linux/ext3, and it works here. I don't
  know what will happen anywhere else.

- I imagine there's a much better implementation inside of Wanderlust,
  if you can dig through all the libraries.

- It's not really commented, but I hope the function names are pretty
  self-explanatory.

- It requires that the directory in the `Fcc:' header already exist and
  be a maildir (i.e. have cur/, new/, and tmp/). It should be pretty
  simple to add in a prompt for creating a directory if it points to a
  nonexistent place.

Anyway, here it is:

http://jkr.acm.jhu.edu/jkr-maildir.el

To use it, set one of the following:

If you want Fcc'd messages to be marked as read:

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

If you want Fcc'd messages to be marked as new:

 (setq message-fcc-handler-function 
  '(lambda (destdir) 
 (jkr/maildir-write-buffer-to-maildir destdir nil)))


Best,
Jesse

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch