#! /usr/local/bin/perl
#
require "$ENV{'HOME'}/cgi-bin/form-to-mail-lib/jcode.pl";
#
# ---- FormDecode&Mail ----
$sendmail = "$ENV{'HOME'}/cgi-bin/form-to-mail-lib/ssendmail";
#
# ---- POST or GET ------
if ($ENV{'REQUEST_METHOD'} eq 'POST'){
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}else{
$buffer = $ENV{'QUERY_STRING'};
}
#
# --- 日付の取得 ---
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime(time);
$jmon = (1,2,3,4,5,6,7,8,9,10,11,12) [(localtime)[4]];
#
# ---- Form Decode ----
$c = 1;
@inputs = split(/&/, $buffer);
foreach (@inputs){
($name, $value) = split(/=/);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
&jcode'convert(*name, 'euc');
# ---- emailaddress pick up ----
if($name eq 'email'){
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
&jcode'convert(*value, 'euc');
$email = $value;
# ---- subject pick up ----
}elsif($name eq 'subject'){
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
&jcode'convert(*value, 'euc');
$subject = $value;
# ---- subject pick up ----
}elsif($name eq 'location'){
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
&jcode'convert(*value, 'euc');
$location = $value;
# ---- data put list ----
}else{
# ---- same name check ----
$d = $c-1;
if($d > 9){
$oldname = "$d".':'."$name";
}else{
$oldname = '0'."$d".':'."$name";
}
if($data{$oldname} eq ''){
if($c > 9){
$name = "$c".':'."$name";
}else{
$name = '0'."$c".':'."$name";
}
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
&jcode'convert(*value, 'euc');
$data{$name} = $value;
$c++;
}else{
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
&jcode'convert(*value, 'euc');
$data{$oldname} .= '-'.$value;
}
}
}
#
# --- senmail open ---
unless (open (MAIL, "| $sendmail -s \"$subject\" $email")) {
&err("Webからのお問い合わせのmail送信エラー");
exit;
}
#
# ---- Form Print ----
foreach $key (sort(keys %data)){
$newname = $key;
$newname =~ s/^\d+:(.*)$/$1/;
$newvalue = $data{$key};
&jcode'convert(*newname, 'jis');
&jcode'convert(*newvalue, 'jis');
print MAIL "------ $newname ------\n";
print MAIL "$newvalue\n";
}
print MAIL "\n"."Local Time: "."$year"."/"."$jmon"."/"."$mday"."/"."$hour".":"."$min"."\n";
#
close (MAIL);
#
# --- disp thanks ---
print "Location: $location\n\n";
exit 0;
#
#入力項目エラー
sub input_error {
close(FOUT);
close(DATA);
$errmsg0 = "以下の誤りが見つかりました。
";
$errmsg0 .= "ブラウザーの [Back] あるいは [戻る] のボタンで
";
$errmsg0 .= "元の入力画面に戻って内容をご確認ください。
";
&jcode'convert(*errmsg0, 'sjis');
&jcode'convert(*errmsg , 'sjis');
print "Content-type: text/html\n\n";
print <ERROR!!
$errmsg0
$errmsg