Files
modoboa/extensions/amavis_quarantine/cleanup.py
T
tonio c01d6de7d8 fix: return receipts are now displayed correctly.
new: parameters module refactored. The API is more simple now, there is no need to provide a module name anymore, this last is automatically guessed. Also, a new 'label' field can be provide when declaring a new parameter. It will be used instead of the name.

new: email parsing refactored. My first attempt was really ugly. I did not really studied the various RFC describing how messages are formatted or what IMAP fetch queries can do. Now, I hope this new code will face better unknown types. At least, It will be simpler to update.
2010-09-17 09:23:35 +02:00

33 lines
854 B
Python
Executable File

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from modoboa.lib import db, parameters
if __name__ == "__main__":
from modoboa.extensions.amavis_quarantine import main
main.init()
conn = db.getconnection("amavis_quarantine")
max_messages_age = int(parameters.get_admin("MAX_MESSAGES_AGE"))
print "Deleting messages older than %d days..." % max_messages_age
db.execute(conn, """
DELETE FROM msgs WHERE time_num < UNIX_TIMESTAMP()-%d*24*3600;
""" % max_messages_age)
print "Deleting unreferenced e-mail addresses..."
db.execute(conn, """
DELETE FROM maddr
WHERE NOT EXISTS (SELECT 1 FROM msgs WHERE sid=id)
AND NOT EXISTS (SELECT 1 FROM msgrcpt WHERE rid=id);
""")
print "Optimizing tables..."
db.execute(conn, """
OPTIMIZE TABLE msgs, msgrcpt, quarantine, maddr;
""")
db.close(conn)
print "Done."