mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-10 06:48:19 +02:00
Merge 804d91f2ad into 34f2d2b98b
This commit is contained in:
commit
0854b81b07
5 changed files with 55 additions and 20 deletions
|
|
@ -10,6 +10,7 @@ from email.utils import formatdate, parseaddr
|
|||
from urllib.parse import parse_qs, unquote, urlparse
|
||||
from quopri import encode as encode_quopri
|
||||
from io import BytesIO
|
||||
from functools import partial
|
||||
import base64
|
||||
import email
|
||||
import logging
|
||||
|
|
@ -306,8 +307,8 @@ class Mailbox(models.Model):
|
|||
self._get_dehydrated_message(part, record)
|
||||
)
|
||||
elif (
|
||||
settings['strip_unallowed_mimetypes']
|
||||
and not msg.get_content_type() in settings['allowed_mimetypes']
|
||||
settings['strip_unallowed_mimetypes']
|
||||
and not msg.get_content_type() in settings['allowed_mimetypes']
|
||||
):
|
||||
for header, value in msg.items():
|
||||
new[header] = value
|
||||
|
|
@ -315,16 +316,16 @@ class Mailbox(models.Model):
|
|||
# payload, it will be expecting a body for this.
|
||||
del new['Content-Transfer-Encoding']
|
||||
new[settings['altered_message_header']] = (
|
||||
'Stripped; Content type %s not allowed' % (
|
||||
msg.get_content_type()
|
||||
)
|
||||
'Stripped; Content type %s not allowed' % (
|
||||
msg.get_content_type()
|
||||
)
|
||||
)
|
||||
new.set_payload('')
|
||||
elif (
|
||||
(
|
||||
msg.get_content_type() not in settings['text_stored_mimetypes']
|
||||
) or
|
||||
('attachment' in msg.get('Content-Disposition', ''))
|
||||
(
|
||||
msg.get_content_type() not in settings['text_stored_mimetypes']
|
||||
) or
|
||||
('attachment' in msg.get('Content-Disposition', ''))
|
||||
):
|
||||
filename = None
|
||||
raw_filename = msg.get_filename()
|
||||
|
|
@ -420,7 +421,7 @@ class Mailbox(models.Model):
|
|||
except KeyError as exc:
|
||||
# email.message.replace_header may raise 'KeyError' if the header
|
||||
# 'content-transfer-encoding' is missing
|
||||
logger.warning("Failed to parse message: %s", exc,)
|
||||
logger.warning("Failed to parse message: %s", exc, )
|
||||
return None
|
||||
msg.set_body(body)
|
||||
if message['in-reply-to']:
|
||||
|
|
@ -576,7 +577,7 @@ class Message(models.Model):
|
|||
eml = models.FileField(
|
||||
_('Raw message contents'),
|
||||
null=True,
|
||||
upload_to="messages",
|
||||
upload_to=partial(utils.get_save_path, setting='message_upload_to'),
|
||||
help_text=_('Original full content of message')
|
||||
)
|
||||
objects = models.Manager()
|
||||
|
|
@ -715,9 +716,9 @@ class Message(models.Model):
|
|||
encode_base64(new)
|
||||
except MessageAttachment.DoesNotExist:
|
||||
new[settings['altered_message_header']] = (
|
||||
'Missing; Attachment %s not found' % (
|
||||
msg[settings['attachment_interpolation_header']]
|
||||
)
|
||||
'Missing; Attachment %s not found' % (
|
||||
msg[settings['attachment_interpolation_header']]
|
||||
)
|
||||
)
|
||||
new.set_payload('')
|
||||
else:
|
||||
|
|
@ -816,7 +817,7 @@ class MessageAttachment(models.Model):
|
|||
|
||||
document = models.FileField(
|
||||
_('Document'),
|
||||
upload_to=utils.get_attachment_save_path,
|
||||
upload_to=partial(utils.get_save_path, setting='attachment_upload_to'),
|
||||
)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue