From 2817ffd41132027e7f6febc01011700b1301e89b Mon Sep 17 00:00:00 2001 From: missytake Date: Tue, 12 Dec 2023 22:40:06 +0100 Subject: [PATCH] www: get actual account restrictions from chatmail.ini --- cmdeploy/src/cmdeploy/cmdeploy.py | 10 +++- .../cmdeploy/tests/online/test_2_deltachat.py | 2 +- cmdeploy/src/cmdeploy/www.py | 59 +++++++++++++++++++ www/src/info.md | 23 ++++++-- 4 files changed, 86 insertions(+), 8 deletions(-) diff --git a/cmdeploy/src/cmdeploy/cmdeploy.py b/cmdeploy/src/cmdeploy/cmdeploy.py index 7793abb3..d717f74a 100644 --- a/cmdeploy/src/cmdeploy/cmdeploy.py +++ b/cmdeploy/src/cmdeploy/cmdeploy.py @@ -130,7 +130,15 @@ def test_cmd(args, out): out.check_call(f"{sys.executable} -m pip install deltachat") pytest_path = shutil.which("pytest") - pytest_args = [pytest_path, "cmdeploy/src/", "-n4", "-rs", "-x", "-vrx", "--durations=5"] + pytest_args = [ + pytest_path, + "cmdeploy/src/", + "-n4", + "-rs", + "-x", + "-vrx", + "--durations=5", + ] if args.slow: pytest_args.append("--slow") ret = out.run_ret(pytest_args) diff --git a/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py b/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py index a6e789ad..c9bacbeb 100644 --- a/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py +++ b/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py @@ -34,7 +34,7 @@ class TestEndToEndDeltaChat: Example input: 100M, 2.4T, 500 K """ units = {"B": 1, "K": 2**10, "M": 2**20, "G": 2**30, "T": 2**40} - size = re.sub(r'([KMGT])', r' \1', limit.upper()) + size = re.sub(r"([KMGT])", r" \1", limit.upper()) number, unit = [string.strip() for string in size.split()] return int(float(number) * units[unit]) diff --git a/cmdeploy/src/cmdeploy/www.py b/cmdeploy/src/cmdeploy/www.py index 40bebe2e..b7b2c2a1 100644 --- a/cmdeploy/src/cmdeploy/www.py +++ b/cmdeploy/src/cmdeploy/www.py @@ -36,6 +36,53 @@ def build_webpages(src_dir, build_dir, config): print(traceback.format_exc()) +def timespan_to_english(timespan): + val = int(timespan[:-1]) + c = timespan[-1].lower() + match c: + case "y": + return f"{val} years" + case "m": + return f"{val} months" + case "w": + return f"{val} weeks" + case "d": + return f"{val} days" + case "h": + return f"{val} hours" + case "c": + return f"{val} seconds" + case _: + raise ValueError( + c + + " is not a valid time unit. Try [y]ears, [w]eeks, [d]ays, or [h]ours" + ) + + +def int_to_english(number): + if number >= 0 and number <= 12: + a = [ + "zero", + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine", + "ten", + "eleven", + "twelve", + ] + return a[number] + elif number <= 50: + return str(number) + if number > 50: + return "more" + + def _build_webpages(src_dir, build_dir, config): mail_domain = config.mail_domain assert src_dir.exists(), src_dir @@ -48,6 +95,18 @@ def _build_webpages(src_dir, build_dir, config): for path in src_dir.iterdir(): if path.suffix == ".md": render_vars, content = prepare_template(path) + render_vars["username_min_length"] = int_to_english( + config.username_min_length + ) + render_vars["username_max_length"] = int_to_english( + config.username_max_length + ) + render_vars["password_min_length"] = int_to_english( + config.password_min_length + ) + render_vars["delete_mails_after"] = timespan_to_english( + config.delete_mails_after + ) target = build_dir.joinpath(path.stem + ".html") # recursive jinja2 rendering diff --git a/www/src/info.md b/www/src/info.md index bc390886..bd479e7f 100644 --- a/www/src/info.md +++ b/www/src/info.md @@ -9,10 +9,21 @@ In the Delta Chat account setup you may tap `LOG INTO YOUR E-MAIL ACCOUNT` and fill the two fields like this: -- `Address`: invent a word with *exactly* nine characters - and append `@{{config.mail_domain}}` to it. +- `Address`: invent a word with +{% if username_min_length == username_max_length %} + *exactly* {{ username_min_length }} +{% else %} + {{ username_min_length}} + {% if username_max_length == "more" %} + or more + {% else %} + to {{ username_max_length }} + {% endif %} +{% endif %} + characters + and append `@{{config.mail_domain}}` to it. -- `Password`: invent at least 9 characters. +- `Password`: invent at least {{ password_min_length }} characters. If the e-mail address is not yet taken, you'll get that account. The first login sets your password. @@ -24,11 +35,11 @@ The first login sets your password. {{config.mail_domain}} but setting up contact via [QR invite codes](https://delta.chat/en/help#howtoe2ee) allows your messages to pass freely to any outside recipients. -- You may send up to 60 messages per minute +- You may send up to {{ config.max_user_send_per_minute }} messages per minute. -- Seen messages are removed 40 days after arriving on the server +- Seen messages are removed {{ delete_mails_after }} after arriving on the server. -- You can store up to [100MB messages on the server](https://delta.chat/en/help#what-happens-if-i-turn-on-delete-old-messages-from-server) +- You can store up to [{{ config.max_mailbox_size }} messages on the server](https://delta.chat/en/help#what-happens-if-i-turn-on-delete-old-messages-from-server). ### Who are the operators? Which software is running?