--- loncom/interface/lonmsg.pm 2006/01/03 03:18:58 1.166 +++ loncom/interface/lonmsg.pm 2006/01/05 20:10:54 1.169 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.166 2006/01/03 03:18:58 raeburn Exp $ +# $Id: lonmsg.pm,v 1.169 2006/01/05 20:10:54 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -241,6 +241,7 @@ sub unpackagemsg { } } } + if (!exists($content{'recuser'})) { $content{'recuser'} = []; } if ($content{'attachmenturl'}) { my ($fname)=($content{'attachmenturl'}=~m|/([^/]+)$|); if ($notoken) { @@ -266,15 +267,20 @@ sub buildmsgid { } sub unpackmsgid { - my ($msgid,$folder,$skipstatus)=@_; + my ($msgid,$folder,$skipstatus,$status_cache)=@_; $msgid=&Apache::lonnet::unescape($msgid); - my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid)=split(/\:/, - &Apache::lonnet::unescape($msgid)); + 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}=''; } + if (ref($status_cache)) { + $status{$msgid} = $status_cache->{$msgid}; + } else { + 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); @@ -856,14 +862,15 @@ sub sortedmessages { my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix); #unpack the varibles and repack into temp for sorting my @temp; + my %descriptions; + my %status_cache = + &Apache::lonnet::get('email_status'.&foldersuffix($folder),\@messages); foreach (@messages) { my $msgid=&Apache::lonnet::escape($_); my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)= - &Apache::lonmsg::unpackmsgid($msgid,$folder); - my $description; - if ($fromcid) { - $description = &get_course_desc($fromcid); - } + &Apache::lonmsg::unpackmsgid($msgid,$folder,undef, + \%status_cache); + my $description = &get_course_desc($fromcid,\%descriptions); my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status, $msgid,$description); # Check whether message was sent during blocking period. @@ -917,16 +924,24 @@ sub sortedmessages { } sub get_course_desc { - my ($fromcid) = @_; + my ($fromcid,$descriptions) = @_; my $description; - if ($fromcid =~ /^\d+$/) { return $description; } - if (defined($env{'course.'.$fromcid.'.description'})) { - $description = $env{'course.'.$fromcid.'.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 @@ -943,10 +958,7 @@ sub disnew { 'op' => 'Open', 'do' => 'Domain' ); - my @msgids = sort split(/\&/,&Apache::lonnet::reply - ('keys:'.$env{'user.domain'}.':'. - $env{'user.name'}.':nohist_email', - $env{'user.home'})); + my @msgids = sort(&Apache::lonnet::getkeys('nohist_email')); my @newmsgs; my %setters = (); my $startblock = 0; @@ -955,14 +967,15 @@ sub disnew { my $numblocked = 0; # Check for blocking of display because of scheduled online exams. &blockcheck(\%setters,\$startblock,\$endblock); + my %status_cache = + &Apache::lonnet::get('email_status',\@msgids); + my %descriptions; foreach (@msgids) { + my $msgid=&Apache::lonnet::escape($_); my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)= - &Apache::lonmsg::unpackmsgid($_); + &Apache::lonmsg::unpackmsgid($msgid,undef,undef,\%status_cache); if (defined($sendtime) && $sendtime!~/error/) { - my $description; - if ($fromcid) { - $description = &get_course_desc($fromcid); - } + my $description = &get_course_desc($fromcid,\%descriptions); my $numsendtime = $sendtime; $sendtime = &Apache::lonlocal::locallocaltime($sendtime); if ($status eq 'new') { @@ -971,7 +984,7 @@ sub disnew { $numblocked ++; } else { push @newmsgs, { - msgid => $_, + msgid => $msgid, sendtime => $sendtime, shortsub => &Apache::lonnet::unescape($shortsubj), from => $fromname,