#!/bin/sh
AFEW_SERVICE="afew"
MBSYNC_SERVICE="mbsync"
NOTMUCH_SERVICE="notmuch"

if [ $(pidof $AFEW_SERVICE) ] || [ $(pidof $MBSYNC_SERVICE) ] || [ $(pidof $NOTMUCH_SERVICE) ]; then
    echo "Checkmail is already running."
else
    echo "Checking for new mail"
    afew -m -n
    mbsync -a
    notmuch new
    afew -t -n
fi
exit 0
