Skip to content

fix(platform): scope the mail sync to the Inbox and learn its address - #4038

Merged
larryro merged 2 commits into
mainfrom
fix/mail-sync-direction
Oct 1, 2026
Merged

larryro merged 2 commits into
mainfrom
fix/mail-sync-direction

Conversation

@larryro

@larryro larryro commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Why

A Gmail thread the mailbox owner had started showed the owner as the contact and every reply from the other party as the team's (right-hand) message. Six of the dev org's Gmail conversations look like this. Two pre-existing defects compound:

  1. The inbox pass was not scoped to the Inbox. listFolder set no label for Gmail — users.messages.list without one answers every message, Sent included — and no folder for Outlook, whose /me/messages spans every folder. The mailbox's own sent mail became the root of a new conversation.
  2. An OAuth mailbox had no address of its own. config.fromAddress existed only for IMAP (mirrored from the login), so resolveDirection had nothing to compare against and the ingest fell back to "the root sender is the customer" — right for a customer's mail, inverted for the mailbox's.

What

  • listFolder: Gmail labelIds: INBOX / Outlook folder: inbox on the inbox pass (the sent pass already named SENT / sentitems). The triage listing already said in:inbox; the sync now agrees.
  • get_profile on the Gmail (users/me/profile) and Outlook (/me?$select=mail,userPrincipalName, already used by format: email) connectors. healOAuthFromAddress — the IMAP heal's twin — runs on the first pass whose public config resolves no address, keeps the answer on config.fromAddress (the Inbox header and composer read it there too) and hands it to the ingest as accountEmail. Steady state costs nothing; a provider that cannot answer is logged and the pass runs as before. withFromAddress generalises the IMAP helper; withImapFromAddress delegates to it.
  • Docs (builtin.md EN/DE/FR): what a pass reads and how it knows the mailbox's own address. Manual box CONV-F38, coverage row.

Not in scope (by decision): repairing existing inverted threads, and syncing Gmail/Outlook Sent so replies from the mail client appear in the thread.

Proof

  • sync_mailbox.test.ts: the Gmail/Outlook listing inputs now pin labelIds: 'INBOX' / folder: 'inbox'; the heal reads the profile with the listing credential before the list, patches the credential config, hands accountEmail to the ingest, tolerates a failing profile call, and does not ask again once the config resolves. imap_from_address.test.ts covers withFromAddress. Typecheck, type-aware lint, configs:validate, registry tests, lint:manual, @tale/docs test green.
  • Live: pending a backend restart on this branch (or after merge) — one sync pass should stamp the Gmail credential's fromAddress and open no thread with the mailbox as contact.

Two defects compounded into inverted threads: the mailbox's own sent
mail opened conversations with the mailbox as the contact, and every
reply from the other party rendered as the team's.

The sync's inbox pass was not scoped to the Inbox. Gmail's listing
carried no label, and users.messages.list without one answers every
message, Sent included; Outlook's listing hit /me/messages, which spans
every folder. The pass now names the folder both ways (labelIds INBOX,
folder inbox), as the sent pass already did.

An OAuth mailbox had no address of its own: config.fromAddress existed
only for IMAP, mirrored from the login, so the ingest fell back to
"the root sender is the customer" — true for a customer's mail, wrong
for the mailbox's. Gmail and Outlook gain a get_profile action and the
sync's first pass asks it once, keeps the answer on config.fromAddress
(the Inbox header and composer read it there too) and hands it to the
ingest as accountEmail. A provider that cannot answer leaves the pass
to run as before.

Existing inverted threads are left as they are; the sync tests pin the
listing inputs and the heal, the guide says what a pass reads, and
CONV-F38 covers the live check.
# Conflicts:
#	services/platform/tests/manual/reference/automation.md
#	services/platform/tests/manual/suites/conversations.md
@larryro
larryro merged commit 1ad5a5e into main Oct 1, 2026
67 of 69 checks passed
@larryro
larryro deleted the fix/mail-sync-direction branch October 1, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant