Skip to content

Conversation

@benjaminjackson
Copy link
Contributor

Enhanced Gmail functionality with comprehensive email threading support and multi-recipient capabilities:

• Email Threading: Added support for threaded replies with proper In-Reply-To and References headers
• Multi-recipient Support: Added CC and BCC functionality to both send and draft operations
• Code Consolidation: Refactored shared email preparation logic to eliminate duplication

Technical Changes

New Features:

  • Added thread_id, in_reply_to, and references parameters for proper email threading
  • Added cc and bcc parameters for multi-recipient email support
  • Automatic "Re:" prefix handling for reply subjects
  • Thread association for both sent messages and drafts

Note: this duplicates WIP in PR #71 but is more atomic, with no changes to Forms Functionality.

- Add thread_id, in_reply_to, and references parameters for proper reply threading
- Auto-format reply subjects with 'Re:' prefix when replying
- Include proper email headers for threading (In-Reply-To, References)
- Add examples for both new drafts and reply drafts in docstring
- Add thread_id, in_reply_to, and references parameters for proper reply threading
- Auto-format reply subjects with 'Re:' prefix when replying
- Include proper email headers for threading (In-Reply-To, References)
- Add examples for both new emails and reply emails in docstring
- Achieve feature parity between send_gmail_message and draft_gmail_message
@taylorwilsdon
Copy link
Owner

This looks very good, thank you! Will try to get it out it after work wraps up for the day today.

@taylorwilsdon taylorwilsdon requested review from Copilot and taylorwilsdon and removed request for Copilot August 4, 2025 14:22
@taylorwilsdon taylorwilsdon self-assigned this Aug 4, 2025
@taylorwilsdon taylorwilsdon added the enhancement New feature or request label Aug 4, 2025
@taylorwilsdon taylorwilsdon requested a review from Copilot August 4, 2025 14:22
Copy link
Contributor

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 enhances Gmail functionality by adding comprehensive email threading support and multi-recipient capabilities. The changes enable proper email reply threading with In-Reply-To and References headers, while also supporting CC and BCC recipients for both sending and drafting operations.

Key changes:

  • Added email threading parameters (thread_id, in_reply_to, references) to enable proper reply functionality
  • Added CC and BCC support for multi-recipient emails
  • Refactored shared email preparation logic into a reusable _prepare_gmail_message function

thread_id: Optional[str] = None,
in_reply_to: Optional[str] = None,
references: Optional[str] = None,
) -> tuple[str, Optional[str]]:
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

Use Tuple from typing instead of the built-in tuple for better compatibility with older Python versions. Import Tuple from typing and change to -> Tuple[str, Optional[str]]:

Suggested change
) -> tuple[str, Optional[str]]:
) -> Tuple[str, Optional[str]]:

Copilot uses AI. Check for mistakes.
"""
# Handle reply subject formatting
reply_subject = subject
if in_reply_to and not subject.lower().startswith('re:'):
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

The condition checks for 'Re:' prefix but should handle variations like 'RE:', 'Re:', 'rE:', etc. Consider using a case-insensitive regex or normalizing the check: if in_reply_to and not re.match(r'^re:\s*', subject, re.IGNORECASE):

Suggested change
if in_reply_to and not subject.lower().startswith('re:'):
if in_reply_to and not re.match(r'^\s*re:\s*', subject, re.IGNORECASE):

Copilot uses AI. Check for mistakes.
Comment on lines +574 to +575
if thread_id_final:
send_body["threadId"] = thread_id_final
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

The variable thread_id_final is always the same as the input thread_id parameter since _prepare_gmail_message returns it unchanged. This check should use thread_id directly instead of thread_id_final.

Suggested change
if thread_id_final:
send_body["threadId"] = thread_id_final
if thread_id:
send_body["threadId"] = thread_id

Copilot uses AI. Check for mistakes.
Comment on lines +660 to +661
if thread_id_final:
draft_body["message"]["threadId"] = thread_id_final
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

Same issue as in send_gmail_message - thread_id_final is always identical to the input thread_id. Use thread_id directly instead of thread_id_final.

Suggested change
if thread_id_final:
draft_body["message"]["threadId"] = thread_id_final
if thread_id:
draft_body["message"]["threadId"] = thread_id

Copilot uses AI. Check for mistakes.
@taylorwilsdon taylorwilsdon merged commit 6fcefd5 into taylorwilsdon:main Aug 4, 2025
@taylorwilsdon
Copy link
Owner

Works perfectly with no changes, the copilot suggestions are worthless. Good stuff, thanks @benjaminjackson!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants