diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-13 17:20:09 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-13 17:20:09 +0200 |
| commit | 73539f9d3863013d8a6baebfd05da0b10b4190c7 (patch) | |
| tree | 33c76aab7efde9a4478e62c1db25b530f48c3585 /mail-overview/mail-notify.sh | |
| parent | 4ad2936cb5a4a6a44c46911ae7810bc161402dbb (diff) | |
| download | quickshell-73539f9d3863013d8a6baebfd05da0b10b4190c7.tar.gz quickshell-73539f9d3863013d8a6baebfd05da0b10b4190c7.zip | |
feat(mail-overview): build notification bodies
Three rows of author and subject, then +N more, which bounds the
height so a mailing list burst is not a wall. Markup characters are
escaped because dunst renders body markup and a subject is untrusted
text off the internet.
Diffstat (limited to 'mail-overview/mail-notify.sh')
| -rwxr-xr-x | mail-overview/mail-notify.sh | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/mail-overview/mail-notify.sh b/mail-overview/mail-notify.sh index 1cadce4..ed0c3e3 100755 --- a/mail-overview/mail-notify.sh +++ b/mail-overview/mail-notify.sh @@ -80,6 +80,36 @@ parse_accounts() { return 0 } +# Renders notmuch search JSON into notification body text. +# $1 the JSON array from `notmuch search --format=json` +# $2 the true total for this batch, which may exceed the rows present +# +# dunst has body-markup in its capabilities, so a subject containing < or & +# would be parsed as markup and could vanish from the notification. Subjects +# are attacker-controlled text arriving from the internet, so the three XML +# characters are escaped here. This is the one place in this script where +# untrusted text reaches a renderer. +# +# 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 body + body="$(printf '%s' "$json" | jq -r ' + .[] | ((.authors // "(unknown)") + " — " + (.subject // "(no subject)")) + | gsub("&"; "&") | gsub("<"; "<") | gsub(">"; ">") + ' 2>/dev/null)" || return 0 + [[ -n "$body" ]] || return 0 + + shown="$(printf '%s\n' "$body" | wc -l)" + printf '%s' "$body" + if [[ "$total" -gt "$shown" ]]; then + printf '\n+%d more' "$((total - shown))" + fi + printf '\n' +} + main() { echo "not implemented" } |
