Browse Source

Merge pull request #1154 from anandpdoshi/email-threading-fix

[fix] email threading when sender's email client does not support Message-ID passing via In-Reply-To
version-14
Nabin Hait 10 years ago
parent
commit
0aa28d7898
2 changed files with 15 additions and 3 deletions
  1. +12
    -3
      frappe/email/doctype/email_account/email_account.py
  2. +3
    -0
      frappe/utils/user.py

+ 12
- 3
frappe/email/doctype/email_account/email_account.py View File

@@ -5,7 +5,8 @@ from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import validate_email_add, cint, get_datetime, DATE_FORMAT
from frappe.utils import validate_email_add, cint, get_datetime, DATE_FORMAT, strip
from frappe.utils.user import is_system_user
from frappe.email.smtp import SMTPServer
from frappe.email.receive import POP3Server, Email
from poplib import error_proto
@@ -204,8 +205,7 @@ class EmailAccount(Document):
# try and match by subject and sender
# if sent by same sender with same subject,
# append it to old coversation

subject = re.sub("(Re|RE)[^:]*:\s*", "", email.subject)
subject = strip(re.sub("^\s*(Re|RE)[^:]*:\s*", "", email.subject))

parent = frappe.db.get_all(self.append_to, filters={
sender_field: email.from_email,
@@ -213,6 +213,15 @@ class EmailAccount(Document):
"creation": (">", (get_datetime() - relativedelta(days=10)).strftime(DATE_FORMAT))
}, fields="name")

# match only subject field
# when the from_email is of a user in the system
# and subject is atleast 10 chars long
if not parent and len(subject) > 10 and is_system_user(email.from_email):
parent = frappe.db.get_all(self.append_to, filters={
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


+ 3
- 0
frappe/utils/user.py View File

@@ -285,3 +285,6 @@ def get_enabled_system_users():

def is_website_user():
return frappe.get_user().doc.user_type == "Website User"

def is_system_user(username):
return frappe.db.get_value("User", {"name": username, "enabled": 1, "user_type": "System User"})

Loading…
Cancel
Save