Marty Oehme
be688572f5
Added `mail-searchcontacts` script, which uses notmuch to search for all contacts of the mail database. Can be invoked without any arguments to list *all* contacts of the dataase in descending order of message count. Otherwise, it will filter known contacts, first by prioritizing the 'from:' field, and otherwise by searching through the whole database for the keywords passed in. It will also re-format the results so that the list consists of tab-delineated 'mail name' rows. If there is no name, the row will only contain the bare e-mail address. This format is best accepted by aerc, for which the script is written. aerc uses the contacts script for its address completion in editing e-mail headers. Renamed `checkmail` to `mail-check` to fit the naming scheme of `mail-[action]` for mail scripts, to better be able to group them in the shell.
69 lines
1.5 KiB
Bash
Executable file
69 lines
1.5 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 && afew --tag --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
|
|
}
|
|
|
|
notmuch_foldertags() {
|
|
notmuch tag +dump -inbox -deleted -- folder:Dump and not folder:Inbox
|
|
notmuch tag +archived -inbox -deleted -- folder:Archive and not folder:Inbox
|
|
notmuch tag +deleted -inbox -archived -- folder:Trash and not folder:Inbox
|
|
}
|
|
|
|
main
|
|
notmuch_foldertags
|