commit 80f10e6e7df3101fae8090d7fe31a72e9361e937
parent 52c46f4b98c50817f449b13537ff8763814614d5
Author: Luke Smith <luke@lukesmith.xyz>
Date: Tue, 6 Apr 2021 14:31:04 -0400
give individual notifications only if < 5
in accordance with #694
Diffstat:
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/bin/mailsync b/bin/mailsync
@@ -59,15 +59,16 @@ syncandnotify() {
if [ -z "$opts" ]; then mbsync "$acc"; else mbsync "$opts" "$acc"; fi
new=$(find "$HOME/.local/share/mail/$acc/INBOX/new/" "$HOME/.local/share/mail/$acc/Inbox/new/" "$HOME/.local/share/mail/$acc/inbox/new/" -type f -newer "${XDG_CONFIG_HOME:-$HOME/.config}/mutt/.mailsynclastrun" 2> /dev/null)
newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l)
- if [ "$newcount" -gt "0" ]; then
- notify "$acc" "$newcount" &
- 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
- fi
+ case 1 in
+ $((newcount > 5)) ) notify "$acc" "$newcount" ;;
+ $((newcount > 0)) ) notify "$acc" "$newcount"
+ 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 ;;
+ esac
}
# Sync accounts passed as argument or all.