mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-12 08:53:56 +01:00
30 lines
794 B
Python
Executable File
30 lines
794 B
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from mailng.lib import db, parameters
|
|
|
|
if __name__ == "__main__":
|
|
conn = db.getconnection("amavis_quarantine")
|
|
max_messages_age = parameters.get_admin("amavis_quarantine", "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."
|