@@ -560,7 +560,7 @@ def set_email_password(email_account, user, password): | |||
return True | |||
def setup_user_email_inbox(email_account, awaiting_password, email_id): | |||
def setup_user_email_inbox(email_account, awaiting_password, email_id, enable_outgoing): | |||
""" setup email inbox for user """ | |||
def add_user_email(user): | |||
user = frappe.get_doc("User", user) | |||
@@ -569,6 +569,7 @@ def setup_user_email_inbox(email_account, awaiting_password, email_id): | |||
row.email_id = email_id | |||
row.email_account = email_account | |||
row.awaiting_password = awaiting_password or 0 | |||
row.enable_outgoing = enable_outgoing or 0 | |||
user.save(ignore_permissions=True) | |||
@@ -593,12 +594,13 @@ def setup_user_email_inbox(email_account, awaiting_password, email_id): | |||
add_user_email(user) | |||
else: | |||
# update awaiting password for email account | |||
update_awaiting_password = True | |||
udpate_user_email_settings = True | |||
if update_awaiting_password: | |||
frappe.db.sql("""UPDATE `tabUser Email` SET awaiting_password = %(awaiting_password)s | |||
WHERE email_account = %(email_account)s""", { | |||
if udpate_user_email_settings: | |||
frappe.db.sql("""UPDATE `tabUser Email` SET awaiting_password = %(awaiting_password)s, | |||
enable_outgoing = %(enable_outgoing)s WHERE email_account = %(email_account)s""", { | |||
"email_account": email_account, | |||
"enable_outgoing": enable_outgoing, | |||
"awaiting_password": awaiting_password or 0 | |||
}) | |||
else: | |||
@@ -1,5 +1,6 @@ | |||
{ | |||
"allow_copy": 0, | |||
"allow_guest_to_view": 0, | |||
"allow_import": 0, | |||
"allow_rename": 0, | |||
"beta": 0, | |||
@@ -21,6 +22,7 @@ | |||
"ignore_user_permissions": 0, | |||
"ignore_xss_filter": 0, | |||
"in_filter": 0, | |||
"in_global_search": 0, | |||
"in_list_view": 1, | |||
"in_standard_filter": 0, | |||
"label": "Email Account", | |||
@@ -39,6 +41,64 @@ | |||
"set_only_once": 0, | |||
"unique": 0 | |||
}, | |||
{ | |||
"allow_on_submit": 0, | |||
"bold": 0, | |||
"collapsible": 0, | |||
"columns": 0, | |||
"fieldname": "email_id", | |||
"fieldtype": "Data", | |||
"hidden": 0, | |||
"ignore_user_permissions": 0, | |||
"ignore_xss_filter": 0, | |||
"in_filter": 0, | |||
"in_global_search": 0, | |||
"in_list_view": 0, | |||
"in_standard_filter": 0, | |||
"label": "Email ID", | |||
"length": 0, | |||
"no_copy": 0, | |||
"options": "email_account.email_id", | |||
"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 | |||
}, | |||
{ | |||
"allow_on_submit": 0, | |||
"bold": 0, | |||
"collapsible": 0, | |||
"columns": 0, | |||
"fieldname": "column_break_3", | |||
"fieldtype": "Column Break", | |||
"hidden": 0, | |||
"ignore_user_permissions": 0, | |||
"ignore_xss_filter": 0, | |||
"in_filter": 0, | |||
"in_global_search": 0, | |||
"in_list_view": 0, | |||
"in_standard_filter": 0, | |||
"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 | |||
}, | |||
{ | |||
"allow_on_submit": 0, | |||
"bold": 0, | |||
@@ -50,6 +110,7 @@ | |||
"ignore_user_permissions": 0, | |||
"ignore_xss_filter": 0, | |||
"in_filter": 0, | |||
"in_global_search": 0, | |||
"in_list_view": 1, | |||
"in_standard_filter": 0, | |||
"label": "Awaiting Password", | |||
@@ -73,18 +134,19 @@ | |||
"bold": 0, | |||
"collapsible": 0, | |||
"columns": 0, | |||
"fieldname": "email_id", | |||
"fieldtype": "Data", | |||
"fieldname": "enable_outgoing", | |||
"fieldtype": "Check", | |||
"hidden": 0, | |||
"ignore_user_permissions": 0, | |||
"ignore_xss_filter": 0, | |||
"in_filter": 0, | |||
"in_global_search": 0, | |||
"in_list_view": 0, | |||
"in_standard_filter": 0, | |||
"label": "Email ID", | |||
"label": "Enable Outgoing", | |||
"length": 0, | |||
"no_copy": 0, | |||
"options": "email_account.email_id", | |||
"options": "email_account.enable_outgoing", | |||
"permlevel": 0, | |||
"precision": "", | |||
"print_hide": 0, | |||
@@ -98,17 +160,17 @@ | |||
"unique": 0 | |||
} | |||
], | |||
"has_web_view": 0, | |||
"hide_heading": 0, | |||
"hide_toolbar": 0, | |||
"idx": 0, | |||
"image_view": 0, | |||
"in_create": 0, | |||
"in_dialog": 0, | |||
"is_submittable": 0, | |||
"issingle": 0, | |||
"istable": 1, | |||
"max_attachments": 0, | |||
"modified": "2017-01-13 07:07:40.049130", | |||
"modified": "2017-03-29 16:48:51.320616", | |||
"modified_by": "Administrator", | |||
"module": "Core", | |||
"name": "User Email", | |||
@@ -118,6 +180,7 @@ | |||
"quick_entry": 0, | |||
"read_only": 0, | |||
"read_only_onload": 0, | |||
"show_name_in_global_search": 0, | |||
"sort_field": "modified", | |||
"sort_order": "DESC", | |||
"track_changes": 0, | |||
@@ -89,10 +89,8 @@ class EmailAccount(Document): | |||
from frappe.core.doctype.user.user import ask_pass_update, setup_user_email_inbox | |||
self.there_must_be_only_one_default() | |||
if self.enable_incoming: | |||
# add user inbox only if mail incoming is enabled | |||
setup_user_email_inbox(email_account=self.name, | |||
awaiting_password=self.awaiting_password, email_id=self.email_id) | |||
setup_user_email_inbox(email_account=self.name, awaiting_password=self.awaiting_password, | |||
email_id=self.email_id, enable_outgoing=self.enable_outgoing) | |||
def there_must_be_only_one_default(self): | |||
"""If current Email Account is default, un-default all other accounts.""" | |||
@@ -8,7 +8,7 @@ def get_email_accounts(user=None): | |||
email_accounts = [] | |||
accounts = frappe.get_all("User Email", filters={ "parent": user }, | |||
fields=["email_account", "email_id"], | |||
fields=["email_account", "email_id", "enable_outgoing"], | |||
distinct=True, order_by="idx") | |||
if not accounts: | |||
@@ -86,7 +86,8 @@ frappe.views.CommunicationComposer = Class.extend({ | |||
// add from if user has access to multiple email accounts | |||
email_accounts = frappe.boot.email_accounts.filter(function(account, idx){ | |||
return !inList(["All Accounts", "Sent", "Spam", "Trash"], account.email_account) | |||
return !inList(["All Accounts", "Sent", "Spam", "Trash"], account.email_account) && | |||
account.enable_outgoing | |||
}) | |||
if(frappe.boot.email_accounts && email_accounts.length > 1) { | |||
fields = [ | |||