From 895fcff4b73cca76c0a33db0e5d046f45e587065 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Sun, 20 Jan 2013 16:51:10 -0800 Subject: [PATCH] Code cleanup; ensure no tb in the event of a very-long filename. --- django_mailbox/admin.py | 1 + django_mailbox/models.py | 12 +++++++++++- readme.rst | 13 +++++++++---- setup.py | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/django_mailbox/admin.py b/django_mailbox/admin.py index 0093dc9..7e965d7 100644 --- a/django_mailbox/admin.py +++ b/django_mailbox/admin.py @@ -37,6 +37,7 @@ class MessageAdmin(admin.ModelAdmin): ) raw_id_fields = ( 'in_reply_to', + 'attachments', ) if getattr(settings, 'DJANGO_MAILBOX_ADMIN_ENABLED', True): diff --git a/django_mailbox/models.py b/django_mailbox/models.py index 2a8b72d..5aac832 100755 --- a/django_mailbox/models.py +++ b/django_mailbox/models.py @@ -15,6 +15,12 @@ from django_mailbox.transports import Pop3Transport, ImapTransport,\ MMDFTransport from django_mailbox.signals import message_received +SKIPPED_EXTENSIONS = getattr( + settings, + 'DJANGO_MAILBOX_SKIPPED_EXTENSIONS', + ['.p7s'] +) + class ActiveMailboxManager(models.Manager): def get_query_set(self): return super(ActiveMailboxManager, self).get_query_set().filter( @@ -172,7 +178,11 @@ class Mailbox(models.Model): filename = part.get_filename() # ignore SMIME extension 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 data = part.get_payload(decode=True) if not data: diff --git a/readme.rst b/readme.rst index 56cafe2..e05cc7d 100755 --- a/readme.rst +++ b/readme.rst @@ -189,7 +189,12 @@ To subscribe to the incoming mail signal, following this lead:: Settings ======== -You can disable mailbox information from being listed in the Django admin -by adding a setting named ``DJANGO_MAILBOX_ADMIN_ENABLED`` -indicating your preference toward whether or not the models appear in the admin -(defaulting to ``True``). ++---------------------------------------+--------------+-------------------------------------------------------------------------+ +| Setting | Default | Notes | ++=======================================+==============+=========================================================================+ +| ``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. | ++---------------------------------------+--------------+-------------------------------------------------------------------------+ + + diff --git a/setup.py b/setup.py index c182488..18f7af4 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ tests_require=['django'] setup( name='django-mailbox', - version='1.7', + version='1.8', 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.', author='Adam Coddington',