Skip to content

Comments

assistant: fix CC/BCC recipients not being added to draft replies#1156

Merged
elie222 merged 4 commits intomainfrom
fix/draft-cc-bcc
Jan 1, 2026
Merged

assistant: fix CC/BCC recipients not being added to draft replies#1156
elie222 merged 4 commits intomainfrom
fix/draft-cc-bcc

Conversation

@elie222
Copy link
Owner

@elie222 elie222 commented Dec 31, 2025

User description

assistant: fix CC/BCC recipients not being added to draft replies

Fixes a bug where CC/BCC recipients configured in rules were not passed to the draft creation logic.

  • Added cc and bcc to EmailProvider.draftEmail interface
  • Updated AI action handler to pass configured CC/BCC to provider
  • Merged manual CC recipients with automatically detected reply-all recipients in Gmail/Outlook implementations

Generated description

Below is a concise technical summary of the changes proposed in this PR:
Resolves a bug preventing CC/BCC recipients from being included in draft replies by extending the EmailProvider.draftEmail interface to support these fields. Integrates a new mergeAndDedupeRecipients utility within the GmailProvider and OutlookProvider implementations to correctly combine and deduplicate recipients, ensuring that AI actions can now successfully pass configured CC/BCC addresses to the email drafting logic.

TopicDetails
Draft Email CC/BCC Extend the email drafting functionality to correctly process and include CC and BCC recipients. This involves updating the EmailProvider interface, modifying the AI action handler to pass these fields, and adapting the GmailProvider and OutlookProvider implementations to utilize the new recipient merging logic for draft email creation.
Modified files (6)
  • apps/web/utils/email/types.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/gmail/mail.ts
Latest Contributors(2)
UserCommitDate
elie222Improve-SentryDecember 19, 2025
eduardoleliss@gmail.comFix-draft-missing-mail...August 18, 2025
Recipient Utilities Introduce a new utility function mergeAndDedupeRecipients to combine and deduplicate email addresses from various sources, ensuring proper sanitization and case-insensitivity. Additionally, enhance the buildReplyAllRecipients function to improve the robustness of CC list generation for reply-all scenarios, and add comprehensive unit tests for the new merging utility.
Modified files (2)
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/email/reply-all.ts
Latest Contributors(2)
UserCommitDate
elie222testSeptember 14, 2025
cursoragent@cursor.comRefactor-Extract-reply...September 14, 2025
Internal Tooling Updates Update internal developer documentation and tooling files. This includes adding notes about sandbox mode to PR command scripts, introducing new step-by-step execution instructions, and clarifying how to run tests using pnpm test.
Modified files (5)
  • .cursor/rules/testing.mdc
  • .cursor/commands/create-pr.md
  • .cursor/commands/step-by-step.md
  • .cursor/commands/next-step.md
  • .cursor/commands/address-pr-comments.md
Latest Contributors(1)
UserCommitDate
elie222chore-add-cursor-comma...December 31, 2025
This pull request is reviewed by Baz. Review like a pro on (Baz).

@vercel
Copy link

vercel bot commented Dec 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
inbox-zero Ready Ready Preview Jan 1, 2026 10:12am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 31, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adds optional cc and bcc support across the email-drafting flow: expands provider/type signatures, forwards cc/bcc from the AI draft action, merges/deduplicates reply-all CCs, and includes BCC handling in Gmail and Outlook draft builders and tests. (47 words)

Changes

Cohort / File(s) Summary
Email Provider Types & Interfaces
apps/web/utils/email/types.ts, apps/web/utils/email/google.ts, apps/web/utils/email/microsoft.ts
Extended draftEmail argument types to accept optional cc?: string and bcc?: string.
AI Action Handler
apps/web/utils/ai/actions.ts
draft action signature updated to include optional cc and bcc; forwarded in draftArgs to client.draftEmail.
Gmail draft builder
apps/web/utils/gmail/mail.ts
Accepts args.cc and args.bcc; uses mergeAndDedupeRecipients, builds deduplicated ccList and bccList, and includes cc/bcc in raw MIME construction.
Outlook draft builder
apps/web/utils/outlook/mail.ts
Accepts args.cc and args.bcc; merges reply-all CCs with manual CCs, sanitizes CC/BCC, constructs ccRecipients and conditional bccRecipients, and includes them when updating the draft.
Reply-all utilities & tests
apps/web/utils/email/reply-all.ts, apps/web/utils/email/reply-all.test.ts
Added mergeAndDedupeRecipients(existing, manual) and updated reply-all deduplication logic; tests added/updated for merging, case-insensitive dedupe, and sanitization.
Docs / CLI snippets
.cursor/commands/* (e.g., address-pr-comments.md, create-pr.md, next-step.md, step-by-step.md)
Small documentation additions (sandbox caution) and new step guidance files.

Sequence Diagram

sequenceDiagram
    participant AI as AI Action Handler
    participant Client as Email Provider Layer
    participant Gmail as Gmail Draft Builder
    participant Outlook as Outlook Draft Builder
    participant Util as Reply-All Utility

    AI->>Client: draftEmail(email, {to, subject, content, cc, bcc})
    Client->>Util: buildReplyAllRecipients(email) 
    Util-->>Client: existingReplyAllCCs
    Client->>Gmail: draftEmail(email, args) activate
    Note right of Gmail: merge reply-all CCs\nwith args.cc (dedupe)
    Gmail->>Gmail: build ccList & bccList
    Gmail-->>Client: drafted message (raw with cc/bcc) deactivate

    Client->>Outlook: draftEmail(email, args) activate
    Note right of Outlook: merge reply-all CCs\nwith args.cc (dedupe) and parse bcc
    Outlook->>Outlook: build ccRecipients & bccRecipients
    Outlook-->>Client: patched draft (with cc/bcc) deactivate
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • johnlowe399-blip
  • anakarentorosserrano-star

Poem

🐰 I hopped through threads to tidy each name,
Merged CCs with care so none look the same.
BCCs slipped softly, hidden from view,
Drafts now include everyone true.
A rabbit's small patch—quick and new! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: enabling CC/BCC recipients to be added to draft replies, which is the core objective of this changeset.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@macroscopeapp
Copy link
Contributor

macroscopeapp bot commented Dec 31, 2025

Fix draft replies by adding CC/BCC handling across EmailProvider.draftEmail, GmailProvider.draftEmail, and OutlookProvider.draftEmail

Add cc and bcc to draft creation, merge and dedupe recipients case-insensitively for reply-all, and include CC/BCC in Gmail and Outlook draft payloads; update actions to pass through cc/bcc and add unit tests for recipient merging.

📍Where to Start

Start with recipient merging in buildReplyAllRecipients and mergeAndDedupeRecipients in reply-all.ts, then follow draft creation flows in mail.ts and mail.ts, and the action entry in actions.ts.


Macroscope summarized f18f032.

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: 0

🧹 Nitpick comments (2)
apps/web/utils/gmail/mail.ts (1)

272-281: Consider normalizing email addresses when checking for CC duplicates.

The current duplicate detection uses includes() which performs case-sensitive string matching. This could allow duplicate recipients with different formatting:

  • user@example.com vs User@example.com (different casing)
  • John <user@example.com> vs user@example.com (with/without display name)
💡 Suggested improvement with email normalization
  // Merge CC from reply-all with CC from args
  const ccList = [...recipients.cc];
  if (args.cc) {
    const manualCc = args.cc.split(",").map((s) => s.trim());
+   // Normalize existing CCs for comparison
+   const normalizedExisting = ccList.map(addr => 
+     extractEmailAddress(addr).toLowerCase()
+   );
    for (const email of manualCc) {
-     if (!ccList.includes(email)) {
+     const normalizedEmail = extractEmailAddress(email).toLowerCase();
+     if (!normalizedExisting.includes(normalizedEmail)) {
        ccList.push(email);
+       normalizedExisting.push(normalizedEmail);
      }
    }
  }

Note: You'll need to import extractEmailAddress from @/utils/email if this approach is adopted.

apps/web/utils/outlook/mail.ts (1)

218-235: Consider normalizing email addresses when checking for CC duplicates.

Similar to the Gmail implementation, the duplicate detection uses includes() which performs case-sensitive string matching. This could result in duplicate recipients with different casing or formatting.

For consistency across providers and to prevent duplicate recipients, consider using the same email normalization approach as suggested for the Gmail implementation (extracting and lowercasing email addresses for comparison).

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a0d4df and d3a7735.

📒 Files selected for processing (6)
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/email/types.ts
  • apps/web/utils/gmail/mail.ts
  • apps/web/utils/outlook/mail.ts
🧰 Additional context used
📓 Path-based instructions (16)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/data-fetching.mdc)

**/*.{ts,tsx}: For API GET requests to server, use the swr package
Use result?.serverError with toastError from @/components/Toast for error handling in async operations

**/*.{ts,tsx}: Use wrapper functions for Gmail message operations (get, list, batch, etc.) from @/utils/gmail/message.ts instead of direct API calls
Use wrapper functions for Gmail thread operations from @/utils/gmail/thread.ts instead of direct API calls
Use wrapper functions for Gmail label operations from @/utils/gmail/label.ts instead of direct API calls

**/*.{ts,tsx}: For early access feature flags, create hooks using the naming convention use[FeatureName]Enabled that return a boolean from useFeatureFlagEnabled("flag-key")
For A/B test variant flags, create hooks using the naming convention use[FeatureName]Variant that define variant types, use useFeatureFlagVariantKey() with type casting, and provide a default "control" fallback
Use kebab-case for PostHog feature flag keys (e.g., inbox-cleaner, pricing-options-2)
Always define types for A/B test variant flags (e.g., type PricingVariant = "control" | "variant-a" | "variant-b") and provide type safety through type casting

**/*.{ts,tsx}: Don't use primitive type aliases or misleading types
Don't use empty type parameters in type aliases and interfaces
Don't use this and super in static contexts
Don't use any or unknown as type constraints
Don't use the TypeScript directive @ts-ignore
Don't use TypeScript enums
Don't export imported variables
Don't add type annotations to variables, parameters, and class properties that are initialized with literal expressions
Don't use TypeScript namespaces
Don't use non-null assertions with the ! postfix operator
Don't use parameter properties in class constructors
Don't use user-defined types
Use as const instead of literal types and type annotations
Use either T[] or Array<T> consistently
Initialize each enum member value explicitly
Use export type for types
Use `impo...

Files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/prisma-enum-imports.mdc)

Always import Prisma enums from @/generated/prisma/enums instead of @/generated/prisma/client to avoid Next.js bundling errors in client components

Import Prisma using the project's centralized utility: import prisma from '@/utils/prisma'

Files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
apps/web/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

Import specific lodash functions rather than entire lodash library to minimize bundle size (e.g., import groupBy from 'lodash/groupBy')

apps/web/**/*.{ts,tsx}: Use TypeScript with strict null checks
Do not export types/interfaces that are only used within the same file. Export later if needed

Files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/security.mdc)

**/*.ts: ALL database queries MUST be scoped to the authenticated user/account by including user/account filtering in WHERE clauses to prevent unauthorized data access
Always validate that resources belong to the authenticated user before performing operations, using ownership checks in WHERE clauses or relationships
Always validate all input parameters for type, format, and length before using them in database queries
Use SafeError for error responses to prevent information disclosure. Generic error messages should not reveal internal IDs, logic, or resource ownership details
Only return necessary fields in API responses using Prisma's select option. Never expose sensitive data such as password hashes, private keys, or system flags
Prevent Insecure Direct Object References (IDOR) by validating resource ownership before operations. All findUnique/findFirst calls MUST include ownership filters
Prevent mass assignment vulnerabilities by explicitly whitelisting allowed fields in update operations instead of accepting all user-provided data
Prevent privilege escalation by never allowing users to modify system fields, ownership fields, or admin-only attributes through user input
All findMany queries MUST be scoped to the user's data by including appropriate WHERE filters to prevent returning data from other users
Use Prisma relationships for access control by leveraging nested where clauses (e.g., emailAccount: { id: emailAccountId }) to validate ownership

Files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
**/*.{tsx,ts}

📄 CodeRabbit inference engine (.cursor/rules/ui-components.mdc)

**/*.{tsx,ts}: Use Shadcn UI and Tailwind for components and styling
Use next/image package for images
For API GET requests to server, use the swr package with hooks like useSWR to fetch data
For text inputs, use the Input component with registerProps for form integration and error handling

Files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
**/*.{tsx,ts,css}

📄 CodeRabbit inference engine (.cursor/rules/ui-components.mdc)

Implement responsive design with Tailwind CSS using a mobile-first approach

Files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)

**/*.{js,jsx,ts,tsx}: Don't use accessKey attribute on any HTML element
Don't set aria-hidden="true" on focusable elements
Don't add ARIA roles, states, and properties to elements that don't support them
Don't use distracting elements like <marquee> or <blink>
Only use the scope prop on <th> elements
Don't assign non-interactive ARIA roles to interactive HTML elements
Make sure label elements have text content and are associated with an input
Don't assign interactive ARIA roles to non-interactive HTML elements
Don't assign tabIndex to non-interactive HTML elements
Don't use positive integers for tabIndex property
Don't include "image", "picture", or "photo" in img alt prop
Don't use explicit role property that's the same as the implicit/default role
Make static elements with click handlers use a valid role attribute
Always include a title element for SVG elements
Give all elements requiring alt text meaningful information for screen readers
Make sure anchors have content that's accessible to screen readers
Assign tabIndex to non-interactive HTML elements with aria-activedescendant
Include all required ARIA attributes for elements with ARIA roles
Make sure ARIA properties are valid for the element's supported roles
Always include a type attribute for button elements
Make elements with interactive roles and handlers focusable
Give heading elements content that's accessible to screen readers (not hidden with aria-hidden)
Always include a lang attribute on the html element
Always include a title attribute for iframe elements
Accompany onClick with at least one of: onKeyUp, onKeyDown, or onKeyPress
Accompany onMouseOver/onMouseOut with onFocus/onBlur
Include caption tracks for audio and video elements
Use semantic elements instead of role attributes in JSX
Make sure all anchors are valid and navigable
Ensure all ARIA properties (aria-*) are valid
Use valid, non-abstract ARIA roles for elements with ARIA roles
Use valid AR...

Files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
!(pages/_document).{jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)

Don't use the next/head module in pages/_document.js on Next.js projects

Files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/utilities.mdc)

**/*.{js,ts,jsx,tsx}: Use lodash utilities for common operations (arrays, objects, strings)
Import specific lodash functions to minimize bundle size (e.g., import groupBy from 'lodash/groupBy')

Files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
**/{utils,helpers,lib}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/logging.mdc)

Logger should be passed as a parameter to helper functions instead of creating their own logger instances

Files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
apps/web/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (apps/web/CLAUDE.md)

apps/web/**/*.{ts,tsx,js,jsx}: Use @/ path aliases for imports from project root
Prefer self-documenting code over comments; use descriptive variable and function names instead of explaining intent with comments
Add helper functions to the bottom of files, not the top
All imports go at the top of files, no mid-file dynamic imports

Files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
apps/web/**/*.{ts,tsx,js,jsx,json,css}

📄 CodeRabbit inference engine (apps/web/CLAUDE.md)

Format code with Prettier

Files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
apps/web/**/*.{example,ts,json}

📄 CodeRabbit inference engine (apps/web/CLAUDE.md)

Add environment variables to .env.example, env.ts, and turbo.json

Files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
apps/web/{utils/ai,utils/llms,__tests__}/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/llm.mdc)

LLM-related code must be organized in specific directories: apps/web/utils/ai/ for main implementations, apps/web/utils/llms/ for core utilities and configurations, and apps/web/__tests__/ for LLM-specific tests

Files:

  • apps/web/utils/ai/actions.ts
apps/web/utils/ai/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/llm.mdc)

apps/web/utils/ai/**/*.ts: LLM feature functions must import from zod for schema validation, use createScopedLogger from @/utils/logger, chatCompletionObject and createGenerateObject from @/utils/llms, and import EmailAccountWithAI type from @/utils/llms/types
LLM feature functions must follow a standard structure: accept options with inputData and emailAccount parameters, implement input validation with early returns, define separate system and user prompts, create a Zod schema for response validation, and use createGenerateObject to execute the LLM call
System prompts must define the LLM's role and task specifications
User prompts must contain the actual data and context, and should be kept separate from system prompts
Always define a Zod schema for LLM response validation and make schemas as specific as possible to guide the LLM output
Use descriptive scoped loggers for each LLM feature, log inputs and outputs with appropriate log levels, and include relevant context in log messages
Implement early returns for invalid LLM inputs, use proper error types and logging, implement fallbacks for AI failures, and add retry logic for transient failures using withRetry
Use XML-like tags to structure data in prompts, remove excessive whitespace and truncate long inputs, and format data consistently across similar LLM functions
Use TypeScript types for all LLM function parameters and return values, and define clear interfaces for complex input/output structures
Keep related AI functions in the same file or directory, extract common patterns into utility functions, and document complex AI logic with clear comments

Files:

  • apps/web/utils/ai/actions.ts
apps/web/utils/gmail/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/gmail-api.mdc)

apps/web/utils/gmail/**/*.{ts,tsx}: Always use wrapper functions from @/utils/gmail/ for Gmail API operations instead of direct provider API calls
Keep Gmail provider-specific implementation details isolated within the apps/web/utils/gmail/ directory

Files:

  • apps/web/utils/gmail/mail.ts
🧠 Learnings (7)
📚 Learning: 2025-07-17T04:19:57.099Z
Learnt from: edulelis
Repo: elie222/inbox-zero PR: 576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.099Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses `[key: string]: DigestItem[] | undefined | string | Date | undefined` instead of intersection types like `& Record<string, DigestItem[] | undefined>` due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.

Applied to files:

  • apps/web/utils/email/types.ts
📚 Learning: 2025-11-25T14:37:22.660Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-11-25T14:37:22.660Z
Learning: Applies to **/*.{ts,tsx} : Use wrapper functions for Gmail thread operations from @/utils/gmail/thread.ts instead of direct API calls

Applied to files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:37:22.660Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-11-25T14:37:22.660Z
Learning: Applies to **/*.{ts,tsx} : Use wrapper functions for Gmail label operations from @/utils/gmail/label.ts instead of direct API calls

Applied to files:

  • apps/web/utils/email/types.ts
  • apps/web/utils/email/google.ts
  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:37:22.660Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-11-25T14:37:22.660Z
Learning: Applies to **/*.{ts,tsx} : Use wrapper functions for Gmail message operations (get, list, batch, etc.) from @/utils/gmail/message.ts instead of direct API calls

Applied to files:

  • apps/web/utils/email/google.ts
  • apps/web/utils/outlook/mail.ts
  • apps/web/utils/email/microsoft.ts
  • apps/web/utils/ai/actions.ts
  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:37:22.660Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-11-25T14:37:22.660Z
Learning: Applies to apps/web/utils/gmail/**/*.{ts,tsx} : Keep Gmail provider-specific implementation details isolated within the apps/web/utils/gmail/ directory

Applied to files:

  • apps/web/utils/email/google.ts
  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:37:22.660Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-11-25T14:37:22.660Z
Learning: Applies to apps/web/utils/gmail/**/*.{ts,tsx} : Always use wrapper functions from @/utils/gmail/ for Gmail API operations instead of direct provider API calls

Applied to files:

  • apps/web/utils/email/google.ts
  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:38:07.606Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-11-25T14:38:07.606Z
Learning: Applies to apps/web/utils/ai/**/*.ts : LLM feature functions must import from `zod` for schema validation, use `createScopedLogger` from `@/utils/logger`, `chatCompletionObject` and `createGenerateObject` from `@/utils/llms`, and import `EmailAccountWithAI` type from `@/utils/llms/types`

Applied to files:

  • apps/web/utils/ai/actions.ts
🧬 Code graph analysis (2)
apps/web/utils/outlook/mail.ts (1)
apps/web/utils/email.ts (2)
  • extractEmailAddress (19-52)
  • extractNameFromEmail (9-16)
apps/web/utils/gmail/mail.ts (1)
apps/web/utils/email/reply-all.ts (1)
  • formatCcList (67-69)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Baz Reviewer
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Macroscope - Correctness Check
  • GitHub Check: test
🔇 Additional comments (6)
apps/web/utils/email/types.ts (1)

105-116: LGTM! Type definition correctly extended for CC/BCC support.

The addition of optional cc and bcc fields to the draftEmail method signature is clean and consistent with the existing pattern. This properly enables CC/BCC functionality across all email provider implementations.

apps/web/utils/email/google.ts (1)

629-640: LGTM! Provider signature correctly updated.

The draftEmail method signature has been properly extended to accept optional cc and bcc fields, maintaining consistency with the EmailProvider interface and enabling these fields to be passed through to the Gmail implementation layer.

apps/web/utils/gmail/mail.ts (1)

283-296: LGTM! Raw message creation correctly includes merged CC and BCC.

The code properly:

  • Formats the merged CC list using formatCcList() which handles empty arrays
  • Passes through BCC with nullish coalescing to undefined
  • Maintains the reply-all threading information
apps/web/utils/ai/actions.ts (1)

151-187: LGTM! Draft action correctly extended to support CC/BCC.

The implementation properly:

  • Adds cc and bcc to the action function signature with nullable string types
  • Converts null to undefined using nullish coalescing (consistent with other fields)
  • Passes the fields through to client.draftEmail()

This enables AI-generated rules to specify CC/BCC recipients for draft replies.

apps/web/utils/outlook/mail.ts (1)

237-293: LGTM! BCC handling and draft update correctly implemented.

The implementation properly:

  • Parses BCC addresses and formats them for the Outlook API with both address and display name
  • Uses conditional spread to only include ccRecipients and bccRecipients when they have content
  • Prevents sending empty arrays to the API

The defensive coding pattern here is excellent.

apps/web/utils/email/microsoft.ts (1)

486-497: LGTM! Provider signature correctly updated.

The draftEmail method signature has been properly extended to accept optional cc and bcc fields, maintaining consistency with the EmailProvider interface and enabling these fields to be passed through to the Outlook implementation layer.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 6 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="apps/web/utils/gmail/mail.ts">

<violation number="1" location="apps/web/utils/gmail/mail.ts:275">
P2: Email addresses from `args.cc` are not normalized before comparison. The `recipients.cc` array contains emails normalized via `extractEmailAddress()`, but `manualCc` only trims whitespace. This can cause duplicate CC entries when formats differ (e.g., `&quot;John &lt;john@example.com&gt;&quot;` vs `&quot;john@example.com&quot;`).</violation>
</file>

<file name="apps/web/utils/outlook/mail.ts">

<violation number="1" location="apps/web/utils/outlook/mail.ts:223">
P2: CC deduplication compares raw strings but should compare extracted email addresses. If `args.cc` contains `&quot;John Doe &lt;john@example.com&gt;&quot;` and `recipients.cc` already has `&quot;john@example.com&quot;`, the `includes()` check will fail (different string formats), causing duplicate CC recipients.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

if (args.cc) {
const manualCc = args.cc.split(",").map((s) => s.trim());
for (const email of manualCc) {
if (!ccAddresses.includes(email)) {
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Dec 31, 2025

Choose a reason for hiding this comment

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

P2: CC deduplication compares raw strings but should compare extracted email addresses. If args.cc contains "John Doe <john@example.com>" and recipients.cc already has "john@example.com", the includes() check will fail (different string formats), causing duplicate CC recipients.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/web/utils/outlook/mail.ts, line 223:

<comment>CC deduplication compares raw strings but should compare extracted email addresses. If `args.cc` contains `&quot;John Doe &lt;john@example.com&gt;&quot;` and `recipients.cc` already has `&quot;john@example.com&quot;`, the `includes()` check will fail (different string formats), causing duplicate CC recipients.</comment>

<file context>
@@ -213,14 +215,35 @@ export async function draftEmail(
+  if (args.cc) {
+    const manualCc = args.cc.split(&quot;,&quot;).map((s) =&gt; s.trim());
+    for (const email of manualCc) {
+      if (!ccAddresses.includes(email)) {
+        ccAddresses.push(email);
+      }
</file context>

✅ Addressed in dae6d57

Copy link
Owner Author

Choose a reason for hiding this comment

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

Fixed. Updated Outlook logic to use the same centralized deduplication utility that extracts email addresses before comparison.

Copy link
Contributor

Choose a reason for hiding this comment

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

Commit dae6d57 addressed this comment by replacing the problematic raw string comparison logic with a centralized mergeAndDedupeRecipients utility function. This function properly extracts and compares email addresses before deduplication, eliminating the bug where different formats of the same email address would be treated as duplicates.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the feedback! I've saved this as a new learning to improve future reviews.

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: 0

🧹 Nitpick comments (2)
apps/web/utils/email/reply-all.ts (2)

36-52: Remove unused raw property for cleaner code.

The raw property is extracted but never used—only email is accessed when adding to ccSet. This adds unnecessary computation.

🔎 Proposed refactor
   if (headers.cc) {
     const originalCcAddresses = headers.cc
       .split(",")
-      .map((addr) => ({
-        raw: addr.trim(),
-        email: extractEmailAddress(addr.trim()),
-      }))
+      .map((addr) => extractEmailAddress(addr.trim()))
       .filter(
-        ({ email }) => email && email !== replyTo && email !== currentUser,
+        (email) => email && email !== replyTo && email !== currentUser,
       );
 
-    for (const { raw, email } of originalCcAddresses) {
+    for (const email of originalCcAddresses) {
       const key = email.toLowerCase();
       if (!seenEmails.has(key)) {
         seenEmails.add(key);
         ccSet.add(email);
       }
     }
   }

57-73: Remove unused raw property for cleaner code.

Same issue as the CC section—the raw property is extracted but never used.

🔎 Proposed refactor
   if (headers.to) {
     const originalToAddresses = headers.to
       .split(",")
-      .map((addr) => ({
-        raw: addr.trim(),
-        email: extractEmailAddress(addr.trim()),
-      }))
+      .map((addr) => extractEmailAddress(addr.trim()))
       .filter(
-        ({ email }) => email && email !== replyTo && email !== currentUser,
+        (email) => email && email !== replyTo && email !== currentUser,
       );
 
-    for (const { raw, email } of originalToAddresses) {
+    for (const email of originalToAddresses) {
       const key = email.toLowerCase();
       if (!seenEmails.has(key)) {
         seenEmails.add(key);
         ccSet.add(email);
       }
     }
   }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3a7735 and dae6d57.

📒 Files selected for processing (8)
  • .cursor/commands/address-pr-comments.md
  • .cursor/commands/create-pr.md
  • .cursor/commands/next-step.md
  • .cursor/commands/step-by-step.md
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/gmail/mail.ts
  • apps/web/utils/outlook/mail.ts
✅ Files skipped from review due to trivial changes (3)
  • .cursor/commands/address-pr-comments.md
  • .cursor/commands/step-by-step.md
  • .cursor/commands/next-step.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/utils/outlook/mail.ts
🧰 Additional context used
📓 Path-based instructions (18)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/data-fetching.mdc)

**/*.{ts,tsx}: For API GET requests to server, use the swr package
Use result?.serverError with toastError from @/components/Toast for error handling in async operations

**/*.{ts,tsx}: Use wrapper functions for Gmail message operations (get, list, batch, etc.) from @/utils/gmail/message.ts instead of direct API calls
Use wrapper functions for Gmail thread operations from @/utils/gmail/thread.ts instead of direct API calls
Use wrapper functions for Gmail label operations from @/utils/gmail/label.ts instead of direct API calls

**/*.{ts,tsx}: For early access feature flags, create hooks using the naming convention use[FeatureName]Enabled that return a boolean from useFeatureFlagEnabled("flag-key")
For A/B test variant flags, create hooks using the naming convention use[FeatureName]Variant that define variant types, use useFeatureFlagVariantKey() with type casting, and provide a default "control" fallback
Use kebab-case for PostHog feature flag keys (e.g., inbox-cleaner, pricing-options-2)
Always define types for A/B test variant flags (e.g., type PricingVariant = "control" | "variant-a" | "variant-b") and provide type safety through type casting

**/*.{ts,tsx}: Don't use primitive type aliases or misleading types
Don't use empty type parameters in type aliases and interfaces
Don't use this and super in static contexts
Don't use any or unknown as type constraints
Don't use the TypeScript directive @ts-ignore
Don't use TypeScript enums
Don't export imported variables
Don't add type annotations to variables, parameters, and class properties that are initialized with literal expressions
Don't use TypeScript namespaces
Don't use non-null assertions with the ! postfix operator
Don't use parameter properties in class constructors
Don't use user-defined types
Use as const instead of literal types and type annotations
Use either T[] or Array<T> consistently
Initialize each enum member value explicitly
Use export type for types
Use `impo...

Files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/prisma-enum-imports.mdc)

Always import Prisma enums from @/generated/prisma/enums instead of @/generated/prisma/client to avoid Next.js bundling errors in client components

Import Prisma using the project's centralized utility: import prisma from '@/utils/prisma'

Files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
apps/web/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

Import specific lodash functions rather than entire lodash library to minimize bundle size (e.g., import groupBy from 'lodash/groupBy')

apps/web/**/*.{ts,tsx}: Use TypeScript with strict null checks
Do not export types/interfaces that are only used within the same file. Export later if needed

Files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/security.mdc)

**/*.ts: ALL database queries MUST be scoped to the authenticated user/account by including user/account filtering in WHERE clauses to prevent unauthorized data access
Always validate that resources belong to the authenticated user before performing operations, using ownership checks in WHERE clauses or relationships
Always validate all input parameters for type, format, and length before using them in database queries
Use SafeError for error responses to prevent information disclosure. Generic error messages should not reveal internal IDs, logic, or resource ownership details
Only return necessary fields in API responses using Prisma's select option. Never expose sensitive data such as password hashes, private keys, or system flags
Prevent Insecure Direct Object References (IDOR) by validating resource ownership before operations. All findUnique/findFirst calls MUST include ownership filters
Prevent mass assignment vulnerabilities by explicitly whitelisting allowed fields in update operations instead of accepting all user-provided data
Prevent privilege escalation by never allowing users to modify system fields, ownership fields, or admin-only attributes through user input
All findMany queries MUST be scoped to the user's data by including appropriate WHERE filters to prevent returning data from other users
Use Prisma relationships for access control by leveraging nested where clauses (e.g., emailAccount: { id: emailAccountId }) to validate ownership

Files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
**/*.{tsx,ts}

📄 CodeRabbit inference engine (.cursor/rules/ui-components.mdc)

**/*.{tsx,ts}: Use Shadcn UI and Tailwind for components and styling
Use next/image package for images
For API GET requests to server, use the swr package with hooks like useSWR to fetch data
For text inputs, use the Input component with registerProps for form integration and error handling

Files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
**/*.{tsx,ts,css}

📄 CodeRabbit inference engine (.cursor/rules/ui-components.mdc)

Implement responsive design with Tailwind CSS using a mobile-first approach

Files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)

**/*.{js,jsx,ts,tsx}: Don't use accessKey attribute on any HTML element
Don't set aria-hidden="true" on focusable elements
Don't add ARIA roles, states, and properties to elements that don't support them
Don't use distracting elements like <marquee> or <blink>
Only use the scope prop on <th> elements
Don't assign non-interactive ARIA roles to interactive HTML elements
Make sure label elements have text content and are associated with an input
Don't assign interactive ARIA roles to non-interactive HTML elements
Don't assign tabIndex to non-interactive HTML elements
Don't use positive integers for tabIndex property
Don't include "image", "picture", or "photo" in img alt prop
Don't use explicit role property that's the same as the implicit/default role
Make static elements with click handlers use a valid role attribute
Always include a title element for SVG elements
Give all elements requiring alt text meaningful information for screen readers
Make sure anchors have content that's accessible to screen readers
Assign tabIndex to non-interactive HTML elements with aria-activedescendant
Include all required ARIA attributes for elements with ARIA roles
Make sure ARIA properties are valid for the element's supported roles
Always include a type attribute for button elements
Make elements with interactive roles and handlers focusable
Give heading elements content that's accessible to screen readers (not hidden with aria-hidden)
Always include a lang attribute on the html element
Always include a title attribute for iframe elements
Accompany onClick with at least one of: onKeyUp, onKeyDown, or onKeyPress
Accompany onMouseOver/onMouseOut with onFocus/onBlur
Include caption tracks for audio and video elements
Use semantic elements instead of role attributes in JSX
Make sure all anchors are valid and navigable
Ensure all ARIA properties (aria-*) are valid
Use valid, non-abstract ARIA roles for elements with ARIA roles
Use valid AR...

Files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
!(pages/_document).{jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)

Don't use the next/head module in pages/_document.js on Next.js projects

Files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • .cursor/commands/create-pr.md
  • apps/web/utils/gmail/mail.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/utilities.mdc)

**/*.{js,ts,jsx,tsx}: Use lodash utilities for common operations (arrays, objects, strings)
Import specific lodash functions to minimize bundle size (e.g., import groupBy from 'lodash/groupBy')

Files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
**/{utils,helpers,lib}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/logging.mdc)

Logger should be passed as a parameter to helper functions instead of creating their own logger instances

Files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
apps/web/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (apps/web/CLAUDE.md)

apps/web/**/*.{ts,tsx,js,jsx}: Use @/ path aliases for imports from project root
Prefer self-documenting code over comments; use descriptive variable and function names instead of explaining intent with comments
Add helper functions to the bottom of files, not the top
All imports go at the top of files, no mid-file dynamic imports

Files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
apps/web/**/*.{ts,tsx,js,jsx,json,css}

📄 CodeRabbit inference engine (apps/web/CLAUDE.md)

Format code with Prettier

Files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
apps/web/**/*.{example,ts,json}

📄 CodeRabbit inference engine (apps/web/CLAUDE.md)

Add environment variables to .env.example, env.ts, and turbo.json

Files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/testing.mdc)

**/*.test.{ts,tsx}: Use vitest for testing the application
Tests should be colocated next to the tested file with .test.ts or .test.tsx extension (e.g., dir/format.ts and dir/format.test.ts)
Mock server-only using vi.mock("server-only", () => ({}))
Mock Prisma using vi.mock("@/utils/prisma") and import the mock from @/utils/__mocks__/prisma
Use vi.clearAllMocks() in beforeEach to clean up mocks between tests
Each test should be independent
Use descriptive test names
Mock external dependencies in tests
Do not mock the Logger
Avoid testing implementation details
Use test helpers getEmail, getEmailAccount, and getRule from @/__tests__/helpers for mocking emails, accounts, and rules

Files:

  • apps/web/utils/email/reply-all.test.ts
**/*.{test,spec}.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)

**/*.{test,spec}.{js,jsx,ts,tsx}: Don't nest describe() blocks too deeply in test files
Don't use callbacks in asynchronous tests and hooks
Don't have duplicate hooks in describe blocks
Don't use export or module.exports in test files
Don't use focused tests
Make sure the assertion function, like expect, is placed inside an it() function call
Don't use disabled tests

Files:

  • apps/web/utils/email/reply-all.test.ts
apps/web/**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (apps/web/CLAUDE.md)

Co-locate test files next to source files (e.g., utils/example.test.ts). Only E2E and AI tests go in __tests__/

Files:

  • apps/web/utils/email/reply-all.test.ts
**/*.test.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/notes.mdc)

Co-locate test files next to source files (e.g., utils/example.test.ts). Only E2E and AI tests go in __tests__/

Files:

  • apps/web/utils/email/reply-all.test.ts
apps/web/utils/gmail/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/gmail-api.mdc)

apps/web/utils/gmail/**/*.{ts,tsx}: Always use wrapper functions from @/utils/gmail/ for Gmail API operations instead of direct provider API calls
Keep Gmail provider-specific implementation details isolated within the apps/web/utils/gmail/ directory

Files:

  • apps/web/utils/gmail/mail.ts
🧠 Learnings (13)
📓 Common learnings
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-11-25T14:37:22.660Z
Learning: Design Gmail wrapper functions to be provider-agnostic to support future email providers like Outlook and ProtonMail
📚 Learning: 2025-11-25T14:37:22.660Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-11-25T14:37:22.660Z
Learning: Applies to **/*.{ts,tsx} : Use wrapper functions for Gmail thread operations from @/utils/gmail/thread.ts instead of direct API calls

Applied to files:

  • apps/web/utils/email/reply-all.ts
  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:37:56.430Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-11-25T14:37:56.430Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Prefer using existing helpers from `@/__tests__/helpers.ts` (`getEmailAccount`, `getEmail`, `getRule`, `getMockMessage`, `getMockExecutedRule`) instead of creating custom test data helpers

Applied to files:

  • apps/web/utils/email/reply-all.test.ts
📚 Learning: 2025-11-25T14:40:00.833Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-11-25T14:40:00.833Z
Learning: Applies to **/*.test.{ts,tsx} : Use test helpers `getEmail`, `getEmailAccount`, and `getRule` from `@/__tests__/helpers` for mocking emails, accounts, and rules

Applied to files:

  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:37:22.660Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-11-25T14:37:22.660Z
Learning: Applies to **/*.{ts,tsx} : Use wrapper functions for Gmail message operations (get, list, batch, etc.) from @/utils/gmail/message.ts instead of direct API calls

Applied to files:

  • apps/web/utils/email/reply-all.test.ts
  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:37:56.430Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-11-25T14:37:56.430Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Use vitest imports (`describe`, `expect`, `test`, `vi`, `beforeEach`) in LLM test files

Applied to files:

  • apps/web/utils/email/reply-all.test.ts
📚 Learning: 2025-11-25T14:37:22.660Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-11-25T14:37:22.660Z
Learning: Applies to **/*.{ts,tsx} : Use wrapper functions for Gmail label operations from @/utils/gmail/label.ts instead of direct API calls

Applied to files:

  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:37:22.660Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-11-25T14:37:22.660Z
Learning: Applies to apps/web/utils/gmail/**/*.{ts,tsx} : Keep Gmail provider-specific implementation details isolated within the apps/web/utils/gmail/ directory

Applied to files:

  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:37:22.660Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-11-25T14:37:22.660Z
Learning: Applies to apps/web/utils/gmail/**/*.{ts,tsx} : Always use wrapper functions from @/utils/gmail/ for Gmail API operations instead of direct provider API calls

Applied to files:

  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:38:07.606Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-11-25T14:38:07.606Z
Learning: Applies to apps/web/utils/ai/**/*.ts : LLM feature functions must import from `zod` for schema validation, use `createScopedLogger` from `@/utils/logger`, `chatCompletionObject` and `createGenerateObject` from `@/utils/llms`, and import `EmailAccountWithAI` type from `@/utils/llms/types`

Applied to files:

  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:42:11.919Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/utilities.mdc:0-0
Timestamp: 2025-11-25T14:42:11.919Z
Learning: Applies to utils/**/*.{js,ts,jsx,tsx} : The `utils` folder contains core app logic such as Next.js Server Actions and Gmail API requests

Applied to files:

  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:37:22.660Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-11-25T14:37:22.660Z
Learning: Design Gmail wrapper functions to be provider-agnostic to support future email providers like Outlook and ProtonMail

Applied to files:

  • apps/web/utils/gmail/mail.ts
📚 Learning: 2025-11-25T14:42:16.602Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/utilities.mdc:0-0
Timestamp: 2025-11-25T14:42:16.602Z
Learning: The `utils` folder contains core app logic such as Next.js Server Actions and Gmail API requests

Applied to files:

  • apps/web/utils/gmail/mail.ts
🧬 Code graph analysis (3)
apps/web/utils/email/reply-all.ts (1)
apps/web/utils/email.ts (1)
  • extractEmailAddress (19-52)
apps/web/utils/email/reply-all.test.ts (1)
apps/web/utils/email/reply-all.ts (1)
  • mergeAndDedupeRecipients (94-120)
apps/web/utils/gmail/mail.ts (1)
apps/web/utils/email/reply-all.ts (2)
  • mergeAndDedupeRecipients (94-120)
  • formatCcList (86-88)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: test
  • GitHub Check: Macroscope - Correctness Check
🔇 Additional comments (3)
apps/web/utils/email/reply-all.test.ts (1)

412-433: LGTM! Comprehensive test coverage for the new helper.

The test suite properly validates display-name handling, case-insensitive deduplication, and sanitization of invalid entries—all critical behaviors for the CC/BCC merging logic.

apps/web/utils/gmail/mail.ts (1)

276-285: LGTM! CC/BCC merging and sanitization are correctly implemented.

The code properly merges reply-all CCs with manual CCs using mergeAndDedupeRecipients, and sanitizes BCCs. The helper handles normalization, case-insensitive deduplication, and filtering of invalid entries.

apps/web/utils/email/reply-all.ts (1)

94-120: LGTM! Well-designed deduplication helper.

The function properly handles email normalization, case-insensitive deduplication, and sanitization while preserving original formatting (display names). The implementation aligns with the test coverage and addresses the CC/BCC propagation requirements.

@elie222 elie222 merged commit 3433179 into main Jan 1, 2026
18 checks passed
@elie222 elie222 deleted the fix/draft-cc-bcc branch January 1, 2026 10:30
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