Repository navigation
Conversation
Opening a conversation asked for each member's body separately: one `MailRequest::LoadBody` per message, and the worker answers those one at a time with `uid_fetch(uid, "(BODY.PEEK[])")`. A ten-message thread was ten sequential waits on the server. On a real cache only 20.8% of messages have a cached body, so an archived thread hits the network for nearly all of it. `LoadBodies` takes the whole (account, folder) group and fetches the UID set in one round trip; members the disk cache can answer are served without a connection, and a fully cached conversation never reaches the network at all. POP3 has no set fetch, so its arm is the same loop it always was. The blinking has the same root. `render()` sets `webview_ready = false`, which drops a themed cover over the whole reader until WebKit finishes loading — right for a new message, wrong for the re-render each arriving body queues, because the conversation is one document rebuilt in full every time. Bodies trickling in therefore covered and uncovered the reader once per arrival. The cover is now raised only when the document is being replaced by a *different* message; an incremental re-render leaves the old one on screen until the new load swaps in. Two tests cover the grouping: a single-folder thread becomes one fetch in thread order (primary first), and one spanning folders and accounts splits per folder without dropping members. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Ty7i3o9ZdQBuqn1N7Nxza
Gmail exposes labels as IMAP folders, so one message sits in INBOX, All Mail and Important at the same time — three folder/UID pairs carrying a single Message-ID. `merge_related` deduped a conversation on those pairs alone, so every copy joined it: a six-message thread rendered as eighteen, each message three times over. This is the normal case rather than an edge one — on a real cache 1210 of an account's 1212 messages are labelled that way. The related lookup's results are now reduced to one copy per Message-ID before they are merged, and the copy from the folder the reader is showing wins, so the "from folder X" label and the actions on a message refer to the mail actually on screen. A message carrying no Message-ID has nothing to match on and is left alone, so two such messages stay two. The bug predates the conversation work and was simply hard to see: bodies arriving one per round trip re-rendered the reader on each arrival, so a thread flickered its way through loading and the copies were lost in it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Ty7i3o9ZdQBuqn1N7Nxza
Collapsing a conversation's label copies exposed a second half of the same problem. Bodies, sender checks and attachments are keyed by (folder, uid), which for Gmail means per *label copy*: a body read while the user was in All Mail is invisible to the INBOX copy of the same mail, and its downloaded attachments come back empty — so the reader offers a "Load attachments" button instead of the files it already has on disk. On this cache 176 messages hold a body under only some of their labels and 31 have their attachments under only some, and attachments land almost anywhere but INBOX (4 messages there against 14 in Paratype alone). Showing one copy per message therefore lost data that showing all three had accidentally covered. The three cache lookups now fall back to the message's other copies, matched on Message-ID, before reporting a miss. The exact copy is still tried first, so the common path is unchanged, and an empty Message-ID matches nothing rather than everything. `load_bodies` is also made as forgiving as `load_body` about how a response arrives: `load_body` scans every fetch item for the body rather than trusting the first, and the batch now does the same. An item with no body is not an empty message, and treating it as one would have written "(empty message)" over a real body in the cache. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Ty7i3o9ZdQBuqn1N7Nxza
Two hardenings on the conversation work, neither Gmail-specific. Message-ID was treated as identity on its own, by both the label-copy collapse and the cache's sibling lookup. It is written by whoever sent the mail, and spam and some list software reuse one across genuinely different messages — where showing one message's body for another is worse than the cache miss the fallback exists to avoid. Sender and timestamp now have to agree too. Subject deliberately does not: a re-decoded encoded-word can rewrite it under one label and not another. This costs nothing where it was meant to fire — on a real 8300-message cache the strict comparison finds the same 412 copies that could borrow a sibling's body as the loose one did, and 49 that can borrow attachments, because no Message-ID there covers two different senders or timestamps. A conversation's bodies are also no longer asked for in a single command. `BODY.PEEK[]` returns whole messages, attachments included, so up to THREAD_MEMBER_LIMIT of them in one fetch is potentially tens of megabytes in one response: nothing on screen until all of it arrives, and nothing to show for it if the connection drops on the way — which one-at-a-time fetching, for all its round trips, never risked. Ten per fetch keeps round trips at a fifth of the old cost while the reader fills in as each batch lands, and a batch that fails reconnects before the next rather than abandoning the rest. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Ty7i3o9ZdQBuqn1N7Nxza
… request Gmail exposes labels as IMAP folders, so one message is stored in INBOX, All Mail and Important at once — three folder/UID pairs carrying a single Message-ID. The conversation code keyed on those pairs, so a six-message thread rendered as eighteen, and each copy cost its own round trip. On the contributor's cache 1210 of one account's 1212 messages sit under more than one label: the ordinary case for Gmail, not an edge one. Related results are now reduced to one copy per message before merging, and the copy from the folder on screen wins, so a message's folder label and its actions refer to the mail actually being shown. Bodies, sender checks and attachments were keyed by folder and UID too, so a body read under All Mail was invisible to the INBOX copy of the same mail and its downloaded attachments came back empty. Each now falls back to the message's other copies, matching on Message-ID with sender and timestamp required to agree — an id is written by whoever sent the mail, and serving one message's body for another would be worse than the miss it avoids. A conversation's bodies are fetched as a UID set, in batches of ten rather than the whole thread: BODY.PEEK[] returns whole messages, attachments included, so a set that large can be tens of megabytes in one response with nothing to show if the connection drops. Ten still cuts the round trips to a fifth. Landed from #45 with two changes. The reader's cover rule is kept as it is here — this branch already reaches the same end by rendering a conversation once rather than once per body, and holds the spinner until the document has painted. And the batched fetch is applied to both places a conversation asks for bodies, the second of which arrived after the pull request was opened. Co-Authored-By: Alexander Lubovenko <2742734+typedev@users.noreply.github.com>
|
Landed in v1.14.0, as c9dbd3c, credited to you in the commit trailer, the README and the About window's Thanks page. Taken as written: the label-copy collapse in the related lookup with the on-screen copy preferred; the Two changes, both worth explaining. The reader's cover rule is not yours. The batched fetch is applied twice. A second place now asks for a conversation's bodies — On the cutoff: you left it to #42 and that was the right call, but your measurement made the case. 1.14.0 adds "Thread older messages too", off by default. The two things the date bound was quietly holding down are bounded by count instead — the cross-folder links, and the size of one conversation, capped at 25 messages newest-first. Worth noting your largest thread of 49 now renders its newest 25. One thing your writeup taught me beyond the fix: Thank you — this was unusually well evidenced, and the numbers in the description are what made it easy to trust. |
… request Gmail exposes labels as IMAP folders, so one message is stored in INBOX, All Mail and Important at once — three folder/UID pairs carrying a single Message-ID. The conversation code keyed on those pairs, so a six-message thread rendered as eighteen, and each copy cost its own round trip. On the contributor's cache 1210 of one account's 1212 messages sit under more than one label: the ordinary case for Gmail, not an edge one. Related results are now reduced to one copy per message before merging, and the copy from the folder on screen wins, so a message's folder label and its actions refer to the mail actually being shown. Bodies, sender checks and attachments were keyed by folder and UID too, so a body read under All Mail was invisible to the INBOX copy of the same mail and its downloaded attachments came back empty. Each now falls back to the message's other copies, matching on Message-ID with sender and timestamp required to agree — an id is written by whoever sent the mail, and serving one message's body for another would be worse than the miss it avoids. A conversation's bodies are fetched as a UID set, in batches of ten rather than the whole thread: BODY.PEEK[] returns whole messages, attachments included, so a set that large can be tens of megabytes in one response with nothing to show if the connection drops. Ten still cuts the round trips to a fifth. Landed from hyprlab#45 with two changes. The reader's cover rule is kept as it is here — this branch already reaches the same end by rendering a conversation once rather than once per body, and holds the spinner until the document has painted. And the batched fetch is applied to both places a conversation asks for bodies, the second of which arrived after the pull request was opened. Co-Authored-By: Alexander Lubovenko <2742734+typedev@users.noreply.github.com>
Where this came from
#42 was filed because conversation grouping stopped short: after updating, every
older thread showed as loose messages and the preference looked dead. That turned
out to be the cutoff 1.13.4 stamps into
state.toml— working as designed, not abug.
This PR does not change that decision. But to see what threading an archive
actually costs,
threading_sincewas set to 0 by hand and used that way for awhile. For the record, on an 8300-message cache going back to 2008 it produced
356 conversations covering 1828 messages, the largest of them 49 — inside
THREAD_MEMBER_LIMIT. Whether that changes the case for a settable cutoff isfor #42, not here.
What it did do is put a lot of conversations on screen, and three defects fell
out of using them. The first two meet any Gmail user under the default cutoff
too; the third is a cost the reader pays on every conversation.
One message, three copies
Opening a conversation on a Gmail account shows every message three times, and
pays a network round trip for each copy. Both come from the same place: Gmail
exposes labels as IMAP folders, so one message is stored in INBOX, All Mail and
Important at once — three folder/UID pairs carrying a single Message-ID — while
the conversation code keys on those pairs.
Measured on that same cache: 1210 of one account's 1212 messages sit under more
than one label, and 1131 of the other's 2562. This is the ordinary case for
Gmail, not an edge one.
A six-message thread renders as eighteen
merge_relatedskips a related message only when the conversation already holdsits
(folder_id, uid):The three label copies differ in both, so all three join. Replaying that rule
over the cache above reproduces it exactly — one thread of 6 distinct
Message-IDs comes back as 18 rows, 6 per label; another of 8 comes back as 24.
The thread 8000 count in the message list is right, because it groups by Message-ID;
only the reader is wrong.
Lowering the cutoff is not what exposes this — it only made it frequent enough
to count. Of the 38 messages in that cache that arrived after the date 1.13.4
stamped on its own, 16 already carry several labels, so a conversation forming in
new mail duplicates just the same. A fresh install hits it within days.
Fix: the related lookup's results are reduced to one copy per message before
merging. The copy from the folder the reader is showing wins, so the "from
folder X" label and the actions on a message refer to the mail actually on
screen.
Cached data belongs to the copy, not the message
Bodies, sender checks and attachments are keyed by
(folder, uid)too. A bodyread while the user was in All Mail is invisible to the INBOX copy of the same
mail, and its downloaded attachments come back empty — so the reader offers a
"Load attachments" button for files already on disk. On the same cache, 412
copies have no body of their own while a sibling copy does, and 49 are missing
attachments a sibling has; attachments land almost anywhere but INBOX.
Showing all three copies had been hiding this, since one of them usually had the
data. Collapsing them exposed it.
Fix:
load_body,load_sender_checkandload_attachmentsfall back to themessage's other copies before reporting a miss. The exact copy is still tried
first, so the common path is unchanged.
Identity is not Message-ID alone
Both fixes above match messages by Message-ID. It is written by whoever sent the
mail, and spam and some list software reuse one across genuinely different
messages — where serving one message's body for another would be worse than the
cache miss being avoided. Sender and timestamp have to agree as well.
Subject deliberately does not take part:
redecode_encoded_subjectscan rewriteit under one label and not another.
This costs nothing where the match was meant to fire — the strict comparison
finds the same 412 borrowable bodies as the loose one, because no Message-ID in
that cache covers two different senders or timestamps.
One fetch per conversation, and no blinking
Opening a conversation asked for each member's body separately — one
MailRequest::LoadBodyeach, answered one at a time withuid_fetch(uid, "(BODY.PEEK[])"). A ten-message thread was ten sequential waitson the server, and only 20.8% of that cache's messages have a body stored, so an
archived thread hits the network for nearly all of it.
LoadBodiestakes a whole (account, folder) group and fetches the UID set atonce, in batches of ten. Ten rather than the whole thread on purpose:
BODY.PEEK[]returns whole messages, attachments included, so up toTHREAD_MEMBER_LIMITof them in one command can be tens of megabytes in a singleresponse — nothing on screen until all of it lands, and nothing to show for it if
the connection drops, which one-at-a-time fetching never risked. Ten still cuts
round trips to a fifth. Members the disk cache can answer never reach the
network, and a batch that fails reconnects before the next rather than
abandoning the rest. POP3 has no set fetch, so its arm stays the loop it was.
The blinking has the same root.
render()setswebview_ready = false, droppinga themed cover over the reader until WebKit finishes loading — right for a new
message, wrong for the re-render each arriving body queues, because the
conversation is one document rebuilt in full every time. Bodies trickling in
covered and uncovered the reader once per arrival. The cover is now raised only
when the document is being replaced by a different message.
Testing
cargo test: 176 pass. Nine are new and cover each claim above — three labelscollapsing to one message with the on-screen copy preferred, a copy of a message
already shown being dropped, messages without a Message-ID never merging, a
reused Message-ID from another sender (and from another date) matching nothing, a
body and attachments cached under one label answering for another, a
single-folder thread becoming one fetch in thread order, and a thread spanning
folders and accounts splitting per folder without losing members.
cargo clippyreports the same 19 warnings asmain— no new ones.Verified by building the branch as a Flatpak and running it against those two
accounts: the thread that showed 18 messages now shows 6, attachments appear
without asking, and the reader no longer blinks while a conversation loads.
Notes
changes on other providers is reasoned from the code rather than measured.
Where a message lives in exactly one folder the sibling lookup returns nothing
and behaviour is unchanged; the batch fetch is plain RFC 3501 sequence-set
syntax, and it uses
BODY.PEEK[]rather than a BODYSTRUCTURE fast path, so itkeeps clear of the iCloud parsing trouble noted in
load_body.messageson a cache miss. That is nothing at a fewthousand rows, but an index on
(account_id, message_id)would be worth addingbefore a fully indexed archive of hundreds of thousands.
merge_related, still requests bodies one ata time; it was left alone to keep this change reviewable.