[notmuch] Initial tagging

Carl Worth cworth at cworth.org
Thu Feb 25 17:02:08 PST 2010

On Thu, 25 Feb 2010 16:25:16 -0500, James Vasile <james at hackervisions.org> wrote:
> I'm curious as to what people are doing in this regard.

I'm currently using a script that does tagging not entirely unlike
yours, (though my script isn't clever to retry a call to
notmuch---believe it or not I'm just calling it manually still, not from

> The tagging script uses the inbox tag to identify new mail, tags it
> according to criteria, then removes the inbox tag from anything it found
> a match for.  Uncategorized mail keeps the inbox tag so I can inspect it
> later and make rules for it (or tag it manually).

One distinction is that I have all of my "notmuch tag" commands operate
globally rather than just on new messages. One of the things that really
annoyed be about sup was that the support for automatic tagging worked
as a hook on messages as they were processed. So I couldn't use any of
the tags for searches prior to the time that I had added a particular
tag rule. I definitely didn't want to replicate that bug.

I also don't remove the inbox tag from matched mail, since I have a
"notmuch-folders" configuration that takes advantage of the matched tags
in concert with the inbox tag.

I've included my current auto-tagging script (notmuch-poll) below, as
well as the snippet of my .emacs that sets my notmuch-folders variable.

> Also, prepending "tag:inbox and" to search criteria restricts the
> tagging to a small subset of the db, which makes the tagging script run
> fairly quickly.  My unexpurgated tagging script has almost 100 rules for
> tagging, and I expect it to grow over time.

To do my "global" searches quickly, I do a similar subsetting, but it's
much simpler. If I'm adding the "notmuch" tag I do "and not
tag:notmuch". We've even had the proposal of making "notmuch tag" do
that automatically.

Meanwhile, I'm planning on eventually moving entirely away from any tags
that are driven entirely by searches like this. Instead, I'd like to
just have good support for "saved searches" where we have some syntax to
perform string expansion on configured search terms. So where I'm
currently doing:

	notmuch search tag:notmuch

I could instead do:

	notmuch search query:notmuch

with a configuration associating "notmuch" to "to:notmuchmail.org" and
the above would expand to:

	notmuch search '(' to:notmuchmail.org ')'

We've been talking about these saved searches for a while, but we
haven't implemented them yet, (nor decided firmly on the syntax we
want). I just noticed today that sup recently added a similar
saved-search feature with the following syntax:

	notmuch search {notmuch}

I think I might like something like that with more custom syntax, (since
the existing "prefix:" syntax has a fairly standard meaning that doesn't
fit well with this new feature.

With saved-search support in notmuch, I could get rid of my notmuch-poll
script almost entirely, (I'd still want something to automatically
remove the -inbox tag from some messages, but that's about it).


##### notmuch-poll #####
echo "Importing new mail"
notmuch new

echo "Running global tag additions to tag new mail"

# Tag bug-mail first, (since we use the bugs tag below)
notmuch tag +bugs from:bugzilla-daemon and not tag:bugs

# Note mail sent specifically to me (excluding bug mail)
notmuch tag +to-me to:cworth at cworth.org and not tag:to-me and not tag:bugs
notmuch tag +to-me to:carl at theworths.org and not tag:to-me and not tag:bugs
notmuch tag +to-me to:carl.d.worth at intel.com and not tag:to-me and not tag:bugs

# And note all mail sent from me
notmuch tag +sent from:cworth at cworth.org and not tag:sent
notmuch tag +sent from:carl at theworths.org and not tag:sent
notmuch tag +sent from:carl.d.worth at intel.com and not tag:sent

# Intel mail deserves some distinction
notmuch tag +intel to:carl.d.worth at intel.com and not tag:intel
notmuch tag +intel from:intel.com and not tag:intel
notmuch tag +intel to:intel-gfx and not tag:intel
notmuch tag +intel to:linux-gfx and not tag:intel

# Next, various free-software projects tagged by recipient
notmuch tag +cairo to:cairographics.org and not tag:cairo
notmuch tag +cairo to:pixman at lists.freedesktop.org and not tag:cairo
notmuch tag +xorg-board to:foundation.x.org and not tag:xorg-board
notmuch tag +xorg to:xorg and not tag:xorg
notmuch tag +xorg to:xcb and not tag:xorg
notmuch tag +announce to:announce at lists.debian.org and not tag:announce
notmuch tag +debian to:lists.debian.org and not tag:debian
notmuch tag +sup to:sup-devel at rubyforge.org and not tag:sup
notmuch tag +lca to:lists.lca2010.org.nz and not tag:lca
notmuch tag +notmuch to:notmuchmail.org and not tag:notmuch
notmuch tag +nickle to:nickle.org and not tag:nickle
notmuch tag +meego '( to:dev at moblin.org or to:dev at lists.moblin.org or to:meego-dev at meego.com )' and not tag:meego

# Finally, a few subject-based tags
notmuch tag +intel subject:xf86-video-intel and not tag:intel
notmuch tag +sup subject:sup-talk and not tag:sup
notmuch tag +pdx subject:pdx and not tag:pdx

# And some sender-based tags
notmuch tag +family from:theworths.org and not tag:family'

# Keep most Debian bug traffic out of my inbox
notmuch tag +debbugs '(' to:bugs.debian.org or from:bugs.debian.org ')' and not tag:debbugs
notmuch tag -inbox tag:inbox and tag:debbugs and not '(' '"Package: cairo"' or '"Package: notmuch"' ')'

echo "Done."

##### a snippet of .emacs #####
(setq notmuch-folders '(("inbox" . "tag:inbox")
		      	("tome" . "tag:inbox and (tag:to-me or tag:family)")
		      	("tome-select" . "tag:inbox and (tag:to-me or tag:family) and not tag:notmuch and not tag:cairo")
			("other" . "tag:inbox AND not (tag:to-me or tag:announce or tag:notmuch or tag:intel or tag:bugs or tag:cairo or tag:xorgboard or tag:xorg or tag:debian or tag:sup or tag:lca or tag:meego or tag:nickle or tag:pdx)")
			("announce" . "tag:inbox AND tag:announce")
			("notmuch" . "tag:inbox AND tag:notmuch")
			("intel" . "tag:inbox AND tag:intel")
			("bugs" . "tag:inbox AND tag:bugs")
			("cairo" . "tag:inbox AND tag:cairo")
			("xorgboard" . "tag:inbox AND tag:xorg-board")
			("xorg" . "tag:inbox AND tag:xorg")
			("debian" . "tag:inbox AND tag:debian")
			("sup" . "tag:inbox AND tag:sup")
			("lca" . "tag:inbox AND tag:lca")
			("meego" . "tag:inbox AND tag:meego")
			("nickle" . "tag:inbox AND tag:nickle")
			("pdx" . "tag:inbox AND tag:pdx")
			("todo" . "tag:todo and not tag:cairo and not tag:notmuch and not tag:intel")
			("inteltodo" . "(tag:todo and tag:intel) or tag:todo-intel")
			("notmuchtodo" . "(tag:todo and tag:notmuch) or tag:todo-notmuch")
			("cairotodo" . "(tag:todo and tag:cairo) or tag:todo-cairo")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20100225/c9ddffa6/attachment.pgp>

More information about the notmuch mailing list