version 1.2, 2000/10/20 10:59:02
|
version 1.13, 2001/08/03 14:54:52
|
Line 10
|
Line 10
|
# |
# |
# 10/05 Gerd Kortemeyer) |
# 10/05 Gerd Kortemeyer) |
# |
# |
# 10/19,10/20 Gerd Kortemeyer |
# 10/19,10/20,10/30, |
|
# 02/06/01 Gerd Kortemeyer |
|
# 07/27 Guy Albertelli |
|
# 07/27,07/28,07/30,08/03 Gerd Kortemeyer |
|
|
package Apache::lonmsg; |
package Apache::lonmsg; |
|
|
Line 18 use strict;
|
Line 21 use strict;
|
use Apache::lonnet(); |
use Apache::lonnet(); |
use vars qw($msgcount); |
use vars qw($msgcount); |
use HTML::TokeParser; |
use HTML::TokeParser; |
|
use Apache::Constants qw(:common); |
|
|
# ===================================================================== Package |
# ===================================================================== Package |
|
|
sub package { |
sub packagemsg { |
var ($subject,$message)=@_; |
my ($subject,$message,$citation)=@_; |
$message=~s/\</\<\;/g; |
$message=~s/\</\<\;/g; |
$message=~s/\>/\>\;/g; |
$message=~s/\>/\>\;/g; |
|
$citation=~s/\</\<\;/g; |
|
$citation=~s/\>/\>\;/g; |
$subject=~s/\</\<\;/g; |
$subject=~s/\</\<\;/g; |
$subject=~s/\>/\>\;/g; |
$subject=~s/\>/\>\;/g; |
my $now=time; |
my $now=time; |
$msgcount++; |
$msgcount++; |
$msgid=$now.'_'.$ENV{'user.name'}.'_'. |
my $partsubj=$subject; |
$ENV{'user.domain'}.'_'.$msgcount.'_'.$$; |
$partsubj=&Apache::lonnet::escape($partsubj); |
|
$partsubj=substr($partsubj,0,50); |
|
my $msgid=&Apache::lonnet::escape( |
|
$now.':'.$partsubj.':'.$ENV{'user.name'}.':'. |
|
$ENV{'user.domain'}.':'.$msgcount.':'.$$); |
return $msgid, |
return $msgid, |
'<sendername>'.$ENV{'user.name'}.'</sendername>'. |
'<sendername>'.$ENV{'user.name'}.'</sendername>'. |
'<senderdomain>'.$ENV{'user.domain'}.'</senderdomain>'. |
'<senderdomain>'.$ENV{'user.domain'}.'</senderdomain>'. |
Line 48 sub package {
|
Line 58 sub package {
|
'<role>'.$ENV{'request.role'}.'</role>'. |
'<role>'.$ENV{'request.role'}.'</role>'. |
'<resource>'.$ENV{'request.filename'}.'</resource>'. |
'<resource>'.$ENV{'request.filename'}.'</resource>'. |
'<msgid>'.$msgid.'</msgid>'. |
'<msgid>'.$msgid.'</msgid>'. |
'<message>'.$message.'</message>'; |
'<message>'.$message.'</message>'. |
|
'<citation>'.$citation.'</citation>'; |
} |
} |
|
|
# ================================================== Unpack message into a hash |
# ================================================== Unpack message into a hash |
|
|
sub unpackage { |
sub unpackagemsg { |
my $message=shift; |
my $message=shift; |
my %content=(); |
my %content=(); |
my $parser=HTML::TokeParser->new(\$message); |
my $parser=HTML::TokeParser->new(\$message); |
Line 68 sub unpackage {
|
Line 79 sub unpackage {
|
return %content; |
return %content; |
} |
} |
|
|
|
# ======================================================= Get info out of msgid |
|
|
|
sub unpackmsgid { |
|
my $msgid=&Apache::lonnet::unescape(shift); |
|
my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/, |
|
&Apache::lonnet::unescape($msgid)); |
|
my %status=&Apache::lonnet::get('email_status',[$msgid]); |
|
if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; } |
|
unless ($status{$msgid}) { $status{$msgid}='new'; } |
|
return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid}); |
|
} |
|
|
# =============================== Automated message to the author of a resource |
# =============================== Automated message to the author of a resource |
|
|
sub author_res_msg { |
sub author_res_msg { |
Line 79 sub author_res_msg {
|
Line 102 sub author_res_msg {
|
if ($homeserver ne 'no_host') { |
if ($homeserver ne 'no_host') { |
my $id=unpack("%32C*",$message); |
my $id=unpack("%32C*",$message); |
my $msgid; |
my $msgid; |
($msgid,$message)=package($filename,$message); |
($msgid,$message)=&packagemsg($filename,$message); |
return &Apache::lonnet::put( |
return &Apache::lonnet::reply('put:'.$domain.':'.$author. |
'nohist_res_msgs',$filename.'_'.$id => $message); |
':nohist_res_msgs:'. |
|
&Apache::lonnet::escape($filename.'_'.$id).'='. |
|
&Apache::lonnet::escape($message),$homeserver); |
} |
} |
return 'no_host'; |
return 'no_host'; |
} |
} |
Line 97 sub user_crit_msg {
|
Line 122 sub user_crit_msg {
|
my $homeserver=&Apache::lonnet::homeserver($user,$domain); |
my $homeserver=&Apache::lonnet::homeserver($user,$domain); |
if ($homeserver ne 'no_host') { |
if ($homeserver ne 'no_host') { |
my $msgid; |
my $msgid; |
($msgid,$message)=package($filename,$message); |
($msgid,$message)=&packagemsg($subject,$message); |
$status=&Apache::lonnet::cput('critical',$msgid => $message); |
$status=&Apache::lonnet::critical( |
|
'put:'.$domain.':'.$user.':critical:'. |
|
&Apache::lonnet::escape($msgid).'='. |
|
&Apache::lonnet::escape($message),$homeserver); |
} else { |
} else { |
$status='no_host'; |
$status='no_host'; |
} |
} |
&Apache::lonnet::logthis( |
&Apache::lonnet::logthis( |
'<font color=yellow>INFO: Sending critical email '.$msgid. |
'Sending critical email '.$msgid. |
', log status: '. |
', log status: '. |
&Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'}, |
&Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'}, |
$ENV{'user.home'}, |
$ENV{'user.home'}, |
'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: ' |
'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: ' |
.$status).'</font>'); |
.$status)); |
return $status; |
return $status; |
} |
} |
|
|
# =================================================== Critical message received |
# =================================================== Critical message received |
|
|
sub user_crit_received { |
sub user_crit_received { |
my $message=shift; |
my $msgid=shift; |
|
my %message=&Apache::lonnet::get('critical',[$msgid]); |
|
my %contents=&unpackagemsg($message{$msgid}); |
|
my $status='rec: '. |
|
&user_normal_msg($contents{'sendername'},$contents{'senderdomain'}, |
|
'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}, |
|
'User '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}. |
|
' acknowledged receipt of message "'. |
|
$contents{'subject'}.'" dated '.$contents{'time'}.".\n\n" |
|
.'Message ID: '.$contents{'msgid'}); |
|
$status.=' trans: '. |
|
&Apache::lonnet::put( |
|
'nohist_email',{$contents{'msgid'} => $message{$msgid}}); |
|
$status.=' del: '. |
|
&Apache::lonnet::del('critical',[$contents{'msgid'}]); |
|
&Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'}, |
|
$ENV{'user.home'},'Received critical message '. |
|
$contents{'msgid'}. |
|
', '.$status); |
|
return $status; |
} |
} |
|
|
# ======================================================== Normal communication |
# ======================================================== Normal communication |
|
|
sub user_normal_msg { |
sub user_normal_msg { |
my ($user,$domain,$subject,$message)=@_; |
my ($user,$domain,$subject,$message,$citation)=@_; |
# Check if allowed missing |
# Check if allowed missing |
my $status=''; |
my $status=''; |
my $msgid='undefined'; |
my $msgid='undefined'; |
Line 130 sub user_normal_msg {
|
Line 176 sub user_normal_msg {
|
my $homeserver=&Apache::lonnet::homeserver($user,$domain); |
my $homeserver=&Apache::lonnet::homeserver($user,$domain); |
if ($homeserver ne 'no_host') { |
if ($homeserver ne 'no_host') { |
my $msgid; |
my $msgid; |
($msgid,$message)=package($filename,$message); |
($msgid,$message)=&packagemsg($subject,$message,$citation); |
$status=&Apache::lonnet::cput('nohist_email',$msgid => $message); |
$status=&Apache::lonnet::critical( |
|
'put:'.$domain.':'.$user.':nohist_email:'. |
|
&Apache::lonnet::escape($msgid).'='. |
|
&Apache::lonnet::escape($message),$homeserver); |
} else { |
} else { |
$status='no_host'; |
$status='no_host'; |
} |
} |
Line 141 sub user_normal_msg {
|
Line 190 sub user_normal_msg {
|
return $status; |
return $status; |
} |
} |
|
|
|
# =============================================================== Status Change |
|
|
|
sub statuschange { |
|
my ($msgid,$newstatus)=@_; |
|
my %status=&Apache::lonnet::get('email_status',[$msgid]); |
|
if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; } |
|
unless ($status{$msgid}) { $status{$msgid}='new'; } |
|
unless (($status{$msgid} eq 'replied') || |
|
($status{$msgid} eq 'forwarded')) { |
|
&Apache::lonnet::put('email_status',{$msgid => $newstatus}); |
|
} |
|
} |
|
# ==================================================== Display Critical Message |
|
|
|
sub discrit { |
|
my $r=shift; |
|
$r->print('<h1><font color=red>Critical Messages</font></h1>'. |
|
'<form action=/adm/email method=post>'. |
|
'<input type=hidden name=confirm value=true>'); |
|
my %what=&Apache::lonnet::dump('critical'); |
|
map { |
|
my %content=&unpackagemsg($what{$_}); |
|
$content{'message'}=~s/\n/\<br\>/g; |
|
$r->print('<hr>From: <b>'.$content{'sendername'}.'@'. |
|
$content{'senderdomain'}.'</b> ('.$content{'time'}. |
|
')<br><blockquote>'.$content{'message'}.'</blockquote>'. |
|
'<input type=submit name="rec_'.$_.'" value="Confirm Receipt">'. |
|
'<input type=submit name="reprec_'.$_.'" value="Confirm Receipt and Reply">'); |
|
} sort keys %what; |
|
$r->print('</form>'); |
|
} |
|
|
|
# =============================================================== Compose reply |
|
|
|
sub comprep { |
|
my ($r,$msgid)=@_; |
|
my %message=&Apache::lonnet::get('nohist_email',[$msgid]); |
|
my %content=&unpackagemsg($message{$msgid}); |
|
my $quotemsg='> '.$content{'message'}; |
|
$quotemsg=~s/\r/\n/g; |
|
$quotemsg=~s/\f/\n/g; |
|
$quotemsg=~s/\n+/\n\> /g; |
|
my $subject='Re: '.$content{'subject'}; |
|
my $dispcrit=''; |
|
if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { |
|
$dispcrit= |
|
'<input type=checkbox name=critmsg> Send as critical message<p>'; |
|
} |
|
$r->print(<<"ENDREPLY"); |
|
<form action="/adm/email" method=post> |
|
<input type=hidden name=sendreply value="$msgid"> |
|
Subject: <input type=text size=50 name=subject value="$subject"><p> |
|
<textarea name=message cols=60 rows=10> |
|
$quotemsg |
|
</textarea><p> |
|
$dispcrit |
|
<input type=submit value="Send Reply"> |
|
</form> |
|
ENDREPLY |
|
} |
|
|
|
# ===================================================================== Handler |
|
|
|
sub handler { |
|
my $r=shift; |
|
|
|
# ----------------------------------------------------------- Set document type |
|
|
|
$r->content_type('text/html'); |
|
$r->send_http_header; |
|
|
|
return OK if $r->header_only; |
|
|
|
# --------------------------- Get query string for limited number of parameters |
|
|
|
map { |
|
my ($name, $value) = split(/=/,$_); |
|
$value =~ tr/+/ /; |
|
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; |
|
if (($name eq 'display') || ($name eq 'replyto') || |
|
($name eq 'forward') || ($name eq 'mark') || |
|
($name eq 'sendreply') || ($name eq 'compose') || |
|
($name eq 'sendmail') || ($name eq 'critical')) { |
|
unless ($ENV{'form.'.$name}) { |
|
$ENV{'form.'.$name}=$value; |
|
} |
|
} |
|
} (split(/&/,$ENV{'QUERY_STRING'})); |
|
|
|
# --------------------------------------------------------------- Render Output |
|
|
|
$r->print('<html><head><title>EMail and Messaging</title></head>'); |
|
$r->print( |
|
'<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>'); |
|
$r->print('<h1>EMail</h1>'); |
|
if ($ENV{'form.display'}) { |
|
my $msgid=$ENV{'form.display'}; |
|
&statuschange($msgid,'read'); |
|
my %message=&Apache::lonnet::get('nohist_email',[$msgid]); |
|
my %content=&unpackagemsg($message{$msgid}); |
|
$r->print('<b>Subject:</b> '.$content{'subject'}. |
|
'<br><b>From:</b> '.$content{'sendername'}.' at '. |
|
$content{'senderdomain'}. |
|
'<br><b>Time:</b> '.$content{'time'}.'<hr>Functions: '. |
|
'<a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid). |
|
'"><b>Reply</b></a><hr><pre>'. |
|
$content{'message'}.'</pre><hr>'.$content{'citation'}); |
|
} elsif ($ENV{'form.replyto'}) { |
|
&comprep($r,$ENV{'form.replyto'}); |
|
} elsif ($ENV{'form.sendreply'}) { |
|
my $msgid=$ENV{'form.sendreply'}; |
|
my %message=&Apache::lonnet::get('nohist_email',[$msgid]); |
|
my %content=&unpackagemsg($message{$msgid}); |
|
&statuschange($msgid,'replied'); |
|
if (($ENV{'form.critmsg'}) && |
|
(&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) { |
|
$r->print('Sending critical: '. |
|
&user_crit_msg($content{'sendername'}, |
|
$content{'senderdomain'}, |
|
$ENV{'form.subject'}, |
|
$ENV{'form.message'})); |
|
} else { |
|
$r->print('Sending: '.&user_normal_msg($content{'sendername'}, |
|
$content{'senderdomain'}, |
|
$ENV{'form.subject'}, |
|
$ENV{'form.message'})); |
|
} |
|
} elsif ($ENV{'form.confirm'}) { |
|
map { |
|
if ($_=~/^form\.rec\_(.*)$/) { |
|
$r->print('<b>Confirming Receipt:</b> '. |
|
&user_crit_received($1).'<br>'); |
|
} |
|
if ($_=~/^form\.reprec\_(.*)$/) { |
|
my $msgid=$1; |
|
$r->print('<b>Confirming Receipt:</b> '. |
|
&user_crit_received($msgid).'<br>'); |
|
&comprep($r,$msgid); |
|
} |
|
} keys %ENV; |
|
&discrit($r); |
|
} elsif ($ENV{'form.critical'}) { |
|
&discrit($r); |
|
} elsif ($ENV{'form.forward'}) { |
|
} elsif ($ENV{'form.mark'}) { |
|
} elsif ($ENV{'form.compose'}) { |
|
my $dispcrit=''; |
|
if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { |
|
$dispcrit= |
|
'<input type=checkbox name=critmsg> Send as critical message<p>'; |
|
} |
|
$r->print(<<"ENDCOMP"); |
|
<form action="/adm/email" method=post> |
|
<input type=hidden name=sendmail value=on> |
|
Subject: <input type=text size=50 name=subject value=""><p> |
|
<textarea name=message cols=60 rows=10> |
|
</textarea><p> |
|
$dispcrit |
|
<input type=submit value="Send Mail"> |
|
</form> |
|
ENDCOMP |
|
} elsif ($ENV{'form.sendmail'}) { |
|
} else { |
|
$r->print('<table border=2><tr><th> </th><th>Date</th>'. |
|
'<th>Username</th><th>Domain</th><th>Subject</th><th>Status</th></tr>'); |
|
map { |
|
my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)= |
|
&Apache::lonmsg::unpackmsgid($_); |
|
if ($status eq 'new') { |
|
$r->print('<tr bgcolor="#FFBB77">'); |
|
} elsif ($status eq 'read') { |
|
$r->print('<tr bgcolor="#BBBB77">'); |
|
} elsif ($status eq 'replied') { |
|
$r->print('<tr bgcolor="#AAAA88">'); |
|
} else { |
|
$r->print('<tr bgcolor="#99BBBB">'); |
|
} |
|
$r->print('<td><a href="/adm/email?display='.$_. |
|
'">Open</a></td><td>'.localtime($sendtime).'</td><td>'. |
|
$fromname.'</td><td>'.$fromdomain.'</td><td>'. |
|
&Apache::lonnet::unescape($shortsubj).'</td><td>'. |
|
$status.'</td></tr>'); |
|
} sort split(/\&/,&Apache::lonnet::reply('keys:'. |
|
$ENV{'user.domain'}.':'. |
|
$ENV{'user.name'}.':nohist_email', |
|
$ENV{'user.home'})); |
|
$r->print('</table></body></html>'); |
|
|
|
} |
|
$r->print('</body></html>'); |
|
return OK; |
|
|
|
} |
# ================================================= Main program, reset counter |
# ================================================= Main program, reset counter |
|
|
sub BEGIN { |
sub BEGIN { |