diff --git a/.local/bin/mailsync b/.local/bin/mailsync index 112e199..7cb2231 100755 --- a/.local/bin/mailsync +++ b/.local/bin/mailsync @@ -13,6 +13,8 @@ # and the GPG home. This is done by searching common profile files for variable # assignments. +timestamp="${XDG_STATE_HOME:-$HOME/.local/state}/mailsynclastrun" + eval "$(grep -h -- \ "^\s*\(export \)\?\(XDG_CACHE_HOME\|XDG_CONFIG_HOME\|XDG_DATA_HOME\)=" \ "$HOME/.zshenv" 2>/dev/null)" @@ -37,7 +39,7 @@ notify() { syncandnotify() { acc="$(echo "$account" | sed "s/.*\///")" mbsync "$acc" - new="$(find "${XDG_DATA_HOME:-$HOME/.local/share}"/mail/$acc -path */new/* -type f | grep -iv -e "trash" -e "drafts" 2>/dev/null)" + new="$(find "${XDG_DATA_HOME:-$HOME/.local/share}"/mail/$acc -path */new/* -type f -newer "$timestamp" | grep -iv -e "trash" -e "drafts" 2>/dev/null)" newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l) if [ "$newcount" -gt "0" ]; then notify "$acc" "$newcount" & @@ -57,4 +59,4 @@ wait notmuch new 2>/dev/null #Create a touch file that indicates the time of the last run of mailsync -touch "${XDG_STATE_HOME:-$HOME/.local/state}/mailsynclastrun" +touch $timestamp