In the end, I figured out a hacky way. I’m parsing the “To” header in the user script, since this isn’t modified by the system.
None of the sieve features are working. The notify trick is very helpful to figure out what’s going on.
The issue with sieves are:
In system script
- In the RCPT_TO stage, setting
envelope.toseems to work in the script itself, but Stalwart still use the initial value for validating the account and thus fail with Mailbox doesn’t exist error. This is opposite to the documentation that shows a rewrite example that doesn’t work. - Adding an header in the RCPT_TO stage is completely ignored in the next stages. The header isn’t in the final delivered mail. Maybe it’s expected, but there’s no error whatsoever in the logs. I haven’t tried in the DATA stage, maybe it works here
In user script
- The subaddressing doesn’t appear in the
envelope.tovariable at this stage making filtering and sorting the mail impossible (this used to work in 0.15.x).envelope.toat this step only contains the final delivered email (the same content as in theDelivered-Toheader) - Nor does
if envelope :detail “to”works at this step - Accessing
${2}anywhere in the script doesn’t return an error, but instead give some valuesL. This is unexpected (I was using the 2nd catch group of a regex that should have been empty, but it containedLinstead) - regex matches on a text where it shouldn’t. Sometimes, I have to double escape a special char (like
\\.but not\\+) in the script. Try matching[email protected]with justfwd\.bob@domain\.comand it’ll fail. But[email protected]matches fine withfwd\+bob@domain\\.com.