diff options
author | Luke Smith <luke@lukesmith.xyz> | 2021-04-06 14:31:04 -0400 |
---|---|---|
committer | Luke Smith <luke@lukesmith.xyz> | 2021-04-06 14:31:04 -0400 |
commit | 80f10e6e7df3101fae8090d7fe31a72e9361e937 (patch) | |
tree | 3050ee4e5b03a2a56fccd78eb0efd0f5429175e3 | |
parent | 52c46f4b98c50817f449b13537ff8763814614d5 (diff) |
give individual notifications only if < 5
in accordance with #694
-rwxr-xr-x | bin/mailsync | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/bin/mailsync b/bin/mailsync index f61fb80..fab980a 100755 --- 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. |