This adds an intermediate Postgres-backed queue for inbound messages, that allows us to run filters like spam processing before inserting messages in their final storage (soon to be object storage). Also include misc. refactorings.
ST Messages MPA (Mail Processing Agent)
The MPA container provides spam filtering capabilities using rspamd.
It exposes rspamd's HTTP API for spam checking via the /checkv2 endpoint, which is used by the backend to analyze incoming messages before delivery.
The service is entirely stateless and configurable via environment variables.
Architecture
The MPA container runs:
- rspamd: The spam filtering engine
- nginx: Reverse proxy for the rspamd HTTP API
After receiving an email, the backend sends it to rspamd's /checkv2 API endpoint for spam analysis. The response includes:
action: The recommended action (reject,add header,greylist, orno action)score: The spam scorerequired_score: The threshold for rejectionis_skipped: Whether the check was skipped
Messages with action: "reject" are marked as spam and stored with the is_spam flag set.
Configuration
The service is configured via environment variables:
RSPAMD_password: Password for rspamd API authenticationPORT: Port on which nginx listens (default: 8010)
API Usage
The rspamd API is accessible at http://mpa:8010/_api/checkv2 (internal) or http://localhost:8918/_api/checkv2 (external).
Requests should include:
Content-Type: message/rfc822headerAuthorization: {RSPAMD_AUTH}header (whereRSPAMD_AUTHis the configured auth value, e.g.,Bearer passwordor justpassword)- Raw email message bytes in the request body
Example response:
{
"is_skipped": false,
"score": 15.0,
"required_score": 15.0,
"action": "reject",
"thresholds": {
"reject": 15.0,
"add header": 6.0,
"greylist": 4.0
},
"symbols": {...},
"messages": {},
"time_real": 0.184484
}
Testing
To run the tests, go to the repository root and do:
make mpa-test
The test suite includes:
- Health check verification
- Empty message spam detection
- Simple valid message processing