Skip to content

Comments

Parse to and cc headers#493

Merged
MrgSub merged 9 commits intoMail-0:stagingfrom
danteissaias:parse-to-cc
Mar 21, 2025
Merged

Parse to and cc headers#493
MrgSub merged 9 commits intoMail-0:stagingfrom
danteissaias:parse-to-cc

Conversation

@danteissaias
Copy link
Contributor

@danteissaias danteissaias commented Mar 20, 2025

Description

Parse the to and cc email headers and display them.


Type of Change

Please delete options that are not relevant.

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature with breaking changes)
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • 🔒 Security enhancement
  • ⚡ Performance improvement

Areas Affected

Please check all that apply:

  • Email Integration (Gmail, IMAP, etc.)
  • User Interface/Experience
  • Authentication/Authorization
  • Data Storage/Management
  • API Endpoints
  • Documentation
  • Testing Infrastructure
  • Development Workflow
  • Deployment/Infrastructure

Testing Done

Describe the tests you've done:

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • Cross-browser testing (if UI changes)
  • Mobile responsiveness verified (if UI changes)

Security Considerations

For changes involving data or authentication:

  • No sensitive data is exposed
  • Authentication checks are in place
  • Input validation is implemented
  • Rate limiting is considered (if applicable)

Checklist

  • I have read the CONTRIBUTING document
  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in complex areas
  • I have updated the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix/feature works
  • All tests pass locally
  • Any dependent changes are merged and published

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

    • Enhanced email handling to accurately extract and display recipient ("To") and carbon copy ("CC") addresses, ensuring that multiple recipients are properly shown.
    • Introduced a new interface for email senders, improving the clarity and reusability of code related to message senders.
  • Refactor

    • Improved the parsing and structure of email address data for better consistency and reliability in email communications.

@vercel
Copy link

vercel bot commented Mar 20, 2025

@danteissaias is attempting to deploy a commit to the Zero Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

Walkthrough

The changes update the email processing logic by enhancing header extraction and display. The API driver now extracts “To” and “CC” headers from the email payload. A new utility function, parseAddressList, processes these headers to create structured sender objects. The MailDisplay component is updated to show recipient addresses correctly and conditionally render the CC field. In addition, the type definitions are enhanced by adding a new Sender interface and updating related message interfaces.

Changes

File(s) Change Summary
apps/mail/app/api/driver/google.ts
apps/mail/lib/email-utils.ts
Enhanced email header extraction by introducing filtering for "To" and "CC" headers and using parseAddressList to generate structured sender objects with fallback handling.
apps/mail/components/mail/mail-display.tsx Updated UI logic to render multiple recipient addresses in the "To" field and conditionally display the "CC" field when available.
apps/mail/types/index.ts Added a new Sender interface and updated ParsedMessage and InitialThread interfaces to replace inline sender definitions and include to and cc arrays.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API as "Driver (google.ts)"
    participant Utils as "Email Utils (parseAddressList)"
    participant UI as "MailDisplay Component"

    Client->>API: Sends email payload
    API->>API: Extracts "To" & "CC" headers
    API->>Utils: Parse each header with parseAddressList
    Utils-->>API: Returns array of Sender objects
    API-->>Client: Returns enriched email object (includes to & cc)
    Client->>UI: Loads emailData
    UI->>UI: Render "To" field using emailData.to
    UI->>UI: Conditionally render "CC" field if present
Loading

Possibly related PRs

Poem

I'm a coding rabbit, hopping through the night,
Parsing headers by moonlight, making data bright.
To and CC, now dance in arrays so neat,
In every line of code, there’s a rhythmic beat.
With carrots and code, our improvements take flight!
🥕💻 Happy hoppers, coding right!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3bd8104 and 9511514.

📒 Files selected for processing (2)
  • apps/mail/components/mail/mail-display.tsx (1 hunks)
  • apps/mail/lib/email-utils.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/mail/components/mail/mail-display.tsx
  • apps/mail/lib/email-utils.ts

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
apps/mail/types/index.ts (1)

43-45: Adds proper support for email recipients.

This change properly models email messages by adding to and cc fields as arrays of Sender objects, which aligns with standard email structure. This enables the display of multiple recipients as described in the PR objectives.

Consider adding JSDoc comments to these fields to improve documentation:

+/** The primary sender of the email */
  sender: Sender;
+/** List of direct recipients */
  to: Sender[];
+/** List of carbon-copy recipients */
  cc: Sender[];
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1cbe96f and d7dc75f.

📒 Files selected for processing (5)
  • apps/mail/app/api/driver/google.ts (3 hunks)
  • apps/mail/components/mail/mail-display.tsx (1 hunks)
  • apps/mail/components/mail/mail.tsx (3 hunks)
  • apps/mail/lib/email-utils.ts (2 hunks)
  • apps/mail/types/index.ts (2 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
apps/mail/app/api/driver/google.ts (1)
apps/mail/lib/email-utils.ts (1) (1)
  • parseAddressList (163-180)
apps/mail/lib/email-utils.ts (1)
apps/mail/types/index.ts (1) (1)
  • Sender (32-35)
🔇 Additional comments (13)
apps/mail/app/api/driver/google.ts (4)

6-6: Good update to the import statement.

The import has been properly updated to include the new parseAddressList function along with the existing parseFrom function.


132-135: Well-implemented "To" header parsing.

This implementation correctly:

  1. Filters headers with name "to" (case-insensitive)
  2. Extracts string values and filters out undefined values
  3. Uses the new parseAddressList function to parse each header value
  4. Flattens the results into a single array of recipients

137-140: Well-implemented "CC" header parsing.

The CC headers implementation follows the same robust pattern as the "To" headers parsing, maintaining consistency throughout the codebase.


152-153: Good integration of parsed data into the return object.

The new to and cc properties are properly included in the returned object, making the parsed data available to components that need it.

apps/mail/components/mail/mail.tsx (3)

48-48: Minor whitespace cleanup.

Removed an unnecessary blank line, improving code formatting.


149-154: Improved Drawer component formatting.

Restructured the Drawer component props to be more readable with each prop on its own line. This improves code maintainability without changing functionality.


362-367: Consistent Drawer formatting.

Applied the same formatting improvement to the Drawer component in the MailLayout function, maintaining consistency throughout the codebase.

apps/mail/lib/email-utils.ts (3)

1-1: Updated import to include the address list parser.

Good addition of the parseAddressList import from the email-addresses library alongside the existing parseFrom function.


4-4: Added Sender type import.

Properly imported the Sender interface from types to ensure type safety in the new function.


163-180: Well-implemented parseAddressList function.

The new function follows best practices:

  1. Uses the underlying library function with proper error handling
  2. Returns a fallback sender when no valid address is found
  3. Correctly handles both individual addresses and groups
  4. Maintains consistency with the existing parseFrom function pattern

The implementation handles edge cases well and is structured for maintainability.

apps/mail/types/index.ts (3)

32-35: Good abstraction with the new Sender interface.

Creating a reusable Sender interface is a good practice that promotes code reuse and maintainability. This interface will work well with the email address parsing functionality described in the PR objectives.


73-73: Maintains consistency across interfaces.

Good job applying the Sender interface consistently across both ParsedMessage and InitialThread interfaces, which maintains a uniform structure throughout the codebase.


32-35:

Details

✅ Verification successful

Consider making the name property optional.

Email addresses don't always have an associated name, especially in certain email clients or formatting styles.

export interface Sender {
-  name: string;
+  name?: string;
  email: string;
}

🏁 Script executed:

#!/bin/bash
# Check if there are cases where emails might not have names in the parsing logic
echo "Checking for email parsing implementation:"
rg -A 10 "parseAddressList" --type ts

Length of output: 3580


Update the Sender interface to make the "name" property optional

Based on the current parsing logic (which falls back to a default name when no name is provided), it's a good idea to mark the Sender name as optional to better reflect that some email addresses may not include a name. Please update the interface in apps/mail/types/index.ts as follows:

export interface Sender {
-  name: string;
+  name?: string;
  email: string;
}

@MrgSub
Copy link
Collaborator

MrgSub commented Mar 20, 2025

Is our currently implementation broken?

</span>
<span className="text-muted-foreground ml-3">
{emailData?.sender?.email}
{emailData?.to?.map((t) => t.email).join(', ')}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we replacing sender.email with to.email? shouldn't it be from.email?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To should reflect the value of the to header in the underlying email. Sender is from the from header.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sender = from then why are you replacing sender with to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for {t('common.mailDisplay.to')}:

@danteissaias
Copy link
Contributor Author

Current implementation uses the to header for all fields. This means:

  • CC is not the correct value.
  • If you look an email in "Sent" the to field will show your email, not the email you sent it to.

@MrgSub
Copy link
Collaborator

MrgSub commented Mar 20, 2025

Ok LGTM, please resolve conflicts

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e3bcc89 and 3bd8104.

📒 Files selected for processing (4)
  • apps/mail/app/api/driver/google.ts (3 hunks)
  • apps/mail/components/mail/mail-display.tsx (1 hunks)
  • apps/mail/lib/email-utils.ts (3 hunks)
  • apps/mail/types/index.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/mail/app/api/driver/google.ts
  • apps/mail/types/index.ts
  • apps/mail/components/mail/mail-display.tsx
🧰 Additional context used
🧬 Code Definitions (1)
apps/mail/lib/email-utils.ts (1)
apps/mail/types/index.ts (1) (1)
  • Sender (32-35)
🔇 Additional comments (3)
apps/mail/lib/email-utils.ts (3)

1-1: Good addition of parseAddressList import.

The import statement has been correctly updated to include the parseAddressList function from the email-addresses library, which will be used to parse the "to" and "cc" email headers.


4-4: Good import of Sender type.

Importing the Sender type from "@/types" ensures proper typing for the new function's return value.


163-180: Overall implementation is well-structured.

The new function correctly handles parsing both individual addresses and address groups, following a pattern similar to the existing parseFrom function. This will properly support the "to" and "cc" fields mentioned in the PR objectives.

danteissaias and others added 2 commits March 20, 2025 21:44
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@vercel
Copy link

vercel bot commented Mar 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
0 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 5:16pm

@MrgSub MrgSub merged commit 86ae4fe into Mail-0:staging Mar 21, 2025
4 checks passed
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.

2 participants