email – Postfix – Tap all ingoing and outgoing mails and push to socket or script

I want to extend a new Postfix / Dovecot setup with virtual domains and virtual mailboxes (more or less everything in default configuration) by a simple, self-made email archival solution.

Therefore I want to make Postfix push all incoming and outgoing mails – regardless of virtual domain etc.

  • either to a listening TCP socket (preferred due to performance and easier programming)
  • or to a script (pipe)
  • or to files in the file system.

I don’t want the socket or pipe process to be the final destination for the mails. (For incoming mails, it’s a Dovecot LMTP.)

It’s just about “intercepting” the mails in addition (!) to normal processing.

What are the config options I have to touch? I guess I have to add a service in the master.cf. Maybe someone here has done this before as the task of email archival for postfix seems to be quite common.

mailbox_command is probably not what I’m looking for as I want the mail tap in addition to normal processing and I need it for incoming AND outgoing mails.

This question is NOT about the development of an email archival system. It’s just about configuring Postfix to “blow out” all incoming and outgoing mails to some external process, in addition to normal processing.