From 4ad2936cb5a4a6a44c46911ae7810bc161402dbb Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sun, 13 Sep 2026 17:19:02 +0200 Subject: feat(mail-overview): parse accounts for the notifier Same source the drawer parses, so adding an account in qtmaildir notifies with no edit here. Keys run to the closing bracket because real ones contain dots, and parsing walks lines because a folder named [Gmail]/Bozze ends a section body early. --- mail-overview/mail-notify.sh | 43 +++++++++++++++++++++++++++++++++++++++ mail-overview/test-mail-notify.sh | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) (limited to 'mail-overview') diff --git a/mail-overview/mail-notify.sh b/mail-overview/mail-notify.sh index fbc27c5..1cadce4 100755 --- a/mail-overview/mail-notify.sh +++ b/mail-overview/mail-notify.sh @@ -37,6 +37,49 @@ SCOPE='tag:unread and tag:inbox' # Three matches the drawer's own --limit=3. ROWS=3 +# Accounts in file order, one "keylabel" line each, read from stdin. +# +# Two things here are load-bearing, and both have already broken this +# component once: +# +# The key runs to the closing bracket, NOT to the first dot. Real keys +# contain dots, so splitting on the first one yields a notmuch tag matching +# nothing and an account that silently never notifies. +# +# And this walks lines rather than matching a section body as "everything up +# to the next [". Accounts have folders named like [Gmail]/Bozze, which ends +# the body before its label and makes the account display its raw key. +parse_accounts() { + local line key label + key="" + label="" + + while IFS= read -r line || [[ -n "$line" ]]; do + if [[ "$line" =~ ^\[account\.([^]]+)\] ]]; then + [[ -n "$key" ]] && printf '%s\t%s\n' "$key" "${label:-$key}" + key="${BASH_REMATCH[1]}" + label="" + continue + fi + # Any other section ends the current account. + if [[ "$line" =~ ^\[ ]]; then + [[ -n "$key" ]] && printf '%s\t%s\n' "$key" "${label:-$key}" + key="" + label="" + continue + fi + [[ -n "$key" ]] || continue + if [[ "$line" =~ ^[[:space:]]*label[[:space:]]*=[[:space:]]*(.*)$ ]]; then + label="${BASH_REMATCH[1]}" + # Trailing whitespace only; a label may contain spaces. + label="${label%"${label##*[![:space:]]}"}" + fi + done + + [[ -n "$key" ]] && printf '%s\t%s\n' "$key" "${label:-$key}" + return 0 +} + main() { echo "not implemented" } diff --git a/mail-overview/test-mail-notify.sh b/mail-overview/test-mail-notify.sh index 2b50b52..8be456c 100755 --- a/mail-overview/test-mail-notify.sh +++ b/mail-overview/test-mail-notify.sh @@ -39,5 +39,44 @@ check() { check "library guard does not run main" "loaded" "loaded" +# A config with the two traps in it: a key containing dots, and a folder +# value containing a bracket. Both are real shapes from qtmaildir.conf, with +# placeholder names. +read -r -d '' fixture <<'EOF' +[general] +theme = dark + +[account.simple] +label = Simple +color = #112233 + +[account.provider-first.last] +folder = [Gmail]/Bozze +label = Dotted +color = #445566 + +[account.nolabel] +color = #778899 + +[ui] +label = NotAnAccount +EOF + +check "keys run to the bracket, not the first dot" \ + "simple provider-first.last nolabel" \ + "$(parse_accounts <<<"$fixture" | cut -f1 | tr '\n' ' ' | sed 's/ $//')" + +check "a bracket in a value does not end the section" \ + "Dotted" \ + "$(parse_accounts <<<"$fixture" | awk -F'\t' '$1=="provider-first.last"{print $2}')" + +check "a missing label falls back to the key" \ + "nolabel" \ + "$(parse_accounts <<<"$fixture" | awk -F'\t' '$1=="nolabel"{print $2}')" + +check "a non-account section is not an account" \ + "" \ + "$(parse_accounts <<<"$fixture" | awk -F'\t' '$1=="ui"{print $2}')" + printf '\n%d passed, %d failed\n' "$pass" "$fail" [[ "$fail" -eq 0 ]] -- cgit v1.2.3