Skip to content

feat(mail): add Microsoft 365 Graph sync source with delta state - #39

Closed
eSlider wants to merge 1 commit into
mainfrom
feat/m365-sync-port
Closed

feat(mail): add Microsoft 365 Graph sync source with delta state#39
eSlider wants to merge 1 commit into
mainfrom
feat/m365-sync-port

Conversation

@eSlider

@eSlider eSlider commented Aug 14, 2026

Copy link
Copy Markdown
Owner

What

Adds a GET-only Microsoft Graph source to bin/mail/sync using the client-credentials flow (app registration with Mail.Read application permission). Pulls inbox mail for a list of users without ever marking it read, and persists a per-mailbox delta link so incremental syncs only fetch what's new.

This is a faithful port of a locally-built M365 source onto the current main (57 commits ahead of the fork snapshot).

Changes

  • bin/mail/sync/m365.goM365Client (token cache with expiry, delta-query pagination, message normalization to the shared Message contract, attachment $value download) + m365Source adapter (folder m365/<localpart>/, delta state file).
  • bin/mail/sync/m365_test.go — httptest-based unit tests (token caching, tombstones skipped, delta pagination, message normalization, delta-state commit).
  • bin/mail/sync/sync.goM365Credentials in SyncConfig; Committer interface so a delta link only advances after every listed message downloads (a killed/failed run stays retryable without gaps).
  • bin/mail/sync/cli.go--source m365 with M365_/MS_ env passthrough.
  • Dockerfilemail-build stage builds /mail-sync into the index image.
  • bin/docker-entrypointmail-sync [N] loop (sync → import → index, default 10s, index only when new>0).
  • compose.yamlmail-sync service (index image, shared kb-var volume, secrets read-only from ~/.config/brain/m365.env).

Verification

  • go test ./bin/mail/sync/ ./internal/... all green.
  • Live run against a real tenant: full pull of 6,426 messages (3 mailboxes), then incremental new=0 on subsequent runs; read flags unchanged on the server.
  • Brain rebuild with new indexer: indexed 8146/8146; bin/kb/search returns mail results.

Adds a GET-only Microsoft Graph source to bin/mail/sync (client-credentials,
delta query). Wires it into the CLI (--source m365), the worker pool and the
compose stack:

- m365.go: M365Client (token cache, delta pagination, message normalization,
  attachment download) + m365Source adapter (per-mailbox folders + delta link)
- sync.go: M365Credentials in SyncConfig; Committer interface so delta links
  only advance after a fully successful run (no skips on failure)
- cli.go: --source m365 with M365_/MS_ env passthrough
- Dockerfile: mail-build stage produces /mail-sync into the index image
- docker-entrypoint: mail-sync loop (sync -> import -> index, default 10s)
- compose.yaml: mail-sync service (index image, kb-var volume, secrets ro)
@cursor

cursor Bot commented Aug 14, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@eSlider

eSlider commented Aug 14, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #38 (identical M365 source already merged upstream). Closing as duplicate; local work is reconciled via upstream main.

@eSlider eSlider closed this Aug 14, 2026
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