From 0eae494dc3200c0c1a0b1e20d6dcdd5790d12f85 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 12 Aug 2020 18:28:40 +0530 Subject: [PATCH] fix: email formatting in communication and email queue Co-authored-by: Sahil Khan --- frappe/patches.txt | 1 + .../patches/v12_0/fix_email_id_formatting.py | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 frappe/patches/v12_0/fix_email_id_formatting.py diff --git a/frappe/patches.txt b/frappe/patches.txt index 68b4e5d99c..2b729ad87c 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -298,3 +298,4 @@ frappe.patches.v13_0.create_custom_dashboards_cards_and_charts frappe.patches.v13_0.rename_is_custom_field_in_dashboard_chart 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 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