Using procmail to set tags

bryan hunt mafubryan at gmail.com
Tue May 15 03:14:50 PDT 2012


On Mon, 2012-05-14 at 19:34 -0400, Robert Horn wrote:
> Is it practical (and has anyone documented) using a procmail setup to
> set initial tags for messages using notmuch?
> 
> I've just started using emacs-notmuch to read mail, and I'm using a
> system where I have procmail filters to bin mail by category into
> folders.  I can continue this using folder:value for searching, but one
> reason notmuch interests me is the potential to do more.
> 
> It's practical for me to assign potentially overlapping tags with a more
> sophisticated procmail setup.  Notmuch tags enable having multiple tags
> on one email.
> 
> I don't know enough about the procmail/notmuch process to see just how
> to make this happen.  I'm hoping that someone has already done something
> similar.
> 
> R Horn
> rjhorn at alum.mit.edu

You could have procmail fire a python script to add or remove tags based
upon message content. 

Here's a python script I tried using to untag messages from the Lift
mailing list, there was a problem when I wrote it, but it's probably
been fixed by now.

#!/usr/bin/env python

from notmuch import *

'''
The idea of this script is that it will untag mailing list messages,
keeping them from my inbox unless they are directly related to me.

The problem is that the tag removal isn't being saved. 
I've created a bug report with the developer:

https://bitbucket.org/spaetz/cnotmuch/issue/1/removing-tags-doesnt-seem-to-be-saving

'''
db = Database('/home/bryan/.maildb',False, 'READ_WRITE')
q=db.create_query("'[lift]' -from:bryan tag:inbox")

for msg in q.search_messages():
    print msg.get_tags()
    msg.freeze()
    msg.remove_tag("inbox")
    print msg.get_tags()
    msg.remove_tag("unread")
    print msg.get_tags()
    msg.add_tag("lift")
    print msg.get_tags()
    msg.thaw()
exit()



More information about the notmuch mailing list