Add option to the EmailIgnore model to allow emails from an ignored address to be deleted (previous behaviour was to keep them all, so the mailbox could potentially become quite large - and every message was downloaded again every time the mailbox was checked). Upgrade instructions provided to both add the new database field and automatically switch to the old behaviour.

This commit is contained in:
Ross Poulton 2009-01-23 10:36:41 +00:00
parent 705c32908a
commit e37609de6e
4 changed files with 45 additions and 13 deletions

18
UPGRADE
View File

@ -9,4 +9,20 @@ all commands listed _after_ that checkout.
######################### #########################
0. Table of Contents 0. Table of Contents
######################### #########################
No items yet. 1. 2009-01-23 (Changes added after SVN r99)
#########################
1. 2009-01-23 (Changes added after SVN r99)
#########################
A new flag was added to the 'IgnoreEmail' model to allow emails from ignored
addresses to be either kept in the mailbox (for manual checking) or deleted.
A new column called 'keep_in_mailbox' (type boolean, not required) is to be
added to the 'helpdesk_ignoreemail' table. The 'UPDATE' command will set all
ignore list entries to 'Keep mail from ignored address', which is the previous
behaviour.
ALTER TABLE helpdesk_ignoreemail ADD "keep_in_mailbox" boolean;
UPDATE helpdesk_ignoreemail SET keep_in_mailbox='t';

View File

@ -137,7 +137,11 @@ def ticket_from_message(message, queue):
for ignore in IgnoreEmail.objects.filter(Q(queues=queue) | Q(queues__isnull=True)): for ignore in IgnoreEmail.objects.filter(Q(queues=queue) | Q(queues__isnull=True)):
if ignore.test(sender_email): if ignore.test(sender_email):
return False if ignore.keep_in_mailbox:
# By returning 'False' the message will be kept in the mailbox,
# and the 'True' will cause the message to be deleted.
return False
return True
regex = re.compile("^\[[A-Za-z0-9]+-\d+\]") regex = re.compile("^\[[A-Za-z0-9]+-\d+\]")
if regex.match(subject): if regex.match(subject):

View File

@ -129,7 +129,7 @@ class Queue(models.Model):
help_text=_('Whether to use SSL for IMAP or POP3 - the default ports ' help_text=_('Whether to use SSL for IMAP or POP3 - the default ports '
'when using SSL are 993 for IMAP and 995 for POP3.'), 'when using SSL are 993 for IMAP and 995 for POP3.'),
) )
email_box_user = models.CharField( email_box_user = models.CharField(
_('E-Mail Username'), _('E-Mail Username'),
max_length=200, max_length=200,
@ -847,7 +847,7 @@ class SavedSearch(models.Model):
null=True, null=True,
help_text=_('Should other users see this query?'), help_text=_('Should other users see this query?'),
) )
query = models.TextField( query = models.TextField(
_('Search Query'), _('Search Query'),
help_text=_('Pickled query object. Be wary changing this.'), help_text=_('Pickled query object. Be wary changing this.'),
@ -867,7 +867,7 @@ class UserSettings(models.Model):
We should always refer to user.usersettings.settings['setting_name']. We should always refer to user.usersettings.settings['setting_name'].
""" """
user = models.OneToOneField(User) user = models.OneToOneField(User)
settings_pickled = models.TextField( settings_pickled = models.TextField(
@ -882,7 +882,7 @@ class UserSettings(models.Model):
import cPickle import cPickle
from helpdesk.lib import b64encode from helpdesk.lib import b64encode
self.settings_pickled = b64encode(cPickle.dumps(data)) self.settings_pickled = b64encode(cPickle.dumps(data))
def _get_settings(self): def _get_settings(self):
# return a python dictionary representing the pickled data. # return a python dictionary representing the pickled data.
import cPickle import cPickle
@ -896,7 +896,7 @@ class UserSettings(models.Model):
def __unicode__(self): def __unicode__(self):
return u'Preferences for %s' % self.user return u'Preferences for %s' % self.user
class Meta: class Meta:
verbose_name = 'User Settings' verbose_name = 'User Settings'
verbose_name_plural = 'User Settings' verbose_name_plural = 'User Settings'
@ -949,7 +949,7 @@ class IgnoreEmail(models.Model):
_('Name'), _('Name'),
max_length=100, max_length=100,
) )
date = models.DateField( date = models.DateField(
_('Date'), _('Date'),
help_text=_('Date on which this e-mail address was added'), help_text=_('Date on which this e-mail address was added'),
@ -964,9 +964,18 @@ class IgnoreEmail(models.Model):
'wildcards, eg *@domain.com or postmaster@*.'), 'wildcards, eg *@domain.com or postmaster@*.'),
) )
keep_in_mailbox = models.BooleanField(
_('Save Emails in Mailbox?'),
blank=True,
null=True,
help_text=_('Do you want to save emails from this address in the '
'mailbox? If this is unticked, emails from this address will '
'be deleted.'),
)
def __unicode__(self): def __unicode__(self):
return u'%s' % self.name return u'%s' % self.name
def save(self): def save(self):
if not self.date: if not self.date:
self.date = datetime.now() self.date = datetime.now()
@ -983,7 +992,7 @@ class IgnoreEmail(models.Model):
1-4 return True, 5 returns False. 1-4 return True, 5 returns False.
""" """
own_parts = self.email_address.split("@") own_parts = self.email_address.split("@")
email_parts = email.split("@") email_parts = email.split("@")

View File

@ -10,7 +10,7 @@
<table width='100%'> <table width='100%'>
<thead> <thead>
<tr class='row_tablehead'><td colspan='5'>{% trans "Ignored E-Mail Addresses" %}</td></tr> <tr class='row_tablehead'><td colspan='5'>{% trans "Ignored E-Mail Addresses" %}</td></tr>
<tr class='row_columnheads'><th>{% trans "Name" %}</th><th>{% trans "E-Mail Address" %}</th><th>{% trans "Date Added" %}</th><th>{% trans "Queues" %}</th><th>{% trans "Delete" %}</th></tr> <tr class='row_columnheads'><th>{% trans "Name" %}</th><th>{% trans "E-Mail Address" %}</th><th>{% trans "Date Added" %}</th><th>{% trans "Queues" %}</th><th>{% trans "Keep in mailbox?" %}</th><th>{% trans "Delete" %}</th></tr>
</thead> </thead>
<tbody> <tbody>
{% for ignore in ignore_list %} {% for ignore in ignore_list %}
@ -18,11 +18,14 @@
<td>{{ ignore.name }}</td> <td>{{ ignore.name }}</td>
<td>{{ ignore.email_address }}</td> <td>{{ ignore.email_address }}</td>
<td>{{ ignore.date }}</td> <td>{{ ignore.date }}</td>
<td>{% for queue in ignore.queues.all %}{{ queue.slug }}{% if not forloop.last %}, {% endif %}{% endfor %}{% if not ignore.queues.all %}All{% endif %}</td> <td>{% for queue in ignore.queues.all %}{{ queue.slug }}{% if not forloop.last %}, {% endif %}{% endfor %}{% if not ignore.queues.all %}{% trans "All" %}{% endif %}</td>
<td><a href='{% url helpdesk_email_ignore_del ignore.id %}'>Delete</a></td> <td>{% if ignore.keep_in_mailbox %}{% trans "Keep" %}{% endif %}</td>
<td><a href='{% url helpdesk_email_ignore_del ignore.id %}'>{% trans "Delete" %}</a></td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<p>{% trans "<strong>Note:</strong> If the 'Keep' option is not selected, emails sent from that address will be deleted permanently." %}</p>
{% endblock %} {% endblock %}