From bd7fd89ee715c3e24f0451466c93d9c2091a5e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Pio?= Date: Tue, 16 Dec 2014 21:11:12 -0200 Subject: Fix #195 and #198 special characters handling Added check to see if message body is base64, properly decode the body if they are Saving a draft with special characters now properly uses utf-8, that means it will send the body base64 encoded --- service/pixelated/adapter/mail.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'service/pixelated') diff --git a/service/pixelated/adapter/mail.py b/service/pixelated/adapter/mail.py index 946b921d..847773b7 100644 --- a/service/pixelated/adapter/mail.py +++ b/service/pixelated/adapter/mail.py @@ -25,6 +25,7 @@ import pixelated.support.date from email.MIMEMultipart import MIMEMultipart from pycryptopp.hash import sha256 import re +import base64 class Mail(object): @@ -71,7 +72,7 @@ class Mail(object): if 'content_type' in self.headers and 'charset' in self.headers['content_type']: return re.compile('.*charset=(.*)').match(self.headers['content_type']).group(1) else: - return 'us-ascii' + return 'utf-8' @property def raw(self): @@ -157,7 +158,7 @@ class InputMail(Mail): for part in self.body: mime_multipart.attach(MIMEText(part['raw'], part['content-type'])) else: - mime_multipart.attach(MIMEText(self.body, 'plain')) + mime_multipart.attach(MIMEText(self.body, 'plain', 'utf-8')) return mime_multipart def to_smtp_format(self): @@ -210,7 +211,10 @@ class PixelatedMail(Mail): body += '--' + self.boundary + '--' return body else: - return self.bdoc.content['raw'] + if self.parts and self.parts['alternatives'][0]['headers']['Content-Transfer-Encoding'] == 'base64': + return base64.b64decode(self.parts['alternatives'][0]['content']) + else: + return self.bdoc.content['raw'] @property def headers(self): -- cgit v1.2.3