#!/bin/sh
# {{ ansible_managed }}
# Original source: http://bit.ly/1Ztk5wg
# Send and receive mail when full internet connectivity is available.

STATE=`nmcli networking connectivity`

if [ $STATE = 'full' ]
then
    /usr/local/bin/msmtp-queue -r
{% if mail.sync_tool == "isync" %}
    /usr/bin/mbsync -a
{% elif mail.sync_tool == "offlineimap" %}
    /usr/bin/offlineimap -o
{% endif %}
{% if mail.sync_pim %}
    vdirsyncer sync
{% endif %}
{% if mail.sync_taskwarrior %}
    task sync
{% endif %}
{% if mail.sync_notmuch %}
    notmuch new
{% endif %}
    exit $?
fi
echo "No internet connection."
exit 0
