0

I am trying to find a way to have incoming mails to a specific folder based on sender address. My setup is on Ubuntu Server 14.04, Postfix mail_version = 2.11.0 Courier Imap with spamassasin, amavis, clamav. The setup was based on this this online guide. As the server goes mature day by day I have come to a need to separate my incoming mails based on sender address (much like gmail does with the social tab). I got to create a new folder in my existing account with maildirmake

 maildirmake -f Social /var/mail/virtual/domain/account

In order for the new folder to work properly I copy pasted permissions and ownership from existing folder like so

sudo chown -R --reference=.Sent/ .Social
sudo chmod -R --reference=.Sent/ .Social

After this the new folder is shown up in Thunderbird and I can move emails in there.

Now the tricky part for me, and even thought I searched around I can not find a doable solution is that I want to apply a filter on Postfix maybe? or any other way so if an incoming email is from Twitter let's say, to be shown in the Social folder. Thanks in advance for any direction I can get. Regards.

  • 1
    Maildrop can sort mail if you use the Indirect Delivery method: `mailbox_command = /path/to/maildrop -d ${USER}` then you set up a .forward file with the rules. http://www.postfix.org/local.8.html – NickW May 27 '16 at 11:32
  • 1
    http://www.courier-mta.org/maildropfilter.html – Keval Domadia May 28 '16 at 10:35

1 Answers1

1

Yes, it's possible. Nick_W and Karma already give you an idea to using a maildrop. It should be working in your case where you have virtual user stored in MySQL (based from your tutorial). It will use Courier authlib to determine where is location mailbox.

After installing maildrop, ensure that maildrop service in postfix files master.cf has active

maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/path/to/maildrop -d ${recipient}

and edit main.cf to configure postfix to use maildrop transport instead postfix default virtual transport.

maildrop_destination_recipient_limit = 1
virtual_transport = maildrop

The last step is tell maildrop to filter email based on Sender. That rule should be placed in /etc/maildroprc to enforce global filtering.

if (/^From: *@twitter\.com/)
{
    ... do what you want...
}

Refer to maildropex and maildropfilter for documentation of maildrop filtering syntax.

Additional tutorial:

masegaloeh
  • 17,978
  • 9
  • 56
  • 104