diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-12 10:16:27 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-12 10:16:27 +0200 |
| commit | 2b4e1bb2d62c464d9eb949dc7c60cac8dd57f638 (patch) | |
| tree | 3e9104a950ce10baa813b67ce7e3cfd3752ae89a | |
| parent | 92cf294993c49fa95547ad14ac7d21c7c7a2b837 (diff) | |
| download | quickshell-2b4e1bb2d62c464d9eb949dc7c60cac8dd57f638.tar.gz quickshell-2b4e1bb2d62c464d9eb949dc7c60cac8dd57f638.zip | |
fix(mail-overview): parse account sections by walking lines
Two bugs, both found by actually running the shell rather than reading the
code.
shell.qml used Connections without importing QtQuick, so the config failed to
load outright: "Connections is not a type". That one was loud, and it only
affected the temporary verification probe.
The parser was the real bug and it was quiet. Section bodies were matched as
"everything up to the next [", which is wrong for this file: accounts whose
folders are named like [Gmail]/Bozze end their body at that bracket, before
the label line is reached. Three of the five accounts therefore fell back to
displaying their raw key, and nothing reported a problem because falling back
is a legitimate path for an account that genuinely has no label.
Replaced with a line walk. It says what it means, its only state is which
section is open, and it was checked against the real config before being
trusted: all five accounts now resolve both label and colour. An attempted
fix with a lazy quantifier and a lookahead made things worse, dropping every
label, which is the argument for the boring version.
Verified in a running shell: five accounts in config order with their labels,
counts summing exactly to the global notmuch count, no unknowns, and the
config stays loaded for the full timeout rather than exiting silently.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WWL8JYHu7yhAdtx5pU9PMU
| -rw-r--r-- | mail-overview/Accounts.qml | 49 | ||||
| -rw-r--r-- | mail-overview/shell.qml | 1 |
2 files changed, 31 insertions, 19 deletions
diff --git a/mail-overview/Accounts.qml b/mail-overview/Accounts.qml index 1bb451f..27cdcf9 100644 --- a/mail-overview/Accounts.qml +++ b/mail-overview/Accounts.qml @@ -66,28 +66,39 @@ Singleton { } // Sections in file order, which is the display order. + // + // A line walk rather than one regex over the whole file. The obvious + // pattern for a section body, "everything up to the next [", is wrong + // here: several accounts carry folder names like "[Gmail]/Bozze", so the + // body ended before its label and three of five accounts silently fell + // back to displaying their key. Walking lines says what it means, and the + // only state is which section we are in. function parseAccounts(conf) { const out = []; - // QML's JS engine has no String.matchAll, so this is an exec loop. - // At least one key contains a dot of its own, so the key runs to the - // closing bracket rather than to the first dot. - const re = /^\[account\.([^\]]+)\]([^\[]*)/gm; - let m; - while ((m = re.exec(conf)) !== null) { - const key = m[1]; - const body = m[2]; - const field = name => { - const f = body.match(new RegExp(`^\\s*${name}\\s*=\\s*(.+)$`, "m")); - return f ? f[1].trim() : ""; - }; - out.push({ - key: key, - label: field("label") || key, - color: field("color"), - count: -1, - threads: [], - }); + let cur = null; + + for (const line of conf.split("\n")) { + // At least one key contains a dot of its own, so the key runs to + // the closing bracket rather than to the first dot. + const header = line.match(/^\[account\.([^\]]+)\]/); + if (header) { + cur = { key: header[1], label: "", color: "", count: -1, threads: [] }; + out.push(cur); + continue; + } + // Any other section ends the current account. + if (line.startsWith("[")) { + cur = null; + continue; + } + if (!cur) continue; + + const field = line.match(/^\s*(label|color)\s*=\s*(.+)$/); + if (field) cur[field[1]] = field[2].trim(); } + + // A missing label shows the key, which is ugly but true. + for (const a of out) if (!a.label) a.label = a.key; return out; } diff --git a/mail-overview/shell.qml b/mail-overview/shell.qml index 1925f44..7842bc6 100644 --- a/mail-overview/shell.qml +++ b/mail-overview/shell.qml @@ -11,6 +11,7 @@ import Quickshell import Quickshell.Io +import QtQuick ShellRoot { MailPanel { id: panel } |
