mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +00:00
Compare commits
1 Commits
1.7.0
...
link2xt/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
158fb0b83e |
@@ -361,6 +361,14 @@ def _configure_dovecot(config: Config, debug: bool = False) -> bool:
|
|||||||
config=config,
|
config=config,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
files.put(
|
||||||
|
src=importlib.resources.files(__package__).joinpath("dovecot/remove-seen.py"),
|
||||||
|
dest="/usr/local/bin/remove-seen.py",
|
||||||
|
user="root",
|
||||||
|
group="root",
|
||||||
|
mode="755"
|
||||||
|
)
|
||||||
|
|
||||||
# as per https://doc.dovecot.org/configuration_manual/os/
|
# as per https://doc.dovecot.org/configuration_manual/os/
|
||||||
# it is recommended to set the following inotify limits
|
# it is recommended to set the following inotify limits
|
||||||
for name in ("max_user_instances", "max_user_watches"):
|
for name in ("max_user_instances", "max_user_watches"):
|
||||||
|
|||||||
@@ -9,3 +9,4 @@
|
|||||||
2 0 * * * vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/tmp/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
2 0 * * * vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/tmp/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
2 0 * * * vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/.*/tmp/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
2 0 * * * vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/.*/tmp/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
3 0 * * * vmail find /home/vmail/mail/{{ config.mail_domain }} -name 'maildirsize' -type f -delete
|
3 0 * * * vmail find /home/vmail/mail/{{ config.mail_domain }} -name 'maildirsize' -type f -delete
|
||||||
|
4 0 * * * vmail /usr/local/bin/remove-seen.py /home/vmail/mail/{{ config.mail_domain }}
|
||||||
|
|||||||
41
cmdeploy/src/cmdeploy/dovecot/remove-seen.py
Executable file
41
cmdeploy/src/cmdeploy/dovecot/remove-seen.py
Executable file
@@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Remove seen messages that are older than two days
|
||||||
|
if maildir has more than 80 MB of messages."""
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def getdirsize(path):
|
||||||
|
return sum(f.stat().st_size for f in path.glob("**/*") if f.is_file())
|
||||||
|
|
||||||
|
|
||||||
|
def parse_dovecot_seen(path):
|
||||||
|
return "S" in path.name.split(":2,")[-1]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
now = time.time()
|
||||||
|
|
||||||
|
mailhome = Path(sys.argv[1])
|
||||||
|
|
||||||
|
for p in mailhome.iterdir():
|
||||||
|
dirsize = getdirsize(p / "cur") + getdirsize(p / "new")
|
||||||
|
if dirsize < 80000000:
|
||||||
|
continue
|
||||||
|
|
||||||
|
removed_bytes = 0
|
||||||
|
for mailpath in (p / "cur").iterdir():
|
||||||
|
seen = parse_dovecot_seen(mailpath)
|
||||||
|
stat = mailpath.stat()
|
||||||
|
size = stat.st_size
|
||||||
|
if seen and now > stat.st_mtime + 2 * 24 * 3600:
|
||||||
|
removed_bytes += size
|
||||||
|
mailpath.unlink(missing_ok=True)
|
||||||
|
|
||||||
|
if removed_bytes > 0:
|
||||||
|
(p / "maildirsize").unlink(missing_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user