fix(send): skip IMAP APPEND when server already saved sent message#12932
fix(send): skip IMAP APPEND when server already saved sent message#12932ChristophWurst wants to merge 2 commits into
Conversation
|
/backport to stable5.8 |
|
/backport to stable5.7 |
Some mail servers (e.g. Microsoft Exchange/Office 365) automatically save a copy of sent messages to the Sent folder upon SMTP submission. When Nextcloud Mail also does an IMAP APPEND, the user ends up with duplicates. After SMTP delivery succeeds, search the Sent mailbox for the outgoing message's Message-ID header. If the server already saved it, skip the APPEND. If the IMAP search fails for any reason, fall through and APPEND as normal (safe degradation). AI-assisted: Claude Code (claude-sonnet-4-6) Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
63b0914 to
09a5b4c
Compare
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds Message-ID-based duplicate detection: MessageMapper gains existsInMailboxByMessageId(...), CopySentMessageHandler uses it to skip APPEND when the Sent mailbox already contains the message, and unit + integration tests cover skip and fallback paths. ChangesSkip Append When Server Already Saves Message
sequenceDiagram
participant Handler as CopySentMessageHandler
participant Helper as isAlreadySavedByServer
participant Mapper as MessageMapper
participant IMAP as IMAP Server
Handler->>Helper: extract Message-ID, check server state
Helper->>Mapper: existsInMailboxByMessageId(messageId, mailbox)
Mapper->>IMAP: SEARCH HEADER Message-ID "messageId"
IMAP-->>Mapper: search results (count)
Mapper-->>Helper: exists? (true/false)
alt Server already saved
Helper-->>Handler: true
Handler->>Handler: set STATUS_PROCESSED, skip append
else Need to append
Helper-->>Handler: false
Handler->>Handler: proceed with normal save flow
end
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@lib/Send/CopySentMessageHandler.php`:
- Around line 33-35: The Message-ID regex currently inspects the entire MIME
payload ($rawMessage) in CopySentMessageHandler, which can match a
Message-ID-like line in the body; instead extract the header block only
(everything before the first blank line) and run the Message-ID match against
that header string. Locate the code using $rawMessage (the block with
preg_match('/^Message-ID:.../im', $rawMessage, $m)), split or capture headers
(e.g. split on the first double newline using preg_split or preg_match with
'/\A(.*?)(?:\r?\n){2}/s') to get $headers, then apply the existing
'/^Message-ID:\s*(<[^>]+>)/im' regex to $headers and return false if not found.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: a106c86d-862d-4aca-9cb9-d638dc3622ed
📒 Files selected for processing (4)
lib/IMAP/MessageMapper.phplib/Send/CopySentMessageHandler.phptests/Integration/Service/MailTransmissionIntegrationTest.phptests/Unit/Send/CopySendMessageHandlerTest.php
…sage Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Some mail servers (e.g. Microsoft Exchange/Office 365) automatically save a copy of sent messages to the Sent folder upon SMTP submission. When Nextcloud Mail also does an IMAP APPEND, the user ends up with duplicates.
After SMTP delivery succeeds, search the Sent mailbox for the outgoing message's Message-ID header. If the server already saved it, skip the APPEND. If the IMAP search fails for any reason, fall through and APPEND as normal (safe degradation).
AI-assisted: Claude Code (claude-sonnet-4-6)
Summary by CodeRabbit
Bug Fixes
Tests