#!/usr/bin/perl
#
# userstat.pl - a mail status javascript generator for static html page
#
# 2003/10/08 tung.AT.turtle.ee.ncku.edu.tw
#
# This script is designed to be used by static html pages to
# display openwebmail user mail/calendar status dynamically.
# All you need to do is to include the following block in html source code.
#
#
#
use strict;
use CGI qw(-private_tempfiles :standard);
# where to find the openwebmail scripts
my $ow_cgidir="/usr/local/www/cgi-bin/openwebmail";
my $ow_cgiurl="/cgi-bin/openwebmail";
# play newmail sound if cgi param playsound==1
my $soundurl="/openwebmail/sounds/YouGotMail.English.wav";
# status text to be displayed
my %text = (
has_newmail => "_USER_ has 1 new mail",
has_newmails => "_USER_ has _N_ new mails",
has_mail => "_USER_ has 1 mail",
has_mails => "_USER_ has _N_ mails",
has_newevent => "_USER_ has new event",
has_event => "_USER_ has event",
user_calendar => "_USER_'s calendar"
);
########## No configuration required from here ###################
if (!defined($ENV{'GATEWAY_INTERFACE'})) { # cmd mode
print qq|\nThis script is designed to be used by static html pages to\n|.
qq|display openwebmail user mail/calendar status dynamically.\n|.
qq|All you need to do is to include the following block in html source code.\n\n|.
qq|\n|.
qq|\n|.
qq|\nor\n\n|.
qq|\n\n|;
exit 1;
}
my $user=param('loginname')||cookie('openwebmail-loginname')||'';
my $status='';
my $playsound = param('playsound')||'';
my $html=qq||.
qq|_TEXT_|;
$user=~s/[\/\"\'\`\|\<\>\\\(\)\[\]\{\}\$\s;&]//g; # filter out dangerous chars
if ($user ne '' && length($user)<80) {
$status=`$ow_cgidir/openwebmail-tool.pl -m -e $user`;
}
if ($user eq '' or
$status eq '' or
$status =~ /doesn't exist/) {
sleep 8;
print qq|Pragma: no-cache\n|.
qq|Cache-control: no-cache,no-store\n|.
qq|Content-Type: application/x-javascript\n\n|.
qq|//\n|;
exit 1;
}
if ($status =~ /has no mail/) {
$html=~s|_URL_|$ow_cgiurl/openwebmail.pl?action=calmonth|;
if ($status =~ /has new event/) {
$html=~s|_COLOR_|#cc0000|;
$html=~s|_TEXT_|$text{'has_newevent'}|;
} elsif ($status =~ /has event/) {
$html=~s|_COLOR_|#000000|;
$html=~s|_TEXT_|$text{'has_event'}|;
} else {
$html=~s|_COLOR_|#000000|;
$html=~s|_TEXT_|$text{'user_calendar'}|;
}
} else {
$html=~s|_URL_|$ow_cgiurl/openwebmail.pl|;
if ($status =~ /has (\d+) new mail/) {
my $n=$1;
if ($n>1) {
$html=~s|_TEXT_|$text{'has_newmails'}|;
$html=~s|_N_|$n|;
} else {
$html=~s|_TEXT_|$text{'has_newmail'}|;
}
$html=~s|_COLOR_|#cc0000|;
if ($playsound) {
$html.=qq| |