From 9dfc9f617b6c5e91bfef525e15679d14788b868e Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 5 Jan 2012 13:54:29 +0530 Subject: [PATCH] Fix regarding support ticket to support ticket system email chaining issue --- .../doctype/support_ticket/__init__.py | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/erpnext/support/doctype/support_ticket/__init__.py b/erpnext/support/doctype/support_ticket/__init__.py index f629cbdde6..fcf4e32d0e 100644 --- a/erpnext/support/doctype/support_ticket/__init__.py +++ b/erpnext/support/doctype/support_ticket/__init__.py @@ -40,18 +40,32 @@ class SupportMailbox(POP3Mailbox): else: content, content_type = mail.html_content, 'text/html' - thread_id = mail.get_thread_id() + thread_list = mail.get_thread_id() - if webnotes.conn.exists('Support Ticket', thread_id): - from webnotes.model.code import get_obj - - st = get_obj('Support Ticket', thread_id) - st.make_response_record(content, mail.mail['From'], content_type) - webnotes.conn.set(st.doc, 'status', 'Open') - update_feed(st.doc) - # extract attachments - self.save_attachments(st.doc, mail.attachments) - return + + email_id = mail.mail['From'] + if "<" in mail.mail['From']: + import re + re_result = re.findall('(?<=\<)(\S+)(?=\>)', mail.mail['From']) + if re_result and re_result[0]: email_id = res_result[0] + + + for thread_id in thread_list: + exists = webnotes.conn.sql("""\ + SELECT name + FROM `tabSupport Ticket` + WHERE name=%s AND raised_by LIKE %s + """, (thread_id, "%" + email_id + "%")) + if exists and exists[0] and exists[0][0]: + from webnotes.model.code import get_obj + + st = get_obj('Support Ticket', thread_id) + st.make_response_record(content, mail.mail['From'], content_type) + webnotes.conn.set(st.doc, 'status', 'Open') + update_feed(st.doc) + # extract attachments + self.save_attachments(st.doc, mail.attachments) + return # new ticket from webnotes.model.doc import Document