]> git.donarmstrong.com Git - bin.git/blob - getmail
use the new format for capture in remember-mail
[bin.git] / getmail
1 #!/bin/sh
2
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 )
5 MUA=mutt
6
7 #set -x
8
9 # Don't check mail if ~/.nocheck exists and we're not running
10 # interactively.
11 if [ -z "$CRON" ] && [ -e ~/.nocheck ]; then
12     exit 0;
13 fi;
14
15 if [ -z "$HOSTNAME" ]; then
16     HOSTNAME="$(hostname)"
17 fi;
18
19 IONICE=""
20 if which ionice >/dev/null 2>&1; then
21     IONICE="ionice -c 3"
22 fi;
23
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
28         exit 0;
29     fi;
30     # if there is not a working ssh master, exit.
31     if ! ssh -O check $IMAPHOST 2>&1|grep -q running; then
32         exit 0;
33     fi;
34 fi;
35
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;
39 fi;
40
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;
46                 sleep 5
47                 kill -0 "$PID" >/dev/null 2>&1 && kill -9 "$PID" >/dev/null 2>&1;
48                 PID="$(pgrep -U $(id -u) offlineimap)";
49         fi;
50 fi;
51
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;
59     fi;
60 fi;