Skip to content

Commit

Permalink
Base64 encode attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebegin committed Jul 1, 2013
1 parent 61cbcd8 commit 3aa470a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions marrow/mailer/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ def attach(self, name, data=None, maintype=None, subtype=None,

if data is None:
with open(name, 'rb') as fp:
part.set_payload(fp.read())
part.set_payload(base64.b64encode(fp.read()))
name = os.path.basename(name)
elif isinstance(data, bytes):
part.set_payload(data)
part.set_payload(base64.b64encode(data))
elif hasattr(data, 'read'):
part.set_payload(data.read())
part.set_payload(base64.b64encode(data.read()))
else:
raise TypeError("Unable to read attachment contents")

Expand All @@ -292,6 +292,7 @@ def attach(self, name, data=None, maintype=None, subtype=None,
self.embedded.append(part)
else:
part.add_header('Content-Disposition', 'attachment', filename=name)
part.add_header('Content-Transfer-Encoding','base64')
self.attachments.append(part)

def embed(self, name, data=None):
Expand Down

0 comments on commit 3aa470a

Please sign in to comment.