diff --git a/frappe/patches.txt b/frappe/patches.txt index 77037d491d..9c9fd71661 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -301,6 +301,7 @@ frappe.patches.v13_0.rename_is_custom_field_in_dashboard_chart frappe.patches.v13_0.add_standard_navbar_items frappe.patches.v13_0.generate_theme_files_in_public_folder frappe.patches.v13_0.increase_password_length +frappe.patches.v12_0.fix_email_id_formatting frappe.patches.v13_0.add_toggle_width_in_navbar_settings frappe.patches.v13_0.rename_notification_fields frappe.patches.v13_0.remove_duplicate_navbar_items diff --git a/frappe/patches/v12_0/fix_email_id_formatting.py b/frappe/patches/v12_0/fix_email_id_formatting.py new file mode 100644 index 0000000000..03f606e0cc --- /dev/null +++ b/frappe/patches/v12_0/fix_email_id_formatting.py @@ -0,0 +1,44 @@ +import frappe + +def execute(): + fix_communications() + fix_show_as_cc_email_queue() + fix_email_queue_recipients() + +def fix_communications(): + for communication in frappe.db.sql('''select name, recipients, cc, bcc from tabCommunication + where creation > '2020-06-01' + and communication_medium='Email' + and communication_type='Communication' + and (cc like '%<%' or bcc like '%<%' or recipients like '%<%') + ''', as_dict=1): + + communication['recipients'] = format_email_id(communication.recipients) + communication['cc'] = format_email_id(communication.cc) + communication['bcc'] = format_email_id(communication.bcc) + + frappe.db.sql('''update `tabCommunication` set recipients=%s,cc=%s,bcc=%s + where name =%s ''', (communication['recipients'], communication['cc'], + communication['bcc'], communication['name'])) + +def fix_show_as_cc_email_queue(): + for queue in frappe.get_all("Email Queue", {'creation': ['>', '2020-06-01'], + 'status': 'Not Sent', 'show_as_cc': ['like', '%<%']}, + ['name', 'show_as_cc']): + + frappe.db.set_value('Email Queue', queue['name'], + 'show_as_cc', format_email_id(queue['show_as_cc'])) + +def fix_email_queue_recipients(): + for recipient in frappe.db.sql('''select recipient, name from + `tabEmail Queue Recipient` where recipient like '%<%' + and status='Not Sent' and creation > '2020-06-01' ''', as_dict=1): + + frappe.db.set_value('Email Queue Recipient', recipient['name'], + 'recipient', format_email_id(recipient['recipient'])) + +def format_email_id(email): + if email and ('<' in email and '>' in email): + return email.replace('>', '>').replace('<', '<') + + return email