I wanted to migrate from postfix + dovecot to stalwart, but was stumbling upon my sieve scripts.
Dovecot’s sieve implementation pigeonhole provides a simple extension called extprograms to allow execution of arbitrary, but especially selected scripts.
Those allow to e.g. store emails into the correct maildir by evaluating their tags and creating the maildirs on the fly and using their output then as argument for a fileinto.
Such a sieve script would look like this:
Or to act upon the whole mail and e.g. upload attachments with the associated tags to paperless (whilst I admit, is a rather unusual and kinda questionable use case).
This saves a lot of server resources in contrast to using a polling IMAP/JMAP agent to do this and integrates nicely with other sieve extensions like notify.
I could also try to implement this myself, if desired and you pinpoint me to the correct implementation place.