run sieve on maildir

For my mailserver I have a dovecot, postfix and sieve setup.

I have several hundred mails in my maildir and have recently created some sieve rules for sorting them. Unfortunatelly the sieve rules are by design only applied to incoming messages. Therefore my question:

How can I run sieve against messages in an already existing maildir?

Thanks

--- edit:

Thanks larsks

With the link you provided I ended up using:

mkdir todo
mkdir done
mv cur/* todo
for  i  in todo/*; do
    echo "Delivering message $i ..."
    /usr/lib/dovecot/deliver -d [email protected] < $i && mv $i done/
done

which works like I charm. I can rerun this script for every new filter I create.


I have searched a lot too - rarely documentated.

Meanwhile there is a command

sieve-filter

for it, found on this blog https://mebsd.com/configure-freebsd-servers/dovecot-pigeonhole-sieve-filter-refilter-delivered-email.html for a howto


There's not an easy way to do this, but according to this message you can write a shell script to re-deliver messages using Dovecot's deliver program...so something like this:

produce_message_list |
while read msg; do
  /usr/libexec/dovecot/deliver -d user < $msg && rm -f $msg
done

You'll have to replace produce_message_list with something that produces a list of messages for processing; possibly find will do what you need.