Annotation of loncom/interface/lonmsg.pm, revision 1.22

1.1       www         1: # The LearningOnline Network with CAPA
                      2: #
                      3: # Routines for messaging
                      4: #
                      5: # (Routines to control the menu
                      6: #
                      7: # (TeX Conversion Module
                      8: #
                      9: # 05/29/00,05/30 Gerd Kortemeyer)
                     10: #
                     11: # 10/05 Gerd Kortemeyer)
                     12: #
1.6       www        13: # 10/19,10/20,10/30,
                     14: # 02/06/01 Gerd Kortemeyer
1.11      www        15: # 07/27 Guy Albertelli
1.21      www        16: # 07/27,07/28,07/30,08/03,08/06,08/08,08/09,08/10,8/13,8/15 Gerd Kortemeyer
1.1       www        17: 
                     18: package Apache::lonmsg;
                     19: 
                     20: use strict;
                     21: use Apache::lonnet();
1.2       www        22: use vars qw($msgcount);
                     23: use HTML::TokeParser;
1.5       www        24: use Apache::Constants qw(:common);
1.1       www        25: 
                     26: # ===================================================================== Package
                     27: 
1.3       www        28: sub packagemsg {
1.7       www        29:     my ($subject,$message,$citation)=@_;
1.1       www        30:     $message=~s/\</\&lt\;/g;
                     31:     $message=~s/\>/\&gt\;/g;
1.7       www        32:     $citation=~s/\</\&lt\;/g;
                     33:     $citation=~s/\>/\&gt\;/g;
1.1       www        34:     $subject=~s/\</\&lt\;/g;
                     35:     $subject=~s/\>/\&gt\;/g;
1.2       www        36:     my $now=time;
                     37:     $msgcount++;
1.6       www        38:     my $partsubj=$subject;
                     39:     $partsubj=&Apache::lonnet::escape($partsubj);
                     40:     $partsubj=substr($partsubj,0,50);
                     41:     my $msgid=&Apache::lonnet::escape(
                     42:            $now.':'.$partsubj.':'.$ENV{'user.name'}.':'.
                     43:            $ENV{'user.domain'}.':'.$msgcount.':'.$$);
1.2       www        44:     return $msgid,
                     45:            '<sendername>'.$ENV{'user.name'}.'</sendername>'.
1.1       www        46:            '<senderdomain>'.$ENV{'user.domain'}.'</senderdomain>'.
                     47:            '<subject>'.$subject.'</subject>'.
1.2       www        48: 	   '<time>'.localtime($now).'</time>'.
1.1       www        49: 	   '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
                     50:            '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
                     51: 	   '<client>'.$ENV{'REMOTE_ADDR'}.'</client>'.
                     52: 	   '<browsertype>'.$ENV{'browser.type'}.'</browsertype>'.
                     53: 	   '<browseros>'.$ENV{'browser.os'}.'</browseros>'.
                     54: 	   '<browserversion>'.$ENV{'browser.version'}.'</browserversion>'.
                     55:            '<browsermathml>'.$ENV{'browser.mathml'}.'</browsermathml>'.
                     56: 	   '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
                     57: 	   '<courseid>'.$ENV{'request.course.id'}.'</courseid>'.
                     58: 	   '<role>'.$ENV{'request.role'}.'</role>'.
                     59: 	   '<resource>'.$ENV{'request.filename'}.'</resource>'.
1.2       www        60:            '<msgid>'.$msgid.'</msgid>'.
1.7       www        61: 	   '<message>'.$message.'</message>'.
                     62: 	   '<citation>'.$citation.'</citation>';
1.1       www        63: }
                     64: 
1.2       www        65: # ================================================== Unpack message into a hash
                     66: 
1.3       www        67: sub unpackagemsg {
1.2       www        68:     my $message=shift;
                     69:     my %content=();
                     70:     my $parser=HTML::TokeParser->new(\$message);
                     71:     my $token;
                     72:     while ($token=$parser->get_token) {
                     73:        if ($token->[0] eq 'S') {
                     74: 	   my $entry=$token->[1];
                     75:            my $value=$parser->get_text('/'.$entry);
                     76:            $content{$entry}=$value;
                     77:        }
                     78:     }
                     79:     return %content;
                     80: }
                     81: 
1.6       www        82: # ======================================================= Get info out of msgid
                     83: 
                     84: sub unpackmsgid {
1.7       www        85:     my $msgid=&Apache::lonnet::unescape(shift);
1.6       www        86:     my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/,
1.7       www        87:                           &Apache::lonnet::unescape($msgid));
1.8       albertel   88:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
1.6       www        89:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
                     90:     unless ($status{$msgid}) { $status{$msgid}='new'; }
                     91:     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});
                     92: } 
                     93: 
1.1       www        94: # =============================== Automated message to the author of a resource
                     95: 
                     96: sub author_res_msg {
                     97:     my ($filename,$message)=@_;
1.2       www        98:     unless ($message) { return 'empty'; }
1.1       www        99:     $filename=&Apache::lonnet::declutter($filename);
                    100:     my ($domain,$author,@dummy)=split(/\//,$filename);
                    101:     my $homeserver=&Apache::lonnet::homeserver($author,$domain);
                    102:     if ($homeserver ne 'no_host') {
                    103:        my $id=unpack("%32C*",$message);
1.2       www       104:        my $msgid;
1.3       www       105:        ($msgid,$message)=&packagemsg($filename,$message);
                    106:        return &Apache::lonnet::reply('put:'.$domain.':'.$author.
                    107:          ':nohist_res_msgs:'.
                    108:           &Apache::lonnet::escape($filename.'_'.$id).'='.
                    109:           &Apache::lonnet::escape($message),$homeserver);
1.1       www       110:     }
1.2       www       111:     return 'no_host';
1.1       www       112: }
                    113: 
                    114: # ================================================== Critical message to a user
                    115: 
                    116: sub user_crit_msg {
                    117:     my ($user,$domain,$subject,$message)=@_;
1.2       www       118: # Check if allowed missing
                    119:     my $status='';
                    120:     my $msgid='undefined';
                    121:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
                    122:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
                    123:     if ($homeserver ne 'no_host') {
1.3       www       124:        ($msgid,$message)=&packagemsg($subject,$message);
1.4       www       125:        $status=&Apache::lonnet::critical(
                    126:            'put:'.$domain.':'.$user.':critical:'.
                    127:            &Apache::lonnet::escape($msgid).'='.
                    128:            &Apache::lonnet::escape($message),$homeserver);
1.2       www       129:     } else {
                    130:        $status='no_host';
                    131:     }
                    132:     &Apache::lonnet::logthis(
1.4       www       133:       'Sending critical email '.$msgid.
1.2       www       134:       ', log status: '.
                    135:       &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
                    136:                          $ENV{'user.home'},
                    137:       'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
1.4       www       138:       .$status));
1.2       www       139:     return $status;
                    140: }
                    141: 
                    142: # =================================================== Critical message received
                    143: 
                    144: sub user_crit_received {
1.12      www       145:     my $msgid=shift;
                    146:     my %message=&Apache::lonnet::get('critical',[$msgid]);
                    147:     my %contents=&unpackagemsg($message{$msgid});
1.5       www       148:     my $status='rec: '.
                    149:      &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
1.4       www       150:                      'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'},
                    151:                      'User '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}.
                    152:                      ' acknowledged receipt of message "'.
                    153:                      $contents{'subject'}.'" dated '.$contents{'time'}.".\n\n"
                    154:                      .'Message ID: '.$contents{'msgid'});
1.5       www       155:     $status.=' trans: '.
1.12      www       156:      &Apache::lonnet::put(
                    157:      'nohist_email',{$contents{'msgid'} => $message{$msgid}});
1.5       www       158:     $status.=' del: '.
1.9       albertel  159:      &Apache::lonnet::del('critical',[$contents{'msgid'}]);
1.5       www       160:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
                    161:                          $ENV{'user.home'},'Received critical message '.
                    162:                          $contents{'msgid'}.
                    163:                          ', '.$status);
1.12      www       164:     return $status;
1.2       www       165: }
                    166: 
                    167: # ======================================================== Normal communication
                    168: 
                    169: sub user_normal_msg {
1.7       www       170:     my ($user,$domain,$subject,$message,$citation)=@_;
1.2       www       171: # Check if allowed missing
                    172:     my $status='';
                    173:     my $msgid='undefined';
                    174:     unless (($message)&&($user)&&($domain)) { $status='empty'; };
                    175:     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
                    176:     if ($homeserver ne 'no_host') {
1.7       www       177:        ($msgid,$message)=&packagemsg($subject,$message,$citation);
1.4       www       178:        $status=&Apache::lonnet::critical(
                    179:            'put:'.$domain.':'.$user.':nohist_email:'.
                    180:            &Apache::lonnet::escape($msgid).'='.
                    181:            &Apache::lonnet::escape($message),$homeserver);
1.2       www       182:     } else {
                    183:        $status='no_host';
                    184:     }
                    185:     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
                    186:                          $ENV{'user.home'},
                    187:       'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
                    188:     return $status;
                    189: }
                    190: 
1.7       www       191: # =============================================================== Status Change
                    192: 
                    193: sub statuschange {
                    194:     my ($msgid,$newstatus)=@_;
1.8       albertel  195:     my %status=&Apache::lonnet::get('email_status',[$msgid]);
1.7       www       196:     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
                    197:     unless ($status{$msgid}) { $status{$msgid}='new'; }
                    198:     unless (($status{$msgid} eq 'replied') || 
                    199:             ($status{$msgid} eq 'forwarded')) {
1.10      albertel  200: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
1.7       www       201:     }
1.14      www       202:     if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
                    203: 	&Apache::lonnet::put('email_status',{$msgid => $newstatus});
                    204:     }
1.7       www       205: }
1.14      www       206: 
1.17      www       207: # ======================================================= Display a course list
                    208: 
                    209: sub discourse {
                    210:     my $r=shift;
                    211:     my %courselist=&Apache::lonnet::dump(
                    212:                    'classlist',
                    213: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    214: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    215:     my $now=time;
                    216:     $r->print(<<ENDDISHEADER);
                    217: <input type=hidden name=sendmode value=group>
                    218: <script>
                    219:     function checkall() {
                    220: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
                    221:             if 
                    222:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
                    223: 	      document.forms.compemail.elements[i].checked=true;
                    224:             }
                    225:         }
                    226:     }
                    227: 
1.19      www       228:     function checksec() {
                    229: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
                    230:             if 
                    231:           (document.forms.compemail.elements[i].name.indexOf
                    232:            ('send_to_&&&'+document.forms.compemail.chksec.value)==0) {
                    233: 	      document.forms.compemail.elements[i].checked=true;
                    234:             }
                    235:         }
                    236:     }
                    237: 
1.17      www       238:     function uncheckall() {
                    239: 	for (i=0; i<document.forms.compemail.elements.length; i++) {
                    240:             if 
                    241:           (document.forms.compemail.elements[i].name.indexOf('send_to_')==0) {
                    242: 	      document.forms.compemail.elements[i].checked=false;
                    243:             }
                    244:         }
                    245:     }
                    246: </script>
1.19      www       247: <input type=button onClick="checkall()" value="Check for All">&nbsp;
                    248: <input type=button onClick="checksec()" value="Check for Section/Group">
                    249: <input type=text size=5 name=chksec>&nbsp;
1.17      www       250: <input type=button onClick="uncheckall()" value="Check for None">
                    251: <p>
                    252: ENDDISHEADER
                    253:     map {
                    254:         my ($end,$start)=split(/\:/,$courselist{$_});
                    255:         my $active=1;
                    256:         if (($end) && ($now>$end)) { $active=0; }
                    257:         if ($active) {
                    258:            my ($sname,$sdom)=split(/\:/,$_);
                    259:            my %reply=&Apache::lonnet::get('environment',
                    260:               ['firstname','middlename','lastname','generation'],
                    261:               $sdom,$sname);
1.19      www       262:            my $section=&Apache::lonnet::usection
                    263: 	       ($sdom,$sname,$ENV{'request.course.id'});
                    264:            $r->print(
                    265:         '<br><input type=checkbox name="send_to_&&&'.$section.'&&&_'.$_.'"> '.
1.17      www       266: 		      $reply{'firstname'}.' '. 
                    267:                       $reply{'middlename'}.' '.
                    268:                       $reply{'lastname'}.' '.
                    269:                       $reply{'generation'}.
1.19      www       270:                       ' ('.$_.') '.$section);
1.17      www       271:         } 
                    272:     } sort keys %courselist;
                    273: }
                    274: 
1.13      www       275: # ==================================================== Display Critical Message
1.5       www       276: 
1.12      www       277: sub discrit {
                    278:     my $r=shift;
                    279:       $r->print('<h1><font color=red>Critical Messages</font></h1>'.
                    280:          '<form action=/adm/email method=post>'.
                    281:          '<input type=hidden name=confirm value=true>');
                    282:       my %what=&Apache::lonnet::dump('critical');
                    283:       map {
                    284:           my %content=&unpackagemsg($what{$_});
                    285:           $content{'message'}=~s/\n/\<br\>/g;
                    286: 	  $r->print('<hr>From: <b>'.$content{'sendername'}.'@'.
                    287:                     $content{'senderdomain'}.'</b> ('.$content{'time'}.
                    288:                     ')<br><blockquote>'.$content{'message'}.'</blockquote>'.
1.13      www       289:   '<input type=submit name="rec_'.$_.'" value="Confirm Receipt">'.
                    290:  '<input type=submit name="reprec_'.$_.'" value="Confirm Receipt and Reply">');
1.12      www       291:       } sort keys %what;
1.16      www       292:       $r->print(
                    293:           '<input type=hidden name="displayedcrit" value="true"></form>');
1.12      www       294: }
                    295: 
1.13      www       296: # =============================================================== Compose reply
                    297: 
                    298: sub comprep {
                    299:     my ($r,$msgid)=@_;
                    300:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
                    301:       my %content=&unpackagemsg($message{$msgid});
                    302:       my $quotemsg='> '.$content{'message'};
                    303:       $quotemsg=~s/\r/\n/g;
                    304:       $quotemsg=~s/\f/\n/g;
                    305:       $quotemsg=~s/\n+/\n\> /g;
                    306:       my $subject='Re: '.$content{'subject'};
                    307:       my $dispcrit='';
                    308:       if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
                    309:          $dispcrit=
                    310: 	     '<input type=checkbox name=critmsg> Send as critical message<p>';
                    311:       }
                    312:       $r->print(<<"ENDREPLY");
                    313: <form action="/adm/email" method=post>
                    314: <input type=hidden name=sendreply value="$msgid">
                    315: Subject: <input type=text size=50 name=subject value="$subject"><p>
                    316: <textarea name=message cols=60 rows=10>
                    317: $quotemsg
                    318: </textarea><p>
                    319: $dispcrit
                    320: <input type=submit value="Send Reply">
                    321: </form>
                    322: ENDREPLY
                    323: }
                    324: 
1.15      www       325: # ======================================================== Display all messages
                    326: 
1.14      www       327: sub disall {
                    328:     my $r=shift;
                    329:     $r->print('<h1>Display All Messages</h1>'.
                    330:      '<table border=2><tr><th colspan=2>&nbsp</th><th>Date</th>'.
                    331:      '<th>Username</th><th>Domain</th><th>Subject</th><th>Status</th></tr>');
                    332:     map {
                    333:         my ($sendtime,$shortsubj,$fromname,$fromdomain,$status)=
                    334: 	    &Apache::lonmsg::unpackmsgid($_);
                    335:        unless ($status eq 'deleted') {
                    336:         if ($status eq 'new') {
                    337: 	    $r->print('<tr bgcolor="#FFBB77">');
                    338:         } elsif ($status eq 'read') {
                    339: 	    $r->print('<tr bgcolor="#BBBB77">');
                    340:         } elsif ($status eq 'replied') {
                    341: 	    $r->print('<tr bgcolor="#AAAA88">');
                    342: 	} else {
                    343: 	    $r->print('<tr bgcolor="#99BBBB">');
                    344:         }
                    345:         $r->print('<td><a href="/adm/email?display='.$_.
                    346:                   '">Open</a></td><td><a href="/adm/email?markdel='.$_.
                    347:                   '">Delete</a></td><td>'.localtime($sendtime).'</td><td>'.
                    348:                   $fromname.'</td><td>'.$fromdomain.'</td><td>'.
                    349: 		      &Apache::lonnet::unescape($shortsubj).'</td><td>'.
                    350:                       $status.'</td></tr>');
                    351:        }
                    352:     } sort split(/\&/,&Apache::lonnet::reply('keys:'.
                    353: 					$ENV{'user.domain'}.':'.
                    354:                                         $ENV{'user.name'}.':nohist_email',
                    355:                                         $ENV{'user.home'}));
                    356:     $r->print('</table></body></html>');
                    357: }
                    358: 
1.15      www       359: # ============================================================== Compose output
                    360: 
                    361: sub compout {
1.17      www       362:     my ($r,$forwarding,$broadcast)=@_;
1.15      www       363:       my $dispcrit='';
                    364:     my $dissub='';
                    365:     my $dismsg='';
                    366:     my $func='Send New';
                    367:       if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
                    368:          $dispcrit=
                    369: 	     '<input type=checkbox name=critmsg> Send as critical message<p>';
                    370:       }
                    371:     if ($forwarding) {
                    372:        $dispcrit.='<input type=hidden name=forwid value="'.
                    373: 	   $forwarding.'">';
                    374:        $func='Forward';
                    375:       my %message=&Apache::lonnet::get('nohist_email',[$forwarding]);
                    376:       my %content=&unpackagemsg($message{$forwarding});
                    377: 
                    378:        $dissub='Forwarding: '.$content{'subject'};
                    379:        $dismsg='Forwarded message from '.
                    380: 	   $content{'sendername'}.' at '.$content{'senderdomain'};
                    381:     }
                    382:     my $defdom=$ENV{'user.domain'};
1.22    ! www       383:       $r->print(
        !           384:                 '<form action="/adm/email"  name="compemail" method=post'.
        !           385:                 ' enctype="multipart/form-data">'.
1.17      www       386:                 '<input type=hidden name=sendmail value=on><table>');
1.22    ! www       387:     unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
1.17      www       388:        $r->print(<<"ENDREC");
1.15      www       389: <table>
                    390: <tr><td>Username:</td><td><input type=text size=12 name=recuname></td></tr>
                    391: <tr><td>Domain:</td>
                    392: <td><input type=text size=12 name=recdomain value="$defdom"></td></tr>
1.17      www       393: ENDREC
                    394:     }
1.22    ! www       395:     unless ($broadcast eq 'upload') {
        !           396:        $r->print(<<"ENDCOMP");
1.20      www       397: <tr><td>Additional Recipients<br><tt>username\@domain,username\@domain, ...
                    398: </tt></td><td>
                    399: <input type=text size=50 name=additionalrec></td></tr>
1.15      www       400: <tr><td>Subject:</td><td><input type=text size=50 name=subject value="$dissub">
                    401: </td></tr></table>
                    402: <textarea name=message cols=60 rows=10>$dismsg
                    403: </textarea><p>
                    404: $dispcrit
                    405: <input type=submit value="$func Mail">
                    406: ENDCOMP
1.22    ! www       407:     }
        !           408:     if ($broadcast eq 'upload') {
        !           409: 	$r->print(<<ENDUPLOAD);
        !           410: <input type=hidden name=sendmode value=upload>
        !           411: <h3>Generate messages from a file</h3>
        !           412: Subject: <input type=text size=50 name=subject>
        !           413: <pre>
        !           414: username1\@domain1: text
        !           415: username2\@domain2: text
        !           416: username1\@domain1: text
        !           417: </pre>
        !           418: The messages will be assembled from all lines with the respective 
        !           419: <tt>username\@domain</tt>, and appended to the general message text.<p>
        !           420: <input type=file name=upfile size=20><p>
        !           421: General message text:<p>
        !           422: <textarea name=message cols=60 rows=10>$dismsg
        !           423: </textarea><p>
        !           424: $dispcrit
        !           425: <input type=submit value="Upload and send">
        !           426: ENDUPLOAD
        !           427:     }
1.17      www       428:     if ($broadcast eq 'group') {
                    429:        &discourse;
                    430:     }
                    431:     $r->print('</form>');
1.15      www       432: }
                    433: 
1.13      www       434: # ===================================================================== Handler
                    435: 
1.5       www       436: sub handler {
                    437:     my $r=shift;
                    438: 
                    439: # ----------------------------------------------------------- Set document type
                    440: 
                    441:   $r->content_type('text/html');
                    442:   $r->send_http_header;
                    443: 
                    444:   return OK if $r->header_only;
                    445: 
1.6       www       446: # --------------------------- Get query string for limited number of parameters
                    447: 
                    448:     map {
                    449:        my ($name, $value) = split(/=/,$_);
                    450:        $value =~ tr/+/ /;
                    451:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                    452:        if (($name eq 'display') || ($name eq 'replyto') || 
1.14      www       453:            ($name eq 'forward') || ($name eq 'markread') ||
                    454:            ($name eq 'markdel') || ($name eq 'markunread') ||
1.12      www       455:            ($name eq 'sendreply') || ($name eq 'compose') ||
                    456:            ($name eq 'sendmail') || ($name eq 'critical')) {
1.6       www       457:            unless ($ENV{'form.'.$name}) {
                    458:               $ENV{'form.'.$name}=$value;
                    459: 	   }
                    460:        }
                    461:     } (split(/&/,$ENV{'QUERY_STRING'}));
                    462: 
1.5       www       463: # --------------------------------------------------------------- Render Output
                    464:   
                    465:   $r->print('<html><head><title>EMail and Messaging</title></head>');
1.7       www       466:   $r->print(
                    467:    '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
1.5       www       468:   $r->print('<h1>EMail</h1>');
1.6       www       469:   if ($ENV{'form.display'}) {
1.7       www       470:       my $msgid=$ENV{'form.display'};
                    471:       &statuschange($msgid,'read');
1.8       albertel  472:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7       www       473:       my %content=&unpackagemsg($message{$msgid});
                    474:       $r->print('<b>Subject:</b> '.$content{'subject'}.
                    475:              '<br><b>From:</b> '.$content{'sendername'}.' at '.
                    476:                                  $content{'senderdomain'}.
1.14      www       477:              '<br><b>Time:</b> '.$content{'time'}.'<p>'.
                    478:              '<table border=2><tr bgcolor="#FFFFAA"><td>Functions:</td>'.
                    479:            '<td><a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).
                    480:              '"><b>Reply</b></a></td>'.
1.15      www       481:            '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).
1.14      www       482:              '"><b>Forward</b></a></td>'.
1.15      www       483:         '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).
                    484:              '"><b>Mark Unread</b></a></td>'.
                    485:         '<td><a href="/adm/email"><b>Display all Messages</b></a></td>'.
1.14      www       486:              '</tr></table><p><pre>'.
1.7       www       487:              $content{'message'}.'</pre><hr>'.$content{'citation'});
1.6       www       488:   } elsif ($ENV{'form.replyto'}) {
1.13      www       489:       &comprep($r,$ENV{'form.replyto'});
1.7       www       490:   } elsif ($ENV{'form.sendreply'}) {
                    491:       my $msgid=$ENV{'form.sendreply'};
1.8       albertel  492:       my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7       www       493:       my %content=&unpackagemsg($message{$msgid});
                    494:       &statuschange($msgid,'replied');
1.12      www       495:       if (($ENV{'form.critmsg'}) && 
                    496:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
                    497:          $r->print('Sending critical: '.
                    498:                 &user_crit_msg($content{'sendername'},
1.7       www       499:                                  $content{'senderdomain'},
                    500:                                  $ENV{'form.subject'},
                    501:                                  $ENV{'form.message'}));
1.12      www       502:       } else {
                    503:          $r->print('Sending: '.&user_normal_msg($content{'sendername'},
                    504:                                  $content{'senderdomain'},
                    505:                                  $ENV{'form.subject'},
                    506:                                  $ENV{'form.message'}));
                    507:       }
1.14      www       508:       if ($ENV{'form.displayedcrit'}) {
                    509:           &discrit($r);
                    510:       } else {
                    511: 	  &disall($r);
                    512:       }
1.12      www       513:   } elsif ($ENV{'form.confirm'}) {
                    514:       map {
                    515:           if ($_=~/^form\.rec\_(.*)$/) {
                    516: 	      $r->print('<b>Confirming Receipt:</b> '.
                    517:                         &user_crit_received($1).'<br>');
1.13      www       518:           }
                    519:           if ($_=~/^form\.reprec\_(.*)$/) {
                    520:               my $msgid=$1;
                    521: 	      $r->print('<b>Confirming Receipt:</b> '.
                    522:                         &user_crit_received($msgid).'<br>');
                    523:               &comprep($r,$msgid);
1.12      www       524:           }
                    525:       } keys %ENV;
                    526:       &discrit($r);
                    527:   } elsif ($ENV{'form.critical'}) {
                    528:       &discrit($r);
1.6       www       529:   } elsif ($ENV{'form.forward'}) {
1.15      www       530:       &compout($r,$ENV{'form.forward'});
1.14      www       531:   } elsif ($ENV{'form.markread'}) {
                    532:   } elsif ($ENV{'form.markdel'}) {
                    533:       &statuschange($ENV{'form.markdel'},'deleted');
                    534:       &disall($r);
                    535:   } elsif ($ENV{'form.markunread'}) {
1.15      www       536:       &statuschange($ENV{'form.markunread'},'new');
                    537:       &disall($r);
1.11      www       538:   } elsif ($ENV{'form.compose'}) {
1.17      www       539:       &compout($r,'',$ENV{'form.compose'});
1.11      www       540:   } elsif ($ENV{'form.sendmail'}) {
1.16      www       541:       my %content=();
                    542:       undef %content;
                    543:       if ($ENV{'form.forwid'}) {
                    544:         my $msgid=$ENV{'form.forwid'};
                    545:         my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
                    546:         %content=&unpackagemsg($message{$msgid});
                    547:         &statuschange($msgid,'forwarded');
                    548:         $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
                    549: 	                       $content{'message'};
                    550:       }
1.18      www       551:       my %toaddr=();
                    552:       undef %toaddr;
                    553:       if ($ENV{'form.sendmode'} eq 'group') {
                    554:           map {
1.19      www       555: 	      if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
1.22    ! www       556: 		  $toaddr{$1}='';
1.18      www       557:               }
                    558:           } keys %ENV;
1.22    ! www       559:       } elsif ($ENV{'form.sendmode'} eq 'upload') {
        !           560:           map {
        !           561:               my ($rec,$txt)=split(/\s*\:\s*/,$_);
        !           562:               if ($txt) {
        !           563: 		  $rec=~s/\@/\:/;
        !           564:                   $toaddr{$rec}.=$txt."\n";
        !           565:               }
        !           566:           } split(/[\n\r\f]+/,$ENV{'form.upfile'});
1.18      www       567:       } else {
1.22    ! www       568: 	  $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
1.20      www       569:       }
                    570:       if ($ENV{'form.additionalrec'}) {
                    571: 	  map {
                    572:               my ($auname,$audom)=split(/\@/,$_);
1.22    ! www       573:               $toaddr{$auname.':'.$audom}='';
1.20      www       574:           } split(/\,/,$ENV{'form.additionalrec'});
1.18      www       575:       }
                    576:     map {
                    577:       my ($recuname,$recdomain)=split(/\:/,$_);
1.22    ! www       578:       my $msgtxt=$ENV{'form.message'};
        !           579:       if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }    
1.16      www       580:       if (($ENV{'form.critmsg'}) && 
                    581:           (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
                    582:          $r->print('Sending critical: '.
1.18      www       583:                 &user_crit_msg($recuname,$recdomain,
1.16      www       584:                                  $ENV{'form.subject'},
1.22    ! www       585:                                  $msgtxt,
1.16      www       586:                                  $content{'citation'}));
                    587:       } else {
1.18      www       588:          $r->print('Sending: '.&user_normal_msg($recuname,$recdomain,
1.16      www       589:                                  $ENV{'form.subject'},
1.22    ! www       590:                                  $msgtxt,
1.16      www       591:                                  $content{'citation'}));
                    592:       }
1.18      www       593:       $r->print('<br>');
                    594:     } keys %toaddr;
1.16      www       595:       if ($ENV{'form.displayedcrit'}) {
                    596:           &discrit($r);
                    597:       } else {
                    598: 	  &disall($r);
                    599:       }
1.6       www       600:   } else {
1.14      www       601:       &disall($r);
1.6       www       602:   }
1.5       www       603:   $r->print('</body></html>');
                    604:   return OK;
                    605: 
                    606: }
1.2       www       607: # ================================================= Main program, reset counter
                    608: 
                    609: sub BEGIN {
                    610:     $msgcount=0;
1.1       www       611: }
                    612: 
                    613: 1;
                    614: __END__
                    615: 
                    616: 
                    617: 
                    618: 
                    619: 
                    620: 
                    621: 

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