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