aboutsummaryrefslogtreecommitdiffstats
path: root/servo/models/note.py
diff options
context:
space:
mode:
Diffstat (limited to 'servo/models/note.py')
-rw-r--r--servo/models/note.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/servo/models/note.py b/servo/models/note.py
index e7ab2dd..5650c4c 100644
--- a/servo/models/note.py
+++ b/servo/models/note.py
@@ -291,6 +291,11 @@ class Note(MPTTModel):
Creates a new Note from an email message
"""
sender = decode_header(msg['From'])
+
+ if type(sender[0][0]) == str:
+ enc = sender[0][1] or 'utf-8'
+ sender = [[sender[0][0].encode(enc), enc]]
+
detected = chardet.detect(sender[0][0]).get('encoding')
sender = [i[0].decode(i[1] or detected) for i in sender]
sender = ' '.join(sender)
@@ -300,20 +305,28 @@ class Note(MPTTModel):
note.is_read = False
note.is_reported = False
note.recipient = msg['To']
+ note.type = cls.T_CUSTOMER_NOTE
subject = decode_header(msg['Subject'])[0]
+
+ if type(subject[0][0]) == str:
+ enc = subject[1] or 'utf-8'
+ subject = [subject[0].encode(enc), enc]
+
detected = chardet.detect(subject[0]).get('encoding')
- note.subject = subject[0].decode(subject[1] or detected)
+ encoding = subject[1] or detected
+ note.subject = subject[0].decode(encoding)
note.find_parent(note.subject)
for part in msg.walk():
+
t, s = part.get_content_type().split('/', 1)
charset = part.get_content_charset() or "latin1"
if t == "text":
payload = part.get_payload(decode=True)
- note.body = unicode(payload, str(charset), "ignore")
+ note.body = payload.decode(charset)
if s == "html":
h = html2text.HTML2Text()
h.ignore_images = True
@@ -321,7 +334,7 @@ class Note(MPTTModel):
else:
note.save()
if part.get_filename():
- filename = unicode(part.get_filename())
+ filename = part.get_filename()
payload = part.get_payload()
content = base64.b64decode(payload)
content = ContentFile(content, filename)