--- loncom/interface/lonmsg.pm 2006/04/11 14:17:23 1.181 +++ loncom/interface/lonmsg.pm 2006/12/06 17:14:50 1.188 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.181 2006/04/11 14:17:23 albertel Exp $ +# $Id: lonmsg.pm,v 1.188 2006/12/06 17:14:50 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,6 +33,7 @@ use Apache::lonnet; use HTML::TokeParser(); use Apache::lonlocal; use Mail::Send; +use LONCAPA qw(:DEFAULT :match); { my $uniq; @@ -59,13 +60,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 +109,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,16 +179,18 @@ 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)); + $processid)=split(/\:/,&unescape($msgid)); + $shortsubj = &unescape($shortsubj); + $shortsubj = &HTML::Entities::decode($shortsubj); if (!defined($processid)) { $fromcid = ''; } my %status=(); unless ($skipstatus) { @@ -206,12 +209,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); $msg->add('From',$senderaddress); } if (my $fh = $msg->open()) { print $fh $body; $fh->close; @@ -284,8 +296,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'; } @@ -295,7 +307,7 @@ sub author_res_msg { sub retrieve_author_res_msg { my $url=shift; $url=&Apache::lonnet::declutter($url); - my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//); + my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//); my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$domain,$author); my $msgs=''; foreach (keys %errormsgs) { @@ -315,7 +327,7 @@ sub retrieve_author_res_msg { sub del_url_author_res_msg { my $url=shift; $url=&Apache::lonnet::declutter($url); - my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//); + my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//); my @delmsgs=(); foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) { if ($_=~/^\Q$url\E\_\d+$/) { @@ -329,7 +341,7 @@ sub del_url_author_res_msg { sub clear_author_res_msg { my $url=shift; $url=&Apache::lonnet::declutter($url); - my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//); + my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//); my @delmsgs=(); foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) { if ($_=~/^\Q$url\E/) { @@ -350,6 +362,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 { @@ -365,8 +389,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; } @@ -374,9 +398,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); @@ -404,25 +426,38 @@ sub user_crit_msg_raw { a critical message $message to the $user at $domain. If $sendback is true, a reciept will be sent to the current user when $user recieves the message. + Additionally it will check if the user has a Forwarding address + set, and send the message to that address instead + + returns + - in array context a list of results for each message that was sent + - in scalar context a space seperated list of results for each + message sent + =cut sub user_crit_msg { my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_; - my $status=''; + my @status; my %userenv = &Apache::lonnet::get('environment',['msgforward'], $domain,$user); my $msgforward=$userenv{'msgforward'}; if ($msgforward) { - foreach (split(/\,/,$msgforward)) { - my ($forwuser,$forwdomain)=split(/\:/,$_); - $status.= - &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message, - $sendback,$toperm,$sentmessage).' '; + foreach my $addr (split(/\,/,$msgforward)) { + my ($forwuser,$forwdomain)=split(/\:/,$addr); + push(@status, + &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message, + $sendback,$toperm,$sentmessage)); } } else { - $status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage); + push(@status, + &user_crit_msg_raw($user,$domain,$subject,$message,$sendback, + $toperm,$sentmessage)); } - return $status; + if (wantarray) { + return @status; + } + return join(' ',@status); } # =================================================== Critical message received @@ -471,8 +506,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); @@ -556,8 +591,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; } @@ -566,7 +601,7 @@ sub store_sent_mail { sub foldersuffix { my $folder=shift; unless ($folder) { return ''; } - return '_'.&Apache::lonnet::escape($folder); + return '_'.&escape($folder); } 1;