--- loncom/interface/lonmsg.pm 2006/04/25 19:45:50 1.183 +++ loncom/interface/lonmsg.pm 2006/11/01 22:22:31 1.186 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.183 2006/04/25 19:45:50 albertel Exp $ +# $Id: lonmsg.pm,v 1.186 2006/11/01 22:22:31 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,6 +33,8 @@ use Apache::lonnet; use HTML::TokeParser(); use Apache::lonlocal; use Mail::Send; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; { my $uniq; @@ -59,13 +61,13 @@ sub packagemsg { my $course_context; if (defined($env{'form.replyid'})) { my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)= - split(/\:/,&Apache::lonnet::unescape($env{'form.replyid'})); + split(/\:/,&unescape($env{'form.replyid'})); $course_context = $origcid; } foreach my $key (keys(%env)) { if ($key=~/^form\.(rep)?rec\_(.*)$/) { my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) = - split(/\:/,&Apache::lonnet::unescape($2)); + split(/\:/,&unescape($2)); $course_context = $origcid; last; } @@ -108,8 +110,8 @@ sub packagemsg { for (my $i=0; $i<@{$recuser}; $i++) { if ($type eq 'dcmail') { my ($username,$email) = split(/:/,$$recuser[$i]); - $username = &Apache::lonnet::unescape($username); - $email = &Apache::lonnet::unescape($email); + $username = &unescape($username); + $email = &unescape($email); $username = &HTML::Entities::encode($username,'<>&"'); $email = &HTML::Entities::encode($email,'<>&"'); $result .= ''. @@ -178,17 +180,17 @@ sub unpackagemsg { sub buildmsgid { my ($now,$subject,$uname,$udom,$msgcount,$course_context,$pid) = @_; - $subject=&Apache::lonnet::escape($subject); - return(&Apache::lonnet::escape($now.':'.$subject.':'.$uname.':'. + $subject=&escape($subject); + return(&escape($now.':'.$subject.':'.$uname.':'. $udom.':'.$msgcount.':'.$course_context.':'.$pid)); } sub unpackmsgid { my ($msgid,$folder,$skipstatus,$status_cache)=@_; - $msgid=&Apache::lonnet::unescape($msgid); + $msgid=&unescape($msgid); my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid, - $processid)=split(/\:/,&Apache::lonnet::unescape($msgid)); - $shortsubj = &Apache::lonnet::unescape($shortsubj); + $processid)=split(/\:/,&unescape($msgid)); + $shortsubj = &unescape($shortsubj); $shortsubj = &HTML::Entities::decode($shortsubj); if (!defined($processid)) { $fromcid = ''; } my %status=(); @@ -208,12 +210,21 @@ sub unpackmsgid { sub sendemail { my ($to,$subject,$body)=@_; + my %senderemails=&Apache::loncommon::getemails(); + my $senderaddress=''; + foreach my $type ('notification','permanentemail','critnotification') { + if ($senderemails{$type}) { + $senderaddress=$senderemails{$type}; + } + } $body= "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n". - "*** ".&mt('Please do not reply to this address.')."\n\n".$body; + "*** ".($senderaddress?&mt('You can reply to this message'):&mt('Please do not reply to this address.')."\n*** ". + &mt('A reply will not be received by the recipient!'))."\n\n".$body; my $msg = new Mail::Send; $msg->to($to); $msg->subject('[LON-CAPA] '.$subject); + if ($senderaddress) { $msg->add('Reply-to',$senderaddress); } if (my $fh = $msg->open()) { print $fh $body; $fh->close; @@ -286,8 +297,8 @@ sub author_res_msg { ($msgid,$message)=&packagemsg($filename,$message); return &Apache::lonnet::reply('put:'.$domain.':'.$author. ':nohist_res_msgs:'. - &Apache::lonnet::escape($filename.'_'.$id).'='. - &Apache::lonnet::escape($message),$homeserver); + &escape($filename.'_'.$id).'='. + &escape($message),$homeserver); } return 'no_host'; } @@ -352,6 +363,18 @@ sub all_url_author_res_msg { return %returnhash; } +# ====================================== Add a comment to the User Notes screen + +sub store_instructor_comment { + my ($msg,$uname,$udom) = @_; + my $cid = $env{'request.course.id'}; + my $cnum = $env{'course.'.$cid.'.num'}; + my $cdom = $env{'course.'.$cid.'.domain'}; + my $subject= &mt('Record').' ['.$uname.':'.$udom.']'; + my $result = &user_normal_msg_raw($cnum,$cdom,$subject,$msg); + return $result; +} + # ================================================== Critical message to a user sub user_crit_msg_raw { @@ -367,8 +390,8 @@ sub user_crit_msg_raw { if ($sendback) { $message.='true'; } $status=&Apache::lonnet::critical( 'put:'.$domain.':'.$user.':critical:'. - &Apache::lonnet::escape($msgid).'='. - &Apache::lonnet::escape($message),$homeserver); + &escape($msgid).'='. + &escape($message),$homeserver); if (defined($sentmessage)) { $$sentmessage = $message; } @@ -376,9 +399,7 @@ sub user_crit_msg_raw { $status='no_host'; } # Notifications - my %userenv = &Apache::lonnet::get('environment',['critnotification', - 'permanentemail'], - $domain,$user); + my %userenv = &Apache::loncommon::getemails($user,$domain); if ($userenv{'critnotification'}) { &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1, $text); @@ -486,8 +507,8 @@ sub user_normal_msg_raw { # Store in user folder $status=&Apache::lonnet::critical( 'put:'.$domain.':'.$user.':nohist_email:'. - &Apache::lonnet::escape($msgid).'='. - &Apache::lonnet::escape($packed_message),$homeserver); + &escape($msgid).'='. + &escape($packed_message),$homeserver); # Save new message received time &Apache::lonnet::put ('email_status',{'recnewemail'=>time},$domain,$user); @@ -571,8 +592,8 @@ sub store_sent_mail { my $status =' '.&Apache::lonnet::critical( 'put:'.$env{'user.domain'}.':'.$env{'user.name'}. ':nohist_email_sent:'. - &Apache::lonnet::escape($msgid).'='. - &Apache::lonnet::escape($message),$env{'user.home'}); + &escape($msgid).'='. + &escape($message),$env{'user.home'}); return $status; } @@ -581,7 +602,7 @@ sub store_sent_mail { sub foldersuffix { my $folder=shift; unless ($folder) { return ''; } - return '_'.&Apache::lonnet::escape($folder); + return '_'.&escape($folder); } 1;