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