On 14.5.2012 11.13, Alexander Dalloz wrote:
You are best served if you use a milter. You may find a better suiting milter onhttps://www.milter.org/, but I think there is no better flexible choice than MIMEDefanghttp://www.mimedefang.org/ (available through EPEL). If you speak Perl, you are able to implement what you describe and even more.
Regrettably, my Perl skill is really elementary. But maybe there are recipes on the net. - Jussi