Give the test account a mailbox, read with coreapp inbox

Mail an app sends to coreapp.test@<domain> (resets, invitations,
notifications) is now delivered: the account gets mailEnabled and a
homeDirectory (from extensibleObject, so it takes no uidNumber Superpanel
would give a person), older accounts on their next use. coreapp inbox
shows the newest 10 messages with their text (HTML as text, with links'
addresses); --clear empties it; removing the account removes its mail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 20:47:02 -07:00
co-authored by Claude Opus 5.5
parent c60d99baba
commit c337ba2530
7 changed files with 190 additions and 19 deletions
+10 -3
View File
@@ -467,9 +467,16 @@ Steps:
in its multi-user edition; `coreapp status` shows a database
version only for apps with one; signin runs in the app's folder;
deploy's last line no longer says "from the internet"
- [ ] A mailbox for the test account (`coreapp.test`), so mail to
it is delivered and `coreapp mail` could read it; needs the
Core's mailbox conventions (uidNumber, homeDirectory)
- Done 2026-12-03: the test account has a mailbox, and `coreapp
inbox [--clear]` reads it (coreapps test-inbox: the maildir on
the Core, newest 10, text or HTML as text with links). The
Core's mail server delivers to `mailEnabled: TRUE` entries and
its Dovecot needs `homeDirectory`; people have it from
`posixAccount`, which needs a `uidNumber`, so the test account
gets it from `extensibleObject` instead and never takes a
number Superpanel would give a person. Older entries get it on
the next use. Tested with Supermarket's password reset (sent
through its account, read with its link) and an HTML message
- Skill shortened 2026-12-03 (577 -> ~450 lines): sign-in details in
`references/sign-in.md`, publishing in `references/publishing.md`,
read when SKILL.md says. Rehearsed with Miniflux (upstream image,
+1
View File
@@ -94,6 +94,7 @@ each new app explains the files and the settings it gets.
| `coreapp check` | It answers at `https://<name>.<domain><health>` with a valid certificate |
| `coreapp core` | What the Core in the VM offers apps: PostgreSQL (and which extensions an app can enable), MariaDB, Authelia, the mail server and Traefik with their versions, Docker, and the machine |
| `coreapp mail` | What the Core's mail server did with the mail the app sent in the last day: accepted from its account, then delivered, deferred or bounced, with the reason (apps with `email`) |
| `coreapp inbox [--clear]` | The mail the Core's test account (`coreapp.test@<domain>`) got, the newest 10 with sender, subject and text (HTML as text, links' addresses shown), to check what the app sends; `--clear` empties it |
| `coreapp signin [path]` | Sign in to it as a browser would, with the Core's test account (`coreapp.test@<domain>`, made on the VM's Core when first needed), starting at `path` (default `/login`), and show each step; `--cookies <file>` keeps the app's cookies, `--code` gets a code for apps that start sign-in in the browser, `--remove-account` removes the account |
| `coreapp status` / `logs [-f]` / `shell [command]` | Its container, its log, a shell in it (or one command, without a terminal) |
| `coreapp list` | The apps on the Core installed this way |
+16 -4
View File
@@ -478,10 +478,22 @@ has the `DB_*` variables, `.coreapp` says `needs=postgres`.
account and adds the `SMTP_*` settings.
7. `coreapp mail` after the app sent a message (Supermarket: a password
reset for `coreapp.test@<domain>`): "<time> from <name>@<domain>,
accepted", then "to coreapp.test@<domain>: deferred (... 451 4.3.0 ...
Temporary internal error ...)" (the test account has no mailbox), one
line per message even after retries. No mail in the last day: "has no
mail from <name>". In an app without "email": refused.
accepted", then "to coreapp.test@<domain>: sent", one line per message
even after retries. No mail in the last day: "has no mail from
<name>". In an app without "email": refused.
8. `coreapp inbox` (anywhere): the same reset is there, "From: Supermarket
<supermarket@<domain>>", its subject and text with the `/reset/...`
link. An HTML-only message shows as text, `Confirm
<https://...>` for a link, without its `<style>`; an encoded subject
(`=?utf-8?q?...`) is decoded. `--clear` says how many it removed, then
"inbox is empty". The test account's LDAP entry has
`PostfixBookMailAccount`, `extensibleObject`, `mailEnabled: TRUE` and
`homeDirectory: /home/coreapp.test` and no `uidNumber`; an entry made
before (without them) gets them on the next `coreapp signin` or
`coreapp inbox`, and mail deferred for it is then delivered. `coreapp
signin --remove-account` removes the entry and its maildir
(`/federated/apps/mail/data/var/mail/<domain>/coreapp.test`); `coreapp
inbox` makes both again. `coreapp signin` still signs in afterwards.
### With both
+19
View File
@@ -31,6 +31,8 @@
# get a code for the app's callback from Authelia
# coreapp signin --remove-account
# remove the test account from the Core
# coreapp inbox [--clear] the mail the test account (coreapp.test@<domain>)
# got, newest 10 with their text; --clear empties it
# coreapp remove uninstall it from the Core (asks first)
# coreapp list the apps on the Core installed this way
# coreapp install [--downgrade] <https://host/owner/repo>[@tag]
@@ -430,6 +432,22 @@ cmd_mail() {
core "$REMOTE_INSTALLER/coreapps mail $NAME"
}
# The test account's mailbox (made with the account): what apps sent it
cmd_inbox() {
local password
case "${1:-}" in
"") ;;
--clear) ;;
*) die "coreapp inbox [--clear]" ;;
esac
init_core; sync_installer
# Makes the account if it isn't there yet (or gives an older one its
# mailbox); its password is new and kept nowhere, as for signin
password="$(python3 -c 'import secrets; print(secrets.token_urlsafe(24))')"
printf '%s' "$password" | core "$REMOTE_INSTALLER/coreapps test-account" > /dev/null || exit 1
core "$REMOTE_INSTALLER/coreapps test-inbox ${1:-}"
}
cmd_core() {
init_core
sync_installer
@@ -643,6 +661,7 @@ case "$cmd" in
signin) cmd_signin "$@" ;;
core) cmd_core ;;
mail) cmd_mail ;;
inbox) cmd_inbox "$@" ;;
remove | rm) cmd_remove ;;
list | ls) cmd_list ;;
publish) cmd_publish "$@" ;;
+128 -3
View File
@@ -32,7 +32,9 @@ coreapps core what this Core offers apps: its services
and their versions, and the machine
coreapps test-account [--remove] make (or refresh, with the password on
stdin) the person coreapp signin signs
in with, or remove it
in with, or remove it (with its mailbox)
coreapps test-inbox [--clear] the newest mail in the test account's
mailbox (or empty it)
<source> is a folder with coreapp.toml (and icon.png), or a git
repository: https://host/owner/repo[@tag]. A private repository, and a
@@ -47,7 +49,10 @@ tier would record the app as a billable add-on and --addon-ok isn't given.
"""
import base64
import email.parser
import email.policy
import glob
import html.parser
import json
import os
import re
@@ -1565,6 +1570,15 @@ def app_mail(name, since="24h"):
# never an app's mail account (coreapp-<name>).
TEST_UID = "coreapp.test"
TEST_DESCRIPTION = "coreapps: test account for coreapp signin"
# Its mailbox, so mail apps send it is delivered (coreapp inbox reads it).
# The Core's mail server delivers to entries with mailEnabled TRUE, and its
# Dovecot needs a homeDirectory. People get that from posixAccount, which
# also needs a uidNumber; extensibleObject gives it without one, so the
# test account never takes a number Superpanel would give a person.
TEST_MAILBOX = {"objectClass": ["PostfixBookMailAccount", "extensibleObject"],
"mailEnabled": ["TRUE"], "homeDirectory": [f"/home/{TEST_UID}"]}
INBOX_SHOWN = 10
INBOX_TEXT = 4000
def ldap_base():
@@ -1589,6 +1603,7 @@ def test_account(remove=False):
raise Refused("Can't find the Core's LDAP settings.")
found = ldap(["ldapsearch", "-LLL", "-o", "ldif-wrap=no", "-b", base,
f"(|(uid={TEST_UID})(mail={mail}))", "description"])
maildir = test_maildir(domain)
if found.returncode != 0:
raise Refused(f"Can't search the Core's LDAP: {found.stderr.strip()}")
dn = f"uid={TEST_UID},ou=people,{base}"
@@ -1602,7 +1617,8 @@ def test_account(remove=False):
out = ldap(["ldapdelete", dn])
if out.returncode != 0:
raise Refused(f"Can't remove {dn}: {out.stderr.strip()}")
say(f"Removed the test account {mail}.")
shutil.rmtree(maildir, ignore_errors=True)
say(f"Removed the test account {mail}, with its mailbox.")
else:
say("There's no test account.")
return 0
@@ -1619,9 +1635,11 @@ sn: Test
mail: {mail}
description: {TEST_DESCRIPTION}
userPassword: {{CRYPT}}!
""")
""" + "".join(f"{key}: {v}\n" for key, values in TEST_MAILBOX.items() for v in values))
if out.returncode != 0:
raise Refused(f"Can't add the test account: {out.stderr.strip()}")
else:
add_test_mailbox(dn)
# The server hashes it
out = ldap(["ldappasswd", "-T", "/dev/stdin", dn], password)
if out.returncode != 0:
@@ -1630,6 +1648,111 @@ userPassword: {{CRYPT}}!
return 0
def add_test_mailbox(dn):
"""Give a test account made before it had one its mailbox."""
found = ldap(["ldapsearch", "-LLL", "-o", "ldif-wrap=no", "-b", dn, "-s", "base",
"(objectClass=*)", *TEST_MAILBOX]).stdout.lower()
# Only the values it lacks: adding one that's there is an error
changes = []
for key, values in TEST_MAILBOX.items():
missing = [v for v in values if f"{key.lower()}: {v.lower()}" not in found]
if missing:
changes.append(f"add: {key}\n" + "".join(f"{key}: {v}\n" for v in missing))
if not changes:
return
out = ldap(["ldapmodify"], f"dn: {dn}\nchangetype: modify\n" + "-\n".join(changes))
if out.returncode != 0:
raise Refused(f"Can't give the test account its mailbox: {out.stderr.strip()}")
def test_maildir(domain):
"""Where the Core's mail server keeps the test account's mail."""
return os.path.join(APPS, "mail", "data", "var", "mail", domain.lower(), TEST_UID)
class TextOfHTML(html.parser.HTMLParser):
"""An HTML mail's text, with each link's address after it."""
def __init__(self):
super().__init__()
self.parts, self.href, self.skip = [], None, 0
def handle_starttag(self, tag, attrs):
if tag in ("style", "script", "head"):
self.skip += 1
elif tag == "a":
self.href = dict(attrs).get("href")
elif tag in ("br", "p", "div", "tr", "li", "h1", "h2", "h3", "table"):
self.parts.append("\n")
def handle_endtag(self, tag):
if tag in ("style", "script", "head"):
self.skip = max(0, self.skip - 1)
elif tag == "a" and self.href:
self.parts.append(f" <{self.href}>")
self.href = None
def handle_data(self, data):
if not self.skip:
self.parts.append(data)
def text(self):
lines = (" ".join(line.split()) for line in "".join(self.parts).splitlines())
return re.sub(r"\n{3,}", "\n\n", "\n".join(lines)).strip()
def mail_text(message):
"""A message's text: its plain-text part, or its HTML part as text."""
part = message.get_body(preferencelist=("plain", "html"))
if part is None:
return "(no text in it)"
try:
content = part.get_content()
except (LookupError, UnicodeError):
content = part.get_payload(decode=True).decode("utf-8", "replace")
if part.get_content_subtype() == "html":
parser = TextOfHTML()
parser.feed(content)
content = parser.text()
content = content.strip()
if len(content) > INBOX_TEXT:
content = content[:INBOX_TEXT] + f"\n... ({len(content) - INBOX_TEXT} more characters)"
return content
def test_inbox(clear=False):
"""The newest mail in the test account's mailbox, or empty it."""
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(".")]
if clear:
for path in paths:
os.remove(path)
say(f"Emptied {address}'s inbox ({len(paths)} message(s)).")
return 0
if not paths:
say(f"{address}'s inbox is empty. (coreapp mail shows whether the app's mail "
"was delivered.)")
return 0
paths.sort(key=os.path.getmtime)
shown = paths[-INBOX_SHOWN:]
say(f"{address}'s inbox: {len(paths)} message(s)"
+ (f", the newest {len(shown)}" if len(shown) < len(paths) else "") + ", oldest first.")
for path in shown:
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, '')}")
say("")
say(mail_text(message))
return 0
# --- Command line -----------------------------------------------------------------
def main(args):
@@ -1693,6 +1816,8 @@ def main(args):
return core_info()
if cmd == "test-account" and rest in ([], ["--remove"]):
return test_account(remove=bool(rest))
if cmd == "test-inbox" and rest in ([], ["--clear"]):
return test_inbox(clear=bool(rest))
sys.stderr.write(__doc__.split("\n\n", 2)[2].strip() + "\n")
return 2
+14 -8
View File
@@ -266,14 +266,19 @@ Most apps have SMTP settings; map these onto them. Mail to `SMTP_FROM`
isn't delivered anywhere (the account has no mailbox), so set a reply-to
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). There's no inbox to check that a test message arrived: send
one the app's usual way (e.g. a password reset for `coreapp.test@<domain>`),
then `coreapp mail`: 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 `coreapp.test@<domain>` is accepted and
then deferred ("451 ... Temporary internal error"), because the test
account has no mailbox; that's expected and shows the app's sending
works. Ask the user to confirm delivery to a real address.
app for it).
To test the app's mail, send to the Core's test account,
`coreapp.test@<domain>`, which has a mailbox: trigger the mail the app's
usual way (a password reset, an invitation or a notification for that
address; `coreapp signin` first if the app only knows people who signed
in), then `coreapp inbox` shows what arrived (sender, subject and text,
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.
### Not available yet
@@ -437,6 +442,7 @@ isn't the admin: ask the user to sign in once in a browser as
|---|---|
| `coreapp status` | Its container, address, port, needs, URL, and the Core's PostgreSQL or MariaDB version if it needs one |
| `coreapp mail` | What the Core's mail server did with the mail it sent (apps with `email`) |
| `coreapp inbox [--clear]` | The mail the test account got: the newest 10, with their text (`--clear` empties it) |
| `coreapp logs` / `coreapp logs -f` | The app's own log |
| `coreapp signin [path]` | Signs in with the Core's test account and shows each step |
| `coreapp shell '<command>'` | Run one command in its container, e.g. `coreapp shell 'id; env; ls -l /data'` (without a command it opens an interactive shell, which needs a terminal) |
+2 -1
View File
@@ -98,7 +98,8 @@ else gets the lowest role that can look around. How:
`coreapp signin` signs in to the app as a browser would, on the real
Authelia with the app's real client, as the Core's test account
(`coreapp.test@<domain>`, display name `coreapp.test`, in no groups; made
on the Core in the VM when first needed, with a new password each time).
on the Core in the VM when first needed, with a new password each time;
it has a mailbox, read with `coreapp inbox`).
It prints each step, with Authelia's error if the client doesn't fit, and
says whether it got back to the app signed in. Run it in the app's folder
(it reads `coreapp.toml`).