dotfiles/mail/.local/bin/checkmail
Marty Oehme 5a256186c2
mail: Add basic filtering system
imapfilter now looks for account information in an accounts.lua file in
its configuration directory -- the file should return account
information as a table with each account being a top-level entry in the
table.

A sample spam-moving script has been supplied:
For now, it will take a list of sender addresses and put everything in
the list from the inbox into the dump directory.

An example list of senders has been supplied for testing purposes, but
this should eventually be read from a file containing an extensible list
of senders (and perhaps even different properties such as subject, etc.)

The imapfilter xdg alias has been fixed.

Coherence between the imap folder structure and notmuch tagging system
still has to be achieved -- either by aerc using the folder structure as
a query map, or notmuch tags automatically being applied for specific
imap filtering options.
2020-09-23 17:55:06 +02:00

62 lines
1.2 KiB
Bash
Executable file

#!/usr/bin/env sh
# runs mbsync, with pre-hooks and post-hooks
# by default, first runs imapfilter
# and after indexes with notmuch
#
# To run without invoking any hooks or retry attempts,
# run `checkmail raw`
# this will simply invoke a single isync run on all
# boxes with the correct config file set.
#
# for more advanced, per-account/channel hooks, see
# https://sourceforge.net/p/isync/feature-requests/8/
MBSYNC_MAX_TRIES=3
MBSYNC_PRE="imapfilter -c /home/marty/.config/imapfilter/config.lua"
MBSYNC_POST="notmuch new"
# fail the routine and optionally send a message why
fail() {
[ -n "$1" ] && echo "$1"
exit 1
}
checkmail() {
mbsync -c "$XDG_CONFIG_HOME/isync/mbsyncrc" -a
}
checkonline() {
# Ping 1.1.1.1 to confirm that we are on the internet
ping -c 1 "1.1.1.1" >/dev/null 2>/dev/null || fail "checkmail can not access the internet."
}
# Routine start
# check
# skip any retries and pre/post hooks, just run mbsync
if [ "$1" = "raw" ]; then
checkmail
exit
fi
main() {
$MBSYNC_PRE
tries=0
while true; do
if checkmail; then
break
fi
tries=$((tries + 1))
if [ $tries -gt $MBSYNC_MAX_TRIES ]; then
fail "maximum retries reached without success."
fi
done
unset tries
$MBSYNC_POST
}
main