formatting fix in support ticket autoreply

This commit is contained in:
Rushabh Mehta 2014-07-02 17:13:08 +05:30
parent e8533d15b3
commit 6084a3e63a

View File

@ -4,11 +4,11 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cstr, cint, decode_dict, today from frappe.utils import cstr, cint, decode_dict, today
from frappe.utils.email_lib import sendmail from frappe.utils.email_lib import sendmail
from frappe.utils.email_lib.receive import POP3Mailbox from frappe.utils.email_lib.receive import POP3Mailbox
from frappe.core.doctype.communication.communication import _make from frappe.core.doctype.communication.communication import _make
class SupportMailbox(POP3Mailbox): class SupportMailbox(POP3Mailbox):
def setup(self, args=None): def setup(self, args=None):
self.email_settings = frappe.get_doc("Support Email Settings", "Support Email Settings") self.email_settings = frappe.get_doc("Support Email Settings", "Support Email Settings")
self.settings = args or frappe._dict({ self.settings = args or frappe._dict({
@ -17,7 +17,7 @@ class SupportMailbox(POP3Mailbox):
"username": self.email_settings.mail_login, "username": self.email_settings.mail_login,
"password": self.email_settings.mail_password "password": self.email_settings.mail_password
}) })
def process_message(self, mail): def process_message(self, mail):
if mail.from_email == self.email_settings.get('support_email'): if mail.from_email == self.email_settings.get('support_email'):
return return
@ -26,10 +26,10 @@ class SupportMailbox(POP3Mailbox):
if not (thread_id and frappe.db.exists("Support Ticket", thread_id)): if not (thread_id and frappe.db.exists("Support Ticket", thread_id)):
new_ticket = True new_ticket = True
ticket = add_support_communication(mail.subject, mail.content, mail.from_email, ticket = add_support_communication(mail.subject, mail.content, mail.from_email,
docname=None if new_ticket else thread_id, mail=mail) docname=None if new_ticket else thread_id, mail=mail)
if new_ticket and cint(self.email_settings.send_autoreply) and \ if new_ticket and cint(self.email_settings.send_autoreply) and \
"mailer-daemon" not in mail.from_email.lower(): "mailer-daemon" not in mail.from_email.lower():
self.send_auto_reply(ticket) self.send_auto_reply(ticket)
@ -39,23 +39,25 @@ class SupportMailbox(POP3Mailbox):
response = self.email_settings.get('support_autoreply') or (""" response = self.email_settings.get('support_autoreply') or ("""
A new Ticket has been raised for your query. If you have any additional information, please A new Ticket has been raised for your query. If you have any additional information, please
reply back to this mail. reply back to this mail.
We will get back to you as soon as possible ### We will get back to you as soon as possible
----------------------
---
Original Query: Original Query:
""" + d.description + "\n----------------------\n" + cstr(signature)) """ + d.description + "\n\n---\n\n" + cstr(signature))
sendmail(\ sendmail(\
recipients = [cstr(d.raised_by)], \ recipients = [cstr(d.raised_by)], \
sender = cstr(self.email_settings.get('support_email')), \ sender = cstr(self.email_settings.get('support_email')), \
subject = '['+cstr(d.name)+'] ' + cstr(d.subject), \ subject = '['+cstr(d.name)+'] ' + cstr(d.subject), \
msg = cstr(response)) msg = cstr(response))
def get_support_mails(): def get_support_mails():
if cint(frappe.db.get_value('Support Email Settings', None, 'sync_support_mails')): if cint(frappe.db.get_value('Support Email Settings', None, 'sync_support_mails')):
SupportMailbox() SupportMailbox()
def add_support_communication(subject, content, sender, docname=None, mail=None): def add_support_communication(subject, content, sender, docname=None, mail=None):
if docname: if docname:
ticket = frappe.get_doc("Support Ticket", docname) ticket = frappe.get_doc("Support Ticket", docname)
@ -74,12 +76,12 @@ def add_support_communication(subject, content, sender, docname=None, mail=None)
ticket.ignore_permissions = True ticket.ignore_permissions = True
ticket.ignore_mandatory = True ticket.ignore_mandatory = True
ticket.insert() ticket.insert()
_make(content=content, sender=sender, subject = subject, _make(content=content, sender=sender, subject = subject,
doctype="Support Ticket", name=ticket.name, doctype="Support Ticket", name=ticket.name,
date=mail.date if mail else today(), sent_or_received="Received") date=mail.date if mail else today(), sent_or_received="Received")
if mail: if mail:
mail.save_attachments_in_doc(ticket) mail.save_attachments_in_doc(ticket)
return ticket return ticket