mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-10 06:48:19 +02:00
Delete attachments after they are no longer referenced by an e-mail message. Fixes #1. Bumping version number to 1.8.3
This commit is contained in:
parent
83584af2e0
commit
ee6b4b3e1d
3 changed files with 15 additions and 6 deletions
|
|
@ -236,6 +236,10 @@ class UnreadMessageManager(models.Manager):
|
|||
class MessageAttachment(models.Model):
|
||||
document = models.FileField(upload_to='mailbox_attachments/%Y/%m/%d/')
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
self.document.delete()
|
||||
return super(MessageAttachment, self).delete(*args, **kwargs)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.document.url
|
||||
|
||||
|
|
@ -351,5 +355,12 @@ class Message(models.Model):
|
|||
def get_email_object(self):
|
||||
return email.message_from_string(self.body)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
for attachment in self.attachments.all():
|
||||
if attachment.message_set.count() == 1:
|
||||
# This attachment is attached only to this message.
|
||||
attachment.delete()
|
||||
return super(Message, self).delete(*args, **kwargs)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.subject
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue