Annotation of loncom/interface/lonmsg.pm, revision 1.185
1.1 www 1: # The LearningOnline Network with CAPA
1.26 albertel 2: # Routines for messaging
3: #
1.185 ! albertel 4: # $Id: lonmsg.pm,v 1.184 2006/05/30 12:46:09 www Exp $
1.26 albertel 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: #
1.75 www 28:
1.1 www 29: package Apache::lonmsg;
30:
31: use strict;
1.140 albertel 32: use Apache::lonnet;
1.47 albertel 33: use HTML::TokeParser();
1.180 albertel 34: use Apache::lonlocal;
1.53 www 35: use Mail::Send;
1.184 www 36: use lib '/home/httpd/lib/perl/';
37: use LONCAPA;
1.180 albertel 38:
39: {
40: my $uniq;
41: sub get_uniq {
42: $uniq++;
43: return $uniq;
44: }
45: }
1.65 www 46:
1.1 www 47: # ===================================================================== Package
48:
1.3 www 49: sub packagemsg {
1.108 www 50: my ($subject,$message,$citation,$baseurl,$attachmenturl,
1.174 raeburn 51: $recuser,$recdomain,$msgid,$type,$crsmsgid)=@_;
1.96 albertel 52: $message =&HTML::Entities::encode($message,'<>&"');
53: $citation=&HTML::Entities::encode($citation,'<>&"');
54: $subject =&HTML::Entities::encode($subject,'<>&"');
1.49 albertel 55: #remove machine specification
56: $baseurl =~ s|^http://[^/]+/|/|;
1.96 albertel 57: $baseurl =&HTML::Entities::encode($baseurl,'<>&"');
1.51 www 58: #remove machine specification
59: $attachmenturl =~ s|^http://[^/]+/|/|;
1.96 albertel 60: $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
1.158 raeburn 61: my $course_context;
62: if (defined($env{'form.replyid'})) {
63: my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
1.184 www 64: split(/\:/,&unescape($env{'form.replyid'}));
1.158 raeburn 65: $course_context = $origcid;
66: }
1.160 raeburn 67: foreach my $key (keys(%env)) {
68: if ($key=~/^form\.(rep)?rec\_(.*)$/) {
69: my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =
1.184 www 70: split(/\:/,&unescape($2));
1.160 raeburn 71: $course_context = $origcid;
72: last;
73: }
74: }
1.158 raeburn 75: unless(defined($course_context)) {
76: $course_context = $env{'request.course.id'};
77: }
1.2 www 78: my $now=time;
1.180 albertel 79: my $msgcount = &get_uniq();
1.156 raeburn 80: unless(defined($msgid)) {
1.159 raeburn 81: $msgid = &buildmsgid($now,$subject,$env{'user.name'},$env{'user.domain'},
82: $msgcount,$course_context,$$);
1.156 raeburn 83: }
1.174 raeburn 84: my $result = '<sendername>'.$env{'user.name'}.'</sendername>'.
1.140 albertel 85: '<senderdomain>'.$env{'user.domain'}.'</senderdomain>'.
1.1 www 86: '<subject>'.$subject.'</subject>'.
1.174 raeburn 87: '<time>'.&Apache::lonlocal::locallocaltime($now).'</time>';
88: if (defined($crsmsgid)) {
89: $result.= '<courseid>'.$course_context.'</courseid>'.
90: '<coursesec>'.$env{'request.course.sec'}.'</coursesec>'.
91: '<msgid>'.$msgid.'</msgid>'.
92: '<coursemsgid>'.$crsmsgid.'</coursemsgid>'.
93: '<message>'.$message.'</message>';
94: return ($msgid,$result);
95: }
96: $result .= '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
1.1 www 97: '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
98: '<client>'.$ENV{'REMOTE_ADDR'}.'</client>'.
1.140 albertel 99: '<browsertype>'.$env{'browser.type'}.'</browsertype>'.
100: '<browseros>'.$env{'browser.os'}.'</browseros>'.
101: '<browserversion>'.$env{'browser.version'}.'</browserversion>'.
102: '<browsermathml>'.$env{'browser.mathml'}.'</browsermathml>'.
1.1 www 103: '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
1.158 raeburn 104: '<courseid>'.$course_context.'</courseid>'.
1.140 albertel 105: '<coursesec>'.$env{'request.course.sec'}.'</coursesec>'.
106: '<role>'.$env{'request.role'}.'</role>'.
107: '<resource>'.$env{'request.filename'}.'</resource>'.
1.156 raeburn 108: '<msgid>'.$msgid.'</msgid>';
109: if (ref($recuser) eq 'ARRAY') {
110: for (my $i=0; $i<@{$recuser}; $i++) {
1.162 raeburn 111: if ($type eq 'dcmail') {
112: my ($username,$email) = split(/:/,$$recuser[$i]);
1.184 www 113: $username = &unescape($username);
114: $email = &unescape($email);
1.162 raeburn 115: $username = &HTML::Entities::encode($username,'<>&"');
116: $email = &HTML::Entities::encode($email,'<>&"');
117: $result .= '<recipient username="'.$username.'">'.
118: $email.'</recipient>';
119: } else {
120: $result .= '<recuser>'.$$recuser[$i].'</recuser>'.
121: '<recdomain>'.$$recdomain[$i].'</recdomain>';
122: }
1.156 raeburn 123: }
124: } else {
125: $result .= '<recuser>'.$recuser.'</recuser>'.
126: '<recdomain>'.$recdomain.'</recdomain>';
127: }
128: $result .= '<message>'.$message.'</message>';
1.49 albertel 129: if (defined($citation)) {
130: $result.='<citation>'.$citation.'</citation>';
131: }
132: if (defined($baseurl)) {
133: $result.= '<baseurl>'.$baseurl.'</baseurl>';
134: }
1.51 www 135: if (defined($attachmenturl)) {
1.52 www 136: $result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>';
1.51 www 137: }
1.49 albertel 138: return $msgid,$result;
1.1 www 139: }
140:
1.2 www 141: # ================================================== Unpack message into a hash
142:
1.3 www 143: sub unpackagemsg {
1.52 www 144: my ($message,$notoken)=@_;
1.2 www 145: my %content=();
146: my $parser=HTML::TokeParser->new(\$message);
147: my $token;
148: while ($token=$parser->get_token) {
149: if ($token->[0] eq 'S') {
150: my $entry=$token->[1];
151: my $value=$parser->get_text('/'.$entry);
1.156 raeburn 152: if (($entry eq 'recuser') || ($entry eq 'recdomain')) {
153: push(@{$content{$entry}},$value);
1.162 raeburn 154: } elsif ($entry eq 'recipient') {
155: my $username = $token->[2]{'username'};
156: $username = &HTML::Entities::decode($username,'<>&"');
157: $content{$entry}{$username} = $value;
1.156 raeburn 158: } else {
159: $content{$entry}=$value;
160: }
1.2 www 161: }
162: }
1.168 albertel 163: if (!exists($content{'recuser'})) { $content{'recuser'} = []; }
1.52 www 164: if ($content{'attachmenturl'}) {
1.100 albertel 165: my ($fname)=($content{'attachmenturl'}=~m|/([^/]+)$|);
1.52 www 166: if ($notoken) {
1.100 albertel 167: $content{'message'}.='<p>'.&mt('Attachment').': <tt>'.$fname.'</tt>';
1.52 www 168: } else {
1.99 albertel 169: &Apache::lonnet::allowuploaded('/adm/msg',
170: $content{'attachmenturl'});
171: $content{'message'}.='<p>'.&mt('Attachment').
172: ': <a href="'.$content{'attachmenturl'}.'"><tt>'.
1.100 albertel 173: $fname.'</tt></a>';
1.52 www 174: }
175: }
1.2 www 176: return %content;
177: }
178:
1.6 www 179: # ======================================================= Get info out of msgid
180:
1.159 raeburn 181: sub buildmsgid {
182: my ($now,$subject,$uname,$udom,$msgcount,$course_context,$pid) = @_;
1.184 www 183: $subject=&escape($subject);
184: return(&escape($now.':'.$subject.':'.$uname.':'.
1.159 raeburn 185: $udom.':'.$msgcount.':'.$course_context.':'.$pid));
186: }
187:
1.6 www 188: sub unpackmsgid {
1.169 albertel 189: my ($msgid,$folder,$skipstatus,$status_cache)=@_;
1.184 www 190: $msgid=&unescape($msgid);
1.167 raeburn 191: my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid,
1.184 www 192: $processid)=split(/\:/,&unescape($msgid));
193: $shortsubj = &unescape($shortsubj);
1.182 albertel 194: $shortsubj = &HTML::Entities::decode($shortsubj);
1.167 raeburn 195: if (!defined($processid)) { $fromcid = ''; }
1.164 raeburn 196: my %status=();
197: unless ($skipstatus) {
1.169 albertel 198: if (ref($status_cache)) {
199: $status{$msgid} = $status_cache->{$msgid};
200: } else {
201: my $suffix=&foldersuffix($folder);
202: %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
203: }
204: if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
1.164 raeburn 205: unless ($status{$msgid}) { $status{$msgid}='new'; }
206: }
1.141 raeburn 207: return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid);
208: }
1.6 www 209:
1.53 www 210:
211: sub sendemail {
212: my ($to,$subject,$body)=@_;
213: $body=
1.67 www 214: "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n".
215: "*** ".&mt('Please do not reply to this address.')."\n\n".$body;
1.53 www 216: my $msg = new Mail::Send;
217: $msg->to($to);
218: $msg->subject('[LON-CAPA] '.$subject);
1.97 matthew 219: if (my $fh = $msg->open()) {
1.172 albertel 220: print $fh $body;
221: $fh->close;
1.68 www 222: }
1.53 www 223: }
224:
225: # ==================================================== Send notification emails
226:
227: sub sendnotification {
1.131 www 228: my ($to,$touname,$toudom,$subj,$crit,$text)=@_;
1.140 albertel 229: my $sender=$env{'environment.firstname'}.' '.$env{'environment.lastname'};
1.131 www 230: unless ($sender=~/\w/) {
1.172 albertel 231: $sender=$env{'user.name'}.'@'.$env{'user.domain'};
1.131 www 232: }
1.53 www 233: my $critical=($crit?' critical':'');
1.131 www 234: $text=~s/\<\;/\</gs;
235: $text=~s/\>\;/\>/gs;
236: $text=~s/\<\/*[^\>]+\>//gs;
1.53 www 237: my $url='http://'.
238: $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}.
1.54 www 239: '/adm/email?username='.$touname.'&domain='.$toudom;
1.53 www 240: my $body=(<<ENDMSG);
241: You received a$critical message from $sender in LON-CAPA. The subject is
242:
243: $subj
244:
1.131 www 245: === Excerpt ============================================================
246: $text
247: ========================================================================
248:
1.53 www 249: Use
250:
251: $url
252:
1.131 www 253: to access the full message.
1.53 www 254: ENDMSG
255: &sendemail($to,'New'.$critical.' message from '.$sender,$body);
256: }
1.40 www 257: # ============================================================= Check for email
258:
259: sub newmail {
1.140 albertel 260: if ((time-$env{'user.mailcheck.time'})>300) {
1.40 www 261: my %what=&Apache::lonnet::get('email_status',['recnewemail']);
262: &Apache::lonnet::appenv('user.mailcheck.time'=>time);
263: if ($what{'recnewemail'}>0) { return 1; }
264: }
265: return 0;
266: }
267:
1.1 www 268: # =============================== Automated message to the author of a resource
269:
1.58 bowersj2 270: =pod
271:
272: =item * B<author_res_msg($filename, $message)>: Sends message $message to the owner
273: of the resource with the URI $filename.
274:
275: =cut
276:
1.1 www 277: sub author_res_msg {
278: my ($filename,$message)=@_;
1.2 www 279: unless ($message) { return 'empty'; }
1.1 www 280: $filename=&Apache::lonnet::declutter($filename);
1.72 www 281: my ($domain,$author,@dummy)=split(/\//,$filename);
1.1 www 282: my $homeserver=&Apache::lonnet::homeserver($author,$domain);
283: if ($homeserver ne 'no_host') {
284: my $id=unpack("%32C*",$message);
1.181 albertel 285: $message .= " <p>This error occurred on machine ".
286: $Apache::lonnet::perlvar{'lonHostID'}."</p>";
1.2 www 287: my $msgid;
1.72 www 288: ($msgid,$message)=&packagemsg($filename,$message);
1.3 www 289: return &Apache::lonnet::reply('put:'.$domain.':'.$author.
1.72 www 290: ':nohist_res_msgs:'.
1.184 www 291: &escape($filename.'_'.$id).'='.
292: &escape($message),$homeserver);
1.1 www 293: }
1.2 www 294: return 'no_host';
1.73 www 295: }
296:
297: # =========================================== Retrieve author resource messages
298:
299: sub retrieve_author_res_msg {
1.75 www 300: my $url=shift;
1.73 www 301: $url=&Apache::lonnet::declutter($url);
1.80 www 302: my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
1.76 www 303: my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$domain,$author);
1.73 www 304: my $msgs='';
305: foreach (keys %errormsgs) {
1.80 www 306: if ($_=~/^\Q$url\E\_\d+$/) {
1.73 www 307: my %content=&unpackagemsg($errormsgs{$_});
1.74 www 308: $msgs.='<p><img src="/adm/lonMisc/bomb.gif" /><b>'.
309: $content{'time'}.'</b>: '.$content{'message'}.
310: '<br /></p>';
1.73 www 311: }
312: }
313: return $msgs;
314: }
315:
316:
317: # =============================== Delete all author messages related to one URL
318:
319: sub del_url_author_res_msg {
1.75 www 320: my $url=shift;
1.73 www 321: $url=&Apache::lonnet::declutter($url);
1.77 www 322: my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
323: my @delmsgs=();
324: foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
325: if ($_=~/^\Q$url\E\_\d+$/) {
326: push (@delmsgs,$_);
327: }
328: }
329: return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
1.73 www 330: }
1.152 www 331: # =================================== Clear out all author messages in URL path
1.73 www 332:
1.152 www 333: sub clear_author_res_msg {
334: my $url=shift;
335: $url=&Apache::lonnet::declutter($url);
336: my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
337: my @delmsgs=();
338: foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
339: if ($_=~/^\Q$url\E/) {
340: push (@delmsgs,$_);
341: }
342: }
343: return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
344: }
1.73 www 345: # ================= Return hash with URLs for which there is a resource message
346:
347: sub all_url_author_res_msg {
348: my ($author,$domain)=@_;
1.75 www 349: my %returnhash=();
1.76 www 350: foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
1.75 www 351: $_=~/^(.+)\_\d+/;
352: $returnhash{$1}=1;
353: }
354: return %returnhash;
1.1 www 355: }
356:
1.185 ! albertel 357: # ====================================== Add a comment to the User Notes screen
! 358:
! 359: sub store_instructor_comment {
! 360: my ($msg,$uname,$udom) = @_;
! 361: my $cid = $env{'request.course.id'};
! 362: my $cnum = $env{'course.'.$cid.'.num'};
! 363: my $cdom = $env{'course.'.$cid.'.domain'};
! 364: my $subject= &mt('Record').' ['.$uname.':'.$udom.']';
! 365: my $result = &user_normal_msg_raw($cnum,$cdom,$subject,$msg);
! 366: return $result;
! 367: }
! 368:
1.1 www 369: # ================================================== Critical message to a user
370:
1.38 www 371: sub user_crit_msg_raw {
1.159 raeburn 372: my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
1.2 www 373: # Check if allowed missing
374: my $status='';
375: my $msgid='undefined';
376: unless (($message)&&($user)&&($domain)) { $status='empty'; };
1.131 www 377: my $text=$message;
1.2 www 378: my $homeserver=&Apache::lonnet::homeserver($user,$domain);
379: if ($homeserver ne 'no_host') {
1.3 www 380: ($msgid,$message)=&packagemsg($subject,$message);
1.24 www 381: if ($sendback) { $message.='<sendback>true</sendback>'; }
1.4 www 382: $status=&Apache::lonnet::critical(
383: 'put:'.$domain.':'.$user.':critical:'.
1.184 www 384: &escape($msgid).'='.
385: &escape($message),$homeserver);
1.159 raeburn 386: if (defined($sentmessage)) {
387: $$sentmessage = $message;
388: }
1.2 www 389: } else {
390: $status='no_host';
391: }
1.53 www 392: # Notifications
1.132 www 393: my %userenv = &Apache::lonnet::get('environment',['critnotification',
394: 'permanentemail'],
1.53 www 395: $domain,$user);
396: if ($userenv{'critnotification'}) {
1.131 www 397: &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1,
398: $text);
1.53 www 399: }
1.132 www 400: if ($toperm && $userenv{'permanentemail'}) {
401: &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,1,
402: $text);
403: }
1.53 www 404: # Log this
1.2 www 405: &Apache::lonnet::logthis(
1.4 www 406: 'Sending critical email '.$msgid.
1.2 www 407: ', log status: '.
1.140 albertel 408: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
409: $env{'user.home'},
1.2 www 410: 'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
1.4 www 411: .$status));
1.2 www 412: return $status;
413: }
414:
1.38 www 415: # New routine that respects "forward" and calls old routine
416:
1.58 bowersj2 417: =pod
418:
419: =item * B<user_crit_msg($user, $domain, $subject, $message, $sendback)>: Sends
420: a critical message $message to the $user at $domain. If $sendback is true,
421: a reciept will be sent to the current user when $user recieves the message.
422:
1.183 albertel 423: Additionally it will check if the user has a Forwarding address
424: set, and send the message to that address instead
425:
426: returns
427: - in array context a list of results for each message that was sent
428: - in scalar context a space seperated list of results for each
429: message sent
430:
1.58 bowersj2 431: =cut
432:
1.38 www 433: sub user_crit_msg {
1.159 raeburn 434: my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
1.183 albertel 435: my @status;
1.38 www 436: my %userenv = &Apache::lonnet::get('environment',['msgforward'],
437: $domain,$user);
438: my $msgforward=$userenv{'msgforward'};
439: if ($msgforward) {
1.183 albertel 440: foreach my $addr (split(/\,/,$msgforward)) {
441: my ($forwuser,$forwdomain)=split(/\:/,$addr);
442: push(@status,
443: &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
444: $sendback,$toperm,$sentmessage));
1.38 www 445: }
446: } else {
1.183 albertel 447: push(@status,
448: &user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
449: $toperm,$sentmessage));
1.38 www 450: }
1.183 albertel 451: if (wantarray) {
452: return @status;
453: }
454: return join(' ',@status);
1.38 www 455: }
456:
1.2 www 457: # =================================================== Critical message received
458:
459: sub user_crit_received {
1.12 www 460: my $msgid=shift;
461: my %message=&Apache::lonnet::get('critical',[$msgid]);
1.52 www 462: my %contents=&unpackagemsg($message{$msgid},1);
1.24 www 463: my $status='rec: '.($contents{'sendback'}?
1.5 www 464: &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
1.140 albertel 465: &mt('Receipt').': '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.', '.$contents{'subject'},
466: &mt('User').' '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.
1.42 www 467: ' acknowledged receipt of message'."\n".' "'.
1.67 www 468: $contents{'subject'}.'"'."\n".&mt('dated').' '.
1.42 www 469: $contents{'time'}.".\n"
470: ):'no msg req');
1.5 www 471: $status.=' trans: '.
1.12 www 472: &Apache::lonnet::put(
473: 'nohist_email',{$contents{'msgid'} => $message{$msgid}});
1.5 www 474: $status.=' del: '.
1.9 albertel 475: &Apache::lonnet::del('critical',[$contents{'msgid'}]);
1.140 albertel 476: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
477: $env{'user.home'},'Received critical message '.
1.5 www 478: $contents{'msgid'}.
479: ', '.$status);
1.12 www 480: return $status;
1.2 www 481: }
482:
483: # ======================================================== Normal communication
484:
1.38 www 485: sub user_normal_msg_raw {
1.132 www 486: my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
1.174 raeburn 487: $toperm,$currid,$newid,$sentmessage,$crsmsgid)=@_;
1.2 www 488: # Check if allowed missing
1.173 albertel 489: my ($status,$packed_message);
1.2 www 490: my $msgid='undefined';
1.131 www 491: my $text=$message;
1.2 www 492: unless (($message)&&($user)&&($domain)) { $status='empty'; };
493: my $homeserver=&Apache::lonnet::homeserver($user,$domain);
494: if ($homeserver ne 'no_host') {
1.173 albertel 495: ($msgid,$packed_message)=
496: &packagemsg($subject,$message,$citation,$baseurl,
1.174 raeburn 497: $attachmenturl,$user,$domain,$currid,
498: undef,$crsmsgid);
499:
1.108 www 500: # Store in user folder
1.4 www 501: $status=&Apache::lonnet::critical(
502: 'put:'.$domain.':'.$user.':nohist_email:'.
1.184 www 503: &escape($msgid).'='.
504: &escape($packed_message),$homeserver);
1.108 www 505: # Save new message received time
1.40 www 506: &Apache::lonnet::put
507: ('email_status',{'recnewemail'=>time},$domain,$user);
1.159 raeburn 508: # Into sent-mail folder unless a broadcast message or critical message
509: unless (($env{'request.course.id'}) &&
510: (($env{'form.sendmode'} eq 'group') ||
511: (($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
1.170 albertel 512: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
513: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
514: '/'.$env{'request.course.sec'})))) {
1.174 raeburn 515: (undef, my $packed_message_no_citation)=
516: &packagemsg($subject,$message,undef ,$baseurl,
517: $attachmenturl,$user,$domain,$currid,
518: undef,$crsmsgid);
519:
1.173 albertel 520: $status .= &store_sent_mail($msgid,$packed_message_no_citation);
1.156 raeburn 521: }
1.2 www 522: } else {
523: $status='no_host';
1.53 www 524: }
1.156 raeburn 525: if (defined($newid)) {
526: $$newid = $msgid;
527: }
1.159 raeburn 528: if (defined($sentmessage)) {
1.173 albertel 529: $$sentmessage = $packed_message;
1.159 raeburn 530: }
531:
1.53 www 532: # Notifications
1.132 www 533: my %userenv = &Apache::lonnet::get('environment',['notification',
534: 'permanentemail'],
1.53 www 535: $domain,$user);
536: if ($userenv{'notification'}) {
1.131 www 537: &sendnotification($userenv{'notification'},$user,$domain,$subject,0,
538: $text);
1.2 www 539: }
1.132 www 540: if ($toperm && $userenv{'permanentemail'}) {
1.180 albertel 541: &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,0,
542: $text);
1.132 www 543: }
1.140 albertel 544: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
545: $env{'user.home'},
1.2 www 546: 'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
547: return $status;
548: }
1.38 www 549:
550: # New routine that respects "forward" and calls old routine
551:
1.58 bowersj2 552: =pod
553:
554: =item * B<user_normal_msg($user, $domain, $subject, $message,
555: $citation, $baseurl, $attachmenturl)>: Sends a message to the
556: $user at $domain, with subject $subject and message $message.
557:
558: =cut
559:
1.38 www 560: sub user_normal_msg {
1.132 www 561: my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
1.159 raeburn 562: $toperm,$sentmessage)=@_;
1.38 www 563: my $status='';
564: my %userenv = &Apache::lonnet::get('environment',['msgforward'],
565: $domain,$user);
566: my $msgforward=$userenv{'msgforward'};
567: if ($msgforward) {
1.171 banghart 568: foreach (split(/\,/,$msgforward)) {
1.172 albertel 569: my ($forwuser,$forwdomain)=split(/\:/,$_);
570: $status.=
1.171 banghart 571: &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
1.172 albertel 572: $citation,$baseurl,$attachmenturl,$toperm,
573: undef,undef,$sentmessage).' ';
1.171 banghart 574: }
1.38 www 575: } else {
1.172 albertel 576: $status=&user_normal_msg_raw($user,$domain,$subject,$message,
577: $citation,$baseurl,$attachmenturl,$toperm,
578: undef,undef,$sentmessage);
1.38 www 579: }
580: return $status;
581: }
582:
1.156 raeburn 583: sub store_sent_mail {
584: my ($msgid,$message) = @_;
1.171 banghart 585: my $status =' '.&Apache::lonnet::critical(
586: 'put:'.$env{'user.domain'}.':'.$env{'user.name'}.
587: ':nohist_email_sent:'.
1.184 www 588: &escape($msgid).'='.
589: &escape($message),$env{'user.home'});
1.156 raeburn 590: return $status;
591: }
1.2 www 592:
1.106 www 593: # =============================================================== Folder suffix
594:
595: sub foldersuffix {
596: my $folder=shift;
597: unless ($folder) { return ''; }
1.184 www 598: return '_'.&escape($folder);
1.106 www 599: }
600:
1.180 albertel 601: 1;
1.1 www 602: __END__
603:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>