I recently restructured my email setup and updated my sieve filter (server side email filtering). I now have a sieve configuration file that’s way stricter. Many of the emails in my INBOX would now be sorted into subfolders, but Dovecot applies rules only to incoming messages.
Luckily, Dovecot provides a tool to apply existing rules to existing emails!
sieve-filter -v -C -u email@example.com /home/vmail/bastelfreak.de/tim/.dovecot.sieve INBOX
This will simulate the filters in the .dovecot.sieve file to the INBOX folder from the firstname.lastname@example.org. It won’t actually modify emails. If the output looks good, you can add the -W and -e option. With -e, the emails are processed and, if a rule demands it, copied to another folder. With -W, the source folder will be modified as well. This means: If you add -e but not -W, you will end up with the email in two folders.