From 013267655340a8183c0e40baa776a240d3d096cc Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Thu, 12 Feb 2026 12:18:05 +0530 Subject: [PATCH] fix: consider email account for communication duplicate check --- frappe/core/doctype/communication/communication.py | 2 +- frappe/email/doctype/email_account/test_email_account.py | 6 ++++-- frappe/email/receive.py | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/frappe/core/doctype/communication/communication.py b/frappe/core/doctype/communication/communication.py index 59aefc53bf..16dae174ec 100644 --- a/frappe/core/doctype/communication/communication.py +++ b/frappe/core/doctype/communication/communication.py @@ -419,7 +419,7 @@ class Communication(Document, CommunicationEmailMixin): # Skip timeline links if a "Sent" communication already exists # else will create duplicate timeline entries if self.sent_or_received == "Received" and self.find_one_by_filters( - message_id=self.message_id, sent_or_received="Sent" + message_id=self.message_id, email_account=self.email_account, sent_or_received="Sent" ): return diff --git a/frappe/email/doctype/email_account/test_email_account.py b/frappe/email/doctype/email_account/test_email_account.py index c6f88c2862..93b5c36209 100644 --- a/frappe/email/doctype/email_account/test_email_account.py +++ b/frappe/email/doctype/email_account/test_email_account.py @@ -521,12 +521,14 @@ class TestInboundMail(IntegrationTestCase): def test_mail_exist_validation(self): """Do not create communication record if the mail is already downloaded into the system.""" + email_account = frappe.get_doc("Email Account", "_Test Email Account 1") mail_content = self.get_test_mail(fname="incoming-1.raw") message_id = Email(mail_content).message_id # Create new communication record in DB - communication = self.new_communication(message_id=message_id, sent_or_received="Received") + communication = self.new_communication( + message_id=message_id, email_account=email_account.name, sent_or_received="Received" + ) - email_account = frappe.get_doc("Email Account", "_Test Email Account 1") inbound_mail = InboundMail(mail_content, email_account, 12345, 1) new_communication = inbound_mail.process() diff --git a/frappe/email/receive.py b/frappe/email/receive.py index 8d1c64217a..ce52e98188 100644 --- a/frappe/email/receive.py +++ b/frappe/email/receive.py @@ -721,7 +721,10 @@ class InboundMail(Email): return return Communication.find_one_by_filters( - message_id=self.message_id, sent_or_received="Received", order_by="creation DESC" + message_id=self.message_id, + email_account=self.email_account.name, + sent_or_received="Received", + order_by="creation DESC", ) def is_sender_same_as_receiver(self):