Merge develop into global_search

This commit is contained in:
Himanshu Warekar 2019-09-26 16:29:05 +05:30
commit 6da204ceec
11 changed files with 193 additions and 442 deletions

View file

@ -1043,10 +1043,10 @@ def create_contact(user, ignore_links=False, ignore_mandatory=False):
contact.add_email(user.email, is_primary=True)
if user.phone:
contact.add_phone(user.phone)
contact.add_phone(user.phone, is_primary_phone=True)
if user.mobile_no:
contact.add_phone(user.mobile_no)
contact.add_phone(user.mobile_no, is_primary_mobile_no=True)
contact.insert(ignore_permissions=True, ignore_links=ignore_links, ignore_mandatory=ignore_mandatory)
@frappe.whitelist()

View file

@ -21,6 +21,7 @@
"use_imap",
"email_server",
"use_ssl",
"incoming_port",
"attachment_limit",
"append_to",
"default_incoming",
@ -372,8 +373,8 @@
"read_only": 1
},
{
"fieldname": "section_break_12",
"fieldtype": "Section Break"
"fieldname": "section_break_12",
"fieldtype": "Section Break"
},
{
"default": "0",
@ -381,10 +382,17 @@
"fieldname": "enable_automatic_linking",
"fieldtype": "Check",
"label": "Enable Automatic Linking in Documents"
},
{
"depends_on": "eval:!doc.domain && doc.enable_incoming",
"description": "If non-standard port (e.g. POP3: 995/110, IMAP: 993/143)",
"fieldname": "incoming_port",
"fieldtype": "Data",
"label": "Port"
}
],
"icon": "fa fa-inbox",
"modified": "2019-06-15 19:03:55.283524",
"modified": "2019-08-31 18:01:15.568831",
"modified_by": "Administrator",
"module": "Email",
"name": "Email Account",

View file

@ -23,7 +23,7 @@ from frappe.utils.background_jobs import enqueue, get_jobs
from frappe.core.doctype.communication.email import set_incoming_outgoing_accounts
from frappe.utils.scheduler import log
from frappe.utils.html_utils import clean_email_html
from frappe.email.utils import get_port
class SentEmailInInbox(Exception): pass
@ -117,7 +117,7 @@ class EmailAccount(Document):
fields = [
"name as domain", "use_imap", "email_server",
"use_ssl", "smtp_server", "use_tls",
"smtp_port"
"smtp_port", "incoming_port"
]
return frappe.db.get_value("Email Domain", domain[1], fields, as_dict=True)
except Exception:
@ -153,6 +153,7 @@ class EmailAccount(Document):
"use_imap": self.use_imap,
"email_sync_rule": email_sync_rule,
"uid_validity": self.uidvalidity,
"incoming_port": get_port(self),
"initial_sync_count": self.initial_sync_count or 100
})

View file

@ -1,443 +1,130 @@
{
"allow_copy": 0,
"allow_import": 0,
"allow_rename": 0,
"autoname": "field:domain_name",
"beta": 0,
"creation": "2016-03-29 10:50:48.848239",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "Setup",
"editable_grid": 0,
"autoname": "field:domain_name",
"creation": "2016-03-29 10:50:48.848239",
"doctype": "DocType",
"document_type": "Setup",
"engine": "InnoDB",
"field_order": [
"email_settings",
"domain_name",
"email_id",
"mailbox_settings",
"email_server",
"use_imap",
"use_ssl",
"incoming_port",
"attachment_limit",
"append_to",
"outgoing_mail_settings",
"smtp_server",
"use_tls",
"smtp_port"
],
"fields": [
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "email_settings",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
"fieldname": "email_settings",
"fieldtype": "Section Break"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"description": "",
"fieldname": "domain_name",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "domain name",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"fieldname": "domain_name",
"fieldtype": "Data",
"label": "domain name",
"read_only": 1,
"unique": 1
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"description": "",
"fieldname": "email_id",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Example Email Address",
"length": 0,
"no_copy": 0,
"options": "Email",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"fieldname": "email_id",
"fieldtype": "Data",
"label": "Example Email Address",
"options": "Email",
"reqd": 1
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "mailbox_settings",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"fieldname": "mailbox_settings",
"fieldtype": "Section Break"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "",
"description": "e.g. pop.gmail.com / imap.gmail.com",
"fieldname": "email_server",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Email Server",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"description": "e.g. pop.gmail.com / imap.gmail.com",
"fieldname": "email_server",
"fieldtype": "Data",
"label": "Email Server",
"reqd": 1
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "",
"fieldname": "use_imap",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Use IMAP",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"default": "0",
"fieldname": "use_imap",
"fieldtype": "Check",
"label": "Use IMAP"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "",
"fieldname": "use_ssl",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Use SSL",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"default": "0",
"fieldname": "use_ssl",
"fieldtype": "Check",
"label": "Use SSL"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "1",
"depends_on": "",
"description": "Ignore attachments over this size",
"fieldname": "attachment_limit",
"fieldtype": "Int",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Attachment Limit (MB)",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"default": "1",
"description": "Ignore attachments over this size",
"fieldname": "attachment_limit",
"fieldtype": "Int",
"label": "Attachment Limit (MB)"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "",
"description": "Append as communication against this DocType (must have fields, \"Status\", \"Subject\")",
"fieldname": "append_to",
"fieldtype": "Link",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Append To",
"length": 0,
"no_copy": 0,
"options": "DocType",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"description": "Append as communication against this DocType (must have fields, \"Status\", \"Subject\")",
"fieldname": "append_to",
"fieldtype": "Link",
"hidden": 1,
"in_list_view": 1,
"label": "Append To",
"options": "DocType"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "outgoing_mail_settings",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"fieldname": "outgoing_mail_settings",
"fieldtype": "Section Break"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "",
"description": "e.g. smtp.gmail.com",
"fieldname": "smtp_server",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "SMTP Server",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"description": "e.g. smtp.gmail.com",
"fieldname": "smtp_server",
"fieldtype": "Data",
"label": "SMTP Server",
"reqd": 1
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "",
"fieldname": "use_tls",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Use TLS",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"default": "0",
"fieldname": "use_tls",
"fieldtype": "Check",
"label": "Use TLS"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "",
"description": "If non standard port (e.g. 587)",
"fieldname": "smtp_port",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Port",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
"description": "If non standard port (e.g. 587)",
"fieldname": "smtp_port",
"fieldtype": "Data",
"label": "Port"
},
{
"description": "If non-standard port (e.g. POP3: 995/110, IMAP: 993/143)",
"fieldname": "incoming_port",
"fieldtype": "Data",
"label": "Port"
}
],
"hide_heading": 0,
"hide_toolbar": 0,
"icon": "icon-inbox",
"idx": 0,
"image_view": 0,
"in_create": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2016-12-23 13:31:58.408528",
"modified_by": "Administrator",
"module": "Email",
"name": "Email Domain",
"name_case": "",
"owner": "Administrator",
],
"icon": "icon-inbox",
"modified": "2019-08-31 17:56:48.834704",
"modified_by": "Administrator",
"module": "Email",
"name": "Email Domain",
"owner": "Administrator",
"permissions": [
{
"amend": 0,
"apply_user_permissions": 0,
"cancel": 0,
"create": 1,
"delete": 1,
"email": 0,
"export": 0,
"if_owner": 0,
"import": 0,
"is_custom": 0,
"permlevel": 0,
"print": 0,
"read": 1,
"report": 0,
"role": "System Manager",
"set_user_permissions": 1,
"share": 1,
"submit": 0,
"create": 1,
"delete": 1,
"read": 1,
"role": "System Manager",
"set_user_permissions": 1,
"share": 1,
"write": 1
}
],
"quick_entry": 0,
"read_only": 0,
"read_only_onload": 0,
"sort_field": "modified",
"sort_order": "DESC",
"track_seen": 0
],
"sort_field": "modified",
"sort_order": "DESC"
}

View file

@ -8,13 +8,13 @@ from frappe import _
from frappe.model.document import Document
from frappe.utils import validate_email_address ,cint
import imaplib,poplib,smtplib
from frappe.email.utils import get_port
class EmailDomain(Document):
def autoname(self):
if self.domain_name:
self.name = self.domain_name
def validate(self):
"""Validate email id and check POP3/IMAP and SMTP connections is enabled."""
if self.email_id:
@ -27,15 +27,15 @@ class EmailDomain(Document):
try:
if self.use_imap:
if self.use_ssl:
test = imaplib.IMAP4_SSL(self.email_server)
test = imaplib.IMAP4_SSL(self.email_server, port=get_port(self))
else:
test = imaplib.IMAP4(self.email_server)
test = imaplib.IMAP4(self.email_server, port=get_port(self))
else:
if self.use_ssl:
test = poplib.POP3_SSL(self.email_server)
test = poplib.POP3_SSL(self.email_server, port=get_port(self))
else:
test = poplib.POP3(self.email_server)
test = poplib.POP3(self.email_server, port=get_port(self))
except Exception:
frappe.throw(_("Incoming email account not correct"))
@ -78,4 +78,3 @@ class EmailDomain(Document):
frappe.msgprint(email_account.name)
frappe.throw(e)
return None

View file

@ -48,9 +48,9 @@ class EmailServer:
"""Connect to IMAP"""
try:
if cint(self.settings.use_ssl):
self.imap = Timed_IMAP4_SSL(self.settings.host, timeout=frappe.conf.get("pop_timeout"))
self.imap = Timed_IMAP4_SSL(self.settings.host, self.settings.incoming_port, timeout=frappe.conf.get("pop_timeout"))
else:
self.imap = Timed_IMAP4(self.settings.host, timeout=frappe.conf.get("pop_timeout"))
self.imap = Timed_IMAP4(self.settings.host, self.settings.incoming_port, timeout=frappe.conf.get("pop_timeout"))
self.imap.login(self.settings.username, self.settings.password)
# connection established!
return True
@ -68,9 +68,9 @@ class EmailServer:
#this method return pop connection
try:
if cint(self.settings.use_ssl):
self.pop = Timed_POP3_SSL(self.settings.host, timeout=frappe.conf.get("pop_timeout"))
self.pop = Timed_POP3_SSL(self.settings.host, self.settings.incoming_port, timeout=frappe.conf.get("pop_timeout"))
else:
self.pop = Timed_POP3(self.settings.host, timeout=frappe.conf.get("pop_timeout"))
self.pop = Timed_POP3(self.settings.host, self.settings.incoming_port, timeout=frappe.conf.get("pop_timeout"))
self.pop.user(self.settings.username)
self.pop.pass_(self.settings.password)
@ -585,6 +585,7 @@ class Timed_POP3(TimerMixin, poplib.POP3):
class Timed_POP3_SSL(TimerMixin, poplib.POP3_SSL):
_super = poplib.POP3_SSL
class Timed_IMAP4(TimerMixin, imaplib.IMAP4):
_super = imaplib.IMAP4

17
frappe/email/utils.py Normal file
View file

@ -0,0 +1,17 @@
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals, print_function
import imaplib, poplib
from frappe.utils import cint
def get_port(doc):
if not doc.incoming_port:
if doc.use_imap:
doc.incoming_port = imaplib.IMAP4_SSL_PORT if doc.use_ssl else imaplib.IMAP4_PORT
else:
doc.incoming_port = poplib.POP3_SSL_PORT if doc.use_ssl else poplib.POP3_PORT
return cint(doc.incoming_port)

View file

@ -231,7 +231,7 @@ def update_contacts_to_google_contacts(doc, method=None):
"""
# Workaround to avoid triggering updation when Event is being inserted since
# creation and modified are same when inserting doc
if not frappe.db.exists("Google Contacts", {"name": doc.google_contacts}) or doc.is_new() \
if not frappe.db.exists("Google Contacts", {"name": doc.google_contacts}) or doc.modified == doc.creation \
or not doc.sync_with_google_contacts:
return

View file

@ -250,4 +250,5 @@ frappe.patches.v12_0.rename_events_repeat_on
frappe.patches.v12_0.fix_public_private_files
frappe.patches.v12_0.move_email_and_phone_to_child_table
frappe.patches.v12_0.delete_duplicate_indexes
frappe.patches.v12_0.set_default_incoming_email_port
frappe.patches.v12_0.update_global_search

View file

@ -0,0 +1,29 @@
import frappe
from frappe.email.utils import get_port
def execute():
'''
1. Set default incoming mmail port in email domin
2. Set default incoming mmail port in all email account (for those account where domain is missing)
'''
setup_incomming_email_port_in_email_domains()
setup_incomming_email_port_in_email_accounts()
def setup_incomming_email_port_in_email_domains():
email_domains = frappe.db.get_all("Email Domain", ['incoming_port', 'use_imap', 'use_ssl', 'name'])
for domain in email_domains:
if not domain.incoming_port:
incoming_port = get_port(domain)
frappe.db.set_value("Email Domain", domain.name, 'incoming_port', incoming_port, update_modified=False)
#update incoming email port in all
frappe.db.sql('''update `tabEmail Account` set incoming_port=%s where domain = %s''', (domain.incoming_port, domain.name))
def setup_incomming_email_port_in_email_accounts():
email_accounts = frappe.db.get_all("Email Account", ['incoming_port', 'use_imap', 'use_ssl', 'name', 'enable_incoming'])
for account in email_accounts:
if account.enable_incoming and not account.incoming_port:
incoming_port = get_port(account)
frappe.db.set_value("Email Account", account.name, 'incoming_port', incoming_port, update_modified=False)

View file

@ -56,12 +56,20 @@ frappe.ready(function() {
window.location.replace(window.location.pathname + "?new=1");
return;
}
web_form.prepare(web_form_doc, r.message.doc || {});
let doc = r.message.doc || build_doc(r.message);
web_form.prepare(web_form_doc, doc);
web_form.make();
web_form.set_default_values();
})
function build_doc(form_data) {
let doc = {};
form_data.web_form.web_form_fields.forEach(df => {
if (df.default) return doc[df.fieldname] = df.default;
});
return doc;
}
function get_data() {
return frappe.call({
method: "frappe.website.doctype.web_form.web_form.get_form_data",
@ -108,4 +116,4 @@ frappe.ready(function() {
return form_data;
}
}
});
});