configuration/notmuch-hooks/post-new

86 lines
2.5 KiB
Plaintext
Raw Normal View History

2017-04-27 18:51:18 +02:00
#!/bin/sh
2019-06-28 09:29:53 +02:00
addtag() { notmuch tag +"$1" -- "tag:new and ($2) and not tag:$1"; }
archive() { notmuch tag -new -unread -- "$@" and tag:new; }
spam() { notmuch tag -new -unread +spam -- "$@" and '(' tag:new or tag:unread or not tag:spam ')'; }
# Tag mails by their origin (top-level maildir)
for maildir in /data/mail/*; do
origin="$(basename "$maildir")"
addtag "$origin" "folder:/$origin/"
done
# Spam
spam "subject:/^\[SPAM\]/"
# TODO: Known spammers
# Some aliases
addtag zeus "to:felixvdj@zeus.ugent.be"
addtag dodona "to:dodona@ugent.be"
addtag unipept "to:unipept@ugent.be"
# More complex tagging
for mid in $(notmuch search --output=messages tag:new); do
tag=false
# +-tags become actual tags
for tag in $(notmuch show --format=raw "$mid" | sed -n '/^\tfor/s/.*<[^>]*+\([^@]*\)@.*>.*/\1/p' | sort | uniq); do
addtag "$tag" "$mid"
tag=true
done
# messages from contacts get a contact tag
for sender in $(notmuch address --output=sender --output=address "$mid"); do
if khard list "$sender" > /dev/null 2>&1; then
addtag contact "$mid"
tag=true
fi
done
# mails to posteo must have a tag
if ! "$tag"; then
addtag killed "$mid and tag:posteo"
fi
# list ids
for list in $(notmuch show --format=raw "$mid" | sed -n '/^List-Id:/,/^\w/p' | sed '$d' | tr '\n' ' ' | sed 's/[^<]*<// ; s/\..*//'); do
addtag "lists" "$mid"
addtag "lists/$list" "$mid"
done
done
# Unmute threads with new messages
for mutetag in $(notmuch search --output=tags -- tag:muted and thread:{tag:new} | grep 'muted/'); do
notmuch tag -muted -"$mutetag" +inbox -- tag:"$mutetag" and thread:{tag:new}
done
2019-08-02 10:12:48 +02:00
# Github notifications
addtag github "from:notifications@github.com"
2019-06-28 09:29:53 +02:00
# Uninteresting
archive tag:dodona subject:'Onderwijsinstelling aangemaakt voor .*'
archive tag:dodona from:'logcheck system account'
archive tag:dodona subject:'A request took'
archive tag:github thread:{from:dependabot} \
-subject:Security \
-to:mention@noreply.github.com \
-to:assign@noreply.github.com \
-to:review_requested@noreply.github.com \
-to:security_alert@noreply.github.com
# And stay down!
#addtag killed "thread:{tag:killed}"
2019-06-28 09:29:53 +02:00
# Inbox remaining not-spam
addtag inbox "not tag:spam"
notmuch tag -new -- tag:new
# Unmute threads on their day of unmuting
today="$(date +'%s')"
for mutetag in $(notmuch search --output=tags tag:muted | grep 'muted/'); do
until="$(date -d "${mutetag#*/}" +'%s')"
if [ "$today" -gt "$until" ]; then
notmuch tag -muted -"$mutetag" +inbox -- tag:"$mutetag"
fi
done