#!/bin/sh

# Temporary.
PATH=/usr/local/bin:$PATH
export PATH

# Get new mail.
notmuch new

temp=`mktemp`

# Vaguely ordered by frequency of use, so that later rules don't have
# to plough through so many potential matches (tag:inbox).
#
# These messages _will_ still be tagged 'inbox'.
#
cat >${temp} <<EOF
#
# To me:
to:dme@			+mine
to:david.edmondson@	+mine
#
# Sent:
from:dme@dme.org		+sent
from:dme@sun.com		+sent
from:david.edmondson@sun.com	+sent
EOF

grep -v "^#" ${temp} | while read s t; do
    notmuch tag $t -- tag:inbox AND $s
done

# These messages _will_ _not_ be tagged 'inbox'.
#
cat >${temp} <<EOF
# Cron output:
from:cron		+cron
#
# RSS feeds via Newspipe:
to:dme+rss@dme.org	+rss
#
# OpenSolaris lists:
to:xen-discuss@opensolaris.org		+opensolaris +os-xen +xen
to:opensolaris-discuss@opensolaris.org	+opensolaris +os-discuss
to:laptop-discuss@opensolaris.org	+opensolaris +os-laptop
to:networking-discuss@opensolaris.org	+opensolaris +os-network
#
# Xen lists:
to:xen-changelog@lists.xensource.com	+xen +xen-changelog
to:xen-devel@lists.xensource.com	+xen +xen-devel
to:xen-users@lists.xensource.com	+xen +xen-users
#
# Mailing lists:
to:fork@xent.com		+list/fork
to:ip@v2.listbox.com		+list/interesting-people
to:sun_alumni@yahoogroups.com	+list/sun-alumni
to:notmuch@notmuchmail.org	+list/notmuch
EOF

grep -v "^#" ${temp} | while read s t; do
    notmuch tag -inbox $t -- tag:inbox AND $s
done

# Unread cron messages are not interesting - mark them read.
notmuch tag -unread -- tag:unread AND tag:cron

rm -f ${temp}
