Preserve filename of inline attachments

For ESPs that support both content-id and filename,
don't drop the filename.
This commit is contained in:
medmunds
2016-03-11 10:07:13 -08:00
parent 6214fbbdcd
commit b407e9f452
3 changed files with 21 additions and 9 deletions

View File

@@ -111,9 +111,14 @@ class MailgunPayload(RequestsPayload):
def add_attachment(self, attachment):
# http://docs.python-requests.org/en/v2.4.3/user/advanced/#post-multiple-multipart-encoded-files
field = "inline" if attachment.inline else "attachment"
if attachment.inline:
field = "inline"
name = attachment.cid
else:
field = "attachment"
name = attachment.name
self.files.append(
(field, (attachment.name, attachment.content, attachment.mimetype))
(field, (name, attachment.content, attachment.mimetype))
)
def set_metadata(self, metadata):

View File

@@ -118,10 +118,15 @@ class MandrillPayload(RequestsPayload):
self.data["message"]["html"] = body
def add_attachment(self, attachment):
key = "images" if attachment.inline else "attachments"
self.data["message"].setdefault(key, []).append({
if attachment.inline:
field = "images"
name = attachment.cid
else:
field = "attachments"
name = attachment.name or ""
self.data["message"].setdefault(field, []).append({
"type": attachment.mimetype,
"name": attachment.name or "",
"name": name,
"content": attachment.b64content
})