From 70ac6f5c4ecaa8ad63f9d23912dada61e968189e Mon Sep 17 00:00:00 2001 From: Aleksas Pielikis Date: Mon, 18 Mar 2019 09:38:06 +0200 Subject: [PATCH 1/3] fix(email): Fixed py3 email byte-content decoding (#7058) * Email decode from bytes fix added. * Correction according to comments. --- frappe/email/receive.py | 10 +++++++--- frappe/email/test_email_body.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/frappe/email/receive.py b/frappe/email/receive.py index 94b7da74f1..ea28ae381d 100644 --- a/frappe/email/receive.py +++ b/frappe/email/receive.py @@ -357,9 +357,13 @@ class Email: """Parses headers, content, attachments from given raw message. :param content: Raw message.""" - self.raw = safe_encode(content) if six.PY2 else safe_decode(content) - self.mail = email.message_from_string(self.raw) - + if six.PY2: + self.mail = email.message_from_string(safe_encode(content)) + else: + if isinstance(content, bytes): + self.mail = email.message_from_bytes(content) + else: + self.mail = email.message_from_string(content) self.text_content = '' self.html_content = '' diff --git a/frappe/email/test_email_body.py b/frappe/email/test_email_body.py index b0bfddd4f0..feb8e80007 100644 --- a/frappe/email/test_email_body.py +++ b/frappe/email/test_email_body.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import unittest, os, base64 +from frappe.email.receive import Email from frappe.email.email_body import (replace_filename_with_cid, get_email, inline_style_in_html, get_header) @@ -136,6 +137,20 @@ d85b; border-radius:8px; display:inline-block; height:8px; margin-right:5px= html = get_header('This is string') self.assertTrue('This is string' in html) + def test_8bit_utf_8_decoding(self): + text_content_bytes = b"\xed\x95\x9c\xea\xb8\x80\xe1\xa5\xa1\xe2\x95\xa5\xe0\xba\xaa\xe0\xa4\x8f" + text_content = text_content_bytes.decode('utf-8') + + content_bytes = b"""MIME-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +From: test1_@erpnext.com +Reply-To: test2_@erpnext.com +""" + text_content_bytes + + mail = Email(content_bytes) + self.assertEqual(mail.text_content, text_content) def fixed_column_width(string, chunk_size): parts = [string[0+i:chunk_size+i] for i in range(0, len(string), chunk_size)] From 4ae92edfb94ecaf15efb52705362c378277b49b5 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 19 Mar 2019 14:40:14 +0530 Subject: [PATCH 2/3] fix: do not check password strength while creating system manager --- frappe/utils/user.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/frappe/utils/user.py b/frappe/utils/user.py index f6042cf921..9814b22de4 100755 --- a/frappe/utils/user.py +++ b/frappe/utils/user.py @@ -269,11 +269,6 @@ def add_system_manager(email, first_name=None, last_name=None, send_welcome_emai "send_welcome_email": 1 if send_welcome_email else 0 }) - if password: - user.update({ - "new_password": password - }) - user.insert() # add roles @@ -281,6 +276,10 @@ def add_system_manager(email, first_name=None, last_name=None, send_welcome_emai where name not in ("Administrator", "Guest", "All")""") user.add_roles(*roles) + if password: + from frappe.utils.password import update_password + update_password(user=user.name, pwd=password) + def get_enabled_system_users(): return frappe.db.sql("""select * from tabUser where user_type='System User' and enabled=1 and name not in ('Administrator', 'Guest')""", as_dict=1) From 1e4abd4f5b7e7b77a3f898e807cf1c1593adbebb Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 20 Mar 2019 15:00:47 +0600 Subject: [PATCH 3/3] bumped to version 11.1.15 --- frappe/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index 761dc85886..f7d62c22c1 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -24,7 +24,7 @@ if sys.version[0] == '2': reload(sys) sys.setdefaultencoding("utf-8") -__version__ = '11.1.14' +__version__ = '11.1.15' __title__ = "Frappe Framework" local = Local()