1
0
Fork 1
mirror of https://github.com/coddingtonbear/django-mailbox.git synced 2026-07-09 22:38:19 +02:00

Code cleanup; ensure no tb in the event of a very-long filename.

This commit is contained in:
Adam Coddington 2013-01-20 16:51:10 -08:00
parent 999dfb0ac3
commit 895fcff4b7
4 changed files with 22 additions and 6 deletions

View file

@ -37,6 +37,7 @@ class MessageAdmin(admin.ModelAdmin):
) )
raw_id_fields = ( raw_id_fields = (
'in_reply_to', 'in_reply_to',
'attachments',
) )
if getattr(settings, 'DJANGO_MAILBOX_ADMIN_ENABLED', True): if getattr(settings, 'DJANGO_MAILBOX_ADMIN_ENABLED', True):

View file

@ -15,6 +15,12 @@ from django_mailbox.transports import Pop3Transport, ImapTransport,\
MMDFTransport MMDFTransport
from django_mailbox.signals import message_received from django_mailbox.signals import message_received
SKIPPED_EXTENSIONS = getattr(
settings,
'DJANGO_MAILBOX_SKIPPED_EXTENSIONS',
['.p7s']
)
class ActiveMailboxManager(models.Manager): class ActiveMailboxManager(models.Manager):
def get_query_set(self): def get_query_set(self):
return super(ActiveMailboxManager, self).get_query_set().filter( return super(ActiveMailboxManager, self).get_query_set().filter(
@ -172,7 +178,11 @@ class Mailbox(models.Model):
filename = part.get_filename() filename = part.get_filename()
# ignore SMIME extension # ignore SMIME extension
filename_basename, filename_extension = os.path.splitext(filename) filename_basename, filename_extension = os.path.splitext(filename)
if filename_extension in ('.p7s',): if len(filename) > 100:
# Ensure that there're at least a few chars available afterward
# for duplication things like _1, _2 ... _99
filename = filename_basename[0:100-len(filename_extension)-3]
if filename_extension in SKIPPED_EXTENSIONS:
continue continue
data = part.get_payload(decode=True) data = part.get_payload(decode=True)
if not data: if not data:

View file

@ -189,7 +189,12 @@ To subscribe to the incoming mail signal, following this lead::
Settings Settings
======== ========
You can disable mailbox information from being listed in the Django admin +---------------------------------------+--------------+-------------------------------------------------------------------------+
by adding a setting named ``DJANGO_MAILBOX_ADMIN_ENABLED`` | Setting | Default | Notes |
indicating your preference toward whether or not the models appear in the admin +=======================================+==============+=========================================================================+
(defaulting to ``True``). | ``DJANGO_MAILBOX_ADMIN_ENABLED`` | ``True`` | Controls whether mailboxes appear in the Django Admin. |
+---------------------------------------+--------------+-------------------------------------------------------------------------+
| ``DJANGO_MAILBOX_SKIPPED_EXTENSIONS`` | ``['.p7s']`` | A list of extensions to skip when processing email message attachments. |
+---------------------------------------+--------------+-------------------------------------------------------------------------+

View file

@ -4,7 +4,7 @@ tests_require=['django']
setup( setup(
name='django-mailbox', name='django-mailbox',
version='1.7', version='1.8',
url='http://bitbucket.org/latestrevision/django-mailbox/', url='http://bitbucket.org/latestrevision/django-mailbox/',
description='Import mail from POP3, IMAP, local mailboxes or directly from Postfix or Exim4 into your Django application automatically.', description='Import mail from POP3, IMAP, local mailboxes or directly from Postfix or Exim4 into your Django application automatically.',
author='Adam Coddington', author='Adam Coddington',