#!/usr/bin/env bash
set -euo pipefail

# Starts rspamd in the background, then hands off to mailgoserver as the container's
# main (foreground) process.
#
# ponytail: no supervisor / restart-on-crash for rspamd here — if it dies mid-run, mail
# keeps flowing without the extra scoring rather than the container crashing (the
# built-in heuristic score in internal/mailstore/spam.go always runs regardless, and
# CheckRspamd swallows connection errors rather than rejecting mail over them — see
# internal/mailstore/rspamd.go). Add s6-overlay or supervisord if unattended rspamd
# uptime matters more than that.
rspamd -f &

# Give rspamd's normal worker a moment to bind :11333 before the first message can
# possibly arrive — purely cosmetic, mailgoserver degrades gracefully either way.
sleep 1

exec mailgoserver --host 0.0.0.0 "$@"
