From 2bdcdf5dcf8a62fec0747b96f2a501e73837eb21 Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Tue, 29 Oct 2019 16:13:48 +0530 Subject: [PATCH] fix: decode non-ascii characters for formataddr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit formataddr[1] by default encodes non-ascii characters to `=?utf-8?q`, which needs to be decoded to a human-readable string format. using decode_header and make_header we can decode the string back to human-readable format. before: In [1]: formataddr(("Tèst", "notifications@erpnext.com")) Out[1]: '=?utf-8?b?VMOoc3Q=?= ' after: In [2]: make_header(decode_header(formataddr(("Tèst", "notifications@erpnext.com")))) Out[2]: 'Tèst ' references: [1]: https://docs.python.org/3/library/email.utils.html#email.utils.formataddr Signed-off-by: Chinmay D. Pai --- frappe/utils/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frappe/utils/__init__.py b/frappe/utils/__init__.py index 80bcad3ddb..29c9387248 100644 --- a/frappe/utils/__init__.py +++ b/frappe/utils/__init__.py @@ -10,6 +10,7 @@ from .html_utils import sanitize_html import frappe from frappe.utils.identicon import Identicon from email.utils import parseaddr, formataddr +from email.header import decode_header, make_header # utility functions like cint, int, flt, etc. from frappe.utils.data import * from six.moves.urllib.parse import quote @@ -65,7 +66,7 @@ def get_formatted_email(user): """get Email Address of user formatted as: `John Doe `""" fullname = get_fullname(user) mail = get_email_address(user) - return formataddr((fullname, mail)) + return cstr(make_header(decode_header(formataddr((fullname, mail))))) def extract_email_id(email): """fetch only the email part of the Email Address"""