Skip to content

Conversation

@wolfiesch
Copy link
Collaborator

Summary

  • Add gmail.read method to read full email with body (text/HTML) and attachment info
  • Add gmail.download_attachment method to download attachments by ID
  • Enhance gmail.send to support attachments via file path or base64 data
  • Add cc/bcc recipient support to gmail.send

New Methods

Method Description
gmail.read Read full email with body and attachment metadata
gmail.download_attachment Download attachment to file or return base64

Enhanced gmail.send

Now supports:

  • cc and bcc parameters
  • attachments array with two formats:
    • {"path": "~/file.pdf"} - Load from filesystem
    • {"filename": "data.txt", "data": "base64..."} - Inline data

Example Usage

# Read email with attachments
fgp call gmail.read -p '{"message_id": "abc123"}'

# Download attachment
fgp call gmail.download_attachment -p '{"message_id": "abc123", "attachment_id": "xyz", "save_path": "/tmp/file.pdf"}'

# Send with attachment
fgp call gmail.send -p '{"to": "user@example.com", "subject": "Report", "body": "See attached.", "attachments": [{"path": "~/report.pdf"}]}'

Test plan

  • Test gmail.read with email containing attachments
  • Test gmail.download_attachment with save_path
  • Test gmail.download_attachment without save_path (base64 return)
  • Test gmail.send with file path attachment
  • Test gmail.send with base64 attachment
  • Test gmail.send with cc/bcc

🤖 Generated with Claude Code

Add comprehensive attachment handling to Gmail daemon:

New methods:
- gmail.read: Read full email with body (text/HTML) and attachment info
- gmail.download_attachment: Download attachment by ID (save to file or base64)

Enhanced gmail.send:
- Support for cc and bcc recipients
- Attachments via file path: {"path": "~/file.pdf"}
- Attachments via base64 data: {"filename": "data.txt", "data": "..."}

Implementation:
- Recursive MIME part parsing for multipart messages
- Proper handling of nested attachments
- Base64 encoding/decoding for attachment data
- File type detection via mimetypes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 15, 2026 02:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive attachment support to the Gmail service, including new methods for reading full email bodies and downloading attachments, plus enhanced sending capabilities with cc/bcc support.

Changes:

  • Added gmail.read method to retrieve full email content with body (text/HTML) and attachment metadata
  • Added gmail.download_attachment method for downloading email attachments by ID
  • Enhanced gmail.send to support attachments (via file path or base64) and cc/bcc recipients

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
src/main.rs Updated architecture documentation and method list; switched from subprocess-based CLI to PyO3 warm connection module
module/gmail.py New Python module implementing Gmail API operations with attachment support including read, send with attachments, and download_attachment methods
manifest.json Updated method names to use fully qualified names (gmail.inbox, gmail.unread, etc.)
Comments suppressed due to low confidence (1)

manifest.json:81

  • The manifest.json is missing entries for the new methods 'gmail.read' and 'gmail.download_attachment'. These methods are implemented in the Python module and documented in the code comments but not registered in the manifest, which could cause discrepancies in API documentation and tooling.
  ],

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

module/gmail.py Outdated
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HttpError import is unused in this module. Consider removing it or adding error handling that uses it for better error messages.

Suggested change
from googleapiclient.errors import HttpError

Copilot uses AI. Check for mistakes.
module/gmail.py Outdated
Comment on lines 318 to 323
import base64
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
import mimetypes
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Email and MIME-related imports should be moved to the top of the file with other imports, following Python best practices. Importing within functions can cause slight performance overhead on repeated calls.

Copilot uses AI. Check for mistakes.
module/gmail.py Outdated
if not message_id:
raise ValueError("message_id parameter is required")

import base64
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base64 import should be moved to the top of the file with other imports. It's already imported at the module level (if moved from _cmd_send), and importing within functions goes against Python conventions.

Copilot uses AI. Check for mistakes.
module/gmail.py Outdated
if not attachment_id:
raise ValueError("attachment_id parameter is required")

import base64
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base64 import should be moved to the top of the file with other imports rather than importing within the function.

Copilot uses AI. Check for mistakes.
manifest.json Outdated
{
"name": "send",
"name": "gmail.send",
"description": "Send an email",
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description for gmail.send in manifest.json should be updated to reflect the new attachment support capabilities. It currently says 'Send an email' but should mention 'Send an email with optional attachments' to match the Python module description.

Suggested change
"description": "Send an email",
"description": "Send an email with optional attachments",

Copilot uses AI. Check for mistakes.
module/gmail.py Outdated

import pickle
from pathlib import Path
from typing import Dict, Any, List, Optional
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Optional' is not used.

Suggested change
from typing import Dict, Any, List, Optional
from typing import Dict, Any, List

Copilot uses AI. Check for mistakes.
wolfiesch and others added 2 commits January 14, 2026 18:32
- Move imports to top of file (base64, email.mime.*, mimetypes)
- Remove unused imports (HttpError, Optional)
- Update gmail.send description in manifest.json
- Add gmail.read and gmail.download_attachment to manifest.json

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add examples/basic_operations.py with common Gmail operations
- Add troubleshooting section to README
- Add CI workflow

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@wolfiesch wolfiesch merged commit 10977cb into main Jan 15, 2026
0 of 3 checks passed
@wolfiesch wolfiesch deleted the feat/attachment-support branch January 15, 2026 02:45
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