frappe.ui.form.on("Email Domain", {
	email_id: function (frm) {
		frm.set_value("domain_name", frm.doc.email_id.split("@")[1]);
	},

	refresh: function (frm) {
		if (frm.doc.email_id) {
			frm.set_value("domain_name", frm.doc.email_id.split("@")[1]);
		}

		if (frm.doc.__islocal != 1 && frappe.route_flags.return_to_email_account) {
			var route = frappe.get_prev_route();
			delete frappe.route_flags.return_to_email_account;
			frappe.route_flags.set_domain_values = true;

			(frappe.route_options = {
				domain: frm.doc.name,
				use_imap: frm.doc.use_imap,
				email_server: frm.doc.email_server,
				use_ssl: frm.doc.use_ssl,
				smtp_server: frm.doc.smtp_server,
				use_tls: frm.doc.use_tls,
				smtp_port: frm.doc.smtp_port,
			}),
				frappe.set_route(route);
		}
	},
});

@@ -50,25 +50,24 @@
 nction (frm)
- 
 %7B%0A%09%09frm.set_
@@ -78,33 +78,32 @@
 e(%22domain_name%22,
- 
 frm.doc.email_id
@@ -121,662 +121,12 @@
 %5B1%5D)
-;
 %0A%09%7D,%0A
-%0A%09refresh: function (frm) %7B%0A%09%09if (frm.doc.email_id) %7B%0A%09%09%09frm.set_value(%22domain_name%22, frm.doc.email_id.split(%22@%22)%5B1%5D);%0A%09%09%7D%0A%0A%09%09if (frm.doc.__islocal != 1 && frappe.route_flags.return_to_email_account) %7B%0A%09%09%09var route = frappe.get_prev_route();%0A%09%09%09delete frappe.route_flags.return_to_email_account;%0A%09%09%09frappe.route_flags.set_domain_values = true;%0A%0A%09%09%09(frappe.route_options = %7B%0A%09%09%09%09domain: frm.doc.name,%0A%09%09%09%09use_imap: frm.doc.use_imap,%0A%09%09%09%09email_server: frm.doc.email_server,%0A%09%09%09%09use_ssl: frm.doc.use_ssl,%0A%09%09%09%09smtp_server: frm.doc.smtp_server,%0A%09%09%09%09use_tls: frm.doc.use_tls,%0A%09%09%09%09smtp_port: frm.doc.smtp_port,%0A%09%09%09%7D),%0A%09%09%09%09frappe.set_route(route);%0A%09%09%7D%0A%09%7D,%0A%7D);
+%7D)
 %0A

remove unnecessary refresh event from email domain