diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index 14100f963f..49a60918bb 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -464,16 +464,16 @@ class EmailAccount(Document): :param match_by_email: Find account using emailID :param match_by_doctype: Find account by matching `Append To` doctype """ - doc = cls.find_one_by_filters(enable_incoming=1, email_id=match_by_email) - if doc: + if doc := cls.find_default_incoming(): return doc - doc = cls.find_one_by_filters(enable_incoming=1, append_to=match_by_doctype) - if doc: + if match_by_email and (doc := cls.find_one_by_filters(enable_incoming=1, email_id=match_by_email)): return doc - doc = cls.find_default_incoming() - return doc + if match_by_doctype and ( + doc := cls.find_one_by_filters(enable_incoming=1, append_to=match_by_doctype) + ): + return doc @classmethod def find_default_incoming(cls): diff --git a/frappe/patches.txt b/frappe/patches.txt index c71b45b2cd..add082e78d 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -260,3 +260,4 @@ execute:from frappe.email.doctype.notification.notification import install_notif execute:frappe.db.set_value("Email Account", {}, "add_x_original_from", 1) frappe.patches.v16_0.fix_myanmar_language_name execute:frappe.db.set_value("Email Account", {}, "add_reply_to_header", 1) +frappe.patches.v16_0.set_reply_to_header diff --git a/frappe/patches/v16_0/set_reply_to_header.py b/frappe/patches/v16_0/set_reply_to_header.py new file mode 100644 index 0000000000..510b8db56f --- /dev/null +++ b/frappe/patches/v16_0/set_reply_to_header.py @@ -0,0 +1,15 @@ +import frappe + + +def execute() -> None: + accounts = frappe.db.get_all("Email Account", {"enable_incoming": 1, "enable_outgoing": 1}, pluck="name") + for account in accounts: + doc = frappe.get_doc("Email Account", account) + + if doc.reply_to_addresses: + continue + + doc.append("reply_to_addresses", {"email": doc.email_id}) + doc.flags.ignore_mandatory = True + doc.flags.ignore_validate = True # Ignore SMTP/IMAP validation + doc.save()