カスタマイズcgiの作成
# vi /home/linux/maildelivery.cgi
#!/usr/local/bin/perl
#===================================================================
# MailDelivery Version 1.0
# Copyright (c) First home server construction.
# http://kajuhome.com/
#===================================================================
#==============任意設定(ここから)================
# 差出人のアドレス
$sender='webmaster@xxx.com';
# 転送したいアドレスを設定
@transaddr = ('keitai@xxx.com','pc@xxx.com') ;
# 転送したい本文の文字数
$transcnt = 400 ;
# 内容がHTMLメールだけでも転送する(1:Yes / 0:No)
$transhtm = 0;
#==============任意設定(ここまで)================
#################################################
# sendmailの実行モジュール
$sendmail = '/usr/sbin/sendmail';
# Perl汎用関数集
require '/usr/lib/perl-lib.pl';
# BASE変換ライブラリ(MIMEエンコード)
require "/usr/lib/mimew.pl";
## BASE変換ライブラリ(MIME デコード)
require "/usr/lib/mimer.pl";
# メールファイル(一時ワーク)
$tmp_file = "$ENV{'HOME'}/maildelivery.tmp";
#################################################
push(@INC,'/usr/lib/perl5/network_modules/modules');
require MIME;
@tmp=<>;
open(TMP,">$tmp_file");
print TMP @tmp;
close(TMP);
my $FH = Symbol::gensym();
open($FH, "< $tmp_file");
my $mime = MIME->new(File => $FH);
$mime->decode_message(
Convert => "euc",
Uudecode => 1,
Suffix => [qw(gif png jpeg jpg txt text html htm doc)],
);
# ヘッダ情報を取得
@header = $mime->header();
# ヘッダ各種情報取得
$subject = $mime->header('Subject');
$from = $mime->header('From');
$to = $mime->header('To');
$cc = $mime->header('Cc');
$date = $mime->header('Date');
# ボディ部を取得
$content = $mime->content();
# plainタイプのデータを全て得る
@plain = $mime->content('plain');
# htmlタイプのデータを全て得る
@html = $mime->content('html');
# ========== plain ==========
$tmp_plain = "";
foreach $plain(@plain){
$tmp_plain .= $plain;
}
$tmp_plain =~ s/ //g;
# ========== html ==========
$tmp_html = "";
foreach $html(@html){
$tmp_html .= $html;
}
$tmp_html =~ s/ //g;
@send_body = ();
if("" ne $tmp_plain){
@send_body = @plain;
}elsif("" ne $tmp_html){
if($transhtm eq "1"){
@send_body = @html;
}else{
push(@send_body,"!! HTMLメールの為、転送していません !!");
}
}else{
push(@send_body,"!! 本文がありません !!");
}
$plain_tmp = "";
foreach $send_body(@send_body){
$plain_tmp .= $send_body;
}
$edt_mail_body = &ksubstr($plain_tmp, 0, $transcnt);
# メール本文
@mbody=();
push(@mbody,"以下のメールが[$to]に届きました。\n");
push(@mbody,"------------------------------------------------------------\n");
push(@mbody," 差出人:$from\n");
push(@mbody," 件名:$subject\n");
push(@mbody,"受信日時:$date\n");
push(@mbody,"\n");
push(@mbody,"[本文]\n");
push(@mbody,"$edt_mail_body\n");
push(@mbody,"------------------------------------------------------------\n");
push(@mbody,"※)本文は先頭より[$transcnt]文字転送しています。\n");
# メールタイトルエンコード
$msub = &mimeencode("[kaju mail] New mail arrived");
foreach $transaddr ( @transaddr ) {
# sendmail起動
open(MAIL,"| $sendmail -t");
print MAIL "To: $transaddr\n";
print MAIL "From: $sender\n";
print MAIL "Subject: $msub\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-type: text/plain; charset=ISO-2022-JP\n";
print MAIL "Content-Transfer-Encoding: 7bit\n";
print MAIL "X-Mailer: kaju original\n\n";
foreach $mbody(@mbody) {
&jcode'convert(*mbody, 'jis');
print MAIL $mbody;
}
close(MAIL);
}
close($FH);
unlink($tmp_file);
exit 0;
__END__
作成したcgiスクリプトに実行権付与
# chmod 700 /home/linux/maildelivery.cgi
作成したcgiスクリプトの所有権設定
# chown linux /home/linux/maildelivery.cgi
|