File:  [LON-CAPA] / loncom / interface / lonmsg.pm
Revision 1.185: download - view: text, annotated - select for diffs
Mon Jun 12 22:55:23 2006 UTC (18 years ago) by albertel
Branches: MAIN
CVS tags: version_2_2_X, version_2_2_2, version_2_2_1, version_2_2_0, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, HEAD
- braak at the notes adding lines, for use elsewhere

    1: # The LearningOnline Network with CAPA
    2: # Routines for messaging
    3: #
    4: # $Id: lonmsg.pm,v 1.185 2006/06/12 22:55:23 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::lonmsg;
   30: 
   31: use strict;
   32: use Apache::lonnet;
   33: use HTML::TokeParser();
   34: use Apache::lonlocal;
   35: use Mail::Send;
   36: use lib '/home/httpd/lib/perl/';
   37: use LONCAPA;
   38: 
   39: {
   40:     my $uniq;
   41:     sub get_uniq {
   42: 	$uniq++;
   43: 	return $uniq;
   44:     }
   45: }
   46: 
   47: # ===================================================================== Package
   48: 
   49: sub packagemsg {
   50:     my ($subject,$message,$citation,$baseurl,$attachmenturl,
   51: 	$recuser,$recdomain,$msgid,$type,$crsmsgid)=@_;
   52:     $message =&HTML::Entities::encode($message,'<>&"');
   53:     $citation=&HTML::Entities::encode($citation,'<>&"');
   54:     $subject =&HTML::Entities::encode($subject,'<>&"');
   55:     #remove machine specification
   56:     $baseurl =~ s|^http://[^/]+/|/|;
   57:     $baseurl =&HTML::Entities::encode($baseurl,'<>&"');
   58:     #remove machine specification
   59:     $attachmenturl =~ s|^http://[^/]+/|/|;
   60:     $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
   61:     my $course_context;
   62:     if (defined($env{'form.replyid'})) {
   63:         my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
   64:                    split(/\:/,&unescape($env{'form.replyid'}));
   65:         $course_context = $origcid;
   66:     }
   67:     foreach my $key (keys(%env)) {
   68:         if ($key=~/^form\.(rep)?rec\_(.*)$/) {
   69:             my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =
   70:                                     split(/\:/,&unescape($2));
   71:             $course_context = $origcid;
   72:             last;
   73:         }
   74:     }
   75:     unless(defined($course_context)) {
   76:         $course_context = $env{'request.course.id'};
   77:     }
   78:     my $now=time;
   79:     my $msgcount = &get_uniq();
   80:     unless(defined($msgid)) {
   81:         $msgid = &buildmsgid($now,$subject,$env{'user.name'},$env{'user.domain'},
   82:                             $msgcount,$course_context,$$);
   83:     }
   84:     my $result = '<sendername>'.$env{'user.name'}.'</sendername>'.
   85:            '<senderdomain>'.$env{'user.domain'}.'</senderdomain>'.
   86:            '<subject>'.$subject.'</subject>'.
   87:            '<time>'.&Apache::lonlocal::locallocaltime($now).'</time>';
   88:     if (defined($crsmsgid)) {
   89:         $result.= '<courseid>'.$course_context.'</courseid>'.
   90:                   '<coursesec>'.$env{'request.course.sec'}.'</coursesec>'.
   91:                   '<msgid>'.$msgid.'</msgid>'.
   92:                   '<coursemsgid>'.$crsmsgid.'</coursemsgid>'.
   93:                   '<message>'.$message.'</message>';
   94:         return ($msgid,$result);
   95:     }
   96:     $result .= '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
   97:            '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
   98: 	   '<client>'.$ENV{'REMOTE_ADDR'}.'</client>'.
   99: 	   '<browsertype>'.$env{'browser.type'}.'</browsertype>'.
  100: 	   '<browseros>'.$env{'browser.os'}.'</browseros>'.
  101: 	   '<browserversion>'.$env{'browser.version'}.'</browserversion>'.
  102:            '<browsermathml>'.$env{'browser.mathml'}.'</browsermathml>'.
  103: 	   '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
  104: 	   '<courseid>'.$course_context.'</courseid>'.
  105: 	   '<coursesec>'.$env{'request.course.sec'}.'</coursesec>'.
  106: 	   '<role>'.$env{'request.role'}.'</role>'.
  107: 	   '<resource>'.$env{'request.filename'}.'</resource>'.
  108:            '<msgid>'.$msgid.'</msgid>';
  109:     if (ref($recuser) eq 'ARRAY') {
  110:         for (my $i=0; $i<@{$recuser}; $i++) {
  111:             if ($type eq 'dcmail') {
  112:                 my ($username,$email) = split(/:/,$$recuser[$i]);
  113:                 $username = &unescape($username);
  114:                 $email = &unescape($email);
  115:                 $username = &HTML::Entities::encode($username,'<>&"');
  116:                 $email = &HTML::Entities::encode($email,'<>&"');
  117:                 $result .= '<recipient username="'.$username.'">'.
  118:                                             $email.'</recipient>';
  119:             } else {
  120:                 $result .= '<recuser>'.$$recuser[$i].'</recuser>'.
  121:                            '<recdomain>'.$$recdomain[$i].'</recdomain>';
  122:             }
  123:         }
  124:     } else {
  125:         $result .= '<recuser>'.$recuser.'</recuser>'.
  126:                    '<recdomain>'.$recdomain.'</recdomain>';
  127:     }
  128:     $result .= '<message>'.$message.'</message>';
  129:     if (defined($citation)) {
  130: 	$result.='<citation>'.$citation.'</citation>';
  131:     }
  132:     if (defined($baseurl)) {
  133: 	$result.= '<baseurl>'.$baseurl.'</baseurl>';
  134:     }
  135:     if (defined($attachmenturl)) {
  136: 	$result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>';
  137:     }
  138:     return $msgid,$result;
  139: }
  140: 
  141: # ================================================== Unpack message into a hash
  142: 
  143: sub unpackagemsg {
  144:     my ($message,$notoken)=@_;
  145:     my %content=();
  146:     my $parser=HTML::TokeParser->new(\$message);
  147:     my $token;
  148:     while ($token=$parser->get_token) {
  149:        if ($token->[0] eq 'S') {
  150: 	   my $entry=$token->[1];
  151:            my $value=$parser->get_text('/'.$entry);
  152:            if (($entry eq 'recuser') || ($entry eq 'recdomain')) {
  153:                push(@{$content{$entry}},$value);
  154:            } elsif ($entry eq 'recipient') {
  155:                my $username = $token->[2]{'username'};
  156:                $username = &HTML::Entities::decode($username,'<>&"');
  157:                $content{$entry}{$username} = $value;
  158:            } else {
  159:                $content{$entry}=$value;
  160:            }
  161:        }
  162:     }
  163:     if (!exists($content{'recuser'})) { $content{'recuser'} = []; }
  164:     if ($content{'attachmenturl'}) {
  165:        my ($fname)=($content{'attachmenturl'}=~m|/([^/]+)$|);
  166:        if ($notoken) {
  167: 	   $content{'message'}.='<p>'.&mt('Attachment').': <tt>'.$fname.'</tt>';
  168:        } else {
  169: 	   &Apache::lonnet::allowuploaded('/adm/msg',
  170: 					  $content{'attachmenturl'});
  171: 	   $content{'message'}.='<p>'.&mt('Attachment').
  172: 	       ': <a href="'.$content{'attachmenturl'}.'"><tt>'.
  173: 	       $fname.'</tt></a>';
  174:        }
  175:     }
  176:     return %content;
  177: }
  178: 
  179: # ======================================================= Get info out of msgid
  180: 
  181: sub buildmsgid {
  182:     my ($now,$subject,$uname,$udom,$msgcount,$course_context,$pid) = @_;
  183:     $subject=&escape($subject);
  184:     return(&escape($now.':'.$subject.':'.$uname.':'.
  185:            $udom.':'.$msgcount.':'.$course_context.':'.$pid));
  186: }
  187: 
  188: sub unpackmsgid {
  189:     my ($msgid,$folder,$skipstatus,$status_cache)=@_;
  190:     $msgid=&unescape($msgid);
  191:     my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid,
  192:                      $processid)=split(/\:/,&unescape($msgid));
  193:     $shortsubj = &unescape($shortsubj);
  194:     $shortsubj = &HTML::Entities::decode($shortsubj);
  195:     if (!defined($processid)) { $fromcid = ''; }
  196:     my %status=();
  197:     unless ($skipstatus) {
  198: 	if (ref($status_cache)) {
  199: 	    $status{$msgid} = $status_cache->{$msgid};
  200: 	} else {
  201: 	    my $suffix=&foldersuffix($folder);
  202: 	    %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
  203: 	}
  204: 	if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
  205:         unless ($status{$msgid}) { $status{$msgid}='new'; }
  206:     }
  207:     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid);
  208: }
  209: 
  210: 
  211: sub sendemail {
  212:     my ($to,$subject,$body)=@_;
  213:     $body=
  214:     "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n".
  215:     "*** ".&mt('Please do not reply to this address.')."\n\n".$body;
  216:     my $msg = new Mail::Send;
  217:     $msg->to($to);
  218:     $msg->subject('[LON-CAPA] '.$subject);
  219:     if (my $fh = $msg->open()) {
  220: 	print $fh $body;
  221: 	$fh->close;
  222:     }
  223: }
  224: 
  225: # ==================================================== Send notification emails
  226: 
  227: sub sendnotification {
  228:     my ($to,$touname,$toudom,$subj,$crit,$text)=@_;
  229:     my $sender=$env{'environment.firstname'}.' '.$env{'environment.lastname'};
  230:     unless ($sender=~/\w/) { 
  231: 	$sender=$env{'user.name'}.'@'.$env{'user.domain'};
  232:     }
  233:     my $critical=($crit?' critical':'');
  234:     $text=~s/\&lt\;/\</gs;
  235:     $text=~s/\&gt\;/\>/gs;
  236:     $text=~s/\<\/*[^\>]+\>//gs;
  237:     my $url='http://'.
  238:       $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}.
  239:       '/adm/email?username='.$touname.'&domain='.$toudom;
  240:     my $body=(<<ENDMSG);
  241: You received a$critical message from $sender in LON-CAPA. The subject is
  242: 
  243:  $subj
  244: 
  245: === Excerpt ============================================================
  246: $text
  247: ========================================================================
  248: 
  249: Use
  250: 
  251:  $url
  252: 
  253: to access the full message.
  254: ENDMSG
  255:     &sendemail($to,'New'.$critical.' message from '.$sender,$body);
  256: }
  257: # ============================================================= Check for email
  258: 
  259: sub newmail {
  260:     if ((time-$env{'user.mailcheck.time'})>300) {
  261:         my %what=&Apache::lonnet::get('email_status',['recnewemail']);
  262:         &Apache::lonnet::appenv('user.mailcheck.time'=>time);
  263:         if ($what{'recnewemail'}>0) { return 1; }
  264:     }
  265:     return 0;
  266: }
  267: 
  268: # =============================== Automated message to the author of a resource
  269: 
  270: =pod
  271: 
  272: =item * B<author_res_msg($filename, $message)>: Sends message $message to the owner
  273:     of the resource with the URI $filename.
  274: 
  275: =cut
  276: 
  277: sub author_res_msg {
  278:     my ($filename,$message)=@_;
  279:     unless ($message) { return 'empty'; }
  280:     $filename=&Apache::lonnet::declutter($filename);
  281:     my ($domain,$author,@dummy)=split(/\//,$filename);
  282:     my $homeserver=&Apache::lonnet::homeserver($author,$domain);
  283:     if ($homeserver ne 'no_host') {
  284:        my $id=unpack("%32C*",$message);
  285:        $message .= " <p>This error occurred on machine ".
  286: 	   $Apache::lonnet::perlvar{'lonHostID'}."</p>";
  287:        my $msgid;
  288:        ($msgid,$message)=&packagemsg($filename,$message);
  289:        return &Apache::lonnet::reply('put:'.$domain.':'.$author.
  290:          ':nohist_res_msgs:'.
  291:           &escape($filename.'_'.$id).'='.
  292:           &escape($message),$homeserver);
  293:     }
  294:     return 'no_host';
  295: }
  296: 
  297: # =========================================== Retrieve author resource messages
  298: 
  299: sub retrieve_author_res_msg {
  300:     my $url=shift;
  301:     $url=&Apache::lonnet::declutter($url);
  302:     my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
  303:     my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$domain,$author);
  304:     my $msgs='';
  305:     foreach (keys %errormsgs) {
  306: 	if ($_=~/^\Q$url\E\_\d+$/) {
  307: 	    my %content=&unpackagemsg($errormsgs{$_});
  308: 	    $msgs.='<p><img src="/adm/lonMisc/bomb.gif" /><b>'.
  309: 		$content{'time'}.'</b>: '.$content{'message'}.
  310: 		'<br /></p>';
  311: 	}
  312:     } 
  313:     return $msgs;     
  314: }
  315: 
  316: 
  317: # =============================== Delete all author messages related to one URL
  318: 
  319: sub del_url_author_res_msg {
  320:     my $url=shift;
  321:     $url=&Apache::lonnet::declutter($url);
  322:     my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
  323:     my @delmsgs=();
  324:     foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
  325: 	if ($_=~/^\Q$url\E\_\d+$/) {
  326: 	    push (@delmsgs,$_);
  327: 	}
  328:     }
  329:     return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
  330: }
  331: # =================================== Clear out all author messages in URL path
  332: 
  333: sub clear_author_res_msg {
  334:     my $url=shift;
  335:     $url=&Apache::lonnet::declutter($url);
  336:     my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
  337:     my @delmsgs=();
  338:     foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
  339: 	if ($_=~/^\Q$url\E/) {
  340: 	    push (@delmsgs,$_);
  341: 	}
  342:     }
  343:     return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
  344: }
  345: # ================= Return hash with URLs for which there is a resource message
  346: 
  347: sub all_url_author_res_msg {
  348:     my ($author,$domain)=@_;
  349:     my %returnhash=();
  350:     foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
  351: 	$_=~/^(.+)\_\d+/;
  352: 	$returnhash{$1}=1;
  353:     }
  354:     return %returnhash;
  355: }
  356: 
  357: # ====================================== Add a comment to the User Notes screen
  358: 
  359: sub store_instructor_comment {
  360:     my ($msg,$uname,$udom) = @_;
  361:     my $cid  = $env{'request.course.id'};
  362:     my $cnum = $env{'course.'.$cid.'.num'};
  363:     my $cdom = $env{'course.'.$cid.'.domain'};
  364:     my $subject= &mt('Record').' ['.$uname.':'.$udom.']';
  365:     my $result = &user_normal_msg_raw($cnum,$cdom,$subject,$msg);
  366:     return $result;
  367: }
  368: 
  369: # ================================================== Critical message to a user
  370: 
  371: sub user_crit_msg_raw {
  372:     my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
  373: # Check if allowed missing
  374:     my $status='';
  375:     my $msgid='undefined';
  376:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
  377:     my $text=$message;
  378:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
  379:     if ($homeserver ne 'no_host') {
  380:        ($msgid,$message)=&packagemsg($subject,$message);
  381:        if ($sendback) { $message.='<sendback>true</sendback>'; }
  382:        $status=&Apache::lonnet::critical(
  383:            'put:'.$domain.':'.$user.':critical:'.
  384:            &escape($msgid).'='.
  385:            &escape($message),$homeserver);
  386:         if (defined($sentmessage)) {
  387:             $$sentmessage = $message;
  388:         }
  389:     } else {
  390:        $status='no_host';
  391:     }
  392: # Notifications
  393:     my %userenv = &Apache::lonnet::get('environment',['critnotification',
  394:                                                       'permanentemail'],
  395:                                        $domain,$user);
  396:     if ($userenv{'critnotification'}) {
  397:       &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1,
  398: 			$text);
  399:     }
  400:     if ($toperm && $userenv{'permanentemail'}) {
  401:       &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,1,
  402: 			$text);
  403:     }
  404: # Log this
  405:     &Apache::lonnet::logthis(
  406:       'Sending critical email '.$msgid.
  407:       ', log status: '.
  408:       &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
  409:                          $env{'user.home'},
  410:       'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
  411:       .$status));
  412:     return $status;
  413: }
  414: 
  415: # New routine that respects "forward" and calls old routine
  416: 
  417: =pod
  418: 
  419: =item * B<user_crit_msg($user, $domain, $subject, $message, $sendback)>: Sends
  420:     a critical message $message to the $user at $domain. If $sendback is true,
  421:     a reciept will be sent to the current user when $user recieves the message.
  422: 
  423:     Additionally it will check if the user has a Forwarding address
  424:     set, and send the message to that address instead
  425: 
  426:     returns 
  427:       - in array context a list of results for each message that was sent
  428:       - in scalar context a space seperated list of results for each 
  429:            message sent
  430: 
  431: =cut
  432: 
  433: sub user_crit_msg {
  434:     my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
  435:     my @status;
  436:     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
  437:                                        $domain,$user);
  438:     my $msgforward=$userenv{'msgforward'};
  439:     if ($msgforward) {
  440:        foreach my $addr (split(/\,/,$msgforward)) {
  441: 	 my ($forwuser,$forwdomain)=split(/\:/,$addr);
  442:          push(@status,
  443: 	      &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
  444: 				 $sendback,$toperm,$sentmessage));
  445:        }
  446:     } else { 
  447: 	push(@status,
  448: 	     &user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
  449: 				$toperm,$sentmessage));
  450:     }
  451:     if (wantarray) {
  452: 	return @status;
  453:     }
  454:     return join(' ',@status);
  455: }
  456: 
  457: # =================================================== Critical message received
  458: 
  459: sub user_crit_received {
  460:     my $msgid=shift;
  461:     my %message=&Apache::lonnet::get('critical',[$msgid]);
  462:     my %contents=&unpackagemsg($message{$msgid},1);
  463:     my $status='rec: '.($contents{'sendback'}?
  464:      &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
  465:                      &mt('Receipt').': '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.', '.$contents{'subject'},
  466:                      &mt('User').' '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.
  467:                      ' acknowledged receipt of message'."\n".'   "'.
  468:                      $contents{'subject'}.'"'."\n".&mt('dated').' '.
  469:                      $contents{'time'}.".\n"
  470:                      ):'no msg req');
  471:     $status.=' trans: '.
  472:      &Apache::lonnet::put(
  473:      'nohist_email',{$contents{'msgid'} => $message{$msgid}});
  474:     $status.=' del: '.
  475:      &Apache::lonnet::del('critical',[$contents{'msgid'}]);
  476:     &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
  477:                          $env{'user.home'},'Received critical message '.
  478:                          $contents{'msgid'}.
  479:                          ', '.$status);
  480:     return $status;
  481: }
  482: 
  483: # ======================================================== Normal communication
  484: 
  485: sub user_normal_msg_raw {
  486:     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
  487: 	$toperm,$currid,$newid,$sentmessage,$crsmsgid)=@_;
  488: # Check if allowed missing
  489:     my ($status,$packed_message);
  490:     my $msgid='undefined';
  491:     my $text=$message;
  492:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
  493:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
  494:     if ($homeserver ne 'no_host') {
  495:        ($msgid,$packed_message)=
  496: 	                 &packagemsg($subject,$message,$citation,$baseurl,
  497:                                      $attachmenturl,$user,$domain,$currid,
  498:                                                          undef,$crsmsgid);
  499: 
  500: # Store in user folder
  501:        $status=&Apache::lonnet::critical(
  502:            'put:'.$domain.':'.$user.':nohist_email:'.
  503:            &escape($msgid).'='.
  504:            &escape($packed_message),$homeserver);
  505: # Save new message received time
  506:        &Apache::lonnet::put
  507:                          ('email_status',{'recnewemail'=>time},$domain,$user);
  508: # Into sent-mail folder unless a broadcast message or critical message
  509:        unless (($env{'request.course.id'}) && 
  510:                (($env{'form.sendmode'} eq 'group')  || 
  511:                (($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
  512:                (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
  513: 		|| &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
  514: 					    '/'.$env{'request.course.sec'})))) {
  515:            (undef, my $packed_message_no_citation)=
  516:                              &packagemsg($subject,$message,undef     ,$baseurl,
  517:                                           $attachmenturl,$user,$domain,$currid,
  518:                                                               undef,$crsmsgid);
  519: 
  520:            $status .= &store_sent_mail($msgid,$packed_message_no_citation);
  521:        }
  522:     } else {
  523:        $status='no_host';
  524:     }
  525:     if (defined($newid)) {
  526:         $$newid = $msgid;
  527:     }
  528:     if (defined($sentmessage)) {
  529:         $$sentmessage = $packed_message;
  530:     }
  531: 
  532: # Notifications
  533:     my %userenv = &Apache::lonnet::get('environment',['notification',
  534:                                                       'permanentemail'],
  535:                                        $domain,$user);
  536:     if ($userenv{'notification'}) {
  537: 	&sendnotification($userenv{'notification'},$user,$domain,$subject,0,
  538: 			  $text);
  539:     }
  540:     if ($toperm && $userenv{'permanentemail'}) {
  541: 	&sendnotification($userenv{'permanentemail'},$user,$domain,$subject,0,
  542: 			  $text);
  543:     }
  544:     &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
  545:                          $env{'user.home'},
  546:       'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
  547:     return $status;
  548: }
  549: 
  550: # New routine that respects "forward" and calls old routine
  551: 
  552: =pod
  553: 
  554: =item * B<user_normal_msg($user, $domain, $subject, $message,
  555:     $citation, $baseurl, $attachmenturl)>: Sends a message to the
  556:     $user at $domain, with subject $subject and message $message.
  557: 
  558: =cut
  559: 
  560: sub user_normal_msg {
  561:     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
  562: 	$toperm,$sentmessage)=@_;
  563:     my $status='';
  564:     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
  565:                                        $domain,$user);
  566:     my $msgforward=$userenv{'msgforward'};
  567:     if ($msgforward) {
  568:         foreach (split(/\,/,$msgforward)) {
  569: 	    my ($forwuser,$forwdomain)=split(/\:/,$_);
  570: 	    $status.=
  571: 	        &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
  572: 				     $citation,$baseurl,$attachmenturl,$toperm,
  573: 				     undef,undef,$sentmessage).' ';
  574:         }
  575:     } else { 
  576: 	$status=&user_normal_msg_raw($user,$domain,$subject,$message,
  577: 				     $citation,$baseurl,$attachmenturl,$toperm,
  578: 				     undef,undef,$sentmessage);
  579:     }
  580:     return $status;
  581: }
  582: 
  583: sub store_sent_mail {
  584:     my ($msgid,$message) = @_;
  585:     my $status =' '.&Apache::lonnet::critical(
  586:                'put:'.$env{'user.domain'}.':'.$env{'user.name'}.
  587:                                           ':nohist_email_sent:'.
  588:                &escape($msgid).'='.
  589:                &escape($message),$env{'user.home'});
  590:     return $status;
  591: }
  592: 
  593: # =============================================================== Folder suffix
  594: 
  595: sub foldersuffix {
  596:     my $folder=shift;
  597:     unless ($folder) { return ''; }
  598:     return '_'.&escape($folder);
  599: }
  600: 
  601: 1;
  602: __END__
  603: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>