summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/model/mail.py
diff options
context:
space:
mode:
authorNavaL <mnandri@thoughtworks.com>2015-12-22 18:16:17 +0100
committerNavaL <mnandri@thoughtworks.com>2015-12-22 19:05:10 +0100
commit4cb47c1848bb5d20b5ae167a7ab2879d00825f84 (patch)
treea0a68aeb4c1a7a404483215fbd720c16ead8933f /service/pixelated/adapter/model/mail.py
parent77b5ecdf0664b9b692df9bd0444062d47feddda1 (diff)
decode to base64 the raw attachment that is in bytes... and renaming id to attachment_id in the mail POST
Issue #548
Diffstat (limited to 'service/pixelated/adapter/model/mail.py')
-rw-r--r--service/pixelated/adapter/model/mail.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index 4f06588b..1a505481 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -19,6 +19,8 @@ import logging
from email import message_from_file
from email.mime.text import MIMEText
from email.header import Header
+
+import binascii
from email.MIMEMultipart import MIMEMultipart
from email.mime.nonmultipart import MIMENonMultipart
from pycryptopp.hash import sha256
@@ -111,8 +113,11 @@ class Mail(object):
def _add_attachments(self, mime):
for attachment in getattr(self, '_attachments', []):
major, sub = attachment['content-type'].split('/')
- attachment_mime = MIMENonMultipart(major, sub, Content_Disposition='attachment; filename=%s' % attachment['filename'])
- attachment_mime.set_payload(attachment['raw'])
+ attachment_mime = MIMENonMultipart(major, sub)
+ base64_attachment_file = binascii.b2a_base64(attachment['raw'])
+ attachment_mime.set_payload(base64_attachment_file)
+ attachment_mime['Content-Disposition'] = 'attachment; filename="%s"' % attachment['filename']
+ attachment_mime['Content-Transfer-Encoding'] = 'base64'
mime.attach(attachment_mime)
def _charset(self):