tagging moved messages

Emmanuel Beffara manu at beffara.org
Sat May 19 08:40:43 PDT 2012


Hello,

What would be the proper way of automatically tagging messages whose
file has been renamed?

My use case is the following:

In order to have some synchronization of tags between several machines,
I use folders on the IMAP server. The idea is simply that messages
tagged "foo" are actually moved to a folder "foo". The same applies to
the "inbox" tag, and as an exception, messages in a folder named "saved"
are those with no tags. Of course this excludes having several tags on a
given message (except for the special tags like "unread" and "signed"),
but it does fit my needs for now. The post-new hook says this:

    #!/bin/sh
    for FOLDER in *
    do
        case $FOLDER in
        INBOX) TAG=inbox ;;
        Drafts) TAG=draft ;;
        Trash) TAG=killed ;;
        saved) continue ;;
        *) TAG=$FOLDER
        esac
        notmuch tag -$TAG -- tag:$TAG not folder:$FOLDER
        notmuch tag +$TAG -- folder:$FOLDER not tag:$TAG
    done

It does work but it is rather slow: 8 seconds, for a collection of 16000
messages. I can live with that but it does involve browsing the whole
collection for each tag. Having a tag on all moved messages, like for
the new ones, would dramatically improve this process.

Besides, the "folder:" prefix is not an exact search, so the above does
not work well if one folder name is part of another, like if I had a
folder "bar" and a folder "foo.bar". Is there a way around this?

I have another script called "pre-sync" that moves messages to folders
according to their tags. This one is called before offlineimap does the
full actual synchronization (calling notmuch new after that).

I welcome any comments on my usage pattern, as there may well be better
approaches I didn't think of...

-- 
Emmanuel


More information about the notmuch mailing list