#!/usr/local/bin/perl

$| = 1;
# theme_add_mail.pl
# Registration for sensorium update news mailing list 
# haruki@st.rim.or.jp
# 96/04/30
#
# THIS CODE INCLUDES THESE LIBRARIES
#
#   cgi-lib.pl  Copyright 1994 Steven E. Brenner
#

# jrh
$CgiPath      = '/stage/htdocs/cgi-bin/Japan/Theme/NEW';
push(@INC, "$CgiPath");
$ThisFile = '/stage/htdocs/cgi-bin/Japan/Theme/theme_add_mail.pl';

require 'cgi-lib.pl';

&ReadParse(*in);

#
# “o˜^ƒAƒhƒŒƒX‚ª‹ó‚È‚çI—¹
#
if (!$in{'address'}) {
    &err("Sorry, your comment seems contains no data.\n");
}

#
# ÆþÎÏ¤µ¤ì¤¿¤â¤Î¤¬¥á¡¼¥ë¥¢¥É¥ì¥¹¤«¤É¤¦¤«¥Á¥§¥Ã¥¯
#
if (!($in{'address'} =~ /(.*)\@(.*)/) ||
	!($in{'address'} =~ /\w$/)) {
    &err("Sorry, you input invalid e-mail address. Try once more.\n");
}

#
# ƒ[ƒŠƒ“ƒOƒŠƒXƒg“o˜^\žƒ[ƒ‹‚ð‘—‚é
#
if (open(ML, "| /usr/local/bin/nkf -j | /usr/lib/sendmail -f haruki\@st.rim.or.jp majordomo\@expo96.ad.jp")) {
    print ML "From: haruki\@st.rim.or.jp \n";
    print ML "X-Mailer: theme_add_mail.pl\n";
    print ML "\n";
    print ML "approve Yumiko-Haruki subscribe sensors $in{'address'}\n";
}
close(ML);

#
# “o˜^I—¹‰æ–Ê
#
print "Content-type: text/html\n\n";
print "<html><head>\n";
print "<title>result</title>";
print "</head><body bgcolor=\"#ffffff\">\n";
print "<center><h3><p>‚ ‚è‚ª‚Æ‚¤‚²‚´‚¢‚Ü‚·B\n";
print "<br>‚ ‚È‚½‚Ìƒ[ƒ‹ƒAƒhƒŒƒX‚ð";
print "ƒŠƒXƒg‚É’Ç‰Á‚µ‚Ü‚µ‚½B</p>\n";
print "<p>Thank you!<br>Your mail address has added to list.";
print "</a></p></h3></center>\n";
print "</body><hr><address>theme pavilion \@IWEÕ96 JAPAN</address></html>\n";
exit;


#
# ƒGƒ‰[‚Ìê‡
#
sub err{
    local($msg) = @_;
    print "Content-type: text/html\n\n";
    print "<html><head>\n";
    print "<title>result</title>";
    print "</head><body bgcolor=\"#ffffff\">\n";
    print "<p>$msg</p>\n";
    print "</BODY></HTML>\n";
    exit;
}
