Mailbox queries
MailFathom answers a mailbox listing from its local copy. ListEmails is the first read use case: it takes structured
filters, returns a bounded page of email summaries, issues the cursor that continues the walk, and reports how current
the local copy is. It reaches no mail server, so a listing behaves the same whether or not IMAP is available — and it
never touches the remote \Seen flag, because it speaks no mail protocol at all.
The protocol adapter is not part of this: MailboxTimelineReader is an application use case, and the list_emails MCP
tool that publishes it is described by MCP tools.
MailTimelineBrowser is the same walk read for a screen rather than for a tool, and everything on this page about the
scope, the filters, the order, the bound and the cursor holds for it unchanged. What it adds is stated in two places
below: a preview on every row, and a page that can be asked for in either
direction. GET /api/client/emails
is what publishes it.
MailThreadBrowser is the third read on this page and the one a folder does not scope: it answers one conversation as a
document, across every folder that conversation reached. Reading a conversation is what it
adds and what it borrows from the reads above.
Email search is the second read use case and applies the same structured filters this page documents, so nothing about what a filter means is restated there.
The request contract
ListEmailsRequest carries what a caller asked for, unvalidated. MailboxTimelineReader turns it into a validated
EmailTimelineFilter, so no adapter can reach a query with a filter that skipped validation.
The filters themselves live on MailboxEmailSelection, which search applies too; EmailTimelineFilter adds the reading
direction, which belongs to a timeline alone, and the fingerprint a timeline cursor is issued under. One type and one SQL predicate is what keeps an
attachment filter or a recipient filter from coming to mean one thing in a listing and another in a search — a
divergence neither copy would look wrong for on its own.
| Field | Meaning | Absent means |
|---|---|---|
Accounts |
The accounts to list from, each named by its identifier or by its display name | every account the caller is assigned |
Folders |
The folders to list from, each named by its alias or by the role it plays | every folder those accounts map and let tools read |
SenderAddress |
The address the sender must carry, in any case | any sender |
RecipientAddress |
The address a To or Cc recipient must carry |
any recipient |
SubjectFragment |
Text the subject must contain, compared without regard to case | any subject |
ReceivedOnOrAfter |
Inclusive start of the received range | no start |
ReceivedBefore |
Exclusive end of the received range | no end |
IsRemotelySeen |
The remote \Seen state to require |
either state |
IsRemotelyFlagged |
The remote \Flagged state to require |
either state |
Keyword |
One keyword the email must carry, compared without regard to case | any keyword |
HasAttachments |
Whether attachments are required | either |
Mark |
The reading an enrichment must have left, and the range a commitment falls due in | any reading, and mail with none |
IncludeJunkMail |
Whether the account's junk folder takes part | it does not |
Direction |
Which end of the timeline to read from | NewestFirst |
PageSize |
How many emails the page returns | the default of 25 |
Cursor |
The cursor a previous page returned | the first page |
Accounts and folders are named by their domain identities rather than as text, so an adapter converts a caller's strings
once at its own boundary. A folder alias is MailFathom's own name for a folder and is normalized to upper case, which is why
naming archive and ARCHIVE is naming one folder.
A folder may instead be named by the role it plays,
written role:Junk, and the role becomes an alias here rather than at the boundary above: a role means a different
folder on each account, so it is expanded once the accounts in scope are settled and contributes each of their own
folders. A role no account in scope maps is refused with 53003 MailFolderRoleUnmapped, unlike an alias nothing maps,
which selects nothing — an alias is already a name the caller chose to use, while a role that reached no folder anywhere
would leave a caller reading an empty page as an empty folder.
A listing that names no folder reads every folder the account maps and lets tools read, so a message that exists in two of them — because it was copied, by the mailbox user or by MailFathom — is two entries, one per folder. Nothing collapses them, because a stored row is one stored email in one folder and no identity spans two; what a message MailFathom copied becomes locally states what that costs and why.
What each filter accepts, and what it refuses
Refusing beats absorbing throughout: a filter that was truncated or silently dropped would run as a query nobody wrote, and its result would read as an answer about the mailbox.
- Page size is validated, not clamped. A request that names one outside 1–100 is refused with
51001 MailboxQueryPageSizeOutOfRange, because a page clamped to a hundredth of what a client planned for looks exactly like the page it asked for. Naming none is a different input and takes the default. - Blank text names no filter. A text filter that arrives empty or as whitespace alone is read as one the request did not name, rather than as a value to match: it takes the "absent means" column above. This holds for the addresses, the subject fragment, and a keyword alike, so a client that sends a field it left empty gets the unfiltered read it meant rather than a refusal. The free-text search query is the one exception, and refuses blank, because a search with no text is a listing rather than an unfiltered search.
- Addresses are normalized by the domain into the comparison form the persistence layer indexes, so a filter and a
stored participant are compared in one form by construction. An unusable address is refused with
51002 MailboxQueryFilterInvalidrather than kept as a value that can match no row, and so is one longer than the 320 characters RFC 5321 allows a forward path — the same bound the stored columns carry. - A subject fragment is bounded at 256 characters and matched anywhere in the subject, case-insensitively. Wildcards a
caller writes are escaped, so a fragment of
%matches the character rather than every subject. A control character is refused: PostgreSQL text cannot hold a zero byte, so a fragment carrying one would leave the query as a provider exception rather than as a stable failure, and no subject anyone searches part of contains one. - A keyword is folded the way the stored keywords were, so a caller writing
$Junkmatches mail whose server reported$junk, and is matched whole rather than as a fragment. A value no stored keyword could be — longer than 64 characters, or carrying a control character — is refused with51002 MailboxQueryFilterInvalidrather than kept as a filter that matches nothing, for the reason an unusable address is. Blank is not such a value: it names no keyword filter at all, as the bullet above says of every text filter but the search query. - A received range may be unbounded at either end; only an unbounded page is disallowed. A range whose end is not
after its start selects nothing and is refused. An email whose received timestamp is unknown falls inside neither
bound, so naming either one excludes undated mail. Each bound names an instant, so it may be written at any UTC offset
and the offset chosen changes neither what is selected nor which walk a cursor belongs to:
2026-07-01T10:00:00+02:00and2026-07-01T08:00:00Zare one range asked for twice. - A mark selection narrows by what an enrichment already recorded and derives nothing: it names one
EmailEnrichmentAspectand, for a commitment, the range that commitment falls due in. Naming none of the three is naming no such filter, and an aspect no build publishes is refused withArgumentOutOfRangeExceptionat the boundary that read it rather than carried in as a value nothing can match. A due range whose end is not after its start is refused with51002 MailboxQueryFilterInvalid, for the reason the received range is. Every criterion is met by one mark rather than by the message as a whole, so a message whoseSensemark is old and whoseCommitmentfalls due tomorrow answers a commitment narrowed to tomorrow and does not answer a sense narrowed to it — the predicate is one correlated existence test over the mark table, served by that table's own(StoredEmailId, Aspect)index. A deployment that has derived nothing selects nothing, which is a narrowed list rather than a failure. - The scope accepts at most 64 accounts and 64 folders, counting what a request names rather than what is left after deduplication — that is what lets the limit be enforced while the caller's list is read instead of after it has been materialized. Both lists are then deduplicated and ordered, so two spellings of one scope are one query with one cursor.
- What a question was asked about narrows a scope further, and only a Discover run supplies it: one conversation, or up to 64 individually selected messages, counted the way the two lists above are. It narrows and never widens — the accounts, the folders a mapping admits, and the junk decision all still apply, so a conversation reaching into a folder this caller may not read returns nothing from that folder, and an identifier naming another user's mail matches nothing rather than being refused. It is applied by the query itself rather than to the query's result, which is what makes a question about four messages read four messages. Both narrowings take part in a cursor's fingerprint, because both remove rows from the middle of an ordering that a walk resumed without them would return.
- An account nobody serves is refused with
53001 MailAccountNotAccessiblebefore anything is read. One failure covers both "no such account" and "not yours", and an empty page is deliberately not the answer: it would confirm the name and turn a listing into a way to enumerate accounts. Text matching neither an identifier nor a display name meets that same failure, so a caller cannot learn from it which of the two spellings it was holding. - A role nothing carries is refused with
53003 MailFolderRoleUnmapped, once the accounts in scope are settled and before anything is read. One account of several lacking the folder is not the case: that account contributes nothing and the read narrows to the others, so the refusal means no account in scope maps it at all. It names the role and no account, because a request naming several accounts asked about all of them and naming one would say the refusal was about that one.
Naming an account
An account may be named two ways, and a caller is not required to know which it is holding. The identifier the
deployment generated for it is matched exactly, because it is a key everything else compares exactly; the DisplayName it is published under is
matched without regard to case, because it is prose an operator wrote for a person to retype. Neither is ever matched as
a fragment, so naming one account can never select another whose name contains it.
The two are resolved into one identity before a query runs, which is what keeps the rest of this page true: the scope a
cursor is fingerprinted from holds identifiers, so naming the same account both ways is one account, and a cursor issued
for one spelling stays valid for the other. Configuration is what makes this unambiguous — a display name another of the
same user's accounts already carries as an identifier or as a display name fails startup — so resolution never has to
choose between two matches. list_accounts is where a caller learns both names.
The generated identifier is unique across the whole deployment, and the display name alone is unique only within one
user. Resolution runs against the accounts the caller is assigned, so two users each calling an account Work mail is
no ambiguity at all, and neither of them can name the other's account by its identifier either. A client storing the
identifier stores a deployment-wide key for the mailbox; a client storing the display name stores this user's name for
it, and one that compared that name with a name read for somebody else — another user, or a second deployment — would
be comparing two values that were never in one naming space.
Which accounts an unscoped request reads
Naming no account means every account the caller is assigned, and the request is narrowed to that set before anything
is read rather than left without an account predicate. The two are not the same: the rows of every other user's accounts are
in the same table, so an absent predicate would publish mail the caller's user is not served. Switching MailSynchronization:Enabled off is a
different matter and hides nothing — it stops runs from fetching mail, and the copy already stored stays readable.
Switching a single folder's Synchronize off is a third thing again: that folder's stored mail is kept and withheld
from every reader rather than erased, which
what a mapping decides beyond where the folder is
states.
A deployment that serves no account at all is a configuration the options accept, and a listing then returns an empty page with no freshness entries. Every filter is still validated first, so what a request is refused for never depends on how many accounts happen to be configured.
Because the resolved accounts are what the query runs with, they are also what the cursor's fingerprint covers. A cursor issued while three accounts were served is therefore refused after one of them is removed, which is correct: the result set it named no longer exists.
Folders withheld from tools
A folder mapped with VisibleToTools: false is outside every read a tool performs, whatever the request named. It is not
listed, not searched, not answered from, and not readable by identifier: naming its alias in Folders narrows the
listing to a folder that is then excluded, so the page is empty rather than refused, and asking for one of its emails by
identifier reports the email as not found rather than as withheld. An attachment link minted before the switch was set
stops serving for the same reason, because the question is asked where the download is served rather than where the link
was issued. None of those answers says the folder exists, because a refusal naming it would publish exactly what the
switch withholds.
The same list decides what a tool may write. set_mail_flags resolves the email it was given through this scope
before anything is recorded, so a folder the switch withholds is one no caller can mark, star, or label, and what it
meets is the not-found answer above rather than one that says the folder exists. A write surface that reached what a
read withholds would be a way round the switch rather than a second capability.
A folder no mapping names gives the same answers, and for a stronger reason: the scope carries the folders a mapping names and leaves visible, so a read admits that list and nothing else. Mail stored under an alias whose mapping was later removed is therefore mail no page reaches, no search matches, and no identifier resolves — the rows stay in the table and stop being readable the moment configuration stops naming their folder. An account whose configuration maps no folder at all reads as empty rather than as unrestricted, which is what "a folder MailFathom does not have" has to mean for it to mean anything.
The decision is made once, where the scope every read model is expressed in is resolved, and it narrows by the account and the alias together — one account's mapping never admits or withholds another account's folder of the same name. It deliberately takes no part in the cursor's fingerprint: a cursor stays valid across the change, and the pages after it simply stop admitting the folder, which is what an operator withholding it or removing its mapping meant.
Freshness follows the same rule, so a folder a mapping withholds or does not name is absent from the entries a listing reports rather than present with a timestamp nothing may read behind it. What a mapping decides beyond where the folder is states the switch beside the other two, what an unmapped folder is instead, and how to empty one.
The junk folder, withheld by default and reachable on request
A folder mapped to the Junk special use is outside a listing and a search unless the request asks for it. The default
is the one that matters: mail a filter already set aside is mail written to be read by somebody who did not ask for it,
and an agent reasoning over a timeline has no way to tell it from correspondence. IncludeJunkMail is the caller's
override, and the result reports which of the two answers it gave, so a reader is never left guessing whether an absent
message was missing or withheld.
This is not the switch above, and the difference is the point. VisibleToTools: false is an operator's decision that no
tool may read a folder; the junk exclusion is a default a caller may lift. The two are held apart and a query is handed
their union, so asking for junk can never reveal a folder the operator withheld — a folder that is both is still outside
every read.
Both sets are read from the account records when a read resolves its scope, narrowed to the accounts that read reaches, and the read keeps them for as long as it runs: a conversation assembled from several threads, or a page of a timeline, is judged by the one reading its scope was resolved with. They are held in the columns every account is asked about at once, written with the account's settings, so a folder switched out of tool visibility leaves the next read rather than the next restart.
The override is the caller's own filter rather than configuration, so it does take part in the cursor's fingerprint: including junk adds rows in the middle of an ordering, and a walk resumed under the other answer would skip or repeat. The junk folders themselves stay out of the fingerprint, exactly as the withheld folders above do, so mapping one does not invalidate an outstanding cursor.
get_email_content is unaffected: a message reached by its identifier is a message somebody already has in hand.
ask_mail excludes junk and offers no override, for the reason
spam classification gives.
Attachment presence
HasAttachments follows the classification rule MIME extraction applies, not a Content-Disposition header. A message
whose only non-body parts are inline resources or a cryptographic signature carries no attachments and does not match, so
filtering for mail with attachments does not return every signed message and every message with a logo in a signature
block.
For the same reason the summary reports the counts separately: AttachmentCount and InlineResourceCount are distinct
values, beside the total attachment size and the encrypted, unverified-signature, and unexpanded-TNEF markers.
MIME metadata extraction describes how each part is classified, and
Stored email schema which of it the row keeps.
What a summary carries
EmailSummary is the bounded projection a listing returns: the stable local identifier every later request names the
email by, its account and folder alias, the message identifier, the identifier of the
conversation it belongs to, subject,
sent and received timestamps, size, the sender's display name and address, the sender verdict, the machine-authorship
reading, the To addresses, the attachment summary, whether raw MIME is stored locally, and the remote flag snapshot.
The conversation identifier is absent for a message nothing has assembled one for, which is what a mailbox stored before
threading existed holds until mfctl mailbox rederive reaches it. It is MailFathom's own identifier and carries nothing
a sender wrote, so it is published beside the identifiers rather than scanned with the text.
It carries no raw MIME, no body, and no attachment bytes, and the query that produces it selects only the columns it publishes — a privacy control before a performance one, because it makes the stored content unreachable through this contract rather than merely unused by it. What it does carry is personal data and inherits the classification of the mail it summarizes.
Cc and Reply-To are stored and filterable but not listed. A listing exists to let a reader recognize a message; the
full participant set belongs to reading it.
The subject and the sender's display name are what a summary carries that a message's author wrote, so they are what a switched-on sensitive-content scanner redacts before a listing is served. The display name goes with the subject rather than with the address it accompanies: an address is a routing identity a server issued, while the name in front of it is free text whoever sent the message chose. The identifiers, addresses, timestamps, and flags beside them are what a caller acts on, and are protected by who may reach this deployment rather than by redaction. A scanner that cannot answer refuses the listing. Both switches are off by default, and nothing on this path is scanned then. Sensitive-content scanning § the guarded egress points holds the contract.
The preview a list row shows
A summary carries no body, and a screen drawing a message list needs two lines of one. BrowsedEmail is the summary
with that beside it: EmailPreview.MaximumCharacters characters of the message's own text, whitespace collapsed, or
nothing where nothing has extracted the message yet. The two are separate values rather than one projection because
they come from separate tables and a stored message may have the first without the second.
The text is cut by PostgreSQL and read by identity. IStoredEmailPreviewReader asks for that many characters of
the derived text of the rows one page actually returned, so a body is never in a result set that crosses the boundary
and never in this process — the same arrangement search uses for its snippets. It is a second query
beside the timeline rather than a column on it: the text lives in the search-document table, which is deliberately
absent from every ordinary mailbox query, and joining it would put a body's worth of text into the timeline read for
every filter it considered rather than for the rows it returned.
It reads the trimmed text rather than the untrimmed reading beside it, because quoted history and a signature block are what the opening two hundred characters of a reply would otherwise be.
The bound is then applied again where the text is reflowed, and it is applied on a character boundary rather than at an index. PostgreSQL counts its own cut in codepoints, so a message carrying an emoji arrives with more UTF-16 characters than were asked for; cutting that by index would end inside one character and publish half of it, which a JSON writer refuses to serialize. Collapsing only ever shortens what arrived, so a preview shorter than the bound is a message that was wrapped rather than one that was cut.
The bound is fixed rather than configured, and it is a data-minimization control before it is a display decision: a
caller who could raise it could lift what limits how much mail one page draws out. Being the message's own text, a
preview is scanned wherever a sensitive-content scanner is switched on, at the client_mail_listing egress point
beside the subject and the sender's display name.
How long a row's correspondence is
A row stands for a message, and a screen drawing a list has to say which of those rows stands for an exchange rather
than for a single message. BrowsedEmail therefore carries how many messages the caller may see in the conversation
the row's message belongs to, or nothing at all where threading has placed it in none.
The count is of the conversation rather than of the page, and that is the whole reason it is read here instead of counted by whoever draws the list: a correspondence spans a page boundary as readily as it sits inside one, so counting the rows a page happened to hold would answer a different number depending on where the page was cut.
It is one query for the whole page, keyed by the distinct conversations that page's rows named, exactly as the preview above and the enrichment beside it are read — never a query per row. A page whose rows are in no conversation at all asks nothing.
It counts under the same scope the conversation route reads under, which is neither the account nor the folder the listing was narrowed to, with the junk folder included. A count narrowed to the folder somebody is listing would answer one for nearly every row in it, which is the opposite of what the number is drawn for. What the scope does narrow is unchanged: a folder withheld from tools is counted nowhere, which is what keeps a withheld folder's size from being published one integer at a time.
What it does not share with that read is the assembly bound. A conversation is assembled to at most
IEmailThreadReader.MaximumAssembledEmails messages and says MoreMessagesNotAssembled when it ran further, so
BrowsedThread.MessageCount never exceeds that; this is a count rather than an assembly and has no such ceiling. So the
two part above the bound, deliberately: a row says how long the exchange actually is, and the conversation says how much
of it was assembled and that there is more. Capping the count to make them agree would leave a long correspondence
drawn as though it were exactly the bound, which is the one thing the number exists to tell a reader apart from.
Being a number rather than text, it reaches no sensitive-content scanner; the egress points are for what a message says.
The sender verdict a summary carries
The sender's address is what the message wrote about itself, so the summary carries beside it what somebody else
established: SenderVerification, the pair of what was concluded about the displayed author and whether this
deployment recognizes that author. Both are read from the columns synchronization wrote. A listing evaluates no policy,
resolves no DNS, and re-reads no header — a query that reached a verdict of its own would answer a different question
from the one the message was stored with. That holds unchanged now that a verdict may have been reached here rather than
by the receiving server: verifying a signature is a step of storing a message, never of answering a query.
The summary carries a second value the listing does not publish: SenderAuthenticationEvidence, the domain that
authenticated, the domain the From header displayed, which check established the first, the DMARC result, and which of
the two readings produced all of it — the receiving server's Authentication-Results header, or MailFathom's own
verification of the message's DKIM signatures where no such header was found. One projection reads both because the
single-email read is built from this same summary and is where the evidence is published; a second query for it would let the two reads disagree about one message. Sender
authentication holds what each value means, and
MCP tools holds the published shape.
Every domain either value names is personal data on the same footing as an address, and neither reaches a log line, a metric label, or an exception message.
The machine-authorship reading a summary carries
MachineAuthorshipAssessment sits beside the sender verdict and answers a different question: not who sent the message
but how its text was written. It carries a band and a likelihood, and — for the single-email read, exactly as the
sender evidence is — the signals the text carried and the weighting they were judged under. Every part of it is read
from the columns extraction wrote, so a listing reads no body, weighs nothing, and re-derives nothing.
It is informational and never a finding against the message. Nothing in the query path filters, sorts, ranks, or refuses on it, and it takes no part in the freshness reporting or the bounds around a page. Machine authorship holds what the reading is made of and what it deliberately does not claim.
The remote flag snapshot
RemoteEmailFlagSnapshot reports the flags a server last showed, together with when they were read. The timestamp is
what separates "the server reported none of these flags" from "nobody has looked yet", which no combination of the
booleans can express on its own. Reconciliation refreshes the snapshot one bounded window per run, so a row it has not
reached yet still carries the never-observed value and matches the unseen side of IsRemotelySeen — and WasObserved is
how a caller tells the two apart.
Beside the five system flags the snapshot carries RemoteEmailKeywords, the flags the protocol leaves to whoever set
them. RFC 9051 compares flag names without regard to case, so they are held in one case, deduplicated, and ordered: two
observations that found the same keywords produce the same value whatever order the server listed them in, which is what
keeps the stored mirror from being rewritten by a server that reorders its own answer. What one email keeps is bounded —
at most 64 keywords of at most 64 characters each — and the excess is discarded rather than failing the window, because
a window exists to record what the server said about mail that is already stored.
The snapshot travels in one direction only. Nothing in any read path turns a flag into an IMAP STORE.
Mail the server no longer holds
Every query here — the timeline, search, and the single-email lookup a content read starts from — excludes an email reconciliation found gone from its remote folder. The exclusion is written once, and no filter can opt out of it: an email the server deleted is not part of any mailbox a reader may see. An account configured to erase local copies leaves no row to exclude at all.
One case is deliberately not excluded, and it is the reason the rule reads two columns rather than one. Where MailFathom itself deleted the message on your instruction and the account keeps the local copy, the row stays in every query above although the server no longer holds it — the authored-delete disposition is what chooses that, and nothing else produces it.
A message a delete of MailFathom's only flagged is
excluded the same way while the server still holds it marked \Deleted, unless that same disposition kept it readable.
It comes back when the flag is removed on the server, which undoes the delete.
IsRemotelyDeleted is a different question and is not that exclusion. It is reported on every result and filtered on by
nothing, because it is the server's \Deleted flag on a message the folder still holds and still serves — a message a
reader can legitimately ask for, and one whose flag they can then read.
Ordering and pagination
The order
EmailTimelinePosition is the single statement of the order a timeline is read and paged over: received timestamp, then
the stable local identifier as the tiebreaker. The identifier is part of the position rather than a decoration on it,
because a mail server can record several messages within the same instant and a page boundary computed from a
non-deterministic order silently skips or repeats rows.
Undated mail sorts at the far end of whichever direction is read: last when the newest is read first, first when the
oldest is. OldestFirst is NewestFirst reversed exactly rather than a second decision, which is what makes a cursor
taken in one direction name the same boundary in the other.
The timeline indexes on stored_emails reproduce that order column for column, including the NULLS LAST PostgreSQL
would otherwise invert; Stored email schema records the index definitions. EF
Core publishes no way to state a null sort order in a query, so the read model expresses the same placement as a leading
ordering key. Whether PostgreSQL can then serve that expression from the timeline indexes without a sort step is a
query-plan question the integration suite answers, and the answer there is a matching expression index rather than a different
order here.
A scope naming several accounts is read as a walk per account, appended. The timeline index leads with the account, so it serves one account as an ordered walk and a keyset page costs the page. Across several accounts that ordering is not something a containment over the account list preserves, so one predicate over the list is planned as a read of everything that matched followed by a sort of all of it — which is what a mailbox of tens of thousands of messages per account turns a bounded page into. So each account is walked on its own index, bounded to the page size, and the walks are appended and ordered together: what the outer ordering sorts is at most one page per account rather than everything that matched. Each walk takes the whole page rather than a share of it, because the page may come entirely from one account. A scope naming one account composes no merge at all and issues the query it always has.
The cursor
Pagination is keyset-based, never offset-based: the next page asks for rows beyond a known boundary, so mail arriving between two requests neither shifts a window nor causes a row to be skipped or repeated. Paging with stable filters therefore visits every row exactly once, including across equal timestamps and across undated mail.
The cursor is an opaque string pairing that boundary with a fingerprint of the filters and reading direction it was issued for. It carries no secret and needs no signature, because every value in it is one the caller already supplied or already received; encoding it is about opacity — a client that cannot read a cursor cannot build one, and building one is how a caller would end up asking for a boundary this system never computed.
The fingerprint is computed over a text in which every value carries its own length in front of it. A folder alias may
contain a comma, so joining a list with one would let ["ARCHIVE,SENT", "TRASH"] and ["ARCHIVE", "SENT,TRASH"] produce
the same text — and a cursor accepted across those two scopes names a real row in the wrong result set, which is the one
failure the fingerprint exists to prevent.
- A cursor presented against different filters or a different direction is refused with
52002 MailboxQueryCursorFilterMismatch. It would still name a row, which is exactly why honoring it would be wrong: the caller would receive an arbitrary window of the new result set and would have no way to notice. - A cursor presented with a different page size continues the same walk. Page size moves no boundary and is deliberately not part of the fingerprint.
- Anything else — truncated, hand-written, or from a build whose cursor format differs — is refused with
52001 MailboxQueryCursorMalformedrather than interpreted as far as it parses. - A blank cursor is the first page rather than a malformed one.
- Two requests that select the same emails in the same order share a fingerprint, including when they name the same accounts in a different order or write a subject fragment in a different case.
The absence of a cursor in a result is the end of the result set rather than a hint: the reader establishes it by asking storage for one row beyond the page and finding none. A present cursor never promises that the next page is non-empty — mail can be expunged between two requests — but continuing from it can never skip or repeat a row.
Reading a page backwards
A tool listing walks one way: it asks for the next page until no cursor comes back. A screen scrolls both ways, so
MailTimelineBrowser takes a second value beside the cursor — TimelinePageDirection — saying whether the page asked
for lies after that cursor or before it, and returns a cursor at each end of what it read.
The order a list is sorted in never changes with it. That order is part of what a cursor was issued for, so folding the two questions into one value would make scrolling back a re-sort — a list that turned over under somebody's finger. A backward page is read away from the cursor with the walk reversed and handed back in the sorted order, and its cursors carry the sorted list's fingerprint. That is what lets a client page in both directions from cursors it collected in either, and it needs nothing of the storage port: the reversed walk is the same read model asked for the opposite direction.
Each end is established the same way the single-ended walk establishes its one end — by asking storage for one row beyond the page and finding none — with one case that needs no asking. A page reached from a cursor has whatever that cursor was taken from behind it, so a forward page always offers a previous cursor unless it was read from the leading end; a backward page always offers a next one, because the row its cursor named is still there.
A backward page continues from a cursor and from nothing else. Asking for one without a cursor is refused with
51002 MailboxQueryFilterInvalid, naming the page direction: there is no page before the leading end, and answering
with the leading page would read as having scrolled to the top of the list.
A page that came back empty carries no cursor at either end, because a cursor names a row of the page and there is none. A client that reached the leading end has nothing more to ask for, and one whose backward page came back empty keeps the cursor it already held.
Reading a conversation
A list is a filtered walk over a folder. A conversation is not: it is every message threading put together, whatever
folder each of them landed in, and a read narrowed to the folder somebody happened to be looking at would return the
question without the answer. MailThreadBrowser is that read —
GET /api/client/threads/{threadId} is what publishes it —
and it takes no account and no folder at all. What narrows it is ownership alone, which is the same
MailboxScopeResolver every read on this page narrows through, and the junk folder takes part rather than being
withheld: a reply that landed in junk is part of the exchange somebody is reading rather than mail they asked to be
shown. A folder withheld from tools stays withheld here as everywhere.
Membership, order and count come from the thread reader the MCP content read already uses, so a conversation is one
thing however it is asked for. IEmailThreadReader assembles at most 500 messages the caller may see and reads one row
past that, so a conversation that runs further says so rather than ending silently at the bound; EmailThreadOrder
then produces the one order that conversation has — the reply relation first, the sent time settling messages answering
the same parent, the local identity settling the rest. Nothing here re-sorts it into a screen's own order, which is what
keeps two surfaces of one deployment from showing one exchange two ways.
The same port answers one question without assembling anything, and it is what a list row's conversation size is read through: how many messages the caller may see in each of a page's conversations. It applies no bound, because a count is what says an exchange is long and cutting it at the assembly's 500 would report a long conversation as shorter than it is — and counting is what a database does without carrying any of the rows. It follows no merge either: a merge repoints every message of the folded conversation at the survivor, so the identifiers a page's rows carry are already the ones the counted rows hold.
What each message carries is the list row of the page above, read for the page's messages alone through the identity lookup beside the timeline reader, with the same preview beside it. That preview is what the message added — the trimmed reading, without the quoted history the eight replies above it would otherwise repeat — and the whole message is reached by the identity the row already carries rather than by anything this read returns. A message deleted between the membership read and the row read is left out of the page rather than published as an identity with nothing behind it.
The participants are the conversation's authors, gathered from the whole of it rather than from the page, so a client draws a thread header without walking the messages. Each is an address, the display name their most recent message wrote, and how many of the assembled messages are theirs; at most 50 are named and the answer says when that cut. A message whose sender no reader could establish is counted under no participant.
A page is bounded by MailboxQueryPageSize and continued by a message rather than a position. The order is derived
on every read, so an offset into it names a different message as soon as a reply arrives in the middle, while the
message the last page ended on is still that message wherever it moved. EmailThreadCursor carries that identity and a
fingerprint of the conversation it was issued for, over the shared keyset payload; its position field is written absent,
because a place in a conversation is not an instant. A cursor whose message the conversation no longer shows is refused
with 52004 EmailThreadCursorMessageMissing rather than answered from the beginning, which on screen would read as the
thread having jumped back to the top.
What a conversation spans today is one account's mail, because a thread is assembled from the mail of the account that holds it. This read adds no narrowing of its own on top of ownership, so what bounds a conversation is the assembly rather than the serving.
The subjects, the sender display names, the previews and the participants' display names are guarded at
ClientMailListing, the same egress point the list above publishes through and for the same reasons; a header naming
somebody the rows beneath it had redacted would leave the two disagreeing about who wrote what.
Freshness reporting
Every result carries one MailboxFolderFreshness entry per folder in the request's scope, each reporting when
synchronization last durably committed progress for that folder or that it never has. Without it a caller cannot tell a
folder that holds no matching mail from one whose synchronization has been failing for a week, and both look like an
answer about the mailbox.
A folder with no checkpoint is reported with no timestamp rather than omitted, because it is the folder whose staleness a caller most needs to see. An alias that has been bound to several remote folders over time reports the most recent progress of any of those bindings, which is what "how current is this alias" means to a reader.
PostgreSQL performs that aggregate, so the rows crossing the boundary number one per alias in scope. The count of historical bindings behind an alias grows every time a server recreates the folder, and grouping them in process would make an ordinary listing pay for that history; the result itself is bounded by the folders of the accounts in scope, which configuration bounds.
The reading a reader trusts a mailbox by
The checkpoint is half of what a reader needs and MailAccountFreshnessReader is where the other half joins it. That
use case reduces the per-folder entries twice: once per folder, and once per account above them. Both readings are
MailSynchronizationState — one vocabulary at two sizes, so a reader moving between a mailbox list and a folder tree
does not learn it twice — beside the instant the checkpoint gave and a flag saying whether more mail is known to be
coming.
The per-folder reading joins the checkpoint's instant to what the run ledger observed. Unreachable is a mail server
that did not serve the folder within its resilience budget, Failing is every other way a turn can end short, and a
turn interrupted by a host shutting down is neither — the supervisor counts that under no failure, so an account backed
off for every restart would be one approached less often for being stopped. Being behind is deliberately not one of the
states: a turn that succeeded within its batch budget leaves mail for the next one, so a folder can be behind under any
of them.
The account's reading is the reduction of its folders' rather than a second derivation beside them, which is what keeps a folder tree and the mailbox list above it from disagreeing about one account. A folder that failed outranks one whose server was unreachable, because a run that also failed some other way reached the server; the account's own run answers for what no folder reports, which is a failure to carry its outstanding mailbox changes. The instant is the newest of the account's folders, because it answers "when did this mailbox last take anything in" — the oldest would hold a whole account at the beginning of time over one folder that has been empty since it was mapped. All of it comes from the run ledger rather than from a checkpoint, so it describes the running process and resets with it, exactly as the administrative status route's phase and failure count do.
The facts stay separate because they answer different parts of one question, and the separation is what a reader needs:
an account failing since yesterday, one nobody has written to since yesterday, and one still catching up carry the same
instant. The account-level answer is one line per account and grows with nothing else — not the messages, not the runs.
It is what GET /api/client/accounts publishes.
The folder tree
MailFolderDirectoryReader composes that reading and adds what only a screen drawing folders needs: the role each
folder plays, its place in the mail server's own hierarchy, and how much mail is stored in it. It is a separate use case
from the reading above because it costs more — counting a folder's mail is work proportional to the mail — and because
nothing listing messages needs any of it.
IStoredMailFolderReader is the port that answers those, over the same mailbox scope every other read narrows by, so a
folder withheld from a caller is withheld from its counts as well. It answers in two queries: the newest binding of each
alias, which records where the last pass found the folder and the delimiter its server nests with, and one aggregate
over the mail those aliases hold. The counts are of
every binding's mail together, because an alias rebound after a server recreated the folder still lists what the older
binding stored, and they admit exactly the rows a listing of the folder would return — a count assembled from its own
idea of what is readable would be a figure no listing could reproduce.
The folders this port answers are the ones local state knows of, and an alias configuration maps that nothing has ever
bound to a remote folder is absent from it rather than empty, because there is no binding to read a hierarchy or a count
from. The reading composed on top of it is wider: MailFolderDirectoryReader publishes the folders configuration maps
as well, so a mapped folder that reading did not name is published beside the mirrored ones as never synchronized, at
the place its declaration names and with no mail here. Two cases reach that. A folder an operator asked not to mirror is never
scheduled and therefore never discovered; it is still a folder the account has and still a folder
a move files into, resolution being indifferent to mirroring, so
a client that could not see one would be told an account has nowhere to put a deleted message while its mailbox has a
trash folder. And a folder somebody has just declared is mirrored and takes part in everything, so no run has
discovered it yet and local state names it nowhere — a client that could not see it would report the folder as created
and then draw a tree without it until the account's next pass, which is minutes. A folder an operator withheld from
tools is the one that stays absent, for the same reason it is absent from every other read: it is mirrored and holds
mail, and the resolved scope left it out on purpose. That reading is what
GET /api/client/folders publishes; the whole configured list,
mirrored or not and withheld or not, is the administrative status route.
Where a folder sits is read from its declaration wherever the declaration names a path, and from the newest binding
only for a folder found by the role it plays. A folder act writes the declaration and nothing else, so a binding is a
pass behind every act: a folder just made has none, and one just renamed or moved keeps the binding of the path it
left until the account's next pass reaches it. The declaration is what the act's own FoldersChanged re-read reads, so
the folder is drawn where the act put it at once. A declared path carries no delimiter, being text somebody wrote, so it
is split by the delimiter the folder's own binding recorded and otherwise by the one the account's other bindings
recorded; an account no pass has reached yet has recorded none, and its declared paths read as one level each until one
has.
Where the pieces live
MailFathom.Application.Emails.ListEmails— the use case, its request, and its result.MailFathom.Application.Emails.BrowseTimeline—MailTimelineBrowser, the same walk read for a screen, with its request, its page, the row that pairs a summary with a preview, what a derivation concluded and how long the conversation the row stands for is, and the page direction that says which way a page continues from its cursor. It is a use case of its own rather than a wider listing because both of those are things a tool has no use for, and it shares the scope, the filters, the order, the bound and the cursor codec with the listing rather than restating any of them.MailFathom.Application.Emails.BrowseThread—MailThreadBrowser, one conversation read as the document a thread screen is drawn from, with its request, its page, the message that pairs a summary with what that message added, the participant a header names, andEmailThreadCursor, whose boundary is a message rather than a position. It owns none of the threading: membership, the bound and the order come fromMailFathom.Application.Emails.Threads, which the MCP content read publishes a conversation through as well.MailFathom.Application.Emails.Mailboxes—MailboxEmailSelection,EmailMarkSelectionbeside it, the timeline filter that wraps them, the cursor, the page size, and the query failures shared with the other read models.MailboxScopeResolveris here too: it resolves the accounts a read runs against and refuses one this deployment does not serve, and it is a collaborator rather than a step inside the use case because the refusal is an access decision every read model has to make identically.MailFathom.Application.Emails.Summaries— the summary a read model publishes and the two reader ports that produce it, and beside themEmailPreviewandIStoredEmailPreviewReader: the bound a list row's preview is cut to and the port that reads one. The bound lives with the summary rather than with the screen that shows it, because it is what decides how much of a message a read publishes.MailFathom.Application.Accounts— the two account catalogs,MailAccountDirectoryReader, the one use case that publishes an account set rather than bounding a read with it, andMailAccountFreshnessReader, which reduces that answer to one reading per folder and one per account above them. The second is composed over the first rather than written beside it, so whose accounts these are, which folders count, the grant that is required, and the read that is recorded are decided in one place;MailSynchronizationStateis the vocabulary both of its readings are named in.IDeploymentMailAccountCatalogdescribes every account this deployment serves, andConfiguredMailAccountCatalogimplements it over the bound mail section, so that answer comes from the configuration that defines the accounts.ICallerMailAccountCatalogdescribes the accounts the caller in hand owns, and it is the one every caller-facing read resolves through: its single member answers both questions asked of it, whether the account a request named is accepted and which accounts an unscoped request is narrowed to. The two are told apart by the members they publish rather than by a flag, so a read model reaching the wrong one names something the right one does not have.MailFathom.Application.Folders—MailFolderDirectoryReader, the folder tree a mail screen is drawn from, andIStoredMailFolderReader, the port answering where each folder sits on its server and how much of it is stored. It is a use case of its own rather than a wider mailbox list because counting a folder's mail is work proportional to the mail, and it composes the reading above rather than re-deriving it.MailFathom.Application.Synchronization.Checkpoints— the freshness port and its read model, kept separate from the readers that return mail because every read model attaches freshness.MailFathom.Infrastructure.Persistence.Emails—StoredEmailTimelineReader, which evaluates every filter, the keyset boundary, the ordering, and the row limit in PostgreSQL and tracks no entities.StoredEmailSelectionPredicateis the filter predicate, shared with search, andStoredEmailSummaryRowcarries the column list and the mapping, shared with search and with the single-email lookup. Both are written once because each is a control that decides what a mailbox read can return at all: a second copy would have to be found and read before anyone could say what that is.StoredEmailPreviewReaderis beside them, reading the opening of the derived text of one page's rows by identity and asking PostgreSQL to cut it.MailFathom.Infrastructure.Persistence.Synchronization—SynchronizationFreshnessReader, which answers the freshness the timeline attaches from the same database and under the same no-tracking rule, andStoredMailFolderReader, which answers the folder tree's hierarchy and counts.MailFoldersInScopeis the narrowing both of them apply, written once because two readers reporting on a caller's folders must admit exactly the same folders.