mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-22 06:28:41 +02:00
* Using django's orm to access amavis database * Many UI improvments * Better use of the RS field fixed #88 & #72 see #155
50 lines
1.6 KiB
Python
Executable File
50 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import time
|
|
from modoboa.extensions.amavis_quarantine.models import *
|
|
|
|
if __name__ == "__main__":
|
|
from modoboa.extensions.amavis_quarantine import main
|
|
from modoboa.lib import parameters
|
|
from optparse import OptionParser
|
|
|
|
parser = OptionParser()
|
|
parser.add_option("--debug", action="store_true",
|
|
help="Activate debug output")
|
|
options, args = parser.parse_args()
|
|
|
|
if options.debug:
|
|
import logging
|
|
l = logging.getLogger("django.db.backends")
|
|
l.setLevel(logging.DEBUG)
|
|
l.addHandler(logging.StreamHandler())
|
|
|
|
main.init()
|
|
|
|
max_messages_age = int(parameters.get_admin("MAX_MESSAGES_AGE",
|
|
app="amavis_quarantine"))
|
|
|
|
flags = ['D']
|
|
if parameters.get_admin("RELEASED_MSGS_CLEANUP",
|
|
app="amavis_quarantine") == "yes":
|
|
flags += ['R']
|
|
|
|
print "Deleting marked messages..."
|
|
ids = Msgrcpt.objects.filter(rs__in=flags).values("mail_id")
|
|
for msg in Msgs.objects.filter(mail_id__in=ids):
|
|
if not msg.msgrcpt_set.exclude(rs__in=flags).count():
|
|
msg.delete()
|
|
|
|
print "Deleting messages older than %d days..." % max_messages_age
|
|
limit = int(time.time()) - (max_messages_age * 24 * 3600)
|
|
Msgs.objects.filter(time_num__lt=limit).delete()
|
|
|
|
print "Deleting unreferenced e-mail addresses..."
|
|
for maddr in Maddr.objects.all():
|
|
if not len(maddr.msgs_set.all()) and not len(maddr.msgrcpt_set.all()):
|
|
maddr.delete()
|
|
|
|
print "Done."
|
|
|