version 1.49, 2003/02/18 15:47:40
|
version 1.53, 2003/04/02 00:50:46
|
Line 52 use Apache::Constants qw(:common);
|
Line 52 use Apache::Constants qw(:common);
|
use Apache::loncommon(); |
use Apache::loncommon(); |
use Apache::lontexconvert(); |
use Apache::lontexconvert(); |
use HTML::Entities(); |
use HTML::Entities(); |
|
use Mail::Send; |
|
|
# ===================================================================== Package |
# ===================================================================== Package |
|
|
sub packagemsg { |
sub packagemsg { |
my ($subject,$message,$citation,$baseurl)=@_; |
my ($subject,$message,$citation,$baseurl,$attachmenturl)=@_; |
&Apache::lonnet::logthis("base is $baseurl"); |
|
$message =&HTML::Entities::encode($message); |
$message =&HTML::Entities::encode($message); |
$citation=&HTML::Entities::encode($citation); |
$citation=&HTML::Entities::encode($citation); |
$subject =&HTML::Entities::encode($subject); |
$subject =&HTML::Entities::encode($subject); |
#remove machine specification |
#remove machine specification |
$baseurl =~ s|^http://[^/]+/|/|; |
$baseurl =~ s|^http://[^/]+/|/|; |
$baseurl =&HTML::Entities::encode($baseurl); |
$baseurl =&HTML::Entities::encode($baseurl); |
|
#remove machine specification |
|
$attachmenturl =~ s|^http://[^/]+/|/|; |
|
$attachmenturl =&HTML::Entities::encode($attachmenturl); |
|
|
my $now=time; |
my $now=time; |
$msgcount++; |
$msgcount++; |
my $partsubj=$subject; |
my $partsubj=$subject; |
Line 94 sub packagemsg {
|
Line 98 sub packagemsg {
|
if (defined($baseurl)) { |
if (defined($baseurl)) { |
$result.= '<baseurl>'.$baseurl.'</baseurl>'; |
$result.= '<baseurl>'.$baseurl.'</baseurl>'; |
} |
} |
|
if (defined($attachmenturl)) { |
|
$result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>'; |
|
} |
return $msgid,$result; |
return $msgid,$result; |
} |
} |
|
|
# ================================================== Unpack message into a hash |
# ================================================== Unpack message into a hash |
|
|
sub unpackagemsg { |
sub unpackagemsg { |
my $message=shift; |
my ($message,$notoken)=@_; |
my %content=(); |
my %content=(); |
my $parser=HTML::TokeParser->new(\$message); |
my $parser=HTML::TokeParser->new(\$message); |
my $token; |
my $token; |
Line 109 sub unpackagemsg {
|
Line 116 sub unpackagemsg {
|
my $entry=$token->[1]; |
my $entry=$token->[1]; |
my $value=$parser->get_text('/'.$entry); |
my $value=$parser->get_text('/'.$entry); |
$content{$entry}=$value; |
$content{$entry}=$value; |
&Apache::lonnet::logthis("setting $entry to $value"); |
} |
|
} |
|
if ($content{'attachmenturl'}) { |
|
my ($fname,$ft)=($content{'attachmenturl'}=~/\/(\w+)\.(\w+)$/); |
|
if ($notoken) { |
|
$content{'message'}.='<p>Attachment: <tt>'.$fname.'.'.$ft.'</tt>'; |
|
} else { |
|
$content{'message'}.='<p>Attachment: <a href="'. |
|
&Apache::lonnet::tokenwrapper($content{'attachmenturl'}). |
|
'"><tt>'.$fname.'.'.$ft.'</tt></a>'; |
} |
} |
} |
} |
return %content; |
return %content; |
Line 128 sub unpackmsgid {
|
Line 143 sub unpackmsgid {
|
return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid}); |
return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid}); |
} |
} |
|
|
|
|
|
sub sendemail { |
|
my ($to,$subject,$body)=@_; |
|
$body= |
|
"*** This is an automatic message generated by the LON-CAPA system.\n". |
|
"*** Please do not reply to this address.\n\n".$body; |
|
my $msg = new Mail::Send; |
|
$msg->to($to); |
|
$msg->subject('[LON-CAPA] '.$subject); |
|
my $fh = $msg->open('smtp',Server => 'localhost'); |
|
print $fh $body; |
|
$fh->close; |
|
} |
|
|
|
# ==================================================== Send notification emails |
|
|
|
sub sendnotification { |
|
my ($to,$touname,$toudom,$subj,$crit)=@_; |
|
my $sender=$ENV{'environment.firstname'}.' '.$ENV{'environment.lastname'}; |
|
my $critical=($crit?' critical':''); |
|
my $url='http://'. |
|
$Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}. |
|
'/adm/login&username='.$touname.'&domain='.$toudom; |
|
my $body=(<<ENDMSG); |
|
You received a$critical message from $sender in LON-CAPA. The subject is |
|
|
|
$subj |
|
|
|
Use |
|
|
|
$url |
|
|
|
to access this message. |
|
ENDMSG |
|
&sendemail($to,'New'.$critical.' message from '.$sender,$body); |
|
} |
# ============================================================= Check for email |
# ============================================================= Check for email |
|
|
sub newmail { |
sub newmail { |
Line 185 sub user_crit_msg_raw {
|
Line 236 sub user_crit_msg_raw {
|
} else { |
} else { |
$status='no_host'; |
$status='no_host'; |
} |
} |
|
# Notifications |
|
my %userenv = &Apache::lonnet::get('environment',['critnotification'], |
|
$domain,$user); |
|
if ($userenv{'critnotification'}) { |
|
&sendnotification($userenv{'critnotification'},$user,$domain,$subject,1); |
|
} |
|
# Log this |
&Apache::lonnet::logthis( |
&Apache::lonnet::logthis( |
'Sending critical email '.$msgid. |
'Sending critical email '.$msgid. |
', log status: '. |
', log status: '. |
Line 221 sub user_crit_msg {
|
Line 279 sub user_crit_msg {
|
sub user_crit_received { |
sub user_crit_received { |
my $msgid=shift; |
my $msgid=shift; |
my %message=&Apache::lonnet::get('critical',[$msgid]); |
my %message=&Apache::lonnet::get('critical',[$msgid]); |
my %contents=&unpackagemsg($message{$msgid}); |
my %contents=&unpackagemsg($message{$msgid},1); |
my $status='rec: '.($contents{'sendback'}? |
my $status='rec: '.($contents{'sendback'}? |
&user_normal_msg($contents{'sendername'},$contents{'senderdomain'}, |
&user_normal_msg($contents{'sendername'},$contents{'senderdomain'}, |
'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}, |
'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}, |
Line 245 sub user_crit_received {
|
Line 303 sub user_crit_received {
|
# ======================================================== Normal communication |
# ======================================================== Normal communication |
|
|
sub user_normal_msg_raw { |
sub user_normal_msg_raw { |
my ($user,$domain,$subject,$message,$citation,$baseurl)=@_; |
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_; |
# Check if allowed missing |
# Check if allowed missing |
my $status=''; |
my $status=''; |
my $msgid='undefined'; |
my $msgid='undefined'; |
unless (($message)&&($user)&&($domain)) { $status='empty'; }; |
unless (($message)&&($user)&&($domain)) { $status='empty'; }; |
my $homeserver=&Apache::lonnet::homeserver($user,$domain); |
my $homeserver=&Apache::lonnet::homeserver($user,$domain); |
if ($homeserver ne 'no_host') { |
if ($homeserver ne 'no_host') { |
&Apache::lonnet::logthis("baseraw is $baseurl"); |
($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl, |
($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl); |
$attachmenturl); |
$status=&Apache::lonnet::critical( |
$status=&Apache::lonnet::critical( |
'put:'.$domain.':'.$user.':nohist_email:'. |
'put:'.$domain.':'.$user.':nohist_email:'. |
&Apache::lonnet::escape($msgid).'='. |
&Apache::lonnet::escape($msgid).'='. |
Line 263 sub user_normal_msg_raw {
|
Line 321 sub user_normal_msg_raw {
|
} else { |
} else { |
$status='no_host'; |
$status='no_host'; |
} |
} |
|
# Notifications |
|
my %userenv = &Apache::lonnet::get('environment',['notification'], |
|
$domain,$user); |
|
if ($userenv{'notification'}) { |
|
&sendnotification($userenv{'notification'},$user,$domain,$subject,0); |
|
} |
&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 '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status); |
'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status); |
Line 272 sub user_normal_msg_raw {
|
Line 336 sub user_normal_msg_raw {
|
# New routine that respects "forward" and calls old routine |
# New routine that respects "forward" and calls old routine |
|
|
sub user_normal_msg { |
sub user_normal_msg { |
my ($user,$domain,$subject,$message,$citation,$baseurl)=@_; |
my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl)=@_; |
my $status=''; |
my $status=''; |
my %userenv = &Apache::lonnet::get('environment',['msgforward'], |
my %userenv = &Apache::lonnet::get('environment',['msgforward'], |
$domain,$user); |
$domain,$user); |
Line 282 sub user_normal_msg {
|
Line 346 sub user_normal_msg {
|
my ($forwuser,$forwdomain)=split(/\:/,$_); |
my ($forwuser,$forwdomain)=split(/\:/,$_); |
$status.= |
$status.= |
&user_normal_msg_raw($forwuser,$forwdomain,$subject,$message, |
&user_normal_msg_raw($forwuser,$forwdomain,$subject,$message, |
$citation,$baseurl).' '; |
$citation,$baseurl,$attachmenturl).' '; |
} |
} |
} else { |
} else { |
$status=&user_normal_msg_raw($user,$domain,$subject,$message, |
$status=&user_normal_msg_raw($user,$domain,$subject,$message, |
$citation,$baseurl); |
$citation,$baseurl,$attachmenturl); |
} |
} |
return $status; |
return $status; |
} |
} |
Line 417 $content{'sendername'}.'@'.
|
Line 481 $content{'sendername'}.'@'.
|
sub comprep { |
sub comprep { |
my ($r,$msgid)=@_; |
my ($r,$msgid)=@_; |
my %message=&Apache::lonnet::get('nohist_email',[$msgid]); |
my %message=&Apache::lonnet::get('nohist_email',[$msgid]); |
my %content=&unpackagemsg($message{$msgid}); |
my %content=&unpackagemsg($message{$msgid},1); |
my $quotemsg='> '.$content{'message'}; |
my $quotemsg='> '.$content{'message'}; |
$quotemsg=~s/\r/\n/g; |
$quotemsg=~s/\r/\n/g; |
$quotemsg=~s/\f/\n/g; |
$quotemsg=~s/\f/\n/g; |
Line 766 $content{'sendername'},$content{'senderd
|
Line 830 $content{'sendername'},$content{'senderd
|
} elsif ($ENV{'form.sendreply'}) { |
} elsif ($ENV{'form.sendreply'}) { |
my $msgid=$ENV{'form.sendreply'}; |
my $msgid=$ENV{'form.sendreply'}; |
my %message=&Apache::lonnet::get('nohist_email',[$msgid]); |
my %message=&Apache::lonnet::get('nohist_email',[$msgid]); |
my %content=&unpackagemsg($message{$msgid}); |
my %content=&unpackagemsg($message{$msgid},1); |
&statuschange($msgid,'replied'); |
&statuschange($msgid,'replied'); |
if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && |
if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && |
(&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) { |
(&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) { |
Line 832 $content{'sendername'},$content{'senderd
|
Line 896 $content{'sendername'},$content{'senderd
|
if ($ENV{'form.forwid'}) { |
if ($ENV{'form.forwid'}) { |
my $msgid=$ENV{'form.forwid'}; |
my $msgid=$ENV{'form.forwid'}; |
my %message=&Apache::lonnet::get('nohist_email',[$msgid]); |
my %message=&Apache::lonnet::get('nohist_email',[$msgid]); |
%content=&unpackagemsg($message{$msgid}); |
%content=&unpackagemsg($message{$msgid},1); |
&statuschange($msgid,'forwarded'); |
&statuschange($msgid,'forwarded'); |
$ENV{'form.message'}.="\n\n-- Forwarded message --\n\n". |
$ENV{'form.message'}.="\n\n-- Forwarded message --\n\n". |
$content{'message'}; |
$content{'message'}; |