diff options
| -rwxr-xr-x | mail-overview/mail-notify.sh | 21 | ||||
| -rwxr-xr-x | mail-overview/test-mail-notify.sh | 20 |
2 files changed, 23 insertions, 18 deletions
diff --git a/mail-overview/mail-notify.sh b/mail-overview/mail-notify.sh index 8309b51..f36bef2 100755 --- a/mail-overview/mail-notify.sh +++ b/mail-overview/mail-notify.sh @@ -93,16 +93,17 @@ parse_accounts() { # Malformed JSON prints nothing and succeeds. A notification with no body is # still worth sending: the summary already carries the account and the count. build_body() { - local json="$1" total="$2" shown + local json="$1" total="$2" shown rowtext body - local body - body="$(printf '%s' "$json" | jq -r ' - .[] | ((.authors // "(unknown)") + " — " + (.subject // "(no subject)")) + rowtext="$(printf '%s' "$json" | jq -r ' + .[] | "• " + ((.authors // "(unknown)") + " — " + (.subject // "(no subject)")) | gsub("&"; "&") | gsub("<"; "<") | gsub(">"; ">") ' 2>/dev/null)" || return 0 - [[ -n "$body" ]] || return 0 + [[ -n "$rowtext" ]] || return 0 + + shown="$(printf '%s\n' "$rowtext" | wc -l)" + body="$(printf '%s\n' "$rowtext" | awk 'NR>1{print ""} 1')" - shown="$(printf '%s\n' "$body" | wc -l)" printf '%s' "$body" if [[ "$total" -gt "$shown" ]]; then printf '\n+%d more' "$((total - shown))" @@ -167,8 +168,8 @@ notify_account() { if ! command -v dunstify >/dev/null 2>&1; then # No actions available, but a notification without a click is still # worth having. - notify-send -a mail-overview -u normal -t 10000 \ - "$label · $count new" "$body" + notify-send -a mail-overview -i mail-unread -u normal -t 10000 \ + "New Mail - $label ($count)" "$body" return 0 fi @@ -176,10 +177,10 @@ notify_account() { # clicked. Without this the loop would stall for the full timeout on # every account, and a five-account batch would take most of a minute. ( - if [[ "$(dunstify -a mail-overview -u normal -t 10000 -b \ + if [[ "$(dunstify -a mail-overview -i mail-unread -u normal -t 10000 -b \ -h "string:x-dunst-stack-tag:mail-$key" \ -A "default,open" \ - "$label · $count new" "$body")" == "default" ]]; then + "New Mail - $label ($count)" "$body")" == "default" ]]; then "$HOME/bin/qtmaildir" & fi ) >/dev/null 2>&1 & diff --git a/mail-overview/test-mail-notify.sh b/mail-overview/test-mail-notify.sh index d5db6c3..9fc21a9 100755 --- a/mail-overview/test-mail-notify.sh +++ b/mail-overview/test-mail-notify.sh @@ -87,24 +87,28 @@ rows_json='[ ]' check "a body lists author and subject per row" \ - "Alice Example — First subject -Bob Example — Second subject -Carol Example — Third subject" \ + "• Alice Example — First subject + +• Bob Example — Second subject + +• Carol Example — Third subject" \ "$(build_body "$rows_json" 3)" check "a batch bigger than the rows shown is elided" \ - "Alice Example — First subject -Bob Example — Second subject -Carol Example — Third subject + "• Alice Example — First subject + +• Bob Example — Second subject + +• Carol Example — Third subject +7 more" \ "$(build_body "$rows_json" 10)" check "markup characters are escaped, not rendered" \ - "A & B — <script>" \ + "• A & B — <script>" \ "$(build_body '[{"authors":"A & B","subject":"<script>"}]' 1)" check "a missing subject says so rather than printing nothing" \ - "Alice Example — (no subject)" \ + "• Alice Example — (no subject)" \ "$(build_body '[{"authors":"Alice Example","subject":null}]' 1)" check "malformed json yields an empty body rather than an error" \ |
