1
0
Fork 0

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:
Adam Coddington 2013-02-03 14:52:42 -08:00
parent 83584af2e0
commit ee6b4b3e1d
3 changed files with 15 additions and 6 deletions

View file

@ -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