File:  [LON-CAPA] / loncom / interface / lonmsg.pm
Revision 1.239.2.2: download - view: text, annotated - select for diffs
Mon Jan 4 03:44:12 2021 UTC (3 years, 5 months ago) by raeburn
Branches: version_2_11_X
CVS tags: version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3
Diff to branchpoint 1.239: preferred, unified
- For 2.11
  Backport 1.246

    1: # The LearningOnline Network with CAPA
    2: # Routines for messaging
    3: #
    4: # $Id: lonmsg.pm,v 1.239.2.2 2021/01/04 03:44:12 raeburn 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: =pod
   32: 
   33: =head1 NAME
   34: 
   35: Apache::lonmsg: supports internal messaging
   36: 
   37: =head1 SYNOPSIS
   38: 
   39: lonmsg provides routines for sending messages.
   40: 
   41: Right now, this document will cover just how to send a message, since
   42: it is likely you will not need to programmatically read messages,
   43: since lonmsg already implements that functionality.
   44: 
   45: The routines used to package messages and unpackage messages are not
   46: only used by lonmsg when creating/extracting messages for LON-CAPA's
   47: internal messaging system, but also by lonnotify.pm which is available
   48: for use by Domain Coordinators to broadcast standard e-mail to specified
   49: users in their domain.  The XML packaging used in the two cases is very
   50: similar.  The differences are the use of <recuser>$uname</recuser> and
   51: <recdomain>$udom</recdomain> in stored internal messages, compared
   52: with <recipient username="$uname:$udom">$email</recipient> in stored
   53: Domain Coordinator e-mail for the storage of information about
   54: recipients of the message/e-mail.
   55: 
   56: =head1 SUBROUTINES
   57: 
   58: =over
   59: 
   60: =pod
   61: 
   62: =item packagemsg()
   63: 
   64: Package
   65: 
   66: =item get_course_context()
   67: 
   68: =item unpackagemsg()
   69: 
   70: Unpack message into a hash
   71: 
   72: =item buildmsgid()
   73: 
   74: Get info out of msgid
   75: 
   76: =item unpackmsgid()
   77: 
   78: =item sendemail()
   79: 
   80: =item sendnotification()
   81: 
   82: Send notification emails
   83: 
   84: =item newmail()
   85: 
   86: Check for email
   87: 
   88: =item author_res_msg()
   89: 
   90: Automated message to the author of a resource
   91: 
   92: =item * B<author_res_msg($filename, $message)>: Sends message $message to the owner
   93:     of the resource with the URI $filename.
   94: 
   95: =item retrieve_author_res_msg()
   96: 
   97: Retrieve author resource messages
   98: 
   99: =item del_url_author_res_msg()
  100: 
  101: Delete all author messages related to one URL
  102: 
  103: =item clear_author_res_msg()
  104: 
  105: Clear out all author messages in URL path
  106: 
  107: =item all_url_author_res_msg()
  108: 
  109: Return hash with URLs for which there is a resource message
  110: 
  111: =item store_instructor_comment()
  112: 
  113: Add a comment to the User Notes screen
  114: 
  115: =item user_crit_msg_raw()
  116: 
  117: Critical message to a user
  118: 
  119: =item user_crit_msg()
  120: 
  121: New routine that respects "forward" and calls old routine
  122: 
  123: =item * B<user_crit_msg($user, $domain, $subject, $message, $sendback, $nosentstore, $recipid, $attachmenturl, $permresults)>: 
  124:     Sends a critical message $message to the $user at $domain.  If $sendback
  125:     is true,  a receipt will be sent to the current user when $user receives 
  126:     the message.
  127: 
  128:     Additionally it will check if the user has a Forwarding address
  129:     set, and send the message to that address instead
  130: 
  131:     returns 
  132:       - in array context a list of results for each message that was sent
  133:       - in scalar context a space seperated list of results for each 
  134:            message sent
  135: 
  136: 
  137: =item user_crit_received()
  138: 
  139: Critical message received
  140: 
  141: =item user_normal_msg_raw()
  142: 
  143: Normal communication
  144: 
  145: =item user_normal_msg()
  146: 
  147: New routine that respects "forward" and calls old routine
  148: 
  149: =item * B<user_normal_msg($user, $domain, $subject, $message, $citation,
  150:        $baseurl, $attachmenturl, $toperm, $sentmessage, $symb, $restitle,
  151:        $error,$nosentstore,$recipid,$permresults)>:
  152:  Sends a message to the  $user at $domain, with subject $subject and message $message.
  153: 
  154:     Additionally it will check if the user has a Forwarding address
  155:     set, and send the message to that address instead
  156: 
  157:     returns
  158:       - in array context a list of results for each message that was sent
  159:       - in scalar context a space seperated list of results for each
  160:            message sent
  161: 
  162: =item store_sent_mail()
  163: 
  164: =item store_recipients()
  165: 
  166: =item foldersuffix()
  167: 
  168: =item get_user_folders()
  169: 
  170: User-defined folders 
  171: 
  172: =item secapply()
  173: 
  174: =item B<decide_receiver($feedurl,$author,$question,$course,$policy,$defaultflag)>:
  175: 
  176: Arguments
  177:   $feedurl - /res/ url of resource (only need if $author is true)
  178:   $author,$question,$course,$policy - all true/false parameters
  179:     if true will attempt to find the addresses of user that should receive
  180:     this type of feedback (author - feedback to author of resource $feedurl,
  181:     $question 'Resource Content Questions', $course 'Course Content Question',
  182:     $policy 'Course Policy')
  183:     (Additionally it also checks $env for whether the corresponding form.<name>
  184:     element exists, for ease of use in a html response context)
  185:    
  186:   $defaultflag - (internal should be left blank) if true gather addresses 
  187:                  that aren't for a section even if I have a section
  188:                  (used for reccursion internally, first we look for
  189:                  addresses for our specific section then we recurse
  190:                  and look for non section addresses)
  191: 
  192: Returns
  193:   $typestyle - string of html text, describing what addresses were found
  194:   %to - a hash, which keys are addresses of users to send messages to
  195:         the keys will look like   name:domain
  196: 
  197: =back
  198: 
  199: =cut
  200: 
  201: use strict;
  202: use Apache::lonnet;
  203: use HTML::TokeParser();
  204: use Apache::lonlocal;
  205: use Mail::Send;
  206: use HTML::Entities;
  207: use Encode;
  208: use LONCAPA qw(:DEFAULT :match);
  209: 
  210: {
  211:     my $uniq;
  212:     sub get_uniq {
  213: 	$uniq++;
  214: 	return $uniq;
  215:     }
  216: }
  217: 
  218: 
  219: 
  220: sub packagemsg {
  221:     my ($subject,$message,$citation,$baseurl,$attachmenturl,
  222: 	$recuser,$recdomain,$msgid,$type,$crsmsgid,$symb,$error,$recipid)=@_;
  223:     $message =&HTML::Entities::encode($message,'<>&"');
  224:     $citation=&HTML::Entities::encode($citation,'<>&"');
  225:     $subject =&HTML::Entities::encode($subject,'<>&"');
  226:     #remove machine specification
  227:     $baseurl =~ s|^https?://[^/]+/|/|;
  228:     $baseurl =&HTML::Entities::encode($baseurl,'<>&"');
  229:     #remove machine specification
  230:     $attachmenturl =~ s|^https?://[^/]+/|/|;
  231:     $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
  232:     my $course_context = &get_course_context();
  233:     my $now=time;
  234:     my $ip = &Apache::lonnet::get_requestor_ip();
  235:     my $msgcount = &get_uniq();
  236:     unless(defined($msgid)) {
  237:         $msgid = &buildmsgid($now,$subject,$env{'user.name'},$env{'user.domain'},
  238:                            $msgcount,$course_context,$symb,$error,$$);
  239:     }
  240:     my $result = '<sendername>'.$env{'user.name'}.'</sendername>'.
  241:            '<senderdomain>'.$env{'user.domain'}.'</senderdomain>'.
  242:            '<subject>'.$subject.'</subject>'.
  243:            '<time>'.&Apache::lonlocal::locallocaltime($now).'</time>';
  244:     if (defined($crsmsgid)) {
  245:         $result.= '<courseid>'.$course_context.'</courseid>'.
  246:                   '<coursesec>'.$env{'request.course.sec'}.'</coursesec>'.
  247:                   '<msgid>'.$msgid.'</msgid>'.
  248:                   '<coursemsgid>'.$crsmsgid.'</coursemsgid>'.
  249:                   '<message>'.$message.'</message>';
  250:         return ($msgid,$result);
  251:     }
  252:     $result .= '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
  253:            '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
  254: 	   '<client>'.$ip.'</client>'.
  255: 	   '<browsertype>'.$env{'browser.type'}.'</browsertype>'.
  256: 	   '<browseros>'.$env{'browser.os'}.'</browseros>'.
  257: 	   '<browserversion>'.$env{'browser.version'}.'</browserversion>'.
  258:            '<browsermathml>'.$env{'browser.mathml'}.'</browsermathml>'.
  259: 	   '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
  260: 	   '<courseid>'.$course_context.'</courseid>'.
  261: 	   '<coursesec>'.$env{'request.course.sec'}.'</coursesec>'.
  262: 	   '<role>'.$env{'request.role'}.'</role>'.
  263: 	   '<resource>'.$env{'request.filename'}.'</resource>'.
  264:            '<msgid>'.$msgid.'</msgid>';
  265:     if (defined($env{'form.group'})) {
  266:         $result .= '<group>'.$env{'form.group'}.'</group>';
  267:     }
  268:     if (ref($recuser) eq 'ARRAY') {
  269:         for (my $i=0; $i<@{$recuser}; $i++) {
  270:             if ($type eq 'dcmail') {
  271:                 my ($username,$email) = split(/:/,$$recuser[$i]);
  272:                 $username = &unescape($username);
  273:                 $email = &unescape($email);
  274:                 $username = &HTML::Entities::encode($username,'<>&"');
  275:                 $email = &HTML::Entities::encode($email,'<>&"');
  276:                 $result .= '<recipient username="'.$username.'">'.
  277:                                             $email.'</recipient>';
  278:             } else {
  279:                 $result .= '<recuser>'.$$recuser[$i].'</recuser>'.
  280:                            '<recdomain>'.$$recdomain[$i].'</recdomain>';
  281:             }
  282:         }
  283:     } else {
  284:         $result .= '<recuser>'.$recuser.'</recuser>'.
  285:                    '<recdomain>'.$recdomain.'</recdomain>';
  286:     }
  287:     $result .= '<message>'.$message.'</message>';
  288:     if (defined($citation)) {
  289: 	$result.='<citation>'.$citation.'</citation>';
  290:     }
  291:     if (defined($baseurl)) {
  292: 	$result.= '<baseurl>'.$baseurl.'</baseurl>';
  293:     }
  294:     if (defined($attachmenturl)) {
  295: 	$result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>';
  296:     }
  297:     if (defined($symb)) {
  298:         $result.= '<symb>'.$symb.'</symb>';
  299:         if ($course_context ne '') {
  300:             if ($course_context eq $env{'request.course.id'}) {
  301:                 my $resource_title = &Apache::lonnet::gettitle($symb);
  302:                 if (defined($resource_title)) {
  303:                     $result .= '<resource_title>'.$resource_title.'</resource_title>';
  304:                 }
  305:             }
  306:         }
  307:     }
  308:     if (defined($recipid)) {
  309:         $result.= '<recipid>'.$recipid.'</recipid>';
  310:     }
  311:     if ($env{'form.can_reply'} eq 'N') {
  312:         $result .= '<noreplies>1</noreplies>';
  313:     }
  314:     if ($env{'form.reply_to_addr'}) {
  315:         my ($replytoname,$replytodom) = split(/:/,$env{'form.reply_to_addr'});
  316:         if (!($replytoname eq $env{'user.name'} && $replytodom eq $env{'user.domain'})) {
  317:             if (&Apache::lonnet::homeserver($replytoname,$replytodom) ne 'no_host') {
  318:                 $result .= '<replytoaddr>'.$env{'form.reply_to_addr'}.'</replytoaddr>';
  319:             }
  320:         }
  321:     }
  322:     return ($msgid,$result);
  323: }
  324: 
  325: sub get_course_context {
  326:     my $course_context;
  327:     my $msgkey;
  328:     if (defined($env{'form.replyid'})) {
  329:         $msgkey = $env{'form.replyid'};
  330:     } elsif (defined($env{'form.forwid'})) {
  331:         $msgkey = $env{'form.forwid'}
  332:     } elsif (defined($env{'form.multiforwid'})) {
  333:         $msgkey = $env{'form.multiforwid'};
  334:     }
  335:     if ($msgkey ne '') {
  336:         my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
  337:                    split(/\:/,&unescape($msgkey));
  338:         $course_context = $origcid;
  339:     }
  340:     foreach my $key (keys(%env)) {
  341:         if ($key=~/^form\.(rep)?rec\_(.*)$/) {
  342:             my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =
  343:                                     split(/\:/,&unescape($2));
  344:             $course_context = $origcid;
  345:             last;
  346:         }
  347:     }
  348:     if ($course_context eq '') {
  349:         $course_context = $env{'request.course.id'};
  350:     }
  351:     return $course_context;
  352: }
  353: 
  354: 
  355: sub unpackagemsg {
  356:     my ($message,$notoken,$noattachmentlink)=@_;
  357:     my %content=();
  358:     my $parser=HTML::TokeParser->new(\$message);
  359:     my $token;
  360:     while ($token=$parser->get_token) {
  361:        if ($token->[0] eq 'S') {
  362: 	   my $entry=$token->[1];
  363:            my $value=$parser->get_text('/'.$entry);
  364:            if (($entry eq 'recuser') || ($entry eq 'recdomain')) {
  365:                push(@{$content{$entry}},$value);
  366:            } elsif ($entry eq 'recipient') {
  367:                my $username = $token->[2]{'username'};
  368:                $username = &HTML::Entities::decode($username,'<>&"');
  369:                $content{$entry}{$username} = $value;
  370:            } else {
  371:                $content{$entry}=$value;
  372:            }
  373:        }
  374:     }
  375:     if (!exists($content{'recuser'})) { $content{'recuser'} = []; }
  376:     if (($content{'attachmenturl'}) && (!$noattachmentlink)) {
  377:        my ($fname)=($content{'attachmenturl'}=~m|/([^/]+)$|);
  378:        if ($notoken) {
  379: 	   $content{'message'}.='<p>'.&mt('Attachment').': <tt>'.$fname.'</tt>';
  380:        } else {
  381: 	   &Apache::lonnet::allowuploaded('/adm/msg',
  382: 					  $content{'attachmenturl'});
  383: 	   $content{'message'}.='<p>'.&mt('Attachment').
  384: 	       ': <a href="'.$content{'attachmenturl'}.'"><tt>'.
  385: 	       $fname.'</tt></a>';
  386:        }
  387:     }
  388:     return %content;
  389: }
  390: 
  391: 
  392: sub buildmsgid {
  393:     my ($now,$subject,$uname,$udom,$msgcount,$course_context,$symb,$error,$pid) = @_;
  394:     $subject=&escape($subject);
  395:     $symb = &escape($symb);
  396:     return(&escape($now.':'.$subject.':'.$uname.':'.
  397:            $udom.':'.$msgcount.':'.$course_context.':'.$pid.':'.$symb.':'.$error));
  398: }
  399: 
  400: sub unpackmsgid {
  401:     my ($msgid,$folder,$skipstatus,$status_cache,$onlycid)=@_;
  402:     $msgid=&unescape($msgid);
  403:     my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid,
  404:         $processid,$symb,$error) = split(/\:/,&unescape($msgid));
  405:     if (!defined($processid)) { $fromcid = ''; }
  406:     if (($onlycid) && ($onlycid ne $fromcid)) {
  407:         return ($sendtime,'',$fromname,$fromdomain,'',$fromcid,'',$error);
  408:     }
  409:     $shortsubj = &unescape($shortsubj);
  410:     $shortsubj = &HTML::Entities::decode($shortsubj);
  411:     $symb = &unescape($symb);
  412:     if (!defined($processid)) { $fromcid = ''; }
  413:     my %status=();
  414:     unless ($skipstatus) {
  415: 	if (ref($status_cache)) {
  416: 	    $status{$msgid} = $status_cache->{$msgid};
  417: 	} else {
  418: 	    my $suffix=&foldersuffix($folder);
  419: 	    %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
  420: 	}
  421: 	if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
  422:         unless ($status{$msgid}) { $status{$msgid}='new'; }
  423:     }
  424:     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid,$symb,$error);
  425: }
  426: 
  427: 
  428: sub sendemail {
  429:     my ($to,$subject,$body,$to_uname,$to_udom,$user_lh)=@_;
  430:     my $senderaddress='';
  431:     my $replytoaddress='';
  432:     my $msgsent;
  433:     if ($env{'form.can_reply'} eq 'N') {
  434:         my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
  435:         my $hostname = &Apache::lonnet::hostname($lonhost);
  436:         $replytoaddress = 'do-not-reply@'.$hostname;
  437:     } else {
  438:         my %senderemails;
  439:         my $have_sender;
  440:         if ($env{'form.reply_to_addr'}) {
  441:             my ($replytoname,$replytodom) = split(/:/,$env{'form.reply_to_addr'});
  442:             if (!($replytoname eq $env{'user.name'} && $replytodom eq $env{'user.domain'})) {
  443:                 if (&Apache::lonnet::homeserver($replytoname,$replytodom) ne 'no_host') {
  444:                     %senderemails = 
  445:                         &Apache::loncommon::getemails($replytoname,$replytodom);
  446:                     $have_sender = 1;
  447:                 }
  448:             }
  449:         }
  450:         if (!$have_sender) {
  451:             %senderemails=&Apache::loncommon::getemails();
  452:         }
  453:         foreach my $type ('permanentemail','critnotification','notification') {
  454:             if ($senderemails{$type}) {
  455:                 ($senderaddress) = split(/,/,$senderemails{$type});
  456:                 last if ($senderaddress);
  457:             }
  458:         }
  459:     }
  460:     $body=
  461:     "*** ".&mt_user($user_lh,'This is an automatic e-mail generated by the LON-CAPA system.')."\n".
  462:     "*** ".($senderaddress?&mt_user($user_lh,'You can reply to this e-mail'):&mt_user($user_lh,'Please do not reply to this address.')."\n*** ".
  463:     &mt_user($user_lh,'A reply will not be received by the recipient!'))."\n\n".$body;
  464:     
  465:     my $msg = new Mail::Send;
  466:     $msg->to($to);
  467:     $msg->subject('[LON-CAPA] '.$subject);
  468:     if ($replytoaddress) {
  469:         $msg->add('Reply-to',$replytoaddress);
  470:     }
  471:     if ($senderaddress) {
  472:         $msg->add('From',$senderaddress);
  473:     }
  474:     $msg->add('Content-type','text/plain; charset=UTF-8');
  475:     if (my $fh = $msg->open()) {
  476: 	print $fh $body;
  477: 	$fh->close;
  478:         $msgsent = 1;
  479:     }
  480:     return $msgsent;
  481: }
  482: 
  483: # ==================================================== Send notification emails
  484: 
  485: sub sendnotification {
  486:     my ($to,$touname,$toudom,$subj,$crit,$text,$msgid)=@_;
  487:     my $sender=$env{'environment.firstname'}.' '.$env{'environment.lastname'};
  488:     unless ($sender=~/\w/) { 
  489: 	$sender=$env{'user.name'}.':'.$env{'user.domain'};
  490:     }
  491:     my $critical=($crit?' critical':'');
  492:     my $numsent = 0;
  493: 
  494:     $text=~s/\&lt\;/\</gs;
  495:     $text=~s/\&gt\;/\>/gs;
  496:     my $homeserver = &Apache::lonnet::homeserver($touname,$toudom);
  497:     my $protocol = $Apache::lonnet::protocol{$homeserver};
  498:     $protocol = 'http' if ($protocol ne 'https');
  499:     my $url = $protocol.'://'.&Apache::lonnet::hostname($homeserver).
  500:               '/adm/email?username='.$touname.'&domain='.$toudom.
  501:               '&display='.&escape($msgid);
  502:     my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,
  503:         $symb,$error) = &Apache::lonmsg::unpackmsgid($msgid);
  504:     my ($coursetext,$body,$bodybegin,$bodysubj,$bodyend);
  505:     my $user_lh = &Apache::loncommon::user_lang($touname,$toudom,$fromcid);
  506:     if ($fromcid ne '') {
  507:         $coursetext = "\n".&mt_user($user_lh,'Course').': ';
  508:         if ($env{'course.'.$fromcid.'.description'} ne '') {
  509:             $coursetext .= $env{'course.'.$fromcid.'.description'};
  510:         } else {
  511:             my %coursehash = &Apache::lonnet::coursedescription($fromcid,);
  512:             if ($coursehash{'description'} ne '') {
  513:                 $coursetext .= $coursehash{'description'};
  514:             }
  515:         }
  516:         $coursetext .= "\n\n";
  517:     }
  518:     my @recipients = split(/,/,$to);
  519:     $bodybegin = $coursetext. 
  520:                &mt_user($user_lh,
  521:                          'You received a'.$critical.' message from [_1] in LON-CAPA.',$sender).' ';
  522:     $bodysubj = &mt_user($user_lh,'The subject is 
  523: 
  524:  [_1]
  525: 
  526: ',$subj)."\n".
  527: '=== '.&mt_user($user_lh,'Excerpt')." ============================================================
  528: ";
  529:     $bodyend = "
  530: ========================================================================
  531: 
  532: ".&mt_user($user_lh,'Use 
  533: 
  534:  [_1]
  535: 
  536: to access the full message.',$url);
  537:     my %userenv = &Apache::lonnet::get('environment',['notifywithhtml'],$toudom,$touname);
  538:     my $subject = &mt_user($user_lh,"'New'$critical message from [_1]",$sender);
  539:     unless ($subj eq '') {
  540:         $subject = $subj;
  541:     }
  542:  
  543:     my ($blocked,$blocktext);
  544:     if (!$crit) {
  545:         my %setters;
  546:         my ($startblock,$endblock) = 
  547:             &Apache::loncommon::blockcheck(\%setters,'com',$touname,$toudom);
  548:         if ($startblock && $endblock) {
  549:             $blocked = 1;
  550:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
  551:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
  552:             $blocktext = &mt_user($user_lh,'LON-CAPA messages sent to you between [_1] and [_2] will be inaccessible until the end of this time period, because you are a student in a course with an active communications block.',$showstart,$showend);
  553:         }
  554:     }
  555:     if ($userenv{'notifywithhtml'} ne '') {
  556:         my @htmlexcerpt = split(/,/,$userenv{'notifywithhtml'});
  557:         my $htmlfree = &make_htmlfree($text);
  558:         foreach my $addr (@recipients) {
  559:             if ($blocked) {
  560:                 $body = $bodybegin."\n".$blocktext."\n".$bodyend;
  561:             } else {
  562:                 my $sendtext;
  563:                 if (!grep/^\Q$addr\E/,@htmlexcerpt) {
  564:                     $sendtext = $htmlfree;
  565:                 } else {
  566:                     $sendtext = $text;
  567:                 }
  568:                 $body = $bodybegin.$bodysubj.$sendtext.$bodyend;
  569:             }
  570:             if (&sendemail($addr,$subject,$body,$touname,$toudom,$user_lh)) {
  571:                 $numsent ++;
  572:             }
  573:         }
  574:     } else {
  575:         if ($blocked) {
  576:             $body = $bodybegin."\n".$blocktext."\n".$bodyend;
  577:         } else {
  578:             my $htmlfree = &make_htmlfree($text);
  579:             $body = $bodybegin.$bodysubj.$htmlfree.$bodyend;
  580:         }
  581:         if (&sendemail($to,$subject,$body,$touname,$toudom,$user_lh)) {
  582:             $numsent ++;
  583:         }
  584:     }
  585:     return $numsent;
  586: }
  587: 
  588: sub make_htmlfree {
  589:     my ($text) = @_;
  590:     $text =~ s/\<\/*[^\>]+\>//gs;
  591:     $text = &HTML::Entities::decode($text);
  592:     $text = &Encode::encode('utf8',$text);
  593:     return $text;
  594: }
  595: 
  596: sub mynewmail{
  597: 	&newmail();
  598: 	return $env{'user.mailcheck.lastnewmessagetime'} > $env{'user.mailcheck.lastvisit'};
  599: }
  600: 
  601: 
  602: sub newmail {
  603:     if ((time-$env{'user.mailcheck.time'})>300) {
  604:         my %what=&Apache::lonnet::get('email_status',['recnewemail']);
  605:         &Apache::lonnet::appenv({'user.mailcheck.time'=>time});
  606: 		&Apache::lonnet::appenv({'user.mailcheck.lastnewmessagetime'=> $what{'recnewemail'}});
  607:         if ($what{'recnewemail'}>0) { return 1; }
  608:     }
  609:     return 0;
  610: }
  611: 
  612: 
  613: 
  614: sub author_res_msg {
  615:     my ($filename,$message)=@_;
  616:     unless ($message) { return 'empty'; }
  617:     $filename=&Apache::lonnet::declutter($filename);
  618:     my ($domain,$author,@dummy)=split(/\//,$filename);
  619:     my $homeserver=&Apache::lonnet::homeserver($author,$domain);
  620:     if ($homeserver ne 'no_host') {
  621:        my $id=unpack("%32C*",$message);
  622:        $message .= " <p>This error occurred on machine ".
  623: 	   $Apache::lonnet::perlvar{'lonHostID'}."</p>";
  624:        my $msgid;
  625:        ($msgid,$message)=&packagemsg($filename,$message);
  626:        return &Apache::lonnet::reply('put:'.$domain.':'.$author.
  627:          ':nohist_res_msgs:'.
  628:           &escape($filename.'_'.$id).'='.
  629:           &escape($message),$homeserver);
  630:     }
  631:     return 'no_host';
  632: }
  633: 
  634: 
  635: 
  636: sub retrieve_author_res_msg {
  637:     my $url=shift;
  638:     $url=&Apache::lonnet::declutter($url);
  639:     my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//);
  640:     my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$domain,$author);
  641:     my $msgs='';
  642:     foreach my $msg (keys(%errormsgs)) {
  643: 	if ($msg =~ /^\Q$url\E\_\d+$/) {
  644: 	    my %content=&unpackagemsg($errormsgs{$msg});
  645: 	    $msgs.='<p><img src="/adm/lonMisc/bomb.gif" /><b>'.
  646: 		$content{'time'}.'</b>: '.$content{'message'}.
  647: 		'<br /></p>';
  648: 	}
  649:     } 
  650:     return $msgs;     
  651: }
  652: 
  653: 
  654: 
  655: 
  656: 
  657: sub del_url_author_res_msg {
  658:     my $url=shift;
  659:     $url=&Apache::lonnet::declutter($url);
  660:     my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//);
  661:     my @delmsgs=();
  662:     foreach my $msg (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
  663: 	if ($msg =~ /^\Q$url\E\_\d+$/) {
  664: 	    push (@delmsgs,$msg);
  665: 	}
  666:     }
  667:     return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
  668: }
  669: 
  670: 
  671: sub clear_author_res_msg {
  672:     my $url=shift;
  673:     $url=&Apache::lonnet::declutter($url);
  674:     my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//);
  675:     my @delmsgs=();
  676:     foreach my $msg (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
  677: 	if ($msg =~ /^\Q$url\E/) {
  678: 	    push (@delmsgs,$msg);
  679: 	}
  680:     }
  681:     return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
  682: }
  683: 
  684: 
  685: 
  686: sub all_url_author_res_msg {
  687:     my ($author,$domain)=@_;
  688:     my %returnhash=();
  689:     foreach my $msg (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
  690: 	$msg =~ /^(.+)\_\d+/;
  691: 	$returnhash{$1}=1;
  692:     }
  693:     return %returnhash;
  694: }
  695: 
  696: 
  697: sub store_instructor_comment {
  698:     my ($msg,$uname,$udom) = @_;
  699:     my $cid  = $env{'request.course.id'};
  700:     my $cnum = $env{'course.'.$cid.'.num'};
  701:     my $cdom = $env{'course.'.$cid.'.domain'};
  702:     my $subject= &mt('Record').' ['.$uname.':'.$udom.']';
  703:     my $result = &user_normal_msg_raw($cnum,$cdom,$subject,$msg);
  704:     if ($result eq 'ok' || $result eq 'con_delayed') {
  705:         
  706:     }
  707:     return $result;
  708: }
  709: 
  710: 
  711: sub user_crit_msg_raw {
  712:     my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
  713:         $nosentstore,$recipid,$attachmenturl,$permresults)=@_;
  714: # Check if allowed missing
  715:     my ($status,$packed_message);
  716:     my $msgid='undefined';
  717:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
  718:     my $text=$message;
  719:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
  720:     if ($homeserver ne 'no_host') {
  721:        ($msgid,$packed_message)=&packagemsg($subject,$message,undef,undef,
  722:                                   $attachmenturl,undef,undef,undef,undef,undef,
  723:                                   undef,undef,$recipid);
  724:        if ($sendback) { $packed_message.='<sendback>true</sendback>'; }
  725:        $status=&Apache::lonnet::cput('critical', {$msgid => $packed_message},
  726: 				     $domain,$user);
  727:         if (defined($sentmessage)) {
  728:             $$sentmessage = $packed_message;
  729:         }
  730:         if (!$nosentstore) {
  731:             (undef,my $packed_message_no_citation) =
  732:             &packagemsg($subject,$message,undef,undef,$attachmenturl,$user,
  733:                         $domain,$msgid);
  734:             if ($status eq 'ok' || $status eq 'con_delayed') {
  735:                 &store_sent_mail($msgid,$packed_message_no_citation);
  736:             }
  737:         }
  738:     } else {
  739:        $status='no_host';
  740:     }
  741: 
  742: # Notifications
  743:     my %userenv = &Apache::loncommon::getemails($user,$domain);
  744:     my $critnotify = $userenv{'critnotification'};
  745:     my $permemail = $userenv{'permanentemail'};
  746:     my $numcrit = 0;
  747:     my $numperm = 0;
  748:     my $permlogmsgstatus;
  749:     if ($critnotify) {
  750:         $numcrit = &sendnotification($critnotify,$user,$domain,$subject,1,$text,$msgid);
  751:     }
  752:     if ($toperm && $permemail) {
  753:         if ($critnotify && $numcrit) {
  754:             if (grep(/^\Q$permemail\E/,split(/,/,$critnotify))) {
  755:                 $numperm = 1;
  756:             }
  757:         }
  758:         unless ($numperm) {
  759:             $numperm = &sendnotification($permemail,$user,$domain,$subject,1,$text,$msgid);
  760:         }
  761:     }
  762:     if ($toperm) {
  763:         $permlogmsgstatus = '. Perm. email log status '.
  764:                             &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},$env{'user.home'},
  765:                                                  "Perm. e-mail count $numperm for $user at $domain");
  766:         if (ref($permresults) eq 'HASH') {
  767:             $permresults->{"$user:$domain"} = $numperm;
  768:         }
  769:     }
  770: # Log this
  771:     &Apache::lonnet::logthis(
  772:       'Sending critical '.$msgid.
  773:       ', log status: '.
  774:       &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
  775:                          $env{'user.home'},
  776:       'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status '
  777:       .$status).$permlogmsgstatus);
  778:     return $status;
  779: }
  780: 
  781: 
  782: 
  783: sub user_crit_msg {
  784:     my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
  785:         $nosentstore,$recipid,$attachmenturl,$permresults)=@_;
  786:     my @status;
  787:     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
  788:                                        $domain,$user);
  789:     my $msgforward=$userenv{'msgforward'};
  790:     if ($msgforward) {
  791:        foreach my $addr (split(/\,/,$msgforward)) {
  792: 	 my ($forwuser,$forwdomain)=split(/\:/,$addr);
  793:          push(@status,
  794: 	      &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
  795: 				 $sendback,$toperm,$sentmessage,$nosentstore,
  796:                                  $recipid,$attachmenturl,$permresults));
  797:        }
  798:     } else { 
  799: 	push(@status,
  800: 	     &user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
  801: 				$toperm,$sentmessage,$nosentstore,$recipid,
  802:                                 $attachmenturl,$permresults));
  803:     }
  804:     if (wantarray) {
  805: 	return @status;
  806:     }
  807:     return join(' ',@status);
  808: }
  809: 
  810: 
  811: sub user_crit_received {
  812:     my $msgid=shift;
  813:     my %message=&Apache::lonnet::get('critical',[$msgid]);
  814:     my %contents=&unpackagemsg($message{$msgid},1);
  815:     my $destname = $contents{'sendername'};
  816:     my $destdom = $contents{'senderdomain'};
  817:     if ($contents{'replytoaddr'}) {
  818:         my ($repname,$repdom) = split(/:/,$contents{'replytoaddr'});
  819:         if (&Apache::lonnet::homeserver($repname,$repdom) ne 'no_host') {
  820:             $destname = $repname;
  821:             $destdom = $repdom;    
  822:         }
  823:     }
  824:     my $status='rec: '.($contents{'sendback'}?
  825:      &user_normal_msg($destname,$destdom,&mt('Receipt').': '.$env{'user.name'}.
  826:                       ' '.&mt('at').' '.$env{'user.domain'}.', '.
  827:                       $contents{'subject'},&mt('User').' '.$env{'user.name'}.
  828:                       ' '.&mt('at').' '.$env{'user.domain'}.
  829:                       ' acknowledged receipt of message'."\n".'   "'.
  830:                       $contents{'subject'}.'"'."\n".&mt('dated').' '.
  831:                       $contents{'time'}.".\n"
  832:                       ):'no msg req');
  833:     $status.=' trans: '.
  834:      &Apache::lonnet::put(
  835:      'nohist_email',{$contents{'msgid'} => $message{$msgid}});
  836:     $status.=' del: '.
  837:      &Apache::lonnet::del('critical',[$contents{'msgid'}]);
  838:     &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
  839:                          $env{'user.home'},'Received critical message '.
  840:                          $contents{'msgid'}.
  841:                          ', '.$status);
  842:     return $status;
  843: }
  844: 
  845: 
  846: 
  847: 
  848: sub user_normal_msg_raw {
  849:     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
  850:         $toperm,$currid,$newid,$sentmessage,$crsmsgid,$symb,$restitle,
  851:         $error,$nosentstore,$recipid,$permresults)=@_;
  852: # Check if allowed missing
  853:     my ($status,$packed_message);
  854:     my $msgid='undefined';
  855:     my $text=$message;
  856:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
  857:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
  858:     if ($homeserver ne 'no_host') {
  859:        ($msgid,$packed_message)=
  860: 	                 &packagemsg($subject,$message,$citation,$baseurl,
  861:                                      $attachmenturl,$user,$domain,$currid,
  862:                                      undef,$crsmsgid,$symb,$error,$recipid);
  863: 
  864: # Store in user folder
  865:        $status=
  866: 	   &Apache::lonnet::cput('nohist_email',{$msgid => $packed_message},
  867: 				 $domain,$user);
  868: # Save new message received time
  869:        &Apache::lonnet::put
  870:                          ('email_status',{'recnewemail'=>time},$domain,$user);
  871: # Into sent-mail folder if sent mail storage required
  872:        if (!$nosentstore) {
  873:            (undef,my $packed_message_no_citation) =
  874:                &packagemsg($subject,$message,undef,$baseurl,$attachmenturl,
  875:                            $user,$domain,$currid,undef,$crsmsgid,$symb,$error);
  876:            if ($status eq 'ok' || $status eq 'con_delayed') {
  877:                &store_sent_mail($msgid,$packed_message_no_citation);
  878:            }
  879:        }
  880:        if (ref($newid) eq 'SCALAR') {
  881: 	   $$newid = $msgid;
  882:        }
  883:        if (ref($sentmessage) eq 'SCALAR') {
  884: 	   $$sentmessage = $packed_message;
  885:        }
  886: # Notifications
  887:        my %userenv = &Apache::loncommon::getemails($user,$domain);
  888:        my $notify = $userenv{'notification'};
  889:        my $permemail = $userenv{'permanentemail'};
  890:        my $numnotify = 0;
  891:        my $numperm = 0;
  892:        my $permlogmsgstatus;
  893:        if ($notify) {
  894:            $numnotify = &sendnotification($notify,$user,$domain,$subject,0,$text,$msgid);
  895:        }
  896:        if ($toperm && $permemail) {
  897:            if ($notify && $numnotify) {
  898:                if (grep(/^\Q$permemail\E/,split(/,/,$notify))) {
  899:                    $numperm = 1;
  900:                }
  901:            }
  902:            unless ($numperm) {
  903:                $numperm = &sendnotification($permemail,$user,$domain,$subject,0,
  904:                                             $text,$msgid);
  905:            }
  906:        }
  907:        if ($toperm) {
  908:            $permlogmsgstatus = '. Perm. email log status '.
  909:                          &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},$env{'user.home'},
  910:                                               "Perm. e-mail count $numperm for $user at $domain");
  911:            if (ref($permresults) eq 'HASH') {
  912:                $permresults->{"$user:$domain"} = $numperm;
  913:            }
  914:        }
  915:        &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
  916: 			    $env{'user.home'},
  917: 			    'Sending '.$msgid.' to '.$user.' at '.$domain.' with status '.$status.
  918:                             $permlogmsgstatus);
  919:    } else {
  920:        $status='no_host';
  921:    }
  922:     return $status;
  923: }
  924: 
  925: sub user_normal_msg {
  926:     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
  927: 	$toperm,$sentmessage,$symb,$restitle,$error,$nosentstore,$recipid,
  928:         $permresults)=@_;
  929:     my @status;
  930:     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
  931:                                        $domain,$user);
  932:     my $msgforward=$userenv{'msgforward'};
  933:     if ($msgforward) {
  934:         foreach my $fwd (split(/\,/,$msgforward)) {
  935: 	    my ($forwuser,$forwdomain)=split(/\:/,$fwd);
  936: 	    push(@status,
  937: 	        &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
  938: 				     $citation,$baseurl,$attachmenturl,$toperm,
  939: 				     undef,undef,$sentmessage,undef,$symb,
  940:                                      $restitle,$error,$nosentstore,$recipid,$permresults));
  941:         }
  942:     } else {
  943: 	push(@status,&user_normal_msg_raw($user,$domain,$subject,$message,
  944: 				     $citation,$baseurl,$attachmenturl,$toperm,
  945: 				     undef,undef,$sentmessage,undef,$symb,
  946:                                      $restitle,$error,$nosentstore,$recipid,$permresults));
  947:     }
  948:     if (wantarray) {
  949:         return @status;
  950:     }
  951:     return join(' ',@status);
  952: }
  953: 
  954: sub process_sent_mail {
  955:     my ($msgsubj,$subj_prefix,$numsent,$stamp,$msgname,$msgdom,$msgcount,
  956:         $context,$pid,$savemsg,$recusers,$recudoms,$baseurl,$attachmenturl,
  957:         $symb,$error,$senderuname,$senderdom,$recipid) = @_;
  958:     my $sentsubj;
  959:     if ($numsent > 1) {
  960:         $sentsubj = $subj_prefix.' ('.$numsent.' sent) '.$msgsubj;
  961:     } else {
  962:         if ($subj_prefix) {
  963:             $sentsubj = $subj_prefix.' ';
  964:         }
  965:         $sentsubj .= $msgsubj;
  966:     }
  967:     $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
  968:     my $sentmsgid = 
  969:         &buildmsgid($stamp,$sentsubj,$msgname,$msgdom,$msgcount,$context,$pid);
  970:     (undef,my $sentmessage) =
  971:         &packagemsg($msgsubj,$savemsg,undef,$baseurl,$attachmenturl,$recusers,
  972:                     $recudoms,$sentmsgid,undef,undef,$symb,$error,$recipid);
  973:     my $status = &store_sent_mail($sentmsgid,$sentmessage,$senderuname,
  974:                                   $senderdom);
  975:     return $status;
  976: }
  977: 
  978: sub store_sent_mail {
  979:     my ($msgid,$message,$senderuname,$senderdom) = @_;
  980:     if ($senderuname eq '') {
  981:         $senderuname = $env{'user.name'};
  982:     }
  983:     if ($senderdom eq '') {
  984:         $senderdom = $env{'user.domain'};
  985:     }
  986:     my $status =' '.&Apache::lonnet::cput('nohist_email_sent',
  987: 					  {$msgid => $message},
  988: 					  $senderdom,$senderuname);
  989:     return $status;
  990: }
  991: 
  992: sub store_recipients {
  993:     my ($subject,$sendername,$senderdom,$reciphash) = @_;
  994:     my $context = &get_course_context();
  995:     my $now = time();
  996:     my $msgcount = &get_uniq();
  997:     my $recipid =
  998:         &buildmsgid($now,$subject,$sendername,$senderdom,$msgcount,$context,$$);
  999:     my %recipinfo = (
 1000:                          $recipid => $reciphash,
 1001:                     );
 1002:     my $status = &Apache::lonnet::put('nohist_emailrecip',\%recipinfo,
 1003:                                       $senderdom,$sendername); 
 1004:     if ($status eq 'ok') {
 1005:         return ($recipid,$status);
 1006:     } else {
 1007:         return (undef,$status);
 1008:     }
 1009: }
 1010: 
 1011: 
 1012: sub foldersuffix {
 1013:     my $folder=shift;
 1014:     unless ($folder) { return ''; }
 1015:     my $suffix;
 1016:     my %folderhash = &get_user_folders($folder);
 1017:     if (ref($folderhash{$folder}) eq 'HASH') {
 1018:         $suffix = '_'.&escape($folderhash{$folder}{'id'});
 1019:     } else {
 1020:         $suffix = '_'.&escape($folder);
 1021:     }
 1022:     return $suffix;
 1023: }
 1024: 
 1025: 
 1026: sub get_user_folders {
 1027:     my ($folder) = @_;
 1028:     my %userfolders = 
 1029:           &Apache::lonnet::dump('email_folders',undef,undef,$folder);
 1030:     my $lock = "\0".'lock_counter'; # locks db while counter incremented
 1031:     my $counter = "\0".'idcount';   # used in suffix for email db files
 1032:     if (defined($userfolders{$lock})) {
 1033:         delete($userfolders{$lock});
 1034:     }
 1035:     if (defined($userfolders{$counter})) {
 1036:         delete($userfolders{$counter});
 1037:     }
 1038:     return %userfolders;
 1039: }
 1040: 
 1041: sub secapply {
 1042:     my $rec=shift;
 1043:     my $defaultflag=shift;
 1044:     $rec=~s/\s+//g;
 1045:     unless ($rec =~ /\:/) {
 1046:         $rec=~s/\@/\:/g;
 1047:     }
 1048:     my ($adr,$sections_or_groups)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
 1049:     if ($sections_or_groups) {
 1050: 	foreach my $item (split(/\;/,$sections_or_groups)) {
 1051:             if (($item eq $env{'request.course.sec'}) ||
 1052:                 ($defaultflag && ($item eq '*'))) {
 1053:                 return $adr; 
 1054:             } elsif ($env{'request.course.groups'}) {
 1055:                 my @usersgroups = split(/:/,$env{'request.course.groups'});
 1056:                 if (grep(/^\Q$item\E$/,@usersgroups)) {
 1057:                     return $adr;
 1058:                 }
 1059:             } 
 1060:         }
 1061:     } else {
 1062:        return $rec;
 1063:     }
 1064:     return '';
 1065: }
 1066: 
 1067: sub decide_receiver {
 1068:     my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
 1069:     &Apache::lonenc::check_decrypt(\$feedurl);
 1070:     my $typestyle='';
 1071:     my %to=();
 1072:     if ($env{'form.discuss'} eq 'author' ||$author) {
 1073: 	$typestyle.='Submitting as Author Feedback<br />';
 1074: 	$feedurl=~ m{^/res/($LONCAPA::domain_re)/($LONCAPA::username_re)/};
 1075: 	$to{$2.':'.$1}=1;
 1076:     }
 1077:     my $cid = $env{'request.course.id'};
 1078:     if ($env{'form.discuss'} eq 'question' ||$question) {
 1079: 	$typestyle.=&mt('Submitting as Question').'<br />';
 1080: 	foreach my $item (split(/\,/,$env{'course.'.$cid.'.question.email'})) {
 1081: 	    my $rec=&secapply($item,$defaultflag);
 1082: 	    if ($rec) { $to{$rec}=1; }
 1083: 	} 
 1084:     }
 1085:     if ($env{'form.discuss'} eq 'course' ||$course) {
 1086: 	$typestyle.=&mt('Submitting as Comment').'<br />';
 1087: 	foreach my $item (split(/\,/,$env{'course.'.$cid.'.comment.email'})) {
 1088: 	    my $rec=&secapply($item,$defaultflag);
 1089: 	    if ($rec) { $to{$rec}=1; }
 1090: 	} 
 1091:     }
 1092:     if ($env{'form.discuss'} eq 'policy' ||$policy) {
 1093: 	$typestyle.=&mt('Submitting as Policy Feedback').'<br />';
 1094: 	foreach my $item (split(/\,/,$env{'course.'.$cid.'.policy.email'})) {
 1095: 	    my $rec=&secapply($item,$defaultflag);
 1096: 	    if ($rec) { $to{$rec}=1; }
 1097: 	} 
 1098:     }
 1099:     if ((scalar(%to) eq '0') && (!$defaultflag)) {
 1100: 	($typestyle,%to)=
 1101: 	    &decide_receiver($feedurl,$author,$question,$course,$policy,1);
 1102:     }
 1103:     return ($typestyle,%to);
 1104: }
 1105: 
 1106: 1;
 1107: __END__
 1108: 

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