Dovecot: Apply sieve filter to existing emails

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 tim@bastelfreak.de /home/vmail/bastelfreak.de/tim/.dovecot.sieve INBOX

This will simulate the filters in the .dovecot.sieve file to the INBOX folder from the tim@bastelfreak.de. 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.

This entry was posted in General, Linux, Short Tips. Bookmark the permalink.

One Response to Dovecot: Apply sieve filter to existing emails

  1. Andreas says:

    Thank you, that was exactly what I was looking for.

    But I am using neither -v nor -C and first I change to the sieve directory, so it is like:

    cd /home/myName
    ls -l
    sieve-filter -u myName MoveJunk.sieve INBOX
    sieve-filter -eW -u myname MoveJunk.sieve INBOX

    But thanks a lot for telling me how to do this.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.