--- loncom/interface/lonmsg.pm 2005/11/29 22:41:30 1.159 +++ loncom/interface/lonmsg.pm 2006/01/05 19:52:52 1.168 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.159 2005/11/29 22:41:30 raeburn Exp $ +# $Id: lonmsg.pm,v 1.168 2006/01/05 19:52:52 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -97,6 +97,17 @@ Right now, this document will cover just it is likely you will not need to programmatically read messages, since lonmsg already implements that functionality. +The routines used to package messages and unpackage messages are not +only used by lonmsg when creating/extracting messages for LON-CAPA's +internal messaging system, but also by lonnotify.pm which is available +for use by Domain Coordinators to broadcast standard e-mail to specified +users in their domain. The XML packaging used in the two cases is very +similar. The differences are the use of $uname and +$udom in stored internal messages, compared +with $email in stored +Domain Coordinator e-mail for the storage of information about +recipients of the message/e-mail. + =head1 FUNCTIONS =over 4 @@ -126,7 +137,7 @@ my $interdis; sub packagemsg { my ($subject,$message,$citation,$baseurl,$attachmenturl, - $recuser,$recdomain,$msgid)=@_; + $recuser,$recdomain,$msgid,$type)=@_; $message =&HTML::Entities::encode($message,'<>&"'); $citation=&HTML::Entities::encode($citation,'<>&"'); $subject =&HTML::Entities::encode($subject,'<>&"'); @@ -142,6 +153,14 @@ sub packagemsg { split(/\:/,&Apache::lonnet::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)); + $course_context = $origcid; + last; + } + } unless(defined($course_context)) { $course_context = $env{'request.course.id'}; } @@ -170,8 +189,18 @@ sub packagemsg { ''.$msgid.''; if (ref($recuser) eq 'ARRAY') { for (my $i=0; $i<@{$recuser}; $i++) { - $result .= ''.$$recuser[$i].''. - ''.$$recdomain[$i].''; + if ($type eq 'dcmail') { + my ($username,$email) = split(/:/,$$recuser[$i]); + $username = &Apache::lonnet::unescape($username); + $email = &Apache::lonnet::unescape($email); + $username = &HTML::Entities::encode($username,'<>&"'); + $email = &HTML::Entities::encode($email,'<>&"'); + $result .= ''. + $email.''; + } else { + $result .= ''.$$recuser[$i].''. + ''.$$recdomain[$i].''; + } } } else { $result .= ''.$recuser.''. @@ -203,11 +232,16 @@ sub unpackagemsg { my $value=$parser->get_text('/'.$entry); if (($entry eq 'recuser') || ($entry eq 'recdomain')) { push(@{$content{$entry}},$value); + } elsif ($entry eq 'recipient') { + my $username = $token->[2]{'username'}; + $username = &HTML::Entities::decode($username,'<>&"'); + $content{$entry}{$username} = $value; } else { $content{$entry}=$value; } } } + if (!exists($content{'recuser'})) { $content{'recuser'} = []; } if ($content{'attachmenturl'}) { my ($fname)=($content{'attachmenturl'}=~m|/([^/]+)$|); if ($notoken) { @@ -233,14 +267,18 @@ sub buildmsgid { } sub unpackmsgid { - my ($msgid,$folder)=@_; + my ($msgid,$folder,$skipstatus)=@_; $msgid=&Apache::lonnet::unescape($msgid); - my $suffix=&foldersuffix($folder); - my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid)=split(/\:/, - &Apache::lonnet::unescape($msgid)); - my %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]); - if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; } - unless ($status{$msgid}) { $status{$msgid}='new'; } + my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid, + $processid)=split(/\:/,&Apache::lonnet::unescape($msgid)); + if (!defined($processid)) { $fromcid = ''; } + my %status=(); + unless ($skipstatus) { + my $suffix=&foldersuffix($folder); + %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]); + if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; } + unless ($status{$msgid}) { $status{$msgid}='new'; } + } return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid); } @@ -820,11 +858,12 @@ sub sortedmessages { my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix); #unpack the varibles and repack into temp for sorting my @temp; + my %descriptions; foreach (@messages) { my $msgid=&Apache::lonnet::escape($_); my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)= &Apache::lonmsg::unpackmsgid($msgid,$folder); - my $description = &get_course_desc($fromcid); + my $description = &get_course_desc($fromcid,\%descriptions); my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status, $msgid,$description); # Check whether message was sent during blocking period. @@ -878,15 +917,24 @@ sub sortedmessages { } sub get_course_desc { - my ($fromcid) = @_; - my $description; - if (defined($env{'course.'.$fromcid.'.description'})) { - $description = $env{'course.'.$fromcid.'.description'}; + my ($fromcid,$descriptions) = @_; + my $description; + if (!$fromcid) { + return $description; } else { - my %courseinfo=&Apache::lonnet::coursedescription($fromcid); - $description = $courseinfo{'description'}; + if (defined($$descriptions{$fromcid})) { + $description = $$descriptions{$fromcid}; + } else { + if (defined($env{'course.'.$fromcid.'.description'})) { + $description = $env{'course.'.$fromcid.'.description'}; + } else { + my %courseinfo=&Apache::lonnet::coursedescription($fromcid); $description = $courseinfo{'description'}; + $description = $courseinfo{'description'}; + } + $$descriptions{$fromcid} = $description; + } + return $description; } - return $description; } # ======================================================== Display new messages @@ -915,11 +963,12 @@ sub disnew { my $numblocked = 0; # Check for blocking of display because of scheduled online exams. &blockcheck(\%setters,\$startblock,\$endblock); + my %descriptions; foreach (@msgids) { my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)= &Apache::lonmsg::unpackmsgid($_); if (defined($sendtime) && $sendtime!~/error/) { - my $description = &get_course_desc($fromcid); + my $description = &get_course_desc($fromcid,\%descriptions); my $numsendtime = $sendtime; $sendtime = &Apache::lonlocal::locallocaltime($sendtime); if ($status eq 'new') { @@ -1181,8 +1230,8 @@ sub compout { &mt('and return receipt') . '' . $crithelp . '

'. -'

'; } +''; } my %message; my %content; my $defdom=$env{'user.domain'};