mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Mailgun/SendGrid inbound: workaround Django filename issue
Workaround for Django multipart/form-data limitation where certain attachment filenames cause fields to be dropped or to end up in request.POST rather than request.FILES. Handle the MultiValueDictKeyError in inbound webhooks when this has occurred. Also update docs to recommend avoiding the problem by using Mailgun and SendGrid's "raw MIME" options. Also handle reported cases of empty, duplicate keys in Mailgun's content-id-map. Fixes #272
This commit is contained in:
@@ -99,7 +99,7 @@ class AnymailInboundMessage(Message):
|
||||
def inline_attachments(self):
|
||||
"""dict of Content-ID: attachment (as MIMEPart objects)"""
|
||||
return {unquote(part['Content-ID']): part for part in self.walk()
|
||||
if part.is_inline_attachment() and part['Content-ID']}
|
||||
if part.is_inline_attachment() and part['Content-ID'] is not None}
|
||||
|
||||
def get_address_header(self, header):
|
||||
"""Return the value of header parsed into a (possibly-empty) list of EmailAddress objects"""
|
||||
@@ -299,11 +299,11 @@ class AnymailInboundMessage(Message):
|
||||
# some sort of lazy attachment where the content is only pulled in if/when
|
||||
# requested (and then use file.chunks() to minimize memory usage)
|
||||
return cls.construct_attachment(
|
||||
content_type=file.content_type,
|
||||
content_type=getattr(file, 'content_type', None),
|
||||
content=file.read(),
|
||||
filename=file.name,
|
||||
filename=getattr(file, 'name', None),
|
||||
content_id=content_id,
|
||||
charset=file.charset)
|
||||
charset=getattr(file, 'charset', None))
|
||||
|
||||
@classmethod
|
||||
def construct_attachment(cls, content_type, content,
|
||||
|
||||
Reference in New Issue
Block a user