Skip to content

fix(provider-microsoft): populate attachments on getMessage (fixes #55)#56

Merged
stevenobiajulu merged 1 commit intomainfrom
fix/list-attachments-graph-issue-55
Apr 28, 2026
Merged

fix(provider-microsoft): populate attachments on getMessage (fixes #55)#56
stevenobiajulu merged 1 commit intomainfrom
fix/list-attachments-graph-issue-55

Conversation

@stevenobiajulu
Copy link
Copy Markdown
Member

Summary

  • fix GraphEmailProvider.getMessage() to request Microsoft Graph attachment metadata with $expand=attachments($select=id,name,contentType,size,isInline,contentId)
  • fall back to GET /messages/{id}/attachments?$select=... when Graph rejects the nested $select
  • map Graph attachment metadata into EmailMessage.attachments so list_attachments returns both file and inline attachments instead of []
  • add regression coverage for both the expanded-fetch path and the fallback attachments endpoint

Root Cause

list_attachments reads from ctx.provider.getMessage(message_id), but the Microsoft provider previously fetched only the message record and never populated EmailMessage.attachments. The core action then defensively coerced that missing field to [].

Tests

  • Scenario: getMessage maps Graph attachment metadata and inline content ids
  • Scenario: getMessage falls back to /attachments when expanded query is rejected
  • npm run test:run -w @usejunior/provider-microsoft -- src/email-graph-provider.test.ts
  • npm run test:run
  • npm run build

Fixes #55.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@stevenobiajulu stevenobiajulu marked this pull request as ready for review April 28, 2026 01:14
@stevenobiajulu stevenobiajulu merged commit 6ace1f2 into main Apr 28, 2026
14 checks passed
stevenobiajulu added a commit that referenced this pull request Apr 28, 2026
…lect (fixes #59) (#60)

* fix(provider-microsoft): cast contentId on polymorphic attachment $select (#59)

Microsoft Graph rejects `contentId` in `$select` against the polymorphic
`microsoft.graph.attachment` base type — the property is declared on
`microsoft.graph.fileAttachment`. PR #56 shipped the bare field, so every
Outlook `getMessage()` call (read_email, list_attachments, get_thread,
reply flows) throws HTTP 400.

Source: cast the field — `microsoft.graph.fileAttachment/contentId`.
Verified live against real Graph (HTTP 200, contentId populated).

Tests: add a tiny inlined schema-validating mock with explicit allow-lists
for base attachment props and approved type casts. Convert the three
`getMessage`/`getThread` tests that hard-coded the broken URL to use it.
PR #56's broken string would now fail unit tests instead of passing.

Doc-link comments added to the source constant and the test allow-lists
so future readers can verify the schema against the canonical Graph docs.

Fixes #59.

* chore(provider-microsoft): tighten allow-list and pin Graph doc URLs

Codex peer review on #60 surfaced two optional improvements; both applied:

- Drop `microsoft.graph.fileAttachment/contentLocation` from
  ALLOWED_ATTACHMENT_CASTS. The provider never selects it and Graph
  documents it as unsupported on fileAttachment, so pre-whitelisting
  weakened the "future casts must be deliberate" guard.

- Pin Graph Learn URLs with ?view=graph-rest-1.0 so the doc-link
  comments stop redirecting (and so the version lined up against the
  schema is explicit).
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.

list_attachments always returns [] for Outlook/Graph messages — Microsoft provider never fetches or maps attachments

1 participant