Commit graph parsimony/internal/app/app.go
Author SHA1 Message Date
tgiachi
8d28e48360 feat: configurable cap on confirmation requests, with a warning
When the global cap of unconfirmed requests (300 an hour) was reached,
a subscribe request silently got no mail while the visitor saw "Check
your email"; a newsletter launch can pass 300 signups an hour.

- limits.pending_per_hour (default 300, must be a whole number >= 1)
  is validated at load and set on the store by the app.
- When the global cap refuses a request the store logs a warning naming
  the setting, at most once a minute. The visitor still gets the
  neutral page, so nothing about members is revealed. The per-address
  cap is unchanged and is not logged.
- parsimony.example.yaml documents the setting.
2026-11-10 15:14:04 +01:00
tgiachi
44b3f9d98a fix(web): key the subscribe limit on the real client
Behind a reverse proxy every visitor shared the proxy's address, so the
whole site got 10 signups an hour and one person could block everyone.
Over IPv6 each address of a /64 was a fresh key, so the limit did not
bind and the map grew by one entry per address.

- web.trusted_proxies (addresses or CIDR ranges, default empty) is
  validated at load and passed to the web handler. X-Forwarded-For is
  read only when the TCP peer is a trusted proxy; the client is then the
  right-most entry that is not itself a trusted proxy. An empty or
  malformed header falls back to the peer. With no trusted proxy the
  behaviour is unchanged: the header is ignored.
- IPv6 clients are keyed by their /64, IPv4 clients by address.
- The limiter remembers at most 100000 clients. When full it sweeps
  expired entries first and otherwise answers 429 to new clients until
  the oldest window ends, instead of growing.
2026-11-10 15:11:26 +01:00
tgiachi
adeae3f451 feat(app): pass relay.rate_per_second to the queue worker
- one line of wiring, a commented example in parsimony.example.yaml
- tests: with a rate of 20/s eight deliveries to a sink take at least 350 ms, without a rate they are not paced
2026-11-10 12:37:15 +01:00
tgiachi
5af20f5891 Merge branch 'fix/dup-and-shutdown' into fix/fable-mediums 2026-11-10 12:01:06 +01:00
tgiachi
13e3d16723 fix(app): let LMTP sessions and HTTP requests finish on Close
Close cut the LMTP connections while their handlers still ran, so a post
committed to the queue could lose its 250 and be sent again by the MTA.

- Close stops accepting, waits for the LMTP Serve loop to return, then
  calls smtp.Server.Shutdown and http.Server.Shutdown with one shared
  deadline (shutdownTimeout, 30 s)
- when the deadline passes, the LMTP connections still open are cut
  through a tracking listener (smtp.Server.Close is a no-op once Shutdown
  began) and the HTTP servers are closed
- the queue worker and the store stop only after that
- tests: a post in flight during Close is queued and gets its 250; a hung
  client is cut after the grace period; the open-connections test uses a
  short grace period
2026-11-10 11:55:45 +01:00
tgiachi
38552f8025 fix(app): add read, write and idle timeouts to the HTTP servers
- the API + admin UI server and the public web server get ReadTimeout 30s,
  WriteTimeout 60s and IdleTimeout 120s next to ReadHeaderTimeout
- the archive import extends its own read and write deadlines to 30
  minutes with http.ResponseController, so a big mbox is not cut
- tests: a stalled body and an idle connection are cut on both servers,
  an import longer than the default timeouts succeeds, fields are pinned
- README: document the limits and timeouts
2026-11-10 11:54:50 +01:00
tgiachi
a6601caed7 feat(app): send through the configured relay with TLS and authentication
- Read the relay password and CA file at startup; refuse to start on an unusable one
- Pass TLS mode, server name, CA pool, credentials and EHLO name to the SMTP relay
- Default the EHLO name to the host name
- Test an authenticating STARTTLS relay, a wrong password (mail stays queued) and the startup checks
- Document external relays in the README and the example config
2026-11-10 11:05:24 +01:00
tgiachi
064e8beed8 fix(security): LMTP allow list and a warning for an open LMTP port
- Add lmtp.allow: clients outside the list are dropped before the greeting (TCP only)
- Validate the list at load, naming the bad entry
- Warn at startup when LMTP is reachable beyond the machine and no list is set
- Stop publishing the LMTP port in the README and the example config; add Security notes
2026-11-09 20:20:35 +01:00
tgiachi
dca9117a2e feat(app): sign outgoing mail with the configured DKIM keys
- Load the keys at startup and refuse to start on a broken one
- Sign every outgoing message, confirmation mail included, with the key of its From domain
- Send unsigned when the domain has no key
2026-11-09 19:59:57 +01:00
tgiachi
6c95184adc feat: deliver through the persistent queue
- Router.Deliver queues one entry per recipient atomically; posts are accepted once queued
- LMTP answers 451 only when the database fails, never because the relay is down
- Confirmation mail uses the same queue
- Wire the worker into the daemon: relay.concurrency config, wake on enqueue, interrupt on Close
- Make SMTPRelay honour the context deadline and cancellation on a silent relay
- Test restart survival, relay outage with retry, and Close with a hung relay
2026-11-09 15:53:47 +01:00
tgiachi
5a0dd7f6d6 feat(adminui): embed the admin SPA and serve it next to the API
- Add internal/adminui with a SPA handler: index fallback for client routes, immutable caching for hashed assets, 404 for missing assets, security headers
- Answer 503 with a hint when the UI has not been built, so go build always works
- Mount the UI at / and the API at /api/ on the same listener, no CORS needed
- Scaffold admin/ with Vite, React, TypeScript, Tailwind v4, shadcn/ui and Vitest
2026-11-09 15:29:12 +01:00
tgiachi
8f64ac671d feat: serve the public web from the daemon and document the archive
- Add web.listen config (default 127.0.0.1:8081, empty disables)
- Start the public web in app, close it with the rest
- Add end-to-end test: archive stays private, becomes public, hides addresses, one-click unsubscribe works
- Cover mutation survivors: attachments, first text part, multibyte cap, member id 0, page clamp, API limit cap, closing connections
- Update OpenAPI, README and example config
2026-11-09 15:22:50 +01:00
tgiachi
7fc1bed7e9 fix(app): do not log closed listener errors on shutdown 2026-11-09 15:13:35 +01:00
tgiachi
952fada19c refactor: move daemon wiring into internal/app and test it end to end
- Add app.Start and App.Close, main only parses flags and waits for signals
- Add end-to-end test: API creates a list, LMTP posts, a fake relay receives VERP copies
- Cover disabled API, bad database, busy port and idempotent Close
- Fix a shutdown race: Close before Serve left the LMTP server blocked
2026-11-09 15:12:51 +01:00