Annotation of loncom/interface/lonmsg.pm, revision 1.186
1.1 www 1: # The LearningOnline Network with CAPA
1.26 albertel 2: # Routines for messaging
3: #
1.186 ! www 4: # $Id: lonmsg.pm,v 1.185 2006/06/12 22:55:23 albertel 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)=@_;
1.186 ! www 213: my %senderemails=&Apache::loncommon::getemails();
! 214: my $senderaddress='';
! 215: foreach my $type ('notification','permanentemail','critnotification') {
! 216: if ($senderemails{$type}) {
! 217: $senderaddress=$senderemails{$type};
! 218: }
! 219: }
1.53 www 220: $body=
1.67 www 221: "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n".
1.186 ! www 222: "*** ".($senderaddress?&mt('You can reply to this message'):&mt('Please do not reply to this address.')."\n*** ".
! 223: &mt('A reply will not be received by the recipient!'))."\n\n".$body;
1.53 www 224: my $msg = new Mail::Send;
225: $msg->to($to);
226: $msg->subject('[LON-CAPA] '.$subject);
1.186 ! www 227: if ($senderaddress) { $msg->add('Reply-to',$senderaddress); }
1.97 matthew 228: if (my $fh = $msg->open()) {
1.172 albertel 229: print $fh $body;
230: $fh->close;
1.68 www 231: }
1.53 www 232: }
233:
234: # ==================================================== Send notification emails
235:
236: sub sendnotification {
1.131 www 237: my ($to,$touname,$toudom,$subj,$crit,$text)=@_;
1.140 albertel 238: my $sender=$env{'environment.firstname'}.' '.$env{'environment.lastname'};
1.131 www 239: unless ($sender=~/\w/) {
1.172 albertel 240: $sender=$env{'user.name'}.'@'.$env{'user.domain'};
1.131 www 241: }
1.53 www 242: my $critical=($crit?' critical':'');
1.131 www 243: $text=~s/\<\;/\</gs;
244: $text=~s/\>\;/\>/gs;
245: $text=~s/\<\/*[^\>]+\>//gs;
1.53 www 246: my $url='http://'.
247: $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}.
1.54 www 248: '/adm/email?username='.$touname.'&domain='.$toudom;
1.53 www 249: my $body=(<<ENDMSG);
250: You received a$critical message from $sender in LON-CAPA. The subject is
251:
252: $subj
253:
1.131 www 254: === Excerpt ============================================================
255: $text
256: ========================================================================
257:
1.53 www 258: Use
259:
260: $url
261:
1.131 www 262: to access the full message.
1.53 www 263: ENDMSG
264: &sendemail($to,'New'.$critical.' message from '.$sender,$body);
265: }
1.40 www 266: # ============================================================= Check for email
267:
268: sub newmail {
1.140 albertel 269: if ((time-$env{'user.mailcheck.time'})>300) {
1.40 www 270: my %what=&Apache::lonnet::get('email_status',['recnewemail']);
271: &Apache::lonnet::appenv('user.mailcheck.time'=>time);
272: if ($what{'recnewemail'}>0) { return 1; }
273: }
274: return 0;
275: }
276:
1.1 www 277: # =============================== Automated message to the author of a resource
278:
1.58 bowersj2 279: =pod
280:
281: =item * B<author_res_msg($filename, $message)>: Sends message $message to the owner
282: of the resource with the URI $filename.
283:
284: =cut
285:
1.1 www 286: sub author_res_msg {
287: my ($filename,$message)=@_;
1.2 www 288: unless ($message) { return 'empty'; }
1.1 www 289: $filename=&Apache::lonnet::declutter($filename);
1.72 www 290: my ($domain,$author,@dummy)=split(/\//,$filename);
1.1 www 291: my $homeserver=&Apache::lonnet::homeserver($author,$domain);
292: if ($homeserver ne 'no_host') {
293: my $id=unpack("%32C*",$message);
1.181 albertel 294: $message .= " <p>This error occurred on machine ".
295: $Apache::lonnet::perlvar{'lonHostID'}."</p>";
1.2 www 296: my $msgid;
1.72 www 297: ($msgid,$message)=&packagemsg($filename,$message);
1.3 www 298: return &Apache::lonnet::reply('put:'.$domain.':'.$author.
1.72 www 299: ':nohist_res_msgs:'.
1.184 www 300: &escape($filename.'_'.$id).'='.
301: &escape($message),$homeserver);
1.1 www 302: }
1.2 www 303: return 'no_host';
1.73 www 304: }
305:
306: # =========================================== Retrieve author resource messages
307:
308: sub retrieve_author_res_msg {
1.75 www 309: my $url=shift;
1.73 www 310: $url=&Apache::lonnet::declutter($url);
1.80 www 311: my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
1.76 www 312: my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$domain,$author);
1.73 www 313: my $msgs='';
314: foreach (keys %errormsgs) {
1.80 www 315: if ($_=~/^\Q$url\E\_\d+$/) {
1.73 www 316: my %content=&unpackagemsg($errormsgs{$_});
1.74 www 317: $msgs.='<p><img src="/adm/lonMisc/bomb.gif" /><b>'.
318: $content{'time'}.'</b>: '.$content{'message'}.
319: '<br /></p>';
1.73 www 320: }
321: }
322: return $msgs;
323: }
324:
325:
326: # =============================== Delete all author messages related to one URL
327:
328: sub del_url_author_res_msg {
1.75 www 329: my $url=shift;
1.73 www 330: $url=&Apache::lonnet::declutter($url);
1.77 www 331: my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
332: my @delmsgs=();
333: foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
334: if ($_=~/^\Q$url\E\_\d+$/) {
335: push (@delmsgs,$_);
336: }
337: }
338: return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
1.73 www 339: }
1.152 www 340: # =================================== Clear out all author messages in URL path
1.73 www 341:
1.152 www 342: sub clear_author_res_msg {
343: my $url=shift;
344: $url=&Apache::lonnet::declutter($url);
345: my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
346: my @delmsgs=();
347: foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
348: if ($_=~/^\Q$url\E/) {
349: push (@delmsgs,$_);
350: }
351: }
352: return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
353: }
1.73 www 354: # ================= Return hash with URLs for which there is a resource message
355:
356: sub all_url_author_res_msg {
357: my ($author,$domain)=@_;
1.75 www 358: my %returnhash=();
1.76 www 359: foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
1.75 www 360: $_=~/^(.+)\_\d+/;
361: $returnhash{$1}=1;
362: }
363: return %returnhash;
1.1 www 364: }
365:
1.185 albertel 366: # ====================================== Add a comment to the User Notes screen
367:
368: sub store_instructor_comment {
369: my ($msg,$uname,$udom) = @_;
370: my $cid = $env{'request.course.id'};
371: my $cnum = $env{'course.'.$cid.'.num'};
372: my $cdom = $env{'course.'.$cid.'.domain'};
373: my $subject= &mt('Record').' ['.$uname.':'.$udom.']';
374: my $result = &user_normal_msg_raw($cnum,$cdom,$subject,$msg);
375: return $result;
376: }
377:
1.1 www 378: # ================================================== Critical message to a user
379:
1.38 www 380: sub user_crit_msg_raw {
1.159 raeburn 381: my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
1.2 www 382: # Check if allowed missing
383: my $status='';
384: my $msgid='undefined';
385: unless (($message)&&($user)&&($domain)) { $status='empty'; };
1.131 www 386: my $text=$message;
1.2 www 387: my $homeserver=&Apache::lonnet::homeserver($user,$domain);
388: if ($homeserver ne 'no_host') {
1.3 www 389: ($msgid,$message)=&packagemsg($subject,$message);
1.24 www 390: if ($sendback) { $message.='<sendback>true</sendback>'; }
1.4 www 391: $status=&Apache::lonnet::critical(
392: 'put:'.$domain.':'.$user.':critical:'.
1.184 www 393: &escape($msgid).'='.
394: &escape($message),$homeserver);
1.159 raeburn 395: if (defined($sentmessage)) {
396: $$sentmessage = $message;
397: }
1.2 www 398: } else {
399: $status='no_host';
400: }
1.53 www 401: # Notifications
1.186 ! www 402: my %userenv = &Apache::loncommon::getemails($user,$domain);
1.53 www 403: if ($userenv{'critnotification'}) {
1.131 www 404: &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1,
405: $text);
1.53 www 406: }
1.132 www 407: if ($toperm && $userenv{'permanentemail'}) {
408: &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,1,
409: $text);
410: }
1.53 www 411: # Log this
1.2 www 412: &Apache::lonnet::logthis(
1.4 www 413: 'Sending critical email '.$msgid.
1.2 www 414: ', log status: '.
1.140 albertel 415: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
416: $env{'user.home'},
1.2 www 417: 'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status: '
1.4 www 418: .$status));
1.2 www 419: return $status;
420: }
421:
1.38 www 422: # New routine that respects "forward" and calls old routine
423:
1.58 bowersj2 424: =pod
425:
426: =item * B<user_crit_msg($user, $domain, $subject, $message, $sendback)>: Sends
427: a critical message $message to the $user at $domain. If $sendback is true,
428: a reciept will be sent to the current user when $user recieves the message.
429:
1.183 albertel 430: Additionally it will check if the user has a Forwarding address
431: set, and send the message to that address instead
432:
433: returns
434: - in array context a list of results for each message that was sent
435: - in scalar context a space seperated list of results for each
436: message sent
437:
1.58 bowersj2 438: =cut
439:
1.38 www 440: sub user_crit_msg {
1.159 raeburn 441: my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
1.183 albertel 442: my @status;
1.38 www 443: my %userenv = &Apache::lonnet::get('environment',['msgforward'],
444: $domain,$user);
445: my $msgforward=$userenv{'msgforward'};
446: if ($msgforward) {
1.183 albertel 447: foreach my $addr (split(/\,/,$msgforward)) {
448: my ($forwuser,$forwdomain)=split(/\:/,$addr);
449: push(@status,
450: &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
451: $sendback,$toperm,$sentmessage));
1.38 www 452: }
453: } else {
1.183 albertel 454: push(@status,
455: &user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
456: $toperm,$sentmessage));
1.38 www 457: }
1.183 albertel 458: if (wantarray) {
459: return @status;
460: }
461: return join(' ',@status);
1.38 www 462: }
463:
1.2 www 464: # =================================================== Critical message received
465:
466: sub user_crit_received {
1.12 www 467: my $msgid=shift;
468: my %message=&Apache::lonnet::get('critical',[$msgid]);
1.52 www 469: my %contents=&unpackagemsg($message{$msgid},1);
1.24 www 470: my $status='rec: '.($contents{'sendback'}?
1.5 www 471: &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
1.140 albertel 472: &mt('Receipt').': '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.', '.$contents{'subject'},
473: &mt('User').' '.$env{'user.name'}.' '.&mt('at').' '.$env{'user.domain'}.
1.42 www 474: ' acknowledged receipt of message'."\n".' "'.
1.67 www 475: $contents{'subject'}.'"'."\n".&mt('dated').' '.
1.42 www 476: $contents{'time'}.".\n"
477: ):'no msg req');
1.5 www 478: $status.=' trans: '.
1.12 www 479: &Apache::lonnet::put(
480: 'nohist_email',{$contents{'msgid'} => $message{$msgid}});
1.5 www 481: $status.=' del: '.
1.9 albertel 482: &Apache::lonnet::del('critical',[$contents{'msgid'}]);
1.140 albertel 483: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
484: $env{'user.home'},'Received critical message '.
1.5 www 485: $contents{'msgid'}.
486: ', '.$status);
1.12 www 487: return $status;
1.2 www 488: }
489:
490: # ======================================================== Normal communication
491:
1.38 www 492: sub user_normal_msg_raw {
1.132 www 493: my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
1.174 raeburn 494: $toperm,$currid,$newid,$sentmessage,$crsmsgid)=@_;
1.2 www 495: # Check if allowed missing
1.173 albertel 496: my ($status,$packed_message);
1.2 www 497: my $msgid='undefined';
1.131 www 498: my $text=$message;
1.2 www 499: unless (($message)&&($user)&&($domain)) { $status='empty'; };
500: my $homeserver=&Apache::lonnet::homeserver($user,$domain);
501: if ($homeserver ne 'no_host') {
1.173 albertel 502: ($msgid,$packed_message)=
503: &packagemsg($subject,$message,$citation,$baseurl,
1.174 raeburn 504: $attachmenturl,$user,$domain,$currid,
505: undef,$crsmsgid);
506:
1.108 www 507: # Store in user folder
1.4 www 508: $status=&Apache::lonnet::critical(
509: 'put:'.$domain.':'.$user.':nohist_email:'.
1.184 www 510: &escape($msgid).'='.
511: &escape($packed_message),$homeserver);
1.108 www 512: # Save new message received time
1.40 www 513: &Apache::lonnet::put
514: ('email_status',{'recnewemail'=>time},$domain,$user);
1.159 raeburn 515: # Into sent-mail folder unless a broadcast message or critical message
516: unless (($env{'request.course.id'}) &&
517: (($env{'form.sendmode'} eq 'group') ||
518: (($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
1.170 albertel 519: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
520: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
521: '/'.$env{'request.course.sec'})))) {
1.174 raeburn 522: (undef, my $packed_message_no_citation)=
523: &packagemsg($subject,$message,undef ,$baseurl,
524: $attachmenturl,$user,$domain,$currid,
525: undef,$crsmsgid);
526:
1.173 albertel 527: $status .= &store_sent_mail($msgid,$packed_message_no_citation);
1.156 raeburn 528: }
1.2 www 529: } else {
530: $status='no_host';
1.53 www 531: }
1.156 raeburn 532: if (defined($newid)) {
533: $$newid = $msgid;
534: }
1.159 raeburn 535: if (defined($sentmessage)) {
1.173 albertel 536: $$sentmessage = $packed_message;
1.159 raeburn 537: }
538:
1.53 www 539: # Notifications
1.132 www 540: my %userenv = &Apache::lonnet::get('environment',['notification',
541: 'permanentemail'],
1.53 www 542: $domain,$user);
543: if ($userenv{'notification'}) {
1.131 www 544: &sendnotification($userenv{'notification'},$user,$domain,$subject,0,
545: $text);
1.2 www 546: }
1.132 www 547: if ($toperm && $userenv{'permanentemail'}) {
1.180 albertel 548: &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,0,
549: $text);
1.132 www 550: }
1.140 albertel 551: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
552: $env{'user.home'},
1.2 www 553: 'Sending '.$msgid.' to '.$user.' at '.$domain.' with status: '.$status);
554: return $status;
555: }
1.38 www 556:
557: # New routine that respects "forward" and calls old routine
558:
1.58 bowersj2 559: =pod
560:
561: =item * B<user_normal_msg($user, $domain, $subject, $message,
562: $citation, $baseurl, $attachmenturl)>: Sends a message to the
563: $user at $domain, with subject $subject and message $message.
564:
565: =cut
566:
1.38 www 567: sub user_normal_msg {
1.132 www 568: my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
1.159 raeburn 569: $toperm,$sentmessage)=@_;
1.38 www 570: my $status='';
571: my %userenv = &Apache::lonnet::get('environment',['msgforward'],
572: $domain,$user);
573: my $msgforward=$userenv{'msgforward'};
574: if ($msgforward) {
1.171 banghart 575: foreach (split(/\,/,$msgforward)) {
1.172 albertel 576: my ($forwuser,$forwdomain)=split(/\:/,$_);
577: $status.=
1.171 banghart 578: &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
1.172 albertel 579: $citation,$baseurl,$attachmenturl,$toperm,
580: undef,undef,$sentmessage).' ';
1.171 banghart 581: }
1.38 www 582: } else {
1.172 albertel 583: $status=&user_normal_msg_raw($user,$domain,$subject,$message,
584: $citation,$baseurl,$attachmenturl,$toperm,
585: undef,undef,$sentmessage);
1.38 www 586: }
587: return $status;
588: }
589:
1.156 raeburn 590: sub store_sent_mail {
591: my ($msgid,$message) = @_;
1.171 banghart 592: my $status =' '.&Apache::lonnet::critical(
593: 'put:'.$env{'user.domain'}.':'.$env{'user.name'}.
594: ':nohist_email_sent:'.
1.184 www 595: &escape($msgid).'='.
596: &escape($message),$env{'user.home'});
1.156 raeburn 597: return $status;
598: }
1.2 www 599:
1.106 www 600: # =============================================================== Folder suffix
601:
602: sub foldersuffix {
603: my $folder=shift;
604: unless ($folder) { return ''; }
1.184 www 605: return '_'.&escape($folder);
1.106 www 606: }
607:
1.180 albertel 608: 1;
1.1 www 609: __END__
610:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>