Archiving mails with postfix: how to filter mails

email-serverfilterpostfix

i wanto to implement the following scenario:

we use a postfix mailserver. to archive all old and new mails, i want to setup a second postfix on our fileserver and create a single mailbox "archive". then every mail gets forwarded as bcc to this mailbox automatically. now, i want to create different folders in a maildir structure and let the server move each mail to the right subfolder of the mailbox based on its sender or receiver.

e.g. when we get a mail to one of our employees named "John Doe" at john.doe@foo.bar, the mail should be moved to "Inbox/John Doe Incoming". the same applies when john doe sends a mail, folder would be "Inbox/John Doe Outgoing".

how can i implement this filter behaviour. i heard of Procmail and Maildrop. Which of the two would you prefer? Which is more easy to configure? Any out-of-box solutions here?

thanks in advance!

Best Answer

Why not use sender_bcc_maps and recipient_bcc_maps to copy mail to a dedicated archive domain - say, archive.foo.bar - delivered via transport(5) to an MDA that stores archived mail in dedicated mailboxes?

No second instance needed, and clean solution all-round.

You can use a regex or PCRE map type to map al senders or recipients to mailboxes in the archive domain, e.g.:

/etc/postfix/sender-archive-pcre: /^(.*)@foo\.bar$/ $1-outbound@archive.foo.bar

/etc/postfix/recipient-archive-pcre: /^(.*)@foo\.bar$/ $1-inbound@archive.foo.bar

And in transport(5): @archive.foo.bar unix:your-archive-mda

As for which delivery agent to use: I very strongly suggest you use dovecot 2.x, either the deliver mda or the LMTP server; both have full sieve filter support with the pigeonhole plugin.

Related Topic