My mail configuration

Michal Sojka sojkam1 at
Sun Mar 6 13:34:13 PST 2011

On Wed, 23 Feb 2011, Ben Gamari wrote:
> Here is my mail sorting script that has been slowly evolving for almost
> a year now. It uses the Python bindings, along with Bogofilter for spam
> filtering. There is also an update-spam script which brings the
> Bogofilter database in to synchronization with the notmuch tags. On this
> note, if someone wants to implement the ability to hide certain tags
> (say, those matching /\..+/) in the emacs interface it would be greatly
> appreciated. I have notmuch configured such that all new mail starts
> with just the "new" tag. The sorting script then takes it from
> there. Hope this will give folks some ideas.

Hi Ben,

thanks for sharing your setup. It seems really interesting and probably
useful for many people. I'd propose to put it to wiki at

When compared to shell scripts for initial tagging, this seems to be
much faster because of freezing all new messages and thawing them after
all tagging is done. Also the handling of watch and unseen tag is

The only thing I missed in your email is the definition of tag_search().
You probably define it in notmuch_utils similarly to this:

def tag_search(db, query, *tags):
    logging.debug('tagging %s %s' % (query, tags))
    q = notmuch.Query(db, query)
    for msg in q.search_messages():
        for tagop in tags:
            if tagop[0] == '+':
            elif tagop[0] == '-':

> # Tag things
> for filter, tags in _tags:
>         tag_search(db, '%s and tag:new' % filter, *tags)

Here I would suggest to add parentheses around %s like:

     tag_search(db, '( %s ) and tag:new' % filter, *tags)

I use the 'or' operator in a few of my filters and without the
parentheses the query would be interpreted incorrectly.


More information about the notmuch mailing list