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
|
|
@ -1,9 +1,9 @@
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
from functools import partial
|
||||||
import django_mailbox.utils
|
import django_mailbox.utils
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('django_mailbox', '0004_bytestring_to_unicode'),
|
('django_mailbox', '0004_bytestring_to_unicode'),
|
||||||
]
|
]
|
||||||
|
|
@ -12,6 +12,8 @@ class Migration(migrations.Migration):
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='messageattachment',
|
model_name='messageattachment',
|
||||||
name='document',
|
name='document',
|
||||||
field=models.FileField(upload_to=django_mailbox.utils.get_attachment_save_path, verbose_name='Document'),
|
field=models.FileField(
|
||||||
|
upload_to=partial(django_mailbox.utils.get_save_path, setting='attachment_upload_to'),
|
||||||
|
verbose_name='Document'),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
20
django_mailbox/migrations/0009_auto_20200208_0953.py
Normal file
20
django_mailbox/migrations/0009_auto_20200208_0953.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Generated by Django 2.2.4 on 2020-02-08 09:53
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django_mailbox.utils
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('django_mailbox', '0008_auto_20190219_1553'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='message',
|
||||||
|
name='eml',
|
||||||
|
field=models.FileField(help_text='Original full content of message', null=True, upload_to=functools.partial(django_mailbox.utils.get_save_path, *(), **{'setting': 'message_upload_to'}), verbose_name='Raw message contents'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -10,6 +10,7 @@ from email.utils import formatdate, parseaddr
|
||||||
from urllib.parse import parse_qs, unquote, urlparse
|
from urllib.parse import parse_qs, unquote, urlparse
|
||||||
from quopri import encode as encode_quopri
|
from quopri import encode as encode_quopri
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from functools import partial
|
||||||
import base64
|
import base64
|
||||||
import email
|
import email
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -420,7 +421,7 @@ class Mailbox(models.Model):
|
||||||
except KeyError as exc:
|
except KeyError as exc:
|
||||||
# email.message.replace_header may raise 'KeyError' if the header
|
# email.message.replace_header may raise 'KeyError' if the header
|
||||||
# 'content-transfer-encoding' is missing
|
# 'content-transfer-encoding' is missing
|
||||||
logger.warning("Failed to parse message: %s", exc,)
|
logger.warning("Failed to parse message: %s", exc, )
|
||||||
return None
|
return None
|
||||||
msg.set_body(body)
|
msg.set_body(body)
|
||||||
if message['in-reply-to']:
|
if message['in-reply-to']:
|
||||||
|
|
@ -576,7 +577,7 @@ class Message(models.Model):
|
||||||
eml = models.FileField(
|
eml = models.FileField(
|
||||||
_('Raw message contents'),
|
_('Raw message contents'),
|
||||||
null=True,
|
null=True,
|
||||||
upload_to="messages",
|
upload_to=partial(utils.get_save_path, setting='message_upload_to'),
|
||||||
help_text=_('Original full content of message')
|
help_text=_('Original full content of message')
|
||||||
)
|
)
|
||||||
objects = models.Manager()
|
objects = models.Manager()
|
||||||
|
|
@ -816,7 +817,7 @@ class MessageAttachment(models.Model):
|
||||||
|
|
||||||
document = models.FileField(
|
document = models.FileField(
|
||||||
_('Document'),
|
_('Document'),
|
||||||
upload_to=utils.get_attachment_save_path,
|
upload_to=partial(utils.get_save_path, setting='attachment_upload_to'),
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ import email.header
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from django.utils.deconstruct import deconstructible
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -66,7 +66,13 @@ def get_settings():
|
||||||
settings,
|
settings,
|
||||||
'DJANGO_MAILBOX_default_charset',
|
'DJANGO_MAILBOX_default_charset',
|
||||||
'iso8859-1',
|
'iso8859-1',
|
||||||
|
),
|
||||||
|
'message_upload_to': getattr(
|
||||||
|
settings,
|
||||||
|
'DJANGO_MAILBOX_MESSAGE_UPLOAD_TO',
|
||||||
|
'messages/'
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -138,10 +144,10 @@ def get_body_from_message(message, maintype, subtype):
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
|
||||||
def get_attachment_save_path(instance, filename):
|
def get_save_path(instance, filename, setting):
|
||||||
settings = get_settings()
|
settings = get_settings()
|
||||||
|
|
||||||
path = settings['attachment_upload_to']
|
path = settings[setting]
|
||||||
if '%' in path:
|
if '%' in path:
|
||||||
path = datetime.datetime.utcnow().strftime(path)
|
path = datetime.datetime.utcnow().strftime(path)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,3 +80,9 @@ Settings
|
||||||
* Default: ``False``
|
* Default: ``False``
|
||||||
* Type: ``boolean``
|
* Type: ``boolean``
|
||||||
* Controls whether or not we store original messages in ``eml`` field
|
* Controls whether or not we store original messages in ``eml`` field
|
||||||
|
|
||||||
|
* ``DJANGO_MAILBOX_MESSAGE_UPLOAD_TO``
|
||||||
|
|
||||||
|
* Default: ``messages/``
|
||||||
|
* Type: ``string``
|
||||||
|
* Original message will be saved to this location.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue