forked from mirror/django-mailbox
Setting for original message upload_to
Also changed the default from "messages" to separate-by-date directories "mailbox_messages/%Y/%m/%d/"
This commit is contained in:
parent
eec7fb76f9
commit
3b50b052ef
4 changed files with 47 additions and 5 deletions
19
django_mailbox/migrations/0010_alter_message_eml.py
Normal file
19
django_mailbox/migrations/0010_alter_message_eml.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 5.1.6 on 2025-12-18 12:54
|
||||||
|
|
||||||
|
import django_mailbox.utils
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('django_mailbox', '0009_alter_message_eml'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='message',
|
||||||
|
name='eml',
|
||||||
|
field=models.FileField(blank=True, help_text='Original full content of message', null=True, upload_to=django_mailbox.utils.get_original_message_save_path, verbose_name='Raw message contents'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -593,7 +593,7 @@ class Message(models.Model):
|
||||||
_('Raw message contents'),
|
_('Raw message contents'),
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
upload_to="messages",
|
upload_to=utils.get_original_message_save_path,
|
||||||
help_text=_('Original full content of message')
|
help_text=_('Original full content of message')
|
||||||
)
|
)
|
||||||
objects = models.Manager()
|
objects = models.Manager()
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,11 @@ def get_settings():
|
||||||
'DJANGO_MAILBOX_ORIGINAL_MESSAGE_COMPRESSION',
|
'DJANGO_MAILBOX_ORIGINAL_MESSAGE_COMPRESSION',
|
||||||
6
|
6
|
||||||
),
|
),
|
||||||
|
'original_message_upload_to': getattr(
|
||||||
|
settings,
|
||||||
|
'DJANGO_MAILBOX_ORIGINAL_MESSAGE_UPLOAD_TO',
|
||||||
|
'mailbox_messages/%Y/%m/%d/'
|
||||||
|
),
|
||||||
'default_charset': getattr(
|
'default_charset': getattr(
|
||||||
settings,
|
settings,
|
||||||
'DJANGO_MAILBOX_DEFAULT_CHARSET',
|
'DJANGO_MAILBOX_DEFAULT_CHARSET',
|
||||||
|
|
@ -138,10 +143,7 @@ def get_body_from_message(message, maintype, subtype):
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
|
||||||
def get_attachment_save_path(instance, filename):
|
def _get_save_path(filename, path):
|
||||||
settings = get_settings()
|
|
||||||
|
|
||||||
path = settings['attachment_upload_to']
|
|
||||||
if '%' in path:
|
if '%' in path:
|
||||||
path = datetime.datetime.utcnow().strftime(path)
|
path = datetime.datetime.utcnow().strftime(path)
|
||||||
|
|
||||||
|
|
@ -149,3 +151,15 @@ def get_attachment_save_path(instance, filename):
|
||||||
path,
|
path,
|
||||||
filename,
|
filename,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_attachment_save_path(instance, filename):
|
||||||
|
settings = get_settings()
|
||||||
|
|
||||||
|
path = settings['attachment_upload_to']
|
||||||
|
return _get_save_path(filename, path)
|
||||||
|
|
||||||
|
def get_original_message_save_path(instance, filename):
|
||||||
|
settings = get_settings()
|
||||||
|
|
||||||
|
path = settings['original_message_upload_to']
|
||||||
|
return _get_save_path(filename, path)
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,15 @@ Settings
|
||||||
* 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_ORIGINAL_MESSAGE_UPLOAD_TO``
|
||||||
|
|
||||||
|
* Default: ``mailbox_messages/%Y/%m/%d/``
|
||||||
|
* Type: ``string``
|
||||||
|
* If original messages saving is enabled, they will be saved to this location.
|
||||||
|
Specifies the ``upload_to`` setting for the eml FileField. For more on
|
||||||
|
FileFields and upload_to, see the
|
||||||
|
`Django docs <https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handling-uploaded-files-with-a-model>`__
|
||||||
|
|
||||||
* ``DJANGO_MAILBOX_DEFAULT_CHARSET``
|
* ``DJANGO_MAILBOX_DEFAULT_CHARSET``
|
||||||
|
|
||||||
* Default: ``iso8859-1``
|
* Default: ``iso8859-1``
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue