X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=getmail;h=539fbfe821e60bf7e6a34e4dc8a52a30ed8b2b0e;hb=94c91944bd1d51d7aa514fdd6126c702fa17e2c9;hp=d4e815f91c60f900ee01b01590d35ed02b08900c;hpb=1349b1b70f392948334e45f2ad69c0f53d0636b4;p=bin.git diff --git a/getmail b/getmail index d4e815f..539fbfe 100755 --- a/getmail +++ b/getmail @@ -1,20 +1,38 @@ #!/bin/sh # Configure the two things below for your MUA and the host being run. -IMAPHOST=rzlab.ucr.edu +IMAPHOST=linnode.donarmstrong.com MUA=mutt #set -x # Don't check mail if ~/.nocheck exists and we're not running # interactively. -if [[ -z "$CRON" && -e ~/.nocheck ]]; then +if [ -z "$CRON" ] && [ -e ~/.nocheck ]; then exit 0; fi; -# See if the server exists +if [ -z "$HOSTNAME" ]; then + HOSTNAME="$(hostname)" +fi; + +# if we're not running under cron or there is a mailserver running if [ -z "$CRON" ] || kill -0 `pgrep -U $(id -u) -x $MUA` 2>/dev/null; then + # and we can ping the imap host if ping -q -c 3 $IMAPHOST >/dev/null 2>&1; then + # source the ssh info if it exists + if [ -e ~/.ssh/"ssh_agent_info_$HOSTNAME" ]; then + . ~/.ssh/"ssh_agent_info_$HOSTNAME" > /dev/null; + fi; + PID="$(pgrep -U $(id -u) offlineimap)"; + if [ -n "$PID" ]; then + # if offlineimap has been running for more than 20 minutes + if [ $(( $(date +'%s') - $(stat -c '%Y' /proc/$PID/cmdline) )) -gt 1200 ]; then + kill "$PID" >/dev/null 2>&1 || true; + sleep 1 + kill -0 "$PID" >/dev/null 2>&1 && kill -9 "$PID" >/dev/null 2>&1; + fi; + fi; if nice -n 19 offlineimap -o -u Noninteractive.Basic 2>&1 |grep validity| \ perl -ne 'my ($account,$list) = /UID validity problem for folder ([\w-]+)\.([\w-]+)/; next unless defined $account and length $account; @@ -22,11 +40,11 @@ if [ -z "$CRON" ] || kill -0 `pgrep -U $(id -u) -x $MUA` 2>/dev/null; then # Clean the lists up too for account in bugs lists; do find /home/don/Mail/$account -maxdepth 1 -mindepth 1 -type d \ - -exec sh -c 'test $(find {} -type f |wc -l) -eq 0' ';' \ - -printf '%f\000'|xargs -0 -rn 1 ~/bin/deletemailbox -a $account >/dev/null; + -exec sh -c 'test $(find "{}" -type f |wc -l) -eq 0' ';' \ + -printf '%f\000'|xargs -0 -rn 1 ~/bin/deletemailbox -a $account >/dev/null 2>&1; find /home/don/Mail/$account -maxdepth 2 -mindepth 2 -iname 'new' \ -type d -ctime +60 -printf '%h\n'|xargs -rn 1 basename|xargs \ - -rn 1 /home/don/bin/deletemailbox -a $account >/dev/null; + -rn 1 /home/don/bin/deletemailbox -a $account >/dev/null 2>&1; done; fi; fi;