[mail] cleanup: notify only the maount of mails

no need to get loads of infos, just to know you get a mail
This commit is contained in:
David JULIEN 2022-10-25 12:02:47 +02:00
parent 1249c0099b
commit 9b6842e073
1 changed files with 3 additions and 12 deletions

View File

@ -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
}