[_]: fix/auto reply and dedupe mails - #99
Conversation
|
Warning Review limit reached
Next review available in: 35 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughReply composition now accepts explicit To recipients and preserves self in derived To when applicable. JMAP thread retrieval now fetches message IDs and prefers Inbox copies when deduplicating messages. ChangesReply recipient handling
JMAP thread deduplication
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)Reply recipient derivationsequenceDiagram
participant ReplyRequest
participant EmailService
participant RecipientDerivation
participant ComposedReply
ReplyRequest->>EmailService: submit reply with optional to
EmailService->>RecipientDerivation: pass threading data and dto.to
RecipientDerivation-->>EmailService: derive to and cc
EmailService-->>ComposedReply: compose reply recipients
JMAP thread retrievalsequenceDiagram
participant JmapMailProvider
participant JMAP
participant InboxLookup
participant DedupeByMessageId
JmapMailProvider->>JMAP: fetch thread emails with messageId
JmapMailProvider->>InboxLookup: resolve Inbox mailbox ID
InboxLookup-->>JmapMailProvider: return Inbox mailbox ID
JmapMailProvider->>DedupeByMessageId: deduplicate fetched emails
DedupeByMessageId-->>JmapMailProvider: return selected copies
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
src/modules/email/threading.ts (1)
36-42: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winFlatten the nested ternary.
The new explicit-recipient branch nests the existing Reply-To/From ternary, which SonarCloud flags and makes the fallback semantics harder to review. Extract the threaded recipient list before selecting between explicit and derived recipients.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/modules/email/threading.ts` around lines 36 - 42, Refactor the recipient selection around the to calculation to remove the nested ternary: first derive the threaded recipient list from threading.parentReplyTo or threading.parentFrom, then choose between uniqueAddresses(explicitTo) and that derived list based on explicitTo.length. Preserve the existing explicit-recipient and Reply-To/From fallback behavior.Source: Linters/SAST tools
src/modules/email/threading.spec.ts (1)
143-167: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for explicit reply recipients.
These tests cover self-replies but do not exercise
explicitTo, including precedence overReply-To/Fromand duplicate removal. Add focused cases for the new recipient path, including the explicitly empty-list behavior.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/modules/email/threading.spec.ts` around lines 143 - 167, Extend the threading tests around deriveReplyRecipients with focused explicitTo cases: verify explicit recipients take precedence over parent Reply-To/From, duplicate recipients are removed, and an explicitly empty list remains empty rather than falling back. Reuse the existing newThreadingHeaders, SELF, A, and B fixtures and assert both to and cc results.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/modules/email/threading.ts`:
- Around line 36-42: Update the `to` selection in `composeReply` to distinguish
an omitted `explicitTo` value from a provided empty list; use
`uniqueAddresses(explicitTo)` whenever the list is provided, including `[]`, and
only fall back to `threading.parentReplyTo` or `threading.parentFrom` when it is
undefined.
In `@src/modules/infrastructure/jmap/jmap-mail.provider.ts`:
- Around line 1033-1035: Update dedupeByMessageId() so the trimmed
email.messageId value remains case-sensitive when used as the Map key; remove
the lowercasing while preserving trimming and existing missing-ID handling. Add
a regression case covering Message-IDs that differ only by case and ensure both
emails remain in the deduplicated result.
- Around line 644-646: Update getThread’s mailbox lookup to use a non-throwing
Inbox role resolution, yielding undefined when the account has no Inbox mailbox
instead of propagating an error. Pass that optional inboxMailboxId to
dedupeByMessageId so thread deduplication still runs for accounts without an
Inbox role.
---
Nitpick comments:
In `@src/modules/email/threading.spec.ts`:
- Around line 143-167: Extend the threading tests around deriveReplyRecipients
with focused explicitTo cases: verify explicit recipients take precedence over
parent Reply-To/From, duplicate recipients are removed, and an explicitly empty
list remains empty rather than falling back. Reuse the existing
newThreadingHeaders, SELF, A, and B fixtures and assert both to and cc results.
In `@src/modules/email/threading.ts`:
- Around line 36-42: Refactor the recipient selection around the to calculation
to remove the nested ternary: first derive the threaded recipient list from
threading.parentReplyTo or threading.parentFrom, then choose between
uniqueAddresses(explicitTo) and that derived list based on explicitTo.length.
Preserve the existing explicit-recipient and Reply-To/From fallback behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 67c9386f-f04e-47a2-b326-0386b77b6e73
📒 Files selected for processing (7)
src/modules/email/email.dto.tssrc/modules/email/email.service.tssrc/modules/email/email.types.tssrc/modules/email/threading.spec.tssrc/modules/email/threading.tssrc/modules/infrastructure/jmap/jmap-mail.provider.spec.tssrc/modules/infrastructure/jmap/jmap-mail.provider.ts
|



Implement automatic email replies with email deduplication to avoid duplicate messages when filtering emails from the Inbox and Sent folders. Additionally, allow specifying extra recipients in the To field when replying to an email.
Summary by CodeRabbit
New Features
Bug Fixes