From 491af8745ff9f3e3956d67658e08db2e904e04be Mon Sep 17 00:00:00 2001 From: David Young Date: Fri, 4 Dec 2026 13:45:11 -0700 Subject: [PATCH] New-app rehearsal: mail refusals, Junk in inbox, Reply-To coreapp mail lists mail the Core's mail server refused for sending too fast (2 messages a minute per app; the refusal has no queue id, so it was missing). coreapp inbox reads the test account's Junk folder too, marked as such, and shows Reply-To. New apps ignore __pycache__. Skill: the mail limit (queue, send again on a 4xx), Date and Message-ID, a regular member role where taking part is the point, testing what takes two people, the only readable mailbox, what coreapp new makes. Co-Authored-By: Claude Opus 5.5 --- PLAN.md | 28 +++++++++++++++++++++++ TEST.md | 9 ++++++++ core/coreapps | 45 ++++++++++++++++++++++++++++--------- skills/coreapp/SKILL.md | 39 +++++++++++++++++++++++++++----- templates/app/.dockerignore | 1 + templates/app/.gitignore | 1 + 6 files changed, 108 insertions(+), 15 deletions(-) create mode 100644 templates/app/.gitignore diff --git a/PLAN.md b/PLAN.md index af0f46f..4a9bb4e 100644 --- a/PLAN.md +++ b/PLAN.md @@ -101,6 +101,14 @@ What we learned provisioning (2026-12-02/03): - `/federated/bin/upgrade` has an API token in it, readable by anyone with the image; `lib/functions.sh` has the monitoring registrar's bearer token, and `uninstallapp`'s `set -x` prints it + - The mail server takes 2 messages a minute from each client + (`smtpd_client_message_rate_limit = 2`, `anvil_rate_time_unit = + 60s`) and refuses the rest with 450; every app container is its + own client. Enough for password resets, but a newsletter (listmonk) + or a burst of notifications goes out at 120 an hour. If apps should + send more, a higher limit for the `core` network + (`smtpd_client_event_limit_exceptions`) or for the submission + service would do it - `bin/start` doesn't know apps outside its fixed lists, so a new app in the generic format isn't started by `installapp` @@ -579,6 +587,26 @@ Steps: - [ ] David: sign in to listmonk-app as admin@dev.fedcom.net (Super Admin, Settings), and send a campaign from `listmonk-app@dev.fedcom.net`; remove it when done + - Rehearsed 2026-12-04 with a new app from scratch, Lending Shelf + (`coreapp new --postgres --sso --email`; Python, postgres, sso, + email): deployed at `https://lending-shelf.dev.fedcom.net/`, Core + SSO sign-in (a new account's first), the lending flow end to end + with a second person and the admin made as sessions inside the + container, all four kinds of notification read with `coreapp + inbox`, data kept by `--recreate`. Found: the Core's mail server + takes 2 messages a minute from an app (see "Tell Federated"). + Fixed from it: `coreapp mail` shows mail refused for that (the + refusal has no queue id, so it was missing), `coreapp inbox` + shows `Reply-To` and reads the Junk folder too (a message + without `Date` and `Message-ID` was filed there as spam), and new + apps ignore `__pycache__`. Skill: the mail limit (queue mail, + send again on a 4xx), `Date`/`Message-ID`, a regular member role + for apps where taking part is the point, testing what takes two + people, the test account's is the only readable mailbox, what + `coreapp new` makes (the publish workflow, the README to rewrite; + `--email`/`--mysql` add only the need) + - [ ] David: sign in to lending-shelf as admin@dev.fedcom.net in + a browser ("(admin)", remove a listing); remove it when done - Rehearsed 2026-12-04 with Open WebUI (upstream Python image, the slim variant; postgres with `vector`, sso): deployed at `https://open-webui.dev.fedcom.net/`, its data and vector store diff --git a/TEST.md b/TEST.md index 06fb46f..b419dac 100644 --- a/TEST.md +++ b/TEST.md @@ -543,6 +543,15 @@ has the `DB_*` variables, `.coreapp` says `needs=postgres`. signin --remove-account` removes the entry and its maildir (`/federated/apps/mail/data/var/mail//coreapp.test`); `coreapp inbox` makes both again. `coreapp signin` still signs in afterwards. + A message with `Reply-To` shows it under `From`; one the spam filter + filed in the test account's Junk folder (sent without `Date` and + `Message-ID`) is listed too, marked "(in Junk: ...)", and `--clear` + empties both. +9. An app that sends more than 2 messages within a minute: the third + gets `450 4.7.1 ... too much mail`, and `coreapp mail` lists it as + "refused: too much mail at once (temporary, 450)" in time order with + the accepted ones, then a line on the limit. Refusals of another app + (a name that ends the same) aren't listed. ### With both diff --git a/core/coreapps b/core/coreapps index cc0ca5b..7c5c4fe 100755 --- a/core/coreapps +++ b/core/coreapps @@ -1671,6 +1671,11 @@ def core_info(): # --- The app's mail (coreapp mail) --------------------------------------------------- +# Messages a minute the Core's mail server takes from one client +# (smtpd_client_message_rate_limit in Federated's mail server) +MAIL_RATE = 2 + + def app_mail(name, since="24h"): """What the Core's mail server did with the mail the app sent: accepted from its account, then delivered, deferred or bounced, per recipient.""" @@ -1680,16 +1685,28 @@ def app_mail(name, since="24h"): lines = (out.stdout + out.stderr).splitlines() account = re.compile(r" ([0-9A-F]{6,}): client=\S+, sasl_method=\S+, sasl_username=coreapp-" + re.escape(name) + r"@") - ids = {} + # Refused before it had a queue id: the mail server takes only so many + # messages a minute from one client (anvil), and names the client by + # its container's name on the core network + limited = re.compile(r"rate limit exceeded: \d+ from " + re.escape(name) + r"\.core\[") + events = [] for line in lines: + when = line[:19].replace("T", " ") found = account.search(line) if found: - ids[found.group(1)] = line[:19].replace("T", " ") - if not ids: + events.append((when, found.group(1))) + elif limited.search(line): + events.append((when, None)) + if not events: say(f"The Core's mail server has no mail from {name} in the last {since} " f"(from its account, coreapp-{name}).") return 0 - for qid, when in list(ids.items())[-20:]: + refused = 0 + for when, qid in events[-20:]: + if qid is None: + refused += 1 + say(f"{when} refused: too much mail at once (temporary, 450)") + continue sender, results = "", [] for line in lines: if f" {qid}: " not in line: @@ -1707,6 +1724,9 @@ def app_mail(name, since="24h"): say(r) if not results: say(" (no delivery yet)") + if refused: + say(f"The Core's mail server takes {MAIL_RATE} messages a minute from an app; " + "it refuses the rest for now (450), and the app has to send them again later.") return 0 @@ -1874,9 +1894,11 @@ def test_inbox(clear=False): domain, _ = federated_settings() address = f"{TEST_UID}@{domain}" folder = test_maildir(domain) - paths = [os.path.join(folder, sub, f) for sub in ("new", "cur") - if os.path.isdir(os.path.join(folder, sub)) - for f in os.listdir(os.path.join(folder, sub)) if not f.startswith(".")] + # The inbox and the Junk folder, where the mail server's spam filter + # puts mail that looks like spam (an app's mail can, too) + paths = [os.path.join(folder, box, sub, f) for box in ("", ".Junk") for sub in ("new", "cur") + if os.path.isdir(os.path.join(folder, box, sub)) + for f in os.listdir(os.path.join(folder, box, sub)) if not f.startswith(".")] if clear: for path in paths: os.remove(path) @@ -1894,9 +1916,12 @@ def test_inbox(clear=False): with open(path, "rb") as f: message = email.parser.BytesParser(policy=email.policy.default).parse(f) when = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(os.path.getmtime(path))) - say(f"\n=== {when} UTC") - for header in ("From", "To", "Subject"): - say(f"{header}: {message.get(header, '')}") + junk = os.sep + ".Junk" + os.sep in path + say(f"\n=== {when} UTC" + (" (in Junk: the mail server's spam filter took it for spam)" + if junk else "")) + for header in ("From", "Reply-To", "To", "Subject"): + if header != "Reply-To" or message.get(header): + say(f"{header}: {message.get(header, '')}") say("") say(mail_text(message)) return 0 diff --git a/skills/coreapp/SKILL.md b/skills/coreapp/SKILL.md index e99681c..f069bab 100644 --- a/skills/coreapp/SKILL.md +++ b/skills/coreapp/SKILL.md @@ -248,7 +248,9 @@ Two rules for who may do what, on every Core: Core account may sign in, without an invitation, as a read-only member (a viewer). The app's admins raise people from there. In an app where each person has only their own private things (a feed reader, notes), - a regular user is the lowest role. + or where taking part is the point and each person changes only their + own things (listing what they lend, posting on a board), a regular + member is the lowest role; say so in your report. **Before writing sign-in code, read [references/sign-in.md](references/sign-in.md):** how to find what the app @@ -276,6 +278,17 @@ if people should be able to answer. The account can't sign in to anything else on the Core. `coreapp new --email` adds the need (there's no example app for it). +The Core's mail server takes **2 messages a minute** from an app and +refuses the rest for now (`450 4.7.1 too much mail`). So don't send mail +inside the request that causes it; queue it (in the database, so a restart +doesn't lose it) and send from a background worker that sends a refused +message again later (after a minute, then longer). An app's own SMTP +settings usually do this already; check, and say in your report if it +drops mail on a 4xx. Notifications to many people (a newsletter) go out +slowly: 120 an hour. Give each message a `Date` and a `Message-ID` (most +mail libraries add them; Python's `smtplib` doesn't): without them the +Core's spam filter files it as junk. + To test the app's mail, send to the Core's test account, `coreapp.test@`, which has a mailbox: trigger the mail the app's usual way (a password reset, an invitation or a notification for that @@ -285,8 +298,14 @@ HTML as text with each link's address), so you can check it and follow its link. `coreapp inbox --clear` empties it before a test. If nothing arrives, `coreapp mail` shows what the Core's mail server did with each message from the app's account in the last day (accepted, then delivered, -deferred or bounced, with the reason). Mail to other addresses leaves -the Core; ask the user to confirm delivery to a real one. +deferred or bounced, with the reason; or refused for sending too fast). +`coreapp inbox` shows `From`, `Reply-To`, `To` and `Subject`, and lists +mail the spam filter put in the Junk folder too, marked as such: fix +what made it look like spam. +The test account's is the only mailbox you can read: to see mail meant +for a second person, give that person the test account's address. Mail +to other addresses leaves the Core; ask the user to confirm delivery to a +real one. ### Not available yet @@ -330,8 +349,11 @@ coreapp new --sso my-app # with sign-in (Python example) coreapp new --postgres --sso my-app # both ``` -It makes `./my-app` with a working example, `coreapp.toml` and a README. -Replace the example with the real app. +It makes `./my-app` with a working example, `coreapp.toml`, a README and +`.gitea/workflows/publish.yml` (publishes on a tag; see +references/publishing.md). Replace the example with the real app, and the +README's description of the example with the app's. `--email` and +`--mysql` only add the need; the app's mail and MySQL code are yours. ### 2b. An existing app (porting) @@ -374,6 +396,13 @@ got back to the app signed in; see isn't the admin: ask the user to sign in once in a browser as `admin@` before a release. +There's one test account. To test what takes two people (one asks, +another answers) or the admin's pages, make the other sessions inside the +container with the app's own code (`coreapp shell`: create the person's +row and a signed session the way the app's sign-in does, using the same +secret), then use their cookies with curl. Say in your report which +parts were tested that way rather than through a real sign-in. + ### 4. When something fails | Command | Shows | diff --git a/templates/app/.dockerignore b/templates/app/.dockerignore index 9e32a7a..d250e94 100644 --- a/templates/app/.dockerignore +++ b/templates/app/.dockerignore @@ -3,3 +3,4 @@ coreapp.toml icon.png README.md +__pycache__ diff --git a/templates/app/.gitignore b/templates/app/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/templates/app/.gitignore @@ -0,0 +1 @@ +__pycache__/