Sieve scripts are still wonky

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

  1. In the RCPT_TO stage, setting envelope.to seems 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.
  2. 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

  1. The subaddressing doesn’t appear in the envelope.to variable at this stage making filtering and sorting the mail impossible (this used to work in 0.15.x). envelope.to at this step only contains the final delivered email (the same content as in the Delivered-To header)
  2. Nor does if envelope :detail “to” works at this step
  3. Accessing ${2} anywhere in the script doesn’t return an error, but instead give some values L. This is unexpected (I was using the 2nd catch group of a regex that should have been empty, but it contained L instead)
  4. 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 just fwd\.bob@domain\.com and it’ll fail. But [email protected] matches fine with fwd\+bob@domain\\.com.