summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
authorFábio Pio <fpio@thoughtworks.com>2014-12-16 21:11:12 -0200
committerFábio Pio <fpio@thoughtworks.com>2014-12-16 21:11:12 -0200
commitbd7fd89ee715c3e24f0451466c93d9c2091a5e61 (patch)
tree79b95da4e56f4bc2eb6a7ebc4b99b55510542d47 /service/pixelated
parent614b749b9813ed9bef0bc1f70ea223ca86927df4 (diff)
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
Diffstat (limited to 'service/pixelated')
-rw-r--r--service/pixelated/adapter/mail.py10
1 files changed, 7 insertions, 3 deletions
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):