3 # Configure the two things below for your MUA and the host being run.
4 IMAPHOST=linnode.donarmstrong.com
9 # Don't check mail if ~/.nocheck exists and we're not running
11 if [ -z "$CRON" ] && [ -e ~/.nocheck ]; then
15 if [ -z "$HOSTNAME" ]; then
16 HOSTNAME="$(hostname)"
20 if which ionice >/dev/null 2>&1; then
24 # if we're not running under cron or there is a mailserver running
25 if [ -z "$CRON" ] || kill -0 `pgrep -U $(id -u) -x $MUA` 2>/dev/null; then
26 # and we can ping the imap host
27 if ping -q -c 3 $IMAPHOST >/dev/null 2>&1; then
28 # source the ssh info if it exists
29 if [ -e ~/.ssh/"ssh_agent_info_$HOSTNAME" ]; then
30 . ~/.ssh/"ssh_agent_info_$HOSTNAME" > /dev/null;
32 PID="$(pgrep -U $(id -u) offlineimap)";
33 if [ -n "$PID" ]; then
34 # if offlineimap has been running for more than 20 minutes
35 if [ $(( $(date +'%s') - $(stat -c '%Y' /proc/$PID/cmdline) )) -gt 1200 ]; then
36 kill "$PID" >/dev/null 2>&1 || true;
38 kill -0 "$PID" >/dev/null 2>&1 && kill -9 "$PID" >/dev/null 2>&1;
39 PID="$(pgrep -U $(id -u) offlineimap)";
42 if [ -z "$PID" ]; then
43 if nice -n 19 ${IONICE} offlineimap -o -u Noninteractive.Basic 2>&1 |grep validity| \
44 perl -ne 'my ($account,$list) = /UID validity problem for folder ([\w-]+)\.([\w-]+)/;
45 next unless defined $account and length $account;
46 qx(/home/don/bin/deletemailbox -a $account $list > /dev/null);'; then
47 # Clean the lists up too
48 for account in bugs lists; do
49 find /home/don/Mail/$account -maxdepth 1 -mindepth 1 -type d \
50 -exec sh -c 'test $(find "{}" -type f |wc -l) -eq 0' ';' \
51 -printf '%f\000'|xargs -0 -rn 1 ~/bin/deletemailbox -a $account >/dev/null 2>&1;
52 find /home/don/Mail/$account -maxdepth 2 -mindepth 2 -iname 'new' \
53 -type d -ctime +60 -printf '%h\n'|xargs -rn 1 basename|xargs \
54 -rn 1 /home/don/bin/deletemailbox -a $account >/dev/null 2>&1;
57 if which notmuch >/dev/null 2>&1; then
58 nice -n 19 ${IONICE} notmuch new >/dev/null 2>&1;