#!/usr/bin/env bash MBSYNC_CONFIG="$XDG_CONFIG_HOME/isync/mbsyncrc" # Checking for internet connection. if ! ping -t 1 -c 1 `ip route | awk '/default/ { print $3; exit }'` 1>/dev/null 2>/dev/null ; then echo "[WARN] mailsync: no internet connection at `date +'%Y/%m/%d %H:%M:%S'`" exit 1 fi # Email sync sync_account() { echo "[INFO] Syncing '$1' mail account..." # Count current number of emails. declare -i oldcount=$(ls -l $HOME/mail/$1/INBOX/new/ | tail -n +2 | wc -l) # Running mbsync in the appropriate Tmux session allows to actually # see the output of the command and debug potential unexpected # behaviours. mbsync -c "$MBSYNC_CONFIG" "$1" # Count updated number of emails. declare -i newcount=$(ls -l $HOME/mail/$1/INBOX/new/ | tail -n +2 | wc -l) # Notify about new emails [ $oldcount -lt $newcount ] && \ notify-send -i "$HOME/imgs/icons/mail.png" "$(($newcount - $oldcount)) new mail(s) in '$1' inbox" } sync_account "personal" sync_account "dyamon" sync_account "oxuni" # Calendar sync echo "[INFO] Syncing calendar..." vdirsyncer sync # Log last offlineimap execution echo "[INFO] mailsync: last run at `date +'%Y/%m/%d %H:%M:%S'`"