diff --git a/.local/bin/mailsync b/.local/bin/mailsync index aa37703..112e199 100755 --- a/.local/bin/mailsync +++ b/.local/bin/mailsync @@ -32,25 +32,16 @@ export GPG_TTY=$TTY notify() { notify-send "neomutt" " $2 new mail(s) in \`$1\` account." } -messageinfo() { - notify-send " $from:" "$subject" -} # Check account for new mail. Notify if there is new content. syncandnotify() { acc="$(echo "$account" | sed "s/.*\///")" mbsync "$acc" - new="$(find "${XDG_DATA_HOME:-$HOME/.local/share}"/mail/$acc -path */new/* -type f -newer "${XDG_STATE_HOME:-$HOME/.local/state}/mailsynclastrun" | grep -iv "trash" 2>/dev/null)" + new="$(find "${XDG_DATA_HOME:-$HOME/.local/share}"/mail/$acc -path */new/* -type f | grep -iv -e "trash" -e "drafts" 2>/dev/null)" newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l) if [ "$newcount" -gt "0" ]; then - for file in $new; do - # Extract subject and sender from mail. - from=$(awk '/^From: / && ++n ==1,/^\<.*\>:/' "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | awk '{ $1=""; if (NF>=3)$NF=""; print $0 }' | sed 's/^[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//') - subject=$(awk '/^Subject: / && ++n == 1,/^\<.*\>: / && ++i == 2' "$file" | head -n 1 | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | sed 's/^Subject: //' | sed 's/^{[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//' | tr -d '\n') - messageinfo & - done - notify "$acc" "$newcount" & - [ -n "$(pidof dwmblocks)" ] && kill -40 $(pidof dwmblocks) + notify "$acc" "$newcount" & + [ -n "$(pidof dwmblocks)" ] && kill -40 $(pidof dwmblocks) fi }