-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathfetchmail
executable file
·65 lines (54 loc) · 1.68 KB
/
fetchmail
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
MBOX_TMPFILE="$HOME/Maildir/.geraldine_mbox.tmp"
MAILDIR="$HOME/Maildir"
set -e
function fetchmail()
{
if [[ -s "$MBOX_TMPFILE" ]]; then
echo "Running fdm early to process leftover files in $MBOX_TMPFILE"
fdm -f "$MAILDIR/fdm.conf" -a "geraldine" fetch
fi
if [[ -s "$MBOX_TMPFILE" ]]; then
echo "ERROR: fdm did not process all messages in $MBOX_TMPFILE" >&2
exit 1
fi
echo "Transferring mbox from geraldine.fjfi.cvut.cz"
messages=$(ssh geraldine '$HOME/.local/bin/messages -q')
if [[ "$messages" != "0" ]]; then
# NOTE: movemail supports locking
ssh geraldine '$HOME/.local/bin/movemail /var/mail/klinkovsky $HOME/mbox'
scp -Cq geraldine:mbox "$MBOX_TMPFILE"
ssh geraldine 'rm $HOME/mbox'
fi
fdm -f "$MAILDIR/fdm.conf" fetch
# synchronize with jlk.fjfi.cvut.cz
if [[ $(uname -n) != *".fjfi.cvut.cz" ]]; then
echo "Synchronizing maildir with jlk.fjfi.cvut.cz"
unison maildir -batch -silent -log=false
fi
# synchronize calendars, tasks, contacts
vdirsyncer sync
}
# check online
check_domain=ping.archlinux.org
if ! ping -c 1 "$check_domain" > /dev/null; then
echo "$check_domain is not reachable, check your network status."
exit 1
fi
check_host=10.13.0.1
if ! ping -c 1 "$check_host" > /dev/null; then
echo "$check_host is not reachable, check the host status or WireGuard network."
exit 1
fi
# synchronize metadata (displayname, color)
vdirsyncer metasync
if [[ "$1" == "loop" ]]; then
# ring a bell when the loop breaks
trap 'echo $(tput bel)' EXIT
while true; do
fetchmail
sleep 2m
done
else
fetchmail
fi