Gmail label sync + no-dup backfill, live label/UI updates, account-delete cleanup, Sync-SPAM toggle, sidebar logo
Gmail sync (SPEC: Gmail sync): - Provider fetches X-GM-LABELS when X-GM-EXT-1 is advertised; parses custom labels (system labels dropped, mUTF-7 decoded) onto RemoteMessage. - Engine syncs only system folders + All Mail for Gmail, skips every label folder, and dedupes the All Mail pass by Message-ID — kills the INBOX/All-Mail duplication. - Custom labels ride the message.new event; the labels plugin subscribes and maps them to chips as "<name> [Gmail]" (per-message + thread aggregate + known set), so labels fill in gradually with the sync window. Non-ASCII labels decode right. Labels self-healing (message-driven reconcile): - Per-message keys are the source of truth; t: aggregates and _labels are derived. Reconcile drops labels of deleted messages, regroups survivors by their current thread (fixing JWZ thread merges), rewrites changed t: keys, and rebuilds _labels from live messages — keeping user labels, dropping orphaned Gmail ones. - New SDK reads: sdk.threads.existing / sdk.messages.threads_of. Sidebar refreshes live via a plugin.labels.changed WS event on new labels. Account deletion: prune threads left empty after the cascade (they were user-scoped, so only messages cascaded) + de-list the account from surviving cross-account threads. Sync SPAM: opt-in per-account sync_spam (migration 0015, default off) — the engine skips the Junk folder in backfill and poll unless enabled; wizard checkbox added. Robustness / UX: - WebSocket auto-reconnects with backoff and resyncs on (re)connect, and account add/delete invalidates threads/labels — no more hard refresh for live updates. - Backfill banner + sidebar ring also require done < total, so a completed account can't leave a stuck "X of X". - Scrub lone UTF-16 surrogates from parsed headers/bodies so bad messages no longer crash the backfill on Postgres text/JSONB. - Ultimo signet logo in the Mail/Calendar/Contacts sidebar header (and at the top of the collapsed rail), via the shared plugin-ui.css + MailLayout. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U72FZiF1W1pb8XxyWBTREA
This commit is contained in:
@@ -36,6 +36,7 @@ class PersistResult:
|
||||
message: Message
|
||||
search_doc: SearchDoc
|
||||
has_remote_images: bool
|
||||
gmail_labels: tuple[str, ...] = ()
|
||||
|
||||
|
||||
def _epoch(value: datetime) -> int:
|
||||
@@ -140,8 +141,13 @@ async def persist_message(
|
||||
mailbox_id: uuid.UUID,
|
||||
mailbox_special_use: str | None,
|
||||
remote: RemoteMessage,
|
||||
dedupe_account_scope: bool = False,
|
||||
) -> PersistResult | None:
|
||||
"""Persist one message. Returns None if it already exists (idempotent)."""
|
||||
"""Persist one message. Returns None if it already exists (idempotent).
|
||||
|
||||
``dedupe_account_scope`` skips a message already stored under a *different*
|
||||
mailbox of the same account (same Message-ID) — used for Gmail's All Mail pass so
|
||||
a message already synced from INBOX/Sent isn't duplicated (SPEC: Gmail sync)."""
|
||||
existing = await session.scalar(
|
||||
select(Message.id).where(Message.mailbox_id == mailbox_id, Message.uid == remote.uid)
|
||||
)
|
||||
@@ -154,6 +160,18 @@ async def persist_message(
|
||||
message_id_hdr = await _resolve_message_id(
|
||||
session, user_id=user_id, account_id=account_id, parsed_id=parsed.message_id, raw=remote.raw
|
||||
)
|
||||
if dedupe_account_scope and message_id_hdr is not None:
|
||||
dup = await session.scalar(
|
||||
select(Message.id)
|
||||
.where(
|
||||
Message.account_id == account_id,
|
||||
Message.message_id_hdr == message_id_hdr,
|
||||
Message.mailbox_id != mailbox_id,
|
||||
)
|
||||
.limit(1)
|
||||
)
|
||||
if dup is not None:
|
||||
return None
|
||||
message = Message(
|
||||
id=uuid.uuid4(),
|
||||
user_id=user_id,
|
||||
@@ -223,4 +241,9 @@ async def persist_message(
|
||||
|
||||
await session.flush()
|
||||
doc = _build_search_doc(message, parsed, mailbox_special_use)
|
||||
return PersistResult(message=message, search_doc=doc, has_remote_images=has_remote_images)
|
||||
return PersistResult(
|
||||
message=message,
|
||||
search_doc=doc,
|
||||
has_remote_images=has_remote_images,
|
||||
gmail_labels=remote.gmail_labels,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user