introduce max_message_size config option

This commit is contained in:
holger krekel
2024-07-28 18:16:04 +02:00
parent 4858a67be1
commit ac1f2dadad
6 changed files with 15 additions and 6 deletions

View File

@@ -20,6 +20,7 @@ class Config:
self.mail_domain = params["mail_domain"]
self.max_user_send_per_minute = int(params["max_user_send_per_minute"])
self.max_mailbox_size = params["max_mailbox_size"]
self.max_message_size = int(params.get("max_message_size", "31457280"))
self.delete_mails_after = params["delete_mails_after"]
self.delete_inactive_users_after = int(params["delete_inactive_users_after"])
self.username_min_length = int(params["username_min_length"])
@@ -73,7 +74,7 @@ def write_initial_config(inipath, mail_domain, overrides):
new_line = line.strip()
if new_line and new_line[0] not in "#[":
name, value = map(str.strip, new_line.split("=", maxsplit=1))
value = overrides.pop(name, value)
value = extra.pop(name, value)
new_line = f"{name} = {value}"
new_lines.append(new_line)

View File

@@ -17,6 +17,9 @@ max_user_send_per_minute = 60
# maximum mailbox size of a chatmail address
max_mailbox_size = 100M
# maximum message size for an e-mail in bytes
max_message_size = 31457280
# days after which mails are unconditionally deleted
delete_mails_after = 20

View File

@@ -14,10 +14,11 @@ from chatmaild.config import read_config, write_initial_config
def make_config(tmp_path):
inipath = tmp_path.joinpath("chatmail.ini")
def make_conf(mail_domain):
def make_conf(mail_domain, settings=None):
basedir = tmp_path.joinpath(f"vmail/{mail_domain}")
basedir.mkdir(parents=True, exist_ok=True)
overrides = dict(mailboxes_dir=str(basedir))
overrides = settings.copy() if settings else {}
overrides["mailboxes_dir"] = str(basedir)
write_initial_config(inipath, mail_domain, overrides=overrides)
return read_config(inipath)

View File

@@ -58,3 +58,8 @@ def test_config_userstate_paths(make_config, tmp_path):
with pytest.raises(ValueError):
config.get_user(".")
def test_config_max_message_size(make_config, tmp_path):
config = make_config("something.testrun.org", dict(max_message_size="10000"))
assert config.max_message_size == 10000

View File

@@ -15,7 +15,7 @@ def get_initial_remote_data(sshexec, mail_domain):
def check_initial_remote_data(remote_data, print=print):
mail_domain = remote_data["mail_domain"]
if not remote_data["A"] and not remote_data["AAAA"]:
print("Missing A and/or AAAA DNS records for {mail_domain}!")
print(f"Missing A and/or AAAA DNS records for {mail_domain}!")
elif not remote_data["MTA_STS"]:
print("Missing MTA-STS CNAME record:")
print(f"mta-sts.{mail_domain}. CNAME {mail_domain}")

View File

@@ -62,8 +62,7 @@ mydestination =
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
# maximum 30MB sized messages
message_size_limit = 31457280
message_size_limit = {{config.max_message_size}}
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all