--- loncom/interface/lonmsg.pm 2003/03/30 21:58:17 1.51 +++ loncom/interface/lonmsg.pm 2003/06/23 22:25:14 1.56 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.51 2003/03/30 21:58:17 www Exp $ +# $Id: lonmsg.pm,v 1.56 2003/06/23 22:25:14 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -52,6 +52,7 @@ use Apache::Constants qw(:common); use Apache::loncommon(); use Apache::lontexconvert(); use HTML::Entities(); +use Mail::Send; # ===================================================================== Package @@ -65,7 +66,7 @@ sub packagemsg { $baseurl =&HTML::Entities::encode($baseurl); #remove machine specification $attachmenturl =~ s|^http://[^/]+/|/|; - $attachmenturl =&HTML::Entities::encode($baseurl); + $attachmenturl =&HTML::Entities::encode($attachmenturl); my $now=time; $msgcount++; @@ -98,7 +99,7 @@ sub packagemsg { $result.= ''.$baseurl.''; } if (defined($attachmenturl)) { - $result.= ''.$baseurl.''; + $result.= ''.$attachmenturl.''; } return $msgid,$result; } @@ -106,7 +107,7 @@ sub packagemsg { # ================================================== Unpack message into a hash sub unpackagemsg { - my $message=shift; + my ($message,$notoken)=@_; my %content=(); my $parser=HTML::TokeParser->new(\$message); my $token; @@ -117,6 +118,16 @@ sub unpackagemsg { $content{$entry}=$value; } } + if ($content{'attachmenturl'}) { + my ($fname,$ft)=($content{'attachmenturl'}=~/\/(\w+)\.(\w+)$/); + if ($notoken) { + $content{'message'}.='

Attachment: '.$fname.'.'.$ft.''; + } else { + $content{'message'}.='

Attachment: '.$fname.'.'.$ft.''; + } + } return %content; } @@ -132,6 +143,42 @@ sub unpackmsgid { 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=(<$domform ENDREC } + my $latexHelp = Apache::loncommon::helpLatexCheatsheet(); if ($broadcast ne 'upload') { $r->print(<<"ENDCOMP"); Additional Recipients
username\@domain,username\@domain, ... @@ -563,6 +624,7 @@ ENDREC Subject: +$latexHelp

$dispcrit @@ -770,21 +832,21 @@ $content{'sendername'},$content{'senderd } elsif ($ENV{'form.sendreply'}) { my $msgid=$ENV{'form.sendreply'}; my %message=&Apache::lonnet::get('nohist_email',[$msgid]); - my %content=&unpackagemsg($message{$msgid}); + my %content=&unpackagemsg($message{$msgid},1); &statuschange($msgid,'replied'); if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && (&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'}, + &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), + &Apache::lonfeedback::clear_out_html($ENV{'form.message'}), $ENV{'form.sendbck'})); } else { $r->print('Sending: '.&user_normal_msg($content{'sendername'}, $content{'senderdomain'}, - $ENV{'form.subject'}, - $ENV{'form.message'})); + &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), + &Apache::lonfeedback::clear_out_html($ENV{'form.message'}))); } if ($ENV{'form.displayedcrit'}) { &discrit($r); @@ -836,7 +898,7 @@ $content{'sendername'},$content{'senderd if ($ENV{'form.forwid'}) { my $msgid=$ENV{'form.forwid'}; my %message=&Apache::lonnet::get('nohist_email',[$msgid]); - %content=&unpackagemsg($message{$msgid}); + %content=&unpackagemsg($message{$msgid},1); &statuschange($msgid,'forwarded'); $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n". $content{'message'}; @@ -868,18 +930,18 @@ $content{'sendername'},$content{'senderd } foreach (keys %toaddr) { my ($recuname,$recdomain)=split(/\:/,$_); - my $msgtxt=$ENV{'form.message'}; + my $msgtxt=&Apache::lonfeedback::clear_out_html($ENV{'form.message'}); if ($toaddr{$_}) { $msgtxt.='


'.$toaddr{$_}; } if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) { $r->print('Sending critical: '. &user_crit_msg($recuname,$recdomain, - $ENV{'form.subject'}, + &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), $msgtxt, $ENV{'form.sendbck'})); } else { $r->print('Sending: '.&user_normal_msg($recuname,$recdomain, - $ENV{'form.subject'}, + &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), $msgtxt, $content{'citation'})); }