I am using postfix mail server and i need to replace mail content inside every incoming and outgoing message based on some predefined rules.
What is needed is to filter remote and local mail to replace every instance of [email protected] in header or body with [email protected]
header_checks and body_checks options seem cumbersome, maybe there is better/faster option that works on whole message instead going line by line
You should look at content filters, as mentioned in Postfix's documentation.
You probably want to use a before-queue content filter. This can probably be written fairly easily in something like Perl or Python. The Postfix guide for before-queue filters also links to a program called smtpprox which you might be able to repurpose for your needs.
Postfix support header address rewriting at outgoing mail:
/etc/postfix/generic_map
Using regular expression:
/etc/postfix/generic_map
Isn't supported change in body. You need create you own content filter.
http://www.postfix.org/postconf.5.html#smtp_generic_maps