|
@@ -192,18 +192,27 @@ class EmailAccount(Document): |
|
|
parent = frappe.get_doc(parent.reference_doctype, |
|
|
parent = frappe.get_doc(parent.reference_doctype, |
|
|
parent.reference_name) |
|
|
parent.reference_name) |
|
|
|
|
|
|
|
|
if not parent and self.append_to and subject_field and sender_field: |
|
|
|
|
|
# try and match by subject and sender |
|
|
|
|
|
# if sent by same sender with same subject, |
|
|
|
|
|
# append it to old coversation |
|
|
|
|
|
|
|
|
|
|
|
subject = re.sub("Re[^:]*:\s*", "", email.subject) |
|
|
|
|
|
|
|
|
|
|
|
parent = frappe.db.get_all(self.append_to, filters={ |
|
|
|
|
|
sender_field: email.from_email, |
|
|
|
|
|
subject_field: ("like", "%{0}%".format(subject)), |
|
|
|
|
|
"creation": (">", (get_datetime() - relativedelta(days=10)).strftime(DATE_FORMAT)) |
|
|
|
|
|
}, fields="name") |
|
|
|
|
|
|
|
|
if not parent and self.append_to and sender_field: |
|
|
|
|
|
if subject_field: |
|
|
|
|
|
# try and match by subject and sender |
|
|
|
|
|
# if sent by same sender with same subject, |
|
|
|
|
|
# append it to old coversation |
|
|
|
|
|
|
|
|
|
|
|
subject = re.sub("Re[^:]*:\s*", "", email.subject) |
|
|
|
|
|
|
|
|
|
|
|
parent = frappe.db.get_all(self.append_to, filters={ |
|
|
|
|
|
sender_field: email.from_email, |
|
|
|
|
|
subject_field: ("like", "%{0}%".format(subject)), |
|
|
|
|
|
"creation": (">", (get_datetime() - relativedelta(days=10)).strftime(DATE_FORMAT)) |
|
|
|
|
|
}, fields="name") |
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
|
# try and match by sender only |
|
|
|
|
|
# as there is no subject field, it implies that threading isn't by subject, but by sender only |
|
|
|
|
|
|
|
|
|
|
|
parent = frappe.db.get_all(self.append_to, filters={ |
|
|
|
|
|
sender_field: email.from_email, |
|
|
|
|
|
}, fields="name") |
|
|
|
|
|
|
|
|
if parent: |
|
|
if parent: |
|
|
parent = frappe.get_doc(self.append_to, parent[0].name) |
|
|
parent = frappe.get_doc(self.append_to, parent[0].name) |
|
|