# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from __future__ import unicode_literals

import frappe
from frappe import _
from frappe.desk.doctype.global_search_settings.global_search_settings import update_global_search_doctypes

def install():
	update_genders()
	update_salutations()
	update_global_search_doctypes()
	setup_email_linking()

@frappe.whitelist()
def update_genders():
	default_genders = [_("Male"), _("Female"), _("Other"),_("Transgender"), _("Genderqueer"), _("Non-Conforming"),_("Prefer not to say")]
	records = [{'doctype': 'Gender', 'gender': d} for d in default_genders]
	for record in records:
		frappe.get_doc(record).insert(ignore_permissions=True, ignore_if_duplicate=True)

@frappe.whitelist()
def update_salutations():
	default_salutations = [_("Mr"), _("Ms"), _('Mx'), _("Dr"), _("Mrs"), _("Madam"), _("Miss"), _("Master"), _("Prof")]
	records = [{'doctype': 'Salutation', 'salutation': d} for d in default_salutations]
	for record in records:
		doc = frappe.new_doc(record.get("doctype"))
		doc.update(record)
		doc.insert(ignore_permissions=True, ignore_if_duplicate=True)

def setup_email_linking():
	doc = frappe.get_doc({
		"doctype": "Email Account",
		"email_id": "email_linking@example.com",
	})
	doc.insert(ignore_permissions=True, ignore_if_duplicate=True)
  
@@ -416,16 +416,35 @@
 inking()
+%0A%09add_unsubscribe()
 %0A%0A@frapp
@@ -1394,6 +1394,249 @@
 ue)%0A
-  
+%0Adef add_unsubscribe():%0A%09email_unsubscribe = %5B%0A%09%09%7B%22email%22: %22admin@example.com%22, %22global_unsubscribe%22: 1%7D,%0A%09%09%7B%22email%22: %22guest@example.com%22, %22global_unsubscribe%22: 1%7D%0A%09%5D%0A%0A%09for unsubscribe in email_unsubscribe:%0A%09%09frappe.get_doc(unsubscribe).insert()

add admin to email unsubscribe