version 1.51, 2003/03/30 21:58:17
|
version 1.54, 2003/04/02 14:57:32
|
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 |
|
|
Line 65 sub packagemsg {
|
Line 66 sub packagemsg {
|
$baseurl =&HTML::Entities::encode($baseurl); |
$baseurl =&HTML::Entities::encode($baseurl); |
#remove machine specification |
#remove machine specification |
$attachmenturl =~ s|^http://[^/]+/|/|; |
$attachmenturl =~ s|^http://[^/]+/|/|; |
$attachmenturl =&HTML::Entities::encode($baseurl); |
$attachmenturl =&HTML::Entities::encode($attachmenturl); |
|
|
my $now=time; |
my $now=time; |
$msgcount++; |
$msgcount++; |
Line 98 sub packagemsg {
|
Line 99 sub packagemsg {
|
$result.= '<baseurl>'.$baseurl.'</baseurl>'; |
$result.= '<baseurl>'.$baseurl.'</baseurl>'; |
} |
} |
if (defined($attachmenturl)) { |
if (defined($attachmenturl)) { |
$result.= '<attachmenturl>'.$baseurl.'</attachmenturl>'; |
$result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>'; |
} |
} |
return $msgid,$result; |
return $msgid,$result; |
} |
} |
Line 106 sub packagemsg {
|
Line 107 sub packagemsg {
|
# ================================================== 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 117 sub unpackagemsg {
|
Line 118 sub unpackagemsg {
|
$content{$entry}=$value; |
$content{$entry}=$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 132 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/email?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 189 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 225 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 267 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 276 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 286 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 421 $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 770 $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 836 $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'}; |