3 # Configure the two things below for your MUA and the host being run.
4 IMAPHOST=$( awk -F= '/remotehost/{print $2}' ~/.offlineimaprc | head -n 1 )
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 are running under cron
25 if [ -n "$CRON" ]; then
26 # and there is no MUA open, exit
27 if ! kill -0 `pgrep -U $(id -u) -x $MUA` 2>/dev/null; then
30 # if there is not a working ssh master, exit.
31 if ! ssh -O check $IMAPHOST 2>&1|grep -q running; then
36 # source the ssh info if it exists
37 if [ -e ~/.ssh/"ssh_agent_info_$HOSTNAME" ]; then
38 . ~/.ssh/"ssh_agent_info_$HOSTNAME" > /dev/null;
41 PID="$(pgrep -U $(id -u) offlineimap)";
42 if [ -n "$PID" ]; then
43 # if offlineimap has been running for more than 20 minutes
44 if [ $(( $(date +'%s') - $(stat -c '%Y' /proc/$PID/cmdline) )) -gt 1200 ]; then
45 kill "$PID" >/dev/null 2>&1 || true;
47 kill -0 "$PID" >/dev/null 2>&1 && kill -9 "$PID" >/dev/null 2>&1;
48 PID="$(pgrep -U $(id -u) offlineimap)";
52 if [ -z "$PID" ]; then
53 nice -n 19 ${IONICE} offlineimap -o -u basic 2>&1 |grep validity| \
54 perl -ne 'my ($account,$list) = /UID validity problem for folder ([\w-]+)\.([\w-]+)/;
55 next unless defined $account and length $account;
56 qx(/home/don/bin/deletemailbox -a Inbox $account.$list > /dev/null);';
57 if which notmuch >/dev/null 2>&1; then
58 nice -n 19 ${IONICE} notmuch new >/dev/null 2>&1;