My mail configuration

Ben Gamari bgamari.foss at gmail.com
Fri Mar 11 06:55:37 PST 2011


On Sun, 06 Mar 2011 22:34:13 +0100, Michal Sojka <sojkam1 at fel.cvut.cz> wrote:
> Hi Ben,
> 
> thanks for sharing your setup.
> 
No worries.

> It seems really interesting and probably
> useful for many people. I'd propose to put it to wiki at
> http://notmuchmail.org/initial_tagging/.
> 
Done.

> 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.
> 
Indeed, IMHO the python bindings are perfect for this sort of
application.

> Also the handling of watch and unseen tag is interesting.
> 
The watch tag is one of the defining points of my workflow. I deal with
a lot of lists although generally I'm interested in very few threads
from each. The watch tag makes it very easy to find and follow relevant
discussions.

Just to make sure everyone understands what is happening here, the
workflow works as follows,

 1) When a message starting a new thread is encountered it is marked as
    "unseen"

 2) I look at the "unseen" tag, marking threads of interest with "watch"

 3) When a message comes in associated with an existing thread marked
    with "watch" it is marked with "inbox", otherwise it is ignored

In other words, the "unseen" tag is an indicator of whether I have
evaluated the message for interest. I use the standard "unread" tag to
mark whether I have read the contents of the message.

> The only thing I missed in your email is the definition of tag_search().
> You probably define it in notmuch_utils similarly to this:
> 
Doh, thanks for pointing that out. Your tag_search implementation
matches mine almost verbatim. For the record I have included
notmuch_utils.py below.

> 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.
> 
Good point. Thanks!

- Ben


--8<---------------cut here---------------start------------->8---
import notmuch
import logging

def tag_message(msg, *tags):
        msg.freeze()
        for tag in tags:
                if tag[0] == '+':
                        msg.add_tag(tag[1:])
                elif tag[0] == '-':
                        msg.remove_tag(tag[1:])
                else:
                        msg.add_tag(tag)
        msg.thaw()

def tag_search(db, search, *tags):
        q = notmuch.Query(db, search)
        count = 0
        for msg in q.search_messages():
                count += 1
                tag_message(msg, *tags)

        if count > 0:
                logging.debug('Tagging %d messages with (%s)' % (count, ' '.join(tags)))

--8<---------------cut here---------------end--------------->8---


More information about the notmuch mailing list