mirror of
https://github.com/chatmail/relay.git
synced 2026-05-19 04:18:09 +00:00
don't globally collect files anymore to avoid using growing-with-number-of-mailboxes ram
This commit is contained in:
@@ -97,22 +97,19 @@ class Expiry:
|
|||||||
self.stats = stats
|
self.stats = stats
|
||||||
self.dry = dry
|
self.dry = dry
|
||||||
self.now = now
|
self.now = now
|
||||||
self.del_files = []
|
|
||||||
self.del_mailboxes = []
|
|
||||||
|
|
||||||
def perform_removes(self):
|
def remove_mailbox(self, mboxdir):
|
||||||
for mboxdir in self.del_mailboxes:
|
print_info(f"removing {mboxdir}")
|
||||||
print_info(f"removing {mboxdir}")
|
if not self.dry:
|
||||||
if not self.dry:
|
shutil.rmtree(mboxdir)
|
||||||
shutil.rmtree(mboxdir)
|
|
||||||
for path in self.del_files:
|
def remove_file(self, path):
|
||||||
print_info(f"removing {path}")
|
print_info(f"removing {path}")
|
||||||
if not self.dry:
|
if not self.dry:
|
||||||
try:
|
try:
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print_info(f"delete failed, file vanished? {path}")
|
print_info(f"file not found/vanished {path}")
|
||||||
pass # it's gone already, fine
|
|
||||||
|
|
||||||
def process_mailbox_stat(self, mbox):
|
def process_mailbox_stat(self, mbox):
|
||||||
cutoff_without_login = (
|
cutoff_without_login = (
|
||||||
@@ -123,19 +120,20 @@ class Expiry:
|
|||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
if mbox.last_login and mbox.last_login < cutoff_without_login:
|
if mbox.last_login and mbox.last_login < cutoff_without_login:
|
||||||
self.del_mailboxes.append(mbox.basedir)
|
self.remove_mailbox(mbox.basedir)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
os.chdir(mbox.basedir)
|
||||||
for message in mbox.messages:
|
for message in mbox.messages:
|
||||||
if message.mtime < cutoff_mails:
|
if message.mtime < cutoff_mails:
|
||||||
self.del_files.append(joinpath(mbox.basedir, message.relpath))
|
self.remove_file(message.relpath)
|
||||||
elif message.size > 200000 and message.mtime < cutoff_large_mails:
|
elif message.size > 200000 and message.mtime < cutoff_large_mails:
|
||||||
self.del_files.append(joinpath(mbox.basedir, message.relpath))
|
self.remove_file(message.relpath)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
changed = True
|
changed = True
|
||||||
if changed:
|
if changed:
|
||||||
self.del_files.append(joinpath(mbox.basedir, "maildirsize"))
|
self.remove_file("maildirsize")
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
@@ -175,7 +173,6 @@ def main(args):
|
|||||||
stats = Stats(args.mailboxes_dir, maxnum=maxnum)
|
stats = Stats(args.mailboxes_dir, maxnum=maxnum)
|
||||||
exp = Expiry(config, stats, dry=not args.remove, now=now)
|
exp = Expiry(config, stats, dry=not args.remove, now=now)
|
||||||
stats.iter_mailboxes(exp.process_mailbox_stat)
|
stats.iter_mailboxes(exp.process_mailbox_stat)
|
||||||
exp.perform_removes()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user