[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[postfix-jp:03128] Re: www.amavis.org はどこへ?



こんばんわ、蕪木@自宅です。

ものすごく遅い返事ですいません。

お教えいただいた amavisd-new を導入してみようかなと遊んでいたら、
日本語化対応の為の変更方法があんまりどこにも書いていないので、
どうしても日本語化したくて修正した結果をここにでもUPしておく
事にします。

皆さんのお役に立てれば幸いです。#もうご存知かな?

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
(以下、上級編メモ− 2003.07.xx 版−より抜粋)

★ポイント... 通知メッセージの日本語化

通知メッセージを日本語で送る場合には、色々といじらないといけません。

> # $notify_sender_templ      = read_text('/var/amavis/notify_sender.txt');
> # $notify_virus_sender_templ= read_text('/var/amavis/notify_virus_sender.txt');
> # $notify_virus_admin_templ = read_text('/var/amavis/notify_virus_admin.txt');
> # $notify_virus_recips_templ= read_text('/var/amavis/notify_virus_recips.txt');
> # $notify_spam_sender_templ = read_text('/var/amavis/notify_spam_sender.txt');
> # $notify_spam_admin_templ  = read_text('/var/amavis/notify_spam_admin.txt');

一見すると /etc/amavisd.conf の設定でこれらファイルを用意すればいい
のかな?と思いますが、それは通知メッセージを英語で書く場合です。

日本語で通知するにはエンコーディングしないといけませんが、
そのためにはこのパラメーターの下の

> #   read_l10n_templates('/etc/amavis/en_US');

というパラメーターを有効にして、日本語化した通知メッセージを()内の
ディレクトリにおいて、「charset」と言うファイルで文字コードを指定して
あげないといけません。注意しなければいけない点として、charset は通知
用ファイルの文字コードを書くのであって、通知するメールそのもののエン
コードは amavisd.conf にその設定を書かないといけません。

ここでは

>    read_l10n_templates('/etc/amavis/');

として、この中に「iso-2022-jp」で書いたファイルを置くことにします。

mkdir /etc/amavis

としてディレクトリを作って、charset に文字コードを書いておきます。

cat > /etc/amavis/charset
iso-2022-jp

ちなみにメールを送信するかしないかは

> # Notify virus sender?
> #$warnvirussender = 1;  # (defaults to false (undef))
> 
> # Notify spam sender?
> #$warnspamsender = 1;   # (defaults to false (undef))
> 
> # Notify sender of banned files?
> #$warnbannedsender = 1; # (defaults to false (undef))
> 
> # Notify sender of syntactically invalid header containing non-ASCII characters?
> #$warnbadhsender = 1;   # (defaults to false (undef))
> 
> # Notify virus (or banned files) RECIPIENT?
> #  (not very useful, but some policies demand it)
> #$warnvirusrecip = 1;   # (defaults to false (undef))
> #$warnbannedrecip = 1;  # (defaults to false (undef))
> 
> # Notify also non-local virus/banned recipients if $warn*recip is true?
> #  (including those not matching local_domains*)
> #$warn_offsite = 1;     # (defaults to false (undef), i.e. only notify locals)

このパラメータで決まります。

最近は送信元の詐称は当たり前なので sender に通知しても意味が無いと
思われます。なので、RECIPIENT (送信先)に通知をすれば十分でしょう。

この方法で通知メッセージを日本語化すると、下記のすべてのファイルが
必要になります。

> template-dsn.txt
> template-virus-sender.txt
> template-virus-admin.txt
> template-virus-recipient.txt
> template-spam-sender.txt
> template-spam-admin.txt

まぁとりあえず touch しておけばいいでしょう。(通知しないしね)

touch  /etc/amavis/template-dsn.txt
touch  /etc/amavis/template-virus-sender.txt
touch  /etc/amavis/template-virus-admin.txt
touch  /etc/amavis/template-virus-recipient.txt
touch  /etc/amavis/template-spam-sender.txt
touch  /etc/amavis/template-spam-admin.txt

で、管理者向けの「見つけたぞ」メールの内容を作りましょう。

/usr/local/sbin/amavisd を見てみると、最後の方に通常時のメッセージ
が「# This is a template for... 」という書き出しでかいてあるので、
ここからコピペします。

> # =============================================================================
> # This is a template for VIRUS ADMINISTRATOR NOTIFICATIONS.
> # For syntax and customization instructions see README.customize.
> # Note that only valid header fields are allowed; non-standard header
> # field heads must begin with "X-" .
> #
> Date: %d
> From: %f
> Subject: [? %#V |[? %#F |[? %#X ||INVALID HEADER]|BANNED NAME (%F)]|VIRUS (%V)]#
>  FROM[?%l|| LOCAL] [?%o|(?)|<%o>]
> To: [? %#T |undisclosed-recipients: ;|[<%T>|, ]]
> [? %#C |#|Cc: [<%C>|, ]]
> Message-ID: <VA%n@%h>
> 
> ウィルスを見つけました!どうします?
> OK?
> 
> [? %#X |#|[%X\n]]
> [? %#V |No viruses were found.
> |A virus (%V) was found.
> |Two viruses (%V) were found.
> |%#V viruses were found.
> ]
> [? %#F
> |#|A banned name (%F) was found.
> |Two banned names (%F) were found.
> |%#F banned names were found.
> ]
> [? %#W |#
> |Scanner detecting a virus: %W
> |Scanners detecting a virus: %W
> ]
> The mail originated from: <%o>
> 
> [? %t |#|According to the 'Received:' trace, the message originated at:
>    %t
> ]
> [? %#S |Notification to sender will not be mailed.
> 
> ]#
> [? %#D |#|The message WILL BE delivered to:[
> %D]
> ]
> [? %#N |#|The message WAS NOT delivered to:[
> %N]
> ]
> [? %#V |#|[? %#v |#|Virus scanner output:[
>    %v]
> ]]
> [? %q  |Not quarantined.|The message has been quarantined as:
>    %q
> ]
> ------------------------- BEGIN HEADERS -----------------------------
> [%H
> ]\
> -------------------------- END HEADERS ------------------------------

まんまベタベタですが、まぁ取り合えず日本語化したいわけですから、
とりあえず確認用に日本語メッセージを入れておきましょう。

で、amavisd を起動してみると...

> Error in config file /etc/amavisd.conf: Insecure dependency in eval while running with -T switch at /usr/local/lib/perl5/5.8.0/PerlIO.pm line 22.
> BEGIN failed--compilation aborted.

ありゃ、怒られてしまいました。
うーん、見てみると確かに PerlIO モジュールで eval していますから
このままだと怒られますね。

・・・と、いろいろ調べてみたのですが、どうも5.8のマルチバイト
処理が今ひとつきちんとコーディングされていないようです。

少なくとも通知用メッセージを読み込むときには UTF8 に変換して読み
込んで、メールとして出力するときには ISO-2022-JP にしないといけま
せん。

なので、/usr/local/sbin/amavisd そのものをいじらないといけないの
で、下記の修正ポイントを参照して各自の責任で直して試してください。

まずは perldoc Encode::JP として、Encode 処理をどのように使用した
らいいのかを確認してみました。スーパーユーザーでは見れませんので、
一般ユーザーレベルになってください。

ふむふむほうほう、というわけでやることは、

1./usr/local/sbin/amavisd の中でコメントアウトされている

> # use Encode;  # Perl 5.8  UTF-8 support

を解除します。(必要ないのかな?)

2.出力部分:safe_encode を下記のように修正

> sub safe_encode($$;$) {
>     if (!$unicode_aware) { $_[1] }  # just return the second argument
>     else {
>         my($encoding, $str, $check) = @_;
>         $check = 0  if !defined($check);
>         my($taint) = substr($str,0,0);        # taintedness of the string
> #
> # T.Kabu 2003.07.28
> #
> #       $taint . Encode::encode($encoding, $str, $check); # retain taintedness
>         $taint .= encode($encoding, $str); # retain taintedness
>         $taint;
>     }
> }

3.入力部分:read_text を下記のように修正

> sub read_text($;$) {
>     my($filename,$encoding) = @_;
>     my($inp) = IO::File->new;
>     $inp->open($filename,'r')
>         or die "Can't open file $filename for reading: $!";
> #
> # T.Kabu 2003.07.28
> #
> #    if ($unicode_aware && $encoding ne '') {
> #       binmode($inp,":encoding($encoding)")
> #           or die "Can't set :encoding($encoding) on file $filename: $!";
> #    }
>     my($str) = '';  # must not be undef, work around a Perl UTF8 bug
>     if ($unicode_aware && $encoding ne '') {
>         while(<$inp>) { $str .= decode($encoding, $_); }
>     }
>     else {
>         while(<$inp>) { $str .= $_; }
>     }
>     $inp->close or die "Can't close file $filename: $!";
>     $str;
> }

とするといけます。

特に3番目は、binmode でエンコードできそうなものですが、-T オプション
がついているのでエラーで怒られますのでこうしました。何か他にいい方法が
あったら教えてください。

以上です。

---
Takeshi Kaburagi
Mail Official : kabu@xxxxxxxxx / Private : kabu@xxxxxxxxxxx
HomePage : http://www.fwnet.jp/~kabu/
NOMIKAI : http://www.Murayakuba.jp/

Follow-Ups
[postfix-jp:03129] Re: www.amavis.org はどこへ?, T.Kabu

[検索ページ] [Postfix-JP ML Home]