mirror of
https://github.com/chatmail/relay.git
synced 2026-05-19 12:28:06 +00:00
address link2xt review comments
This commit is contained in:
@@ -22,7 +22,7 @@ QuotaFileEntry = namedtuple("QuotaFileEntry", ("mtime", "quota_size", "path"))
|
|||||||
# Quota cleanup factor of max_mailbox_size. The mailbox is reset to this size.
|
# Quota cleanup factor of max_mailbox_size. The mailbox is reset to this size.
|
||||||
QUOTA_CLEANUP_FACTOR = 0.7
|
QUOTA_CLEANUP_FACTOR = 0.7
|
||||||
|
|
||||||
# e.g. "cur/1775324677.M448978P3029757.nine,S=3235,W=3305:2,S"
|
# e.g. "cur/1775324677.M448978P3029757.exam,S=3235,W=3305:2,S"
|
||||||
_dovecot_fn_rex = re.compile(r".+/(\d+)\..+,S=(\d+)")
|
_dovecot_fn_rex = re.compile(r".+/(\d+)\..+,S=(\d+)")
|
||||||
|
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ def parse_dovecot_filename(relpath):
|
|||||||
|
|
||||||
def scan_mailbox_messages(mbox):
|
def scan_mailbox_messages(mbox):
|
||||||
messages = []
|
messages = []
|
||||||
for sub in ("cur", "new", "tmp"):
|
for sub in ("cur", "new"):
|
||||||
for name in os_listdir_if_exists(mbox / sub):
|
for name in os_listdir_if_exists(mbox / sub):
|
||||||
if entry := parse_dovecot_filename(f"{sub}/{name}"):
|
if entry := parse_dovecot_filename(f"{sub}/{name}"):
|
||||||
messages.append(entry)
|
messages.append(entry)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import itertools
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
@@ -207,10 +208,13 @@ def test_os_listdir_if_exists(tmp_path):
|
|||||||
|
|
||||||
# --- quota expire tests ---
|
# --- quota expire tests ---
|
||||||
|
|
||||||
|
_msg_counter = itertools.count(1)
|
||||||
|
|
||||||
|
|
||||||
def _create_message(basedir, sub, size, days_old=0, disk_size=None):
|
def _create_message(basedir, sub, size, days_old=0, disk_size=None):
|
||||||
|
seq = next(_msg_counter)
|
||||||
mtime = int(time.time() - days_old * 86400)
|
mtime = int(time.time() - days_old * 86400)
|
||||||
name = f"{mtime}.M1P1.host,S={size},W={size}:2,S"
|
name = f"{mtime}.M1P1Q{seq}.hostname,S={size},W={size}:2,S"
|
||||||
path = basedir / sub / name
|
path = basedir / sub / name
|
||||||
path.parent.mkdir(parents=True, exist_ok=True)
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
path.write_bytes(b"x" * (disk_size if disk_size is not None else size))
|
path.write_bytes(b"x" * (disk_size if disk_size is not None else size))
|
||||||
@@ -219,23 +223,21 @@ def _create_message(basedir, sub, size, days_old=0, disk_size=None):
|
|||||||
|
|
||||||
|
|
||||||
def test_parse_dovecot_filename():
|
def test_parse_dovecot_filename():
|
||||||
e = parse_dovecot_filename("cur/1775324677.M448978P3029757.nine,S=3235,W=3305:2,S")
|
e = parse_dovecot_filename("cur/1775324677.M448978P3029757.exam,S=3235,W=3305:2,S")
|
||||||
assert e.path == "cur/1775324677.M448978P3029757.nine,S=3235,W=3305:2,S"
|
assert e.path == "cur/1775324677.M448978P3029757.exam,S=3235,W=3305:2,S"
|
||||||
assert e.mtime == 1775324677
|
assert e.mtime == 1775324677
|
||||||
assert e.quota_size == 3235
|
assert e.quota_size == 3235
|
||||||
assert parse_dovecot_filename("cur/msg_without_structure") is None
|
assert parse_dovecot_filename("cur/msg_without_structure") is None
|
||||||
|
|
||||||
|
|
||||||
def test_expire_to_target(tmp_path):
|
def test_expire_to_target(tmp_path):
|
||||||
# scans cur, new, tmp
|
|
||||||
_create_message(tmp_path, "cur", MB, days_old=10, disk_size=100)
|
_create_message(tmp_path, "cur", MB, days_old=10, disk_size=100)
|
||||||
_create_message(tmp_path, "new", MB, days_old=5)
|
_create_message(tmp_path, "new", MB, days_old=5)
|
||||||
_create_message(tmp_path, "tmp", MB, days_old=1)
|
|
||||||
assert len(scan_mailbox_messages(tmp_path)) == 3
|
|
||||||
# removes oldest first, uses S= size not disk size
|
|
||||||
removed = expire_to_target(tmp_path, 2 * MB)
|
|
||||||
assert removed == 1
|
|
||||||
assert len(scan_mailbox_messages(tmp_path)) == 2
|
assert len(scan_mailbox_messages(tmp_path)) == 2
|
||||||
|
# removes oldest first, uses S= size not disk size
|
||||||
|
removed = expire_to_target(tmp_path, MB)
|
||||||
|
assert removed == 1
|
||||||
|
assert len(scan_mailbox_messages(tmp_path)) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_quota_expire_main(tmp_path, capsys):
|
def test_quota_expire_main(tmp_path, capsys):
|
||||||
|
|||||||
Reference in New Issue
Block a user