How it works content_filter in Postfix using spamassassin and clamav ( filtering order )?

Solution 1:

In general, you have the following options.

  • You may set up the first content filter so it'll not inject data directly back into Postfix, but it will give it to second content filter. Then it can give it further, and only the last filter in the chain will inject mail back into Postfix.
  • Notice, you already are using a dedicated Postfix smtpd instance (see "Advanced filter: injecting mail back into Postfix" on the FILTER_README page), which has content_filter setting cleared. You might add an intermediate smtpd instance, which will receive data from first content filter and feed it into another. Notice Postfix will log each successfully delivered mail three times in this case.
  • Use a filtering manager, such as Amavis. It is the single thing that needs to be hooked into Postfix, and then it'll call Spamassassin and ClamAV by its own means. This is usual "generic" way to do things, there are tons of step-by-step howtos which do it this way, I am surprised you hadn't bump into it yourself.
  • Cease after-queue content_filter and employ before-queue milter processing. In my opinion it's much easier to deploy and maintain, system looks cleaner and more understandable. Connecting several milters is also very easy and covered in the manual. Filtering managers like Amavis also support hooking via milter interface. See http://www.postfix.org/MILTER_README.html .