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