Annotation of loncom/interface/lonmsg.pm, revision 1.26
1.1 www 1: # The LearningOnline Network with CAPA
1.26 ! albertel 2: # Routines for messaging
! 3: #
! 4: # $Id: gplheader.pl,v 1.1 2001/11/29 18:19:27 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/
1.1 www 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: #
1.6 www 37: # 10/19,10/20,10/30,
38: # 02/06/01 Gerd Kortemeyer
1.11 www 39: # 07/27 Guy Albertelli
1.23 www 40: # 07/27,07/28,07/30,08/03,08/06,08/08,08/09,08/10,8/13,8/15,
1.24 www 41: # 10/1,11/5 Gerd Kortemeyer
1.1 www 42:
43: package Apache::lonmsg;
44:
45: use strict;
46: use Apache::lonnet();
1.2 www 47: use vars qw($msgcount);
48: use HTML::TokeParser;
1.5 www 49: use Apache::Constants qw(:common);
1.1 www 50:
51: # ===================================================================== Package
52:
1.3 www 53: sub packagemsg {
1.7 www 54: my ($subject,$message,$citation)=@_;
1.1 www 55: $message=~s/\</\<\;/g;
56: $message=~s/\>/\>\;/g;
1.7 www 57: $citation=~s/\</\<\;/g;
58: $citation=~s/\>/\>\;/g;
1.1 www 59: $subject=~s/\</\<\;/g;
60: $subject=~s/\>/\>\;/g;
1.2 www 61: my $now=time;
62: $msgcount++;
1.6 www 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.':'.$$);
1.2 www 69: return $msgid,
70: '<sendername>'.$ENV{'user.name'}.'</sendername>'.
1.1 www 71: '<senderdomain>'.$ENV{'user.domain'}.'</senderdomain>'.
72: '<subject>'.$subject.'</subject>'.
1.2 www 73: '<time>'.localtime($now).'</time>'.
1.1 www 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>'.
1.2 www 85: '<msgid>'.$msgid.'</msgid>'.
1.7 www 86: '<message>'.$message.'</message>'.
87: '<citation>'.$citation.'</citation>';
1.1 www 88: }
89:
1.2 www 90: # ================================================== Unpack message into a hash
91:
1.3 www 92: sub unpackagemsg {
1.2 www 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:
1.6 www 107: # ======================================================= Get info out of msgid
108:
109: sub unpackmsgid {
1.7 www 110: my $msgid=&Apache::lonnet::unescape(shift);
1.6 www 111: my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/,
1.7 www 112: &Apache::lonnet::unescape($msgid));
1.8 albertel 113: my %status=&Apache::lonnet::get('email_status',[$msgid]);
1.6 www 114: if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
115: unless ($status{$msgid}) { $status{$msgid}='new'; }
116: return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});
117: }
118:
1.1 www 119: # =============================== Automated message to the author of a resource
120:
121: sub author_res_msg {
122: my ($filename,$message)=@_;
1.2 www 123: unless ($message) { return 'empty'; }
1.1 www 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);
1.2 www 129: my $msgid;
1.3 www 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);
1.1 www 135: }
1.2 www 136: return 'no_host';
1.1 www 137: }
138:
139: # ================================================== Critical message to a user
140:
141: sub user_crit_msg {
1.24 www 142: my ($user,$domain,$subject,$message,$sendback)=@_;
1.2 www 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') {
1.3 www 149: ($msgid,$message)=&packagemsg($subject,$message);
1.24 www 150: if ($sendback) { $message.='<sendback>true</sendback>'; }
1.4 www 151: $status=&Apache::lonnet::critical(
152: 'put:'.$domain.':'.$user.':critical:'.
153: &Apache::lonnet::escape($msgid).'='.
154: &Apache::lonnet::escape($message),$homeserver);
1.2 www 155: } else {
156: $status='no_host';
157: }
158: &Apache::lonnet::logthis(
1.4 www 159: 'Sending critical email '.$msgid.
1.2 www 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: '
1.4 www 164: .$status));
1.2 www 165: return $status;
166: }
167:
168: # =================================================== Critical message received
169:
170: sub user_crit_received {
1.12 www 171: my $msgid=shift;
172: my %message=&Apache::lonnet::get('critical',[$msgid]);
173: my %contents=&unpackagemsg($message{$msgid});
1.24 www 174: my $status='rec: '.($contents{'sendback'}?
1.5 www 175: &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
1.4 www 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"
1.24 www 180: .'Message ID: '.$contents{'msgid'}):'no msg req');
1.5 www 181: $status.=' trans: '.
1.12 www 182: &Apache::lonnet::put(
183: 'nohist_email',{$contents{'msgid'} => $message{$msgid}});
1.5 www 184: $status.=' del: '.
1.9 albertel 185: &Apache::lonnet::del('critical',[$contents{'msgid'}]);
1.5 www 186: &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
187: $ENV{'user.home'},'Received critical message '.
188: $contents{'msgid'}.
189: ', '.$status);
1.12 www 190: return $status;
1.2 www 191: }
192:
193: # ======================================================== Normal communication
194:
195: sub user_normal_msg {
1.7 www 196: my ($user,$domain,$subject,$message,$citation)=@_;
1.2 www 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') {
1.7 www 203: ($msgid,$message)=&packagemsg($subject,$message,$citation);
1.4 www 204: $status=&Apache::lonnet::critical(
205: 'put:'.$domain.':'.$user.':nohist_email:'.
206: &Apache::lonnet::escape($msgid).'='.
207: &Apache::lonnet::escape($message),$homeserver);
1.2 www 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:
1.7 www 217: # =============================================================== Status Change
218:
219: sub statuschange {
220: my ($msgid,$newstatus)=@_;
1.8 albertel 221: my %status=&Apache::lonnet::get('email_status',[$msgid]);
1.7 www 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')) {
1.10 albertel 226: &Apache::lonnet::put('email_status',{$msgid => $newstatus});
1.7 www 227: }
1.14 www 228: if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
229: &Apache::lonnet::put('email_status',{$msgid => $newstatus});
230: }
1.7 www 231: }
1.14 www 232:
1.17 www 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:
1.19 www 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:
1.17 www 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>
1.19 www 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>
1.17 www 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);
1.19 www 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.'&&&_'.$_.'"> '.
1.17 www 292: $reply{'firstname'}.' '.
293: $reply{'middlename'}.' '.
294: $reply{'lastname'}.' '.
295: $reply{'generation'}.
1.19 www 296: ' ('.$_.') '.$section);
1.17 www 297: }
298: } sort keys %courselist;
299: }
300:
1.13 www 301: # ==================================================== Display Critical Message
1.5 www 302:
1.12 www 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>'.
1.13 www 315: '<input type=submit name="rec_'.$_.'" value="Confirm Receipt">'.
316: '<input type=submit name="reprec_'.$_.'" value="Confirm Receipt and Reply">');
1.12 www 317: } sort keys %what;
1.16 www 318: $r->print(
319: '<input type=hidden name="displayedcrit" value="true"></form>');
1.12 www 320: }
321:
1.13 www 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=
1.24 www 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>';
1.13 www 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>
1.23 www 344: <textarea name=message cols=64 rows=10 wrap=hard>
1.13 www 345: $quotemsg
346: </textarea><p>
347: $dispcrit
348: <input type=submit value="Send Reply">
349: </form>
350: ENDREPLY
351: }
352:
1.15 www 353: # ======================================================== Display all messages
354:
1.14 www 355: sub disall {
356: my $r=shift;
1.25 www 357: $r->print(
358: '<h1>Display All Messages</h1><form method=post action="/adm/email">'.
1.14 www 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='.$_.
1.25 www 376: '">Delete</a><input type=checkbox name="delmark_'.$_.'"></td>'.
377: '<td>'.localtime($sendtime).'</td><td>'.
1.14 www 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'}));
1.25 www 386: $r->print('</table><p>'.
387: '<input type=submit name="markeddel" value="Delete Checked">'.
388: '</form></body></html>');
1.14 www 389: }
390:
1.15 www 391: # ============================================================== Compose output
392:
393: sub compout {
1.17 www 394: my ($r,$forwarding,$broadcast)=@_;
1.15 www 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=
1.24 www 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>';
1.15 www 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'};
1.22 www 417: $r->print(
418: '<form action="/adm/email" name="compemail" method=post'.
419: ' enctype="multipart/form-data">'.
1.17 www 420: '<input type=hidden name=sendmail value=on><table>');
1.22 www 421: unless (($broadcast eq 'group') || ($broadcast eq 'upload')) {
1.17 www 422: $r->print(<<"ENDREC");
1.15 www 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>
1.17 www 427: ENDREC
428: }
1.22 www 429: unless ($broadcast eq 'upload') {
430: $r->print(<<"ENDCOMP");
1.20 www 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>
1.15 www 434: <tr><td>Subject:</td><td><input type=text size=50 name=subject value="$dissub">
435: </td></tr></table>
1.23 www 436: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
1.15 www 437: </textarea><p>
438: $dispcrit
439: <input type=submit value="$func Mail">
440: ENDCOMP
1.22 www 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>
1.23 www 456: <textarea name=message cols=60 rows=10 wrap=hard>$dismsg
1.22 www 457: </textarea><p>
458: $dispcrit
459: <input type=submit value="Upload and send">
460: ENDUPLOAD
461: }
1.17 www 462: if ($broadcast eq 'group') {
463: &discourse;
464: }
465: $r->print('</form>');
1.15 www 466: }
467:
1.13 www 468: # ===================================================================== Handler
469:
1.5 www 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:
1.6 www 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') ||
1.14 www 487: ($name eq 'forward') || ($name eq 'markread') ||
488: ($name eq 'markdel') || ($name eq 'markunread') ||
1.12 www 489: ($name eq 'sendreply') || ($name eq 'compose') ||
490: ($name eq 'sendmail') || ($name eq 'critical')) {
1.6 www 491: unless ($ENV{'form.'.$name}) {
492: $ENV{'form.'.$name}=$value;
493: }
494: }
495: } (split(/&/,$ENV{'QUERY_STRING'}));
496:
1.5 www 497: # --------------------------------------------------------------- Render Output
498:
499: $r->print('<html><head><title>EMail and Messaging</title></head>');
1.7 www 500: $r->print(
501: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
1.5 www 502: $r->print('<h1>EMail</h1>');
1.6 www 503: if ($ENV{'form.display'}) {
1.7 www 504: my $msgid=$ENV{'form.display'};
505: &statuschange($msgid,'read');
1.8 albertel 506: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7 www 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'}.
1.14 www 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>'.
1.15 www 515: '<td><a href="/adm/email?forward='.&Apache::lonnet::escape($msgid).
1.14 www 516: '"><b>Forward</b></a></td>'.
1.15 www 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>'.
1.14 www 520: '</tr></table><p><pre>'.
1.7 www 521: $content{'message'}.'</pre><hr>'.$content{'citation'});
1.6 www 522: } elsif ($ENV{'form.replyto'}) {
1.13 www 523: &comprep($r,$ENV{'form.replyto'});
1.7 www 524: } elsif ($ENV{'form.sendreply'}) {
525: my $msgid=$ENV{'form.sendreply'};
1.8 albertel 526: my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
1.7 www 527: my %content=&unpackagemsg($message{$msgid});
528: &statuschange($msgid,'replied');
1.24 www 529: if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) &&
1.12 www 530: (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
531: $r->print('Sending critical: '.
532: &user_crit_msg($content{'sendername'},
1.7 www 533: $content{'senderdomain'},
534: $ENV{'form.subject'},
1.24 www 535: $ENV{'form.message'},
536: $ENV{'form.sendbck'}));
1.12 www 537: } else {
538: $r->print('Sending: '.&user_normal_msg($content{'sendername'},
539: $content{'senderdomain'},
540: $ENV{'form.subject'},
541: $ENV{'form.message'}));
542: }
1.14 www 543: if ($ENV{'form.displayedcrit'}) {
544: &discrit($r);
545: } else {
546: &disall($r);
547: }
1.12 www 548: } elsif ($ENV{'form.confirm'}) {
549: map {
550: if ($_=~/^form\.rec\_(.*)$/) {
551: $r->print('<b>Confirming Receipt:</b> '.
552: &user_crit_received($1).'<br>');
1.13 www 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);
1.12 www 559: }
560: } keys %ENV;
561: &discrit($r);
562: } elsif ($ENV{'form.critical'}) {
563: &discrit($r);
1.6 www 564: } elsif ($ENV{'form.forward'}) {
1.15 www 565: &compout($r,$ENV{'form.forward'});
1.14 www 566: } elsif ($ENV{'form.markread'}) {
567: } elsif ($ENV{'form.markdel'}) {
568: &statuschange($ENV{'form.markdel'},'deleted');
1.25 www 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>');
1.14 www 579: &disall($r);
580: } elsif ($ENV{'form.markunread'}) {
1.15 www 581: &statuschange($ENV{'form.markunread'},'new');
582: &disall($r);
1.11 www 583: } elsif ($ENV{'form.compose'}) {
1.17 www 584: &compout($r,'',$ENV{'form.compose'});
1.11 www 585: } elsif ($ENV{'form.sendmail'}) {
1.16 www 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: }
1.18 www 596: my %toaddr=();
597: undef %toaddr;
598: if ($ENV{'form.sendmode'} eq 'group') {
599: map {
1.19 www 600: if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
1.22 www 601: $toaddr{$1}='';
1.18 www 602: }
603: } keys %ENV;
1.22 www 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'});
1.18 www 612: } else {
1.22 www 613: $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
1.20 www 614: }
615: if ($ENV{'form.additionalrec'}) {
616: map {
617: my ($auname,$audom)=split(/\@/,$_);
1.22 www 618: $toaddr{$auname.':'.$audom}='';
1.20 www 619: } split(/\,/,$ENV{'form.additionalrec'});
1.18 www 620: }
621: map {
622: my ($recuname,$recdomain)=split(/\:/,$_);
1.22 www 623: my $msgtxt=$ENV{'form.message'};
624: if ($toaddr{$_}) { $msgtxt.='<hr>'.$toaddr{$_}; }
1.24 www 625: if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) &&
1.16 www 626: (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
627: $r->print('Sending critical: '.
1.18 www 628: &user_crit_msg($recuname,$recdomain,
1.16 www 629: $ENV{'form.subject'},
1.22 www 630: $msgtxt,
1.24 www 631: $ENV{'form.sendbck'}));
1.16 www 632: } else {
1.18 www 633: $r->print('Sending: '.&user_normal_msg($recuname,$recdomain,
1.16 www 634: $ENV{'form.subject'},
1.22 www 635: $msgtxt,
1.16 www 636: $content{'citation'}));
637: }
1.18 www 638: $r->print('<br>');
639: } keys %toaddr;
1.16 www 640: if ($ENV{'form.displayedcrit'}) {
641: &discrit($r);
642: } else {
643: &disall($r);
644: }
1.6 www 645: } else {
1.14 www 646: &disall($r);
1.6 www 647: }
1.5 www 648: $r->print('</body></html>');
649: return OK;
650:
651: }
1.2 www 652: # ================================================= Main program, reset counter
653:
654: sub BEGIN {
655: $msgcount=0;
1.1 www 656: }
657:
658: 1;
659: __END__
660:
661:
662:
663:
664:
665:
666:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>