--- loncom/interface/lonmsg.pm 2004/05/17 19:00:45 1.101 +++ loncom/interface/lonmsg.pm 2004/09/10 06:38:24 1.106 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.101 2004/05/17 19:00:45 raeburn Exp $ +# $Id: lonmsg.pm,v 1.106 2004/09/10 06:38:24 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -201,10 +201,12 @@ sub unpackagemsg { # ======================================================= Get info out of msgid sub unpackmsgid { - my $msgid=&Apache::lonnet::unescape(shift); + my ($msgid,$folder)=@_; + $msgid=&Apache::lonnet::unescape($msgid); + my $suffix=&foldersuffix($folder); my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/, &Apache::lonnet::unescape($msgid)); - my %status=&Apache::lonnet::get('email_status',[$msgid]); + my %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}); @@ -219,10 +221,14 @@ sub sendemail { my $msg = new Mail::Send; $msg->to($to); $msg->subject('[LON-CAPA] '.$subject); + my %oldENV=%ENV; + undef(%ENV); if (my $fh = $msg->open()) { print $fh $body; $fh->close; } + %ENV=%oldENV; + undef(%oldENV); } # ==================================================== Send notification emails @@ -494,22 +500,71 @@ sub user_normal_msg { } +# ============================================================ List all folders + +sub folderlist { + my $folder=shift; + my @allfolders=&Apache::lonnet::getkeys('email_folders'); + if ($allfolders[0]=~/^error:/) { @allfolders=(); } + return '
'; +} +# =============================================================== Folder suffix + +sub foldersuffix { + my $folder=shift; + unless ($folder) { return ''; } + return '_'.&Apache::lonnet::escape($folder); +} + # =============================================================== Status Change sub statuschange { - my ($msgid,$newstatus)=@_; - my %status=&Apache::lonnet::get('email_status',[$msgid]); + my ($msgid,$newstatus,$folder)=@_; + my $suffix=&foldersuffix($folder); + my %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]); if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; } unless ($status{$msgid}) { $status{$msgid}='new'; } unless (($status{$msgid} eq 'replied') || ($status{$msgid} eq 'forwarded')) { - &Apache::lonnet::put('email_status',{$msgid => $newstatus}); + &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus}); } if (($newstatus eq 'deleted') || ($newstatus eq 'new')) { - &Apache::lonnet::put('email_status',{$msgid => $newstatus}); + &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus}); } } +# ============================================================= Make new folder + +sub makefolder { + my ($newfolder)=@_; + &Apache::lonnet::put('email_folders',{$newfolder => time}); +} + +# ======================================================== Move between folders + +sub movemsg { + my ($msgid,$srcfolder,$trgfolder)=@_; + my $srcsuffix=&foldersuffix($srcfolder); + my $trgsuffix=&foldersuffix($trgfolder); + my $srcstatus=&Apache::lonnet::get('email_status'.$srcsuffix,[$msgid]); + my $trgstatus=$srcstatus; + if ($trgstatus eq 'deleted') { $trgstatus='read'; } + &Apache::lonnet::put( + 'nohist_email'.$trgsuffix,{$msgid => + &Apache::lonnet::get('nohist_email'.$srcsuffix,[$msgid])}); + &statuschange($msgid,$trgstatus,$trgfolder); + &Apache::lonnet::del('nohist_email'.$srcsuffix,[$msgid]); + &Apache::lonnet::del('email_status'.$srcsuffix,[$msgid]); +} + # ======================================================= Display a course list sub discourse { @@ -607,13 +662,13 @@ sub discrit { my %content=&unpackagemsg($what{$_}); next if ($content{'senderdomain'} eq ''); $content{'message'}=~s/\n/\'. + '
'.&mt('Subject').': '.$content{'subject'}. + ''. &Apache::lontexconvert::msgtexconverted($content{'message'}). ''. &mt('You have to confirm that you received this message. After confirmation, this message will be moved to your regular inbox'). @@ -625,17 +680,19 @@ $content{'sendername'}.'@'. # Check to see if there were any messages. if ($result eq '') { $result = "".&mt('You have no critical messages.')."
". - ''.&mt('Select a course').''; + ''.&mt('Select a course').'
'. + ''.&mt('Communicate').''; } else { $r->print($header); } $r->print($result); - $r->print(''); + $r->print(''); } sub sortedmessages { - my ($blocked,$startblock,$endblock,$numblocked) = @_; - my @messages = &Apache::lonnet::getkeys('nohist_email'); + my ($blocked,$startblock,$endblock,$numblocked,$folder) = @_; + my $suffix=&foldersuffix($folder); + my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix); #unpack the varibles and repack into temp for sorting my @temp; foreach (@messages) { @@ -691,7 +748,7 @@ sub sortedmessages { # ======================================================== Display all messages sub disall { - my $r=shift; + my ($r,$folder)=@_; my %blocked = (); my %setters = (); my $startblock; @@ -719,9 +776,10 @@ sub disall { } ENDDISHEADER - $r->print(''.&mt('Display All Messages').'