Postfixのコンテンツフィルターを複数設定する方法
Postfixには、ウィルススキャン や アンチSPAM などをフィルターコンテンツフィルターという方法でプラグインできる。
その際に、amavisd-newや自分で作ったカスタムフィルターなどを組み合わせたいときには、複数のコンテンツフィルターを併せて設定すればよい。
カスタムのコンテンツフィルターを追加したいときには、Perlで書かれたトランスペアレントなコンテンツフィルター smtpprox を使うと便利。
今回はsmtpprox を2つ設定した場合の設定手順のログ。
- 最終的には以下のような感じ。
+-----------+ +----------------+ +-------------+ |Postfix:25 |=>|my_filter1:10024|=>|Postfix:10025|=> +-----------+ +----------------+ +-------------+ +----------------+ +-------------+ |my_filter2:20024|=>|Postfix:20025|====> +----------------+ +-------------+
- smtpprox のインストール & 起動
# wget http://bent.latency.net/smtpprox/smtpprox-1.2.tar.gz # tar zxvf smtpprox-1.2.tar.gz # cd smtpprox-1.2 ### my_filter1 ### # ./smtpprox localhost:10024 localhost:10025 ### my_filter2 ### # ./smtpprox localhost:20024 localhost:20025
- Postfix の設定
master.cf を以下のように修正
smtp inet n - n - - smtpd
を
smtp inet n - n - - smtpd -o content_filter=my_filter1:[127.0.0.1]:10024
のようにする。つまりコンテンツフィルタ my_filter1 を使う、という設定を追加する。
my_filter1 を設定(定義)する。
my_filter1 unix - - n - 30 smtp -o smtp_data_done_timeout=1200 -o smtp_send_xforward_command=yes -o disable_dns_lookups=yes
次に、my_filter1 から ポート10025に戻ってくる smtpd の設定を追加する。
その時に、2番目のコンテンツフィルタ my_filter2 を使う設定を行う。(2行目)
127.0.0.1:10025 inet n - n - - smtpd -o content_filter=my_filter2:[127.0.0.1]:20024 -o local_recipient_maps= -o relay_recipient_maps= -o smtpd_restriction_classes= -o smtpd_client_restrictions= -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o mynetworks=127.0.0.0/8 -o strict_rfc821_envelopes=yes -o smtpd_error_sleep_time=0 -o smtpd_soft_error_limit=1001 -o smtpd_hard_error_limit=1000 -o smtpd_client_connection_count_limit=0 -o smtpd_client_connection_rate_limit=0 -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks
先ほどと同様に、my_filter2 の定義を追加する。
my_filter2 unix - - n - 30 smtp -o smtp_data_done_timeout=1200 -o smtp_send_xforward_command=yes -o disable_dns_lookups=yes
次に、my_filter2 から ポート20025に戻ってくる smtpd の設定を追加する。
その時に、コンテンツフィルタを空にしておく。(コンテンツフィルタは使わないので。)間違って指定するとループするかも。
127.0.0.1:20025 inet n - n - - smtpd -o content_filter= -o local_recipient_maps= -o relay_recipient_maps= -o smtpd_restriction_classes= -o smtpd_client_restrictions= -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o mynetworks=127.0.0.0/8 -o strict_rfc821_envelopes=yes -o smtpd_error_sleep_time=0 -o smtpd_soft_error_limit=1001 -o smtpd_hard_error_limit=1000 -o smtpd_client_connection_count_limit=0 -o smtpd_client_connection_rate_limit=0 -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks
最後は、以下のようになる。
smtp inet n - n - - smtpd -o content_filter=my_filter1:[127.0.0.1]:10024 my_filter1 unix - - n - 30 smtp -o smtp_data_done_timeout=1200 -o smtp_send_xforward_command=yes -o disable_dns_lookups=yes 127.0.0.1:10025 inet n - n - - smtpd -o content_filter=my_filter2:[127.0.0.1]:20024 -o local_recipient_maps= -o relay_recipient_maps= -o smtpd_restriction_classes= -o smtpd_client_restrictions= -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o mynetworks=127.0.0.0/8 -o strict_rfc821_envelopes=yes -o smtpd_error_sleep_time=0 -o smtpd_soft_error_limit=1001 -o smtpd_hard_error_limit=1000 -o smtpd_client_connection_count_limit=0 -o smtpd_client_connection_rate_limit=0 -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks my_filter2 unix - - n - 30 smtp -o smtp_data_done_timeout=1200 -o smtp_send_xforward_command=yes -o disable_dns_lookups=yes 127.0.0.1:20025 inet n - n - - smtpd -o content_filter= -o local_recipient_maps= -o relay_recipient_maps= -o smtpd_restriction_classes= -o smtpd_client_restrictions= -o smtpd_client_restrictions= -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o mynetworks=127.0.0.0/8 -o strict_rfc821_envelopes=yes -o smtpd_error_sleep_time=0 -o smtpd_soft_error_limit=1001 -o smtpd_hard_error_limit=1000 -o smtpd_client_connection_count_limit=0 -o smtpd_client_connection_rate_limit=0 -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks 以下略
これで、コンテンツフィルタの中で、メールの中身を煮るなり焼くなりできる。