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