add attachments support to drafts#1536
Conversation
WalkthroughThe changes add support for handling email attachments in both draft parsing and email composition. Attachments are now extracted, converted between base64 and File objects, and included in the draft and sending processes. The draft parsing logic is updated to fetch and include attachments asynchronously, and the email composer initializes with these attachments. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CreateEmail
participant GoogleMailManager
participant EmailComposer
User->>CreateEmail: Open draft
CreateEmail->>GoogleMailManager: getDraft()
GoogleMailManager->>GoogleMailManager: parseDraft (async, fetch attachments)
GoogleMailManager-->>CreateEmail: Draft object with attachments (base64)
CreateEmail->>CreateEmail: Convert base64 attachments to File[]
CreateEmail->>EmailComposer: Pass initialAttachments (File[])
User->>EmailComposer: Compose and send email
EmailComposer->>CreateEmail: Submit with attachments
CreateEmail->>GoogleMailManager: Send email (serializeFiles)
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
apps/mail/components/create/create-email.tsx (1)
171-183: Consider adding tests for attachment handlingThis PR introduces attachment support for drafts but lacks tests. Consider adding unit tests for:
- The
base64ToFileconversion function- Attachment handling in the draft loading flow
- Error cases (malformed base64, missing attachments, etc.)
Would you like me to help generate unit tests for the attachment handling logic?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/mail/components/create/create-email.tsx(5 hunks)apps/server/src/lib/driver/google.ts(4 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: retrogtx
PR: Mail-0/Zero#1468
File: apps/server/src/trpc/routes/mail.ts:386-391
Timestamp: 2025-06-27T04:59:29.709Z
Learning: In apps/server/src/trpc/routes/mail.ts, the attachment processing logic conditionally handles mixed attachment types - it preserves existing File-like objects with arrayBuffer methods while only converting serialized attachments that need processing through toAttachmentFiles.
apps/server/src/lib/driver/google.ts (1)
Learnt from: retrogtx
PR: Mail-0/Zero#1468
File: apps/server/src/trpc/routes/mail.ts:386-391
Timestamp: 2025-06-27T04:59:29.709Z
Learning: In apps/server/src/trpc/routes/mail.ts, the attachment processing logic conditionally handles mixed attachment types - it preserves existing File-like objects with arrayBuffer methods while only converting serialized attachments that need processing through toAttachmentFiles.
apps/mail/components/create/create-email.tsx (1)
Learnt from: retrogtx
PR: Mail-0/Zero#1468
File: apps/server/src/trpc/routes/mail.ts:386-391
Timestamp: 2025-06-27T04:59:29.709Z
Learning: In apps/server/src/trpc/routes/mail.ts, the attachment processing logic conditionally handles mixed attachment types - it preserves existing File-like objects with arrayBuffer methods while only converting serialized attachments that need processing through toAttachmentFiles.
🧬 Code Graph Analysis (2)
apps/server/src/lib/driver/google.ts (1)
apps/server/src/lib/driver/utils.ts (1)
fromBinary(48-49)
apps/mail/components/create/create-email.tsx (3)
apps/mail/components/magicui/file-tree.tsx (1)
File(413-413)apps/server/src/types.ts (1)
Attachment(146-153)apps/mail/types/index.ts (1)
Attachment(98-105)
🔇 Additional comments (1)
apps/mail/components/create/create-email.tsx (1)
120-122: Good defensive programming!The addition of optional chaining prevents potential runtime errors when email addresses are undefined.
Description
Draft attachments are now visible in the composer.
Users can send emails with previously saved attachments.
Type of Change
Please delete options that are not relevant.
Areas Affected
Please check all that apply:
Testing Done
Describe the tests you've done:
Security Considerations
For changes involving data or authentication:
Checklist
Screenshots/Recordings
mail0.mp4
By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.
Summary by CodeRabbit
New Features
Bug Fixes