DoveCot, move messages from certain domains to folder

From Andreida
Jump to: navigation, search

Goal

We will assume the user you are creating filters for is "petra". Petra does not want to see messages from certain domains (corporations) but does want to keep them for a while in her trash, so she can find them if someone calls her and references "his mail from yesterday".

Possible destination folders

Get a list of folders

ls -d /home/petra/Maildir/.*

You will see something like this:

/home/petra/Maildir/.INBOX
/home/petra/Maildir/.INBOX.Trash
/home/petra/Maildir/.INBOX.Archives
/home/petra/Maildir/.INBOX.Sent
/home/petra/Maildir/.INBOX.Templates
/home/petra/Maildir/.INBOX.Junk
/home/petra/Maildir/.INBOX.Drafts

What you get may differ. If - for example - you use Outlook, chances are your output is completely different. That is NOT important. Important is to know what DoveCot works with. So, our target folder for this example is "/home/petra/Maildir/.INBOX.Trash". Inside the filter we will use the "save" command. If given a relative destination, it will insert the home folder of the current user before the given folder. So we will just use "Maildir/.INBOX.Trash/" to be able to copy the file from user to user.

.forward file

We create a ".forward" file in the home directory of Petra. Could be something like

vi /home/petra/.forward

The ownership of the ".forward" file is important. If you just copy the ".forward" file and don't modify the ownership, the ".forward" will not be used.

chown petra:petra /home/petra/.forward

filter

We want a filter for Domain.bad.1 and Domain.bad.2. This is the .forward file:

 # Exim filter
 if  $sender_address contains @domain.bad.1 or
     $sender_address contains @domain.bad.2
 then
     save Maildir/.INBOX.Trash/
 endif