--- loncom/interface/lonmsg.pm 2006/06/12 22:55:23 1.185 +++ loncom/interface/lonmsg.pm 2006/12/06 23:44:33 1.189 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.185 2006/06/12 22:55:23 albertel Exp $ +# $Id: lonmsg.pm,v 1.189 2006/12/06 23:44:33 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,8 +33,7 @@ use Apache::lonnet; use HTML::TokeParser(); use Apache::lonlocal; use Mail::Send; -use lib '/home/httpd/lib/perl/'; -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); { my $uniq; @@ -210,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; @@ -299,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) { @@ -319,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+$/) { @@ -333,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/) { @@ -390,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); @@ -595,7 +601,31 @@ sub store_sent_mail { sub foldersuffix { my $folder=shift; unless ($folder) { return ''; } - return '_'.&escape($folder); + my $suffix; + my %folderhash = &get_user_folders($folder); + if (ref($folderhash{$folder}) eq 'HASH') { + $suffix = '_'.&escape($folderhash{$folder}{'id'}); + } else { + $suffix = '_'.&escape($folder); + } + return $suffix; +} + +# ========================================================= User-defined folders + +sub get_user_folders { + my ($folder) = @_; + my %userfolders = + &Apache::lonnet::dump('email_folders',undef,undef,$folder); + my $lock = "\0".'lock_counter'; # locks db while counter incremented + my $counter = "\0".'idcount'; # used in suffix for email db files + if (defined($userfolders{$lock})) { + delete($userfolders{$lock}); + } + if (defined($userfolders{$counter})) { + delete($userfolders{$counter}); + } + return %userfolders; } 1;