[mailbox] removed separate email settings for jobs, sales, support

This commit is contained in:
Rushabh Mehta
2014-09-15 16:59:38 +05:30
parent 7fb79f6062
commit 5cdc8e560c
32 changed files with 106 additions and 651 deletions

View File

@@ -1,92 +0,0 @@
{
"allow_copy": 1,
"creation": "2014-03-03 19:48:46.000000",
"description": "Email Settings for Outgoing and Incoming Emails.",
"docstatus": 0,
"doctype": "DocType",
"fields": [
{
"description": "Check this to pull emails from your mailbox",
"fieldname": "sync_support_mails",
"fieldtype": "Check",
"label": "Sync Support Mails",
"permlevel": 0
},
{
"description": "Your support email id - must be a valid email - this is where your emails will come!",
"fieldname": "support_email",
"fieldtype": "Data",
"label": "Support Email",
"permlevel": 0
},
{
"description": "POP3 mail server (e.g. pop.gmail.com)",
"fieldname": "mail_server",
"fieldtype": "Data",
"label": "POP3 Mail Server",
"permlevel": 0
},
{
"fieldname": "use_ssl",
"fieldtype": "Check",
"label": "Use SSL",
"permlevel": 0
},
{
"fieldname": "mail_login",
"fieldtype": "Data",
"label": "User Name",
"permlevel": 0
},
{
"fieldname": "mail_password",
"fieldtype": "Password",
"label": "Support Password",
"permlevel": 0
},
{
"fieldname": "cb1",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"description": "Signature to be appended at the end of every email",
"fieldname": "support_signature",
"fieldtype": "Text",
"label": "Signature",
"permlevel": 0
},
{
"default": "1",
"fieldname": "send_autoreply",
"fieldtype": "Check",
"label": "Send Autoreply",
"permlevel": 0
},
{
"description": "Autoreply when a new mail is received",
"fieldname": "support_autoreply",
"fieldtype": "Text",
"label": "Custom Autoreply Message",
"permlevel": 0
}
],
"icon": "icon-cog",
"idx": 1,
"in_create": 1,
"issingle": 1,
"modified": "2014-03-03 20:20:34.000000",
"modified_by": "Administrator",
"module": "Support",
"name": "Support Email Settings",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"permlevel": 0,
"read": 1,
"role": "System Manager",
"write": 1
}
]
}

View File

@@ -1,45 +0,0 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import cint
from frappe.model.document import Document
from frappe.email.receive import POP3Server
import _socket, poplib
class SupportEmailSettings(Document):
def validate(self):
"""
Checks support ticket email settings
"""
if cint(self.sync_support_mails) and self.mail_server and not frappe.local.flags.in_patch:
inc_email = frappe._dict(self.as_dict())
# inc_email.encode()
inc_email.host = self.mail_server
inc_email.use_ssl = self.use_ssl
try:
err_msg = _('User Name or Support Password missing. Please enter and try again.')
if not (self.mail_login and self.mail_password):
raise AttributeError, err_msg
inc_email.username = self.mail_login
inc_email.password = self.mail_password
except AttributeError, e:
frappe.msgprint(err_msg)
raise
pop_mb = POP3Server(inc_email)
try:
pop_mb.connect()
except _socket.error, e:
# Invalid mail server -- due to refusing connection
frappe.msgprint(_('Invalid Mail Server. Please rectify and try again.'))
raise
except poplib.error_proto, e:
frappe.msgprint(_('Invalid User Name or Support Password. Please rectify and try again.'))
raise

View File

@@ -1,87 +0,0 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, decode_dict, today
from frappe.email import sendmail
from frappe.email.receive import POP3Server
from frappe.core.doctype.communication.communication import _make
class SupportMailbox(POP3Server):
def setup(self, args=None):
self.email_settings = frappe.get_doc("Support Email Settings", "Support Email Settings")
self.settings = args or frappe._dict({
"use_ssl": self.email_settings.use_ssl,
"host": self.email_settings.mail_server,
"username": self.email_settings.mail_login,
"password": self.email_settings.mail_password
})
def process_message(self, mail):
if mail.from_email == self.email_settings.get('support_email'):
return
thread_id = mail.get_thread_id()
new_ticket = False
if not (thread_id and frappe.db.exists("Support Ticket", thread_id)):
new_ticket = True
ticket = add_support_communication(mail.subject, mail.content, mail.from_email,
docname=None if new_ticket else thread_id, mail=mail)
if new_ticket and cint(self.email_settings.send_autoreply) and \
"mailer-daemon" not in mail.from_email.lower():
self.send_auto_reply(ticket)
def send_auto_reply(self, d):
signature = self.email_settings.get('support_signature') 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
reply back to this mail.
### We will get back to you as soon as possible
---
Original Query:
""" + d.description + "\n\n---\n\n" + cstr(signature))
sendmail(\
recipients = [cstr(d.raised_by)], \
sender = cstr(self.email_settings.get('support_email')), \
subject = '['+cstr(d.name)+'] ' + cstr(d.subject), \
msg = cstr(response))
def get_support_mails():
if cint(frappe.db.get_value('Support Email Settings', None, 'sync_support_mails')):
SupportMailbox()
def add_support_communication(subject, content, sender, docname=None, mail=None):
if docname:
ticket = frappe.get_doc("Support Ticket", docname)
ticket.status = 'Open'
ticket.ignore_permissions = True
ticket.save()
else:
ticket = frappe.get_doc(decode_dict({
"doctype":"Support Ticket",
"description": content,
"subject": subject,
"raised_by": sender,
"content_type": mail.content_type if mail else None,
"status": "Open",
}))
ticket.ignore_permissions = True
ticket.ignore_mandatory = True
ticket.insert()
_make(content=content, sender=sender, subject = subject,
doctype="Support Ticket", name=ticket.name,
date=mail.date if mail else today(), sent_or_received="Received")
if mail:
mail.save_attachments_in_doc(ticket)
return ticket

View File

@@ -5,26 +5,13 @@ from __future__ import unicode_literals
import frappe
from frappe import _
from erpnext.utilities.transaction_base import TransactionBase
from frappe.utils import now, extract_email_id
from frappe.model.document import Document
from frappe.utils import now
class SupportTicket(TransactionBase):
class SupportTicket(Document):
def get_feed(self):
return "{0}: {1}".format(_(self.status, self.subject))
def get_sender(self, comm):
return frappe.db.get_value('Support Email Settings',None,'support_email')
def get_subject(self, comm):
return '[' + self.name + '] ' + (comm.subject or 'No Subject Specified')
def get_content(self, comm):
signature = frappe.db.get_value('Support Email Settings',None,'support_signature')
content = comm.content
if signature:
content += '<p>' + signature + '</p>'
return content
def get_portal_page(self):
return "ticket"