From e30511d315b3f36727a4c5fe63813f8347a7d1c3 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 3 Mar 2014 20:32:20 +0530 Subject: [PATCH] Email Settings split into Outgoing Email Settings and Support Email Settings --- erpnext/config/setup.py | 3 +- erpnext/config/support.py | 3 +- erpnext/patches.txt | 1 + erpnext/patches/4_0/split_email_settings.py | 50 +++++ .../setup/doctype/email_settings/README.md | 1 - .../setup/doctype/email_settings/__init__.py | 1 - .../doctype/email_settings/email_settings.py | 67 ------- .../doctype/email_settings/email_settings.txt | 188 ------------------ .../setup/page/setup_wizard/setup_wizard.py | 2 +- erpnext/startup/__init__.py | 2 +- .../support_email_settings/__init__.py | 0 .../support_email_settings.py | 47 +++++ .../support_email_settings.txt | 111 +++++++++++ .../support_ticket/get_support_mails.py | 12 +- .../doctype/support_ticket/support_ticket.js | 2 +- .../doctype/support_ticket/support_ticket.py | 4 +- 16 files changed, 222 insertions(+), 272 deletions(-) create mode 100644 erpnext/patches/4_0/split_email_settings.py delete mode 100644 erpnext/setup/doctype/email_settings/README.md delete mode 100644 erpnext/setup/doctype/email_settings/__init__.py delete mode 100644 erpnext/setup/doctype/email_settings/email_settings.py delete mode 100644 erpnext/setup/doctype/email_settings/email_settings.txt create mode 100644 erpnext/support/doctype/support_email_settings/__init__.py create mode 100644 erpnext/support/doctype/support_email_settings/support_email_settings.py create mode 100644 erpnext/support/doctype/support_email_settings/support_email_settings.txt diff --git a/erpnext/config/setup.py b/erpnext/config/setup.py index ca2379fce4..faaec0d966 100644 --- a/erpnext/config/setup.py +++ b/erpnext/config/setup.py @@ -48,8 +48,7 @@ data = [ }, { "type": "doctype", - "name": "Email Settings", - "label": _("Support Email Settings"), + "name": "Support Email Settings", "description": _("Setup incoming server for support email id. (e.g. support@example.com)") }, { diff --git a/erpnext/config/support.py b/erpnext/config/support.py index 0b6e8439ed..09143201f8 100644 --- a/erpnext/config/support.py +++ b/erpnext/config/support.py @@ -48,8 +48,7 @@ data = [ "items": [ { "type": "doctype", - "name": "Email Settings", - "label": _("Support Email Settings"), + "name": "Support Email Settings", "description": _("Setup incoming server for support email id. (e.g. support@example.com)") }, ] diff --git a/erpnext/patches.txt b/erpnext/patches.txt index ffce00cb52..08caa76c83 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -25,3 +25,4 @@ erpnext.patches.4_0.fix_contact_address erpnext.patches.4_0.customer_discount_to_pricing_rule execute:frappe.db.sql("""delete from `tabWebsite Item Group` where ifnull(item_group, '')=''""") erpnext.patches.4_0.remove_module_home_pages +erpnext.patches.4_0.split_email_settings diff --git a/erpnext/patches/4_0/split_email_settings.py b/erpnext/patches/4_0/split_email_settings.py new file mode 100644 index 0000000000..e73095e793 --- /dev/null +++ b/erpnext/patches/4_0/split_email_settings.py @@ -0,0 +1,50 @@ +# 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 + +def execute(): + frappe.reload_doc("core", "doctype", "outgoing_email_settings") + frappe.reload_doc("support", "doctype", "support_email_settings") + + email_settings = frappe.bean("Email Settings") + map_outgoing_email_settings(email_settings) + map_support_email_settings(email_settings) + frappe.delete_doc("Doctype", "Email Settings") + +def map_outgoing_email_settings(email_settings): + outgoing_email_settings = frappe.bean("Outgoing Email Settings") + for fieldname in (("outgoing_mail_server", "mail_server"), + "use_ssl", "mail_port", "mail_login", "mail_password", + "always_use_login_id_as_sender", + "auto_email_id", "send_print_in_body_and_attachment"): + + if isinstance(fieldname, tuple): + from_fieldname, to_fieldname = fieldname + else: + from_fieldname = to_fieldname = fieldname + + outgoing_email_settings.doc.fields[to_fieldname] = email_settings.doc.fields.get(from_fieldname) + + outgoing_email_settings.save() + +def map_support_email_settings(email_settings): + support_email_settings = frappe.bean("Support Email Settings") + + for fieldname in ("sync_support_mails", "support_email", + ("support_host", "mail_server"), + ("support_use_ssl", "use_ssl"), + ("support_username", "mail_login"), + ("support_password", "mail_password"), + "support_signature", "send_autoreply", "support_autoreply"): + + if isinstance(fieldname, tuple): + from_fieldname, to_fieldname = fieldname + else: + from_fieldname = to_fieldname = fieldname + + support_email_settings.doc.fields[to_fieldname] = email_settings.doc.fields.get(from_fieldname) + + support_email_settings.save() + diff --git a/erpnext/setup/doctype/email_settings/README.md b/erpnext/setup/doctype/email_settings/README.md deleted file mode 100644 index a66690241d..0000000000 --- a/erpnext/setup/doctype/email_settings/README.md +++ /dev/null @@ -1 +0,0 @@ -Settings for outgoing emails (SMTP), Support Ticket (POP). \ No newline at end of file diff --git a/erpnext/setup/doctype/email_settings/__init__.py b/erpnext/setup/doctype/email_settings/__init__.py deleted file mode 100644 index baffc48825..0000000000 --- a/erpnext/setup/doctype/email_settings/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from __future__ import unicode_literals diff --git a/erpnext/setup/doctype/email_settings/email_settings.py b/erpnext/setup/doctype/email_settings/email_settings.py deleted file mode 100644 index 17ae283750..0000000000 --- a/erpnext/setup/doctype/email_settings/email_settings.py +++ /dev/null @@ -1,67 +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 cint - -class DocType: - def __init__(self,doc,doclist): - self.doc,self.doclist = doc,doclist - - def validate(self): - """Checks connectivity to email servers before saving""" - self.validate_outgoing() - self.validate_incoming() - - def validate_outgoing(self): - """Checks incoming email settings""" - self.doc.encode() - if self.doc.outgoing_mail_server: - from frappe.utils import cint - from frappe.utils.email_lib.smtp import SMTPServer - smtpserver = SMTPServer(login = self.doc.mail_login, - password = self.doc.mail_password, - server = self.doc.outgoing_mail_server, - port = cint(self.doc.mail_port), - use_ssl = self.doc.use_ssl - ) - - # exceptions are handled in session connect - sess = smtpserver.sess - - def validate_incoming(self): - """ - Checks support ticket email settings - """ - if self.doc.sync_support_mails and self.doc.support_host: - from frappe.utils.email_lib.receive import POP3Mailbox - from frappe.model.doc import Document - import _socket, poplib - - inc_email = Document('Incoming Email Settings') - inc_email.encode() - inc_email.host = self.doc.support_host - inc_email.use_ssl = self.doc.support_use_ssl - try: - err_msg = 'User Name or Support Password missing. Please enter and try again.' - if not (self.doc.support_username and self.doc.support_password): - raise AttributeError, err_msg - inc_email.username = self.doc.support_username - inc_email.password = self.doc.support_password - except AttributeError, e: - frappe.msgprint(err_msg) - raise - - pop_mb = POP3Mailbox(inc_email) - - try: - pop_mb.connect() - except _socket.error, e: - # Invalid mail server -- due to refusing connection - frappe.msgprint('Invalid POP3 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 diff --git a/erpnext/setup/doctype/email_settings/email_settings.txt b/erpnext/setup/doctype/email_settings/email_settings.txt deleted file mode 100644 index 6b28f10f35..0000000000 --- a/erpnext/setup/doctype/email_settings/email_settings.txt +++ /dev/null @@ -1,188 +0,0 @@ -[ - { - "creation": "2013-03-25 17:53:21", - "docstatus": 0, - "modified": "2013-12-06 13:12:25", - "modified_by": "Administrator", - "owner": "Administrator" - }, - { - "allow_copy": 1, - "allow_email": 1, - "allow_print": 1, - "description": "Email Settings for Outgoing and Incoming Emails.", - "doctype": "DocType", - "icon": "icon-cog", - "in_create": 1, - "issingle": 1, - "module": "Setup", - "name": "__common__" - }, - { - "doctype": "DocField", - "name": "__common__", - "parent": "Email Settings", - "parentfield": "fields", - "parenttype": "DocType", - "permlevel": 0 - }, - { - "create": 1, - "doctype": "DocPerm", - "name": "__common__", - "parent": "Email Settings", - "parentfield": "permissions", - "parenttype": "DocType", - "permlevel": 0, - "read": 1, - "role": "System Manager", - "write": 1 - }, - { - "doctype": "DocType", - "name": "Email Settings" - }, - { - "description": "Set your outgoing mail SMTP settings here. All system generated notifications, emails will go from this mail server. If you are not sure, leave this blank to use ERPNext servers (emails will still be sent from your email id) or contact your email provider.", - "doctype": "DocField", - "fieldname": "outgoing_mails", - "fieldtype": "Section Break", - "label": "Outgoing Mails" - }, - { - "description": "SMTP Server (e.g. smtp.gmail.com)", - "doctype": "DocField", - "fieldname": "outgoing_mail_server", - "fieldtype": "Data", - "label": "Outgoing Mail Server" - }, - { - "description": "[?]", - "doctype": "DocField", - "fieldname": "use_ssl", - "fieldtype": "Check", - "label": "Use TLS" - }, - { - "description": "If non standard port (e.g. 587)", - "doctype": "DocField", - "fieldname": "mail_port", - "fieldtype": "Int", - "label": "Mail Port" - }, - { - "doctype": "DocField", - "fieldname": "cb0", - "fieldtype": "Column Break" - }, - { - "description": "Set Login and Password if authentication is required.", - "doctype": "DocField", - "fieldname": "mail_login", - "fieldtype": "Data", - "label": "Login Id" - }, - { - "description": "Check this if you want to send emails as this id only (in case of restriction by your email provider).", - "doctype": "DocField", - "fieldname": "always_use_login_id_as_sender", - "fieldtype": "Check", - "label": "Always use above Login Id as sender" - }, - { - "doctype": "DocField", - "fieldname": "mail_password", - "fieldtype": "Password", - "label": "Mail Password" - }, - { - "description": "System generated mails will be sent from this email id.", - "doctype": "DocField", - "fieldname": "auto_email_id", - "fieldtype": "Data", - "label": "Auto Email Id" - }, - { - "default": "1", - "description": "If checked, an email with an attached HTML format will be added to part of the EMail body as well as attachment. To only send as attachment, uncheck this.", - "doctype": "DocField", - "fieldname": "send_print_in_body_and_attachment", - "fieldtype": "Check", - "label": "Send Print in Body and Attachment" - }, - { - "description": "To automatically create Support Tickets from your incoming mail, set your POP3 settings here. You must ideally create a separate email id for the erp system so that all emails will be synced into the system from that mail id. If you are not sure, please contact your EMail Provider.", - "doctype": "DocField", - "fieldname": "section_break0", - "fieldtype": "Section Break", - "label": "Incoming / Support Mail Setting" - }, - { - "description": "Check this to pull emails from your mailbox", - "doctype": "DocField", - "fieldname": "sync_support_mails", - "fieldtype": "Check", - "label": "Sync Support Mails" - }, - { - "description": "Your support email id - must be a valid email - this is where your emails will come!", - "doctype": "DocField", - "fieldname": "support_email", - "fieldtype": "Data", - "label": "Support Email" - }, - { - "description": "POP3 mail server (e.g. pop.gmail.com)", - "doctype": "DocField", - "fieldname": "support_host", - "fieldtype": "Data", - "label": "POP3 Mail Server" - }, - { - "doctype": "DocField", - "fieldname": "support_use_ssl", - "fieldtype": "Check", - "label": "Use SSL" - }, - { - "doctype": "DocField", - "fieldname": "support_username", - "fieldtype": "Data", - "label": "User Name" - }, - { - "doctype": "DocField", - "fieldname": "support_password", - "fieldtype": "Password", - "label": "Support Password" - }, - { - "doctype": "DocField", - "fieldname": "cb1", - "fieldtype": "Column Break" - }, - { - "description": "Signature to be appended at the end of every email", - "doctype": "DocField", - "fieldname": "support_signature", - "fieldtype": "Text", - "label": "Signature" - }, - { - "default": "1", - "doctype": "DocField", - "fieldname": "send_autoreply", - "fieldtype": "Check", - "label": "Send Autoreply" - }, - { - "description": "Autoreply when a new mail is received", - "doctype": "DocField", - "fieldname": "support_autoreply", - "fieldtype": "Text", - "label": "Custom Autoreply Message" - }, - { - "doctype": "DocPerm" - } -] \ No newline at end of file diff --git a/erpnext/setup/page/setup_wizard/setup_wizard.py b/erpnext/setup/page/setup_wizard/setup_wizard.py index cec6212cf1..3900eba043 100644 --- a/erpnext/setup/page/setup_wizard/setup_wizard.py +++ b/erpnext/setup/page/setup_wizard/setup_wizard.py @@ -160,7 +160,7 @@ def set_defaults(args): hr_settings.doc.emp_created_by = "Naming Series" hr_settings.save() - email_settings = frappe.bean("Email Settings") + email_settings = frappe.bean("Outgoing Email Settings") email_settings.doc.send_print_in_body_and_attachment = 1 email_settings.save() diff --git a/erpnext/startup/__init__.py b/erpnext/startup/__init__.py index faafb76d5c..1c49c8f581 100644 --- a/erpnext/startup/__init__.py +++ b/erpnext/startup/__init__.py @@ -34,7 +34,7 @@ mail_footer = """

\ + cur_frm.footer.help_area.innerHTML = '

'+frappe._("Support Email Settings")+'
\ '+frappe._("Integrate incoming support emails to Support Ticket")+'

'; } }, diff --git a/erpnext/support/doctype/support_ticket/support_ticket.py b/erpnext/support/doctype/support_ticket/support_ticket.py index 13ee178b63..57d141ea01 100644 --- a/erpnext/support/doctype/support_ticket/support_ticket.py +++ b/erpnext/support/doctype/support_ticket/support_ticket.py @@ -13,13 +13,13 @@ class DocType(TransactionBase): self.doclist = doclist def get_sender(self, comm): - return frappe.db.get_value('Email Settings',None,'support_email') + return frappe.db.get_value('Support Email Settings',None,'support_email') def get_subject(self, comm): return '[' + self.doc.name + '] ' + (comm.subject or 'No Subject Specified') def get_content(self, comm): - signature = frappe.db.get_value('Email Settings',None,'support_signature') + signature = frappe.db.get_value('Support Email Settings',None,'support_signature') content = comm.content if signature: content += '

' + signature + '

'