Your question
Is it possible to limit the maximum number of emails in a folder (as a user, server-side)? For example, I subscribe to a mailing list and only want to keep the 1000 newest mails in that folder. I didn’t find a setting in the web ui (/account). Can it be done with sieve?
Using Stalwart 0.16.9 (Podman)
There is no built-in server-side setting (in the WebUI or otherwise) to cap the number of messages in a specific folder. Stalwart’s auto-expunge feature only targets Trash and Junk by age, not by count, and there is no per-folder message-count quota exposed to users.
Can Sieve do it? Standard Sieve extensions supported by Stalwart do not include a way to query the current message count of a mailbox at delivery time (there is no RFC-standard mailboxsize or messagecount test). So a pure Sieve approach to “keep only the newest 1000” is not directly possible either.
Practical alternatives to consider:
- Client-side rules: Most mail clients (Thunderbird, Apple Mail, etc.) support local rules that can delete messages over a certain count in a folder. This is the most practical approach today.
- IMAP tooling: A script using an IMAP client library (e.g. Python
imaplib) run as a cron job could enforce the limit externally.
- Age-based expunge (server-side): If you are an admin, you can configure
expungeTrashAfter on the DataRetention singleton for Trash/Junk folders, but there is no equivalent count-based or arbitrary-folder setting documented. See the maintenance docs for what is available.
In short, a server-side per-folder message-count cap for arbitrary folders is not a feature currently documented for Stalwart.
This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.