Skip to content

Conversation

@gsdali
Copy link

@gsdali gsdali commented Jan 13, 2026

Summary

  • Adds download_attachment method to the base EmailClient class and implements it for both Gmail and Outlook providers
  • Adds new /download_attachment API endpoint
  • Allows downloading attachments by message ID and attachment index
  • Supports both saving to disk and returning base64-encoded data

New Endpoint

GET /download_attachment?msg_id=<id>&attachment_index=0&save_dir=/path/to/save

Parameters:

  • msg_id (required) - The email message ID
  • attachment_index (default: 0) - Which attachment to download (0-based)
  • save_dir (optional) - If provided, saves file to disk; otherwise returns base64 data

Response:

{
  "operation_status": "succeeded",
  "operation_message": "Attachment has been downloaded successfully",
  "result": {
    "filename": "document.pdf",
    "mimeType": "application/pdf",
    "size": 249216,
    "total_attachments": 2,
    "saved": true,
    "filepath": "/path/to/save/document.pdf"
  }
}

Test Results

Test Result
Download as base64 ✅ Works
Save to disk ✅ Works
Multi-attachment email (index selection) ✅ Works
Invalid index error handling ✅ Works
No attachments error handling ✅ Works

Files Changed

  • email_client/BaseEmailProvider.py - Added abstract method + success message
  • email_client/gmail_helpers.py - Gmail implementation
  • email_client/outlook_helpers.py - Outlook/Graph API implementation
  • api/main.py - New endpoint

🤖 Generated with Claude Code

This adds the ability to download attachments from email messages for both
Gmail and Outlook providers. The new endpoint supports downloading by
attachment index and can either save to disk or return base64 encoded data.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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