From 01c5c327985c68c9aa93d41e84a710e35211a705 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Thu, 8 Mar 2018 16:00:56 +0530 Subject: [PATCH 1/2] dict comparision --- frappe/__init__.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/frappe/__init__.py b/frappe/__init__.py index 20c96e4c60..e136ecd7a4 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -9,6 +9,7 @@ from __future__ import unicode_literals, print_function from six import iteritems, binary_type, text_type, string_types from werkzeug.local import Local, release_local import os, sys, importlib, inspect, json +from past.builtins import cmp # public from .exceptions import * @@ -39,6 +40,28 @@ class _dict(dict): def copy(self): return _dict(dict(self).copy()) + def __cmp__(self, other): + diff_keys = lambda a, b: [ + key for key in list(a) + if key not in b or a[key] != b[key] + ] + + if len(self) != len(other): + return cmp(len(self), len(other)) + + try: + adiff = min(diff_keys(self, other)) + except ValueError: + return 0 + + bdiff = min(diff_keys(other, self)) + + if adiff != bdiff: + return cmp(adiff, bdiff) + + return cmp(self[adiff], other[bdiff]) + + def _(msg, lang=None): """Returns translated string in current lang, if exists.""" from frappe.translate import get_full_dict From 97963119a5f4f36e847f03a27a48aa6548c83320 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Thu, 8 Mar 2018 16:35:02 +0530 Subject: [PATCH 2/2] email parse content to unicode --- frappe/__init__.py | 22 ---------------------- frappe/email/receive.py | 5 +++-- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index e136ecd7a4..9a614f97eb 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -40,28 +40,6 @@ class _dict(dict): def copy(self): return _dict(dict(self).copy()) - def __cmp__(self, other): - diff_keys = lambda a, b: [ - key for key in list(a) - if key not in b or a[key] != b[key] - ] - - if len(self) != len(other): - return cmp(len(self), len(other)) - - try: - adiff = min(diff_keys(self, other)) - except ValueError: - return 0 - - bdiff = min(diff_keys(other, self)) - - if adiff != bdiff: - return cmp(adiff, bdiff) - - return cmp(self[adiff], other[bdiff]) - - def _(msg, lang=None): """Returns translated string in current lang, if exists.""" from frappe.translate import get_full_dict diff --git a/frappe/email/receive.py b/frappe/email/receive.py index c4ce928f85..585aeb6ef7 100644 --- a/frappe/email/receive.py +++ b/frappe/email/receive.py @@ -9,7 +9,7 @@ import time, _socket, poplib, imaplib, email, email.utils, datetime, chardet, re from email_reply_parser import EmailReplyParser from email.header import decode_header import frappe -from frappe import _ +from frappe import _, safe_decode from frappe.utils import (extract_email_id, convert_utc_to_user_timezone, now, cint, cstr, strip, markdown, parse_addr) from frappe.utils.scheduler import log @@ -360,9 +360,10 @@ class Email: """Parses headers, content, attachments from given raw message. :param content: Raw message.""" - self.raw = content + self.raw = safe_decode(content) self.mail = email.message_from_string(self.raw) + self.text_content = '' self.html_content = '' self.attachments = []