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 <noreply@anthropic.com>
This commit is contained in:
2026-12-04 13:45:11 -07:00
co-authored by Claude Opus 5.5
parent b855fd53f4
commit 491af8745f
6 changed files with 108 additions and 15 deletions
+35 -10
View File
@@ -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