2019-02-15 23:34:26 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2019-02-15 23:35:18 +00:00
|
|
|
maildir=~/mail
|
|
|
|
# find "$maildir" -mindepth 1 -maxdepth 1 -type d ! -name cur ! -name tmp ! -name new ! -name .notmuch -printf '%f\0' | xargs -0 -n1 --max-procs=0 mbsync
|
|
|
|
mailboxes=$(find "$maildir" -mindepth 1 -maxdepth 1 -type d ! -name cur ! -name tmp ! -name new ! -name .notmuch -printf '%f\n')
|
2019-02-15 23:34:26 +00:00
|
|
|
|
2019-02-15 23:35:18 +00:00
|
|
|
LOCKFILE="/tmp/.mailsync.$USER.lock"
|
|
|
|
# /!\ locking method is susceptible to race condition
|
|
|
|
# Should be fine for cron job
|
|
|
|
if [ -e "$LOCKFILE" ] && kill -0 "$(cat "$LOCKFILE")"; then
|
|
|
|
echo "mailsync is already running"
|
2019-02-15 23:34:26 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-02-15 23:35:18 +00:00
|
|
|
# make sure the lockfile is removed when we exit and then claim it
|
|
|
|
trap "rm -f $LOCKFILE; exit" INT TERM EXIT
|
|
|
|
echo $$ > "$LOCKFILE"
|
|
|
|
|
|
|
|
for m in $mailboxes; do
|
|
|
|
mbsync "$m" &
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
wait
|
|
|
|
|
2019-02-15 23:34:26 +00:00
|
|
|
fdm fetch
|
|
|
|
notmuch new
|
2019-02-15 23:35:18 +00:00
|
|
|
|
|
|
|
rm -f "$LOCKFILE"
|