Annotation of loncom/interface/lonmsg.pm, revision 1.246
1.1 www 1: # The LearningOnline Network with CAPA
1.26 albertel 2: # Routines for messaging
3: #
1.246 ! raeburn 4: # $Id: lonmsg.pm,v 1.245 2020/06/09 21:32:32 raeburn 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:
1.199 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::lonmsg: supports internal messaging
36:
37: =head1 SYNOPSIS
38:
39: lonmsg provides routines for sending messages.
40:
41: Right now, this document will cover just how to send a message, since
42: it is likely you will not need to programmatically read messages,
43: since lonmsg already implements that functionality.
44:
45: The routines used to package messages and unpackage messages are not
46: only used by lonmsg when creating/extracting messages for LON-CAPA's
47: internal messaging system, but also by lonnotify.pm which is available
48: for use by Domain Coordinators to broadcast standard e-mail to specified
49: users in their domain. The XML packaging used in the two cases is very
50: similar. The differences are the use of <recuser>$uname</recuser> and
51: <recdomain>$udom</recdomain> in stored internal messages, compared
52: with <recipient username="$uname:$udom">$email</recipient> in stored
53: Domain Coordinator e-mail for the storage of information about
54: recipients of the message/e-mail.
55:
1.215 jms 56: =head1 SUBROUTINES
1.199 raeburn 57:
1.215 jms 58: =over
59:
60: =pod
61:
62: =item packagemsg()
63:
64: Package
65:
66: =item get_course_context()
67:
68: =item unpackagemsg()
69:
70: Unpack message into a hash
71:
72: =item buildmsgid()
73:
74: Get info out of msgid
75:
76: =item unpackmsgid()
77:
78: =item sendemail()
79:
80: =item sendnotification()
81:
82: Send notification emails
83:
84: =item newmail()
85:
86: Check for email
87:
88: =item author_res_msg()
89:
90: Automated message to the author of a resource
91:
92: =item * B<author_res_msg($filename, $message)>: Sends message $message to the owner
93: of the resource with the URI $filename.
94:
95: =item retrieve_author_res_msg()
96:
97: Retrieve author resource messages
98:
99: =item del_url_author_res_msg()
100:
101: Delete all author messages related to one URL
102:
103: =item clear_author_res_msg()
104:
105: Clear out all author messages in URL path
106:
107: =item all_url_author_res_msg()
108:
109: Return hash with URLs for which there is a resource message
110:
111: =item store_instructor_comment()
112:
113: Add a comment to the User Notes screen
114:
115: =item user_crit_msg_raw()
116:
117: Critical message to a user
118:
119: =item user_crit_msg()
120:
121: New routine that respects "forward" and calls old routine
122:
1.238 raeburn 123: =item * B<user_crit_msg($user, $domain, $subject, $message, $sendback, $nosentstore, $recipid, $attachmenturl, $permresults)>:
1.215 jms 124: Sends a critical message $message to the $user at $domain. If $sendback
125: is true, a receipt will be sent to the current user when $user receives
126: the message.
127:
128: Additionally it will check if the user has a Forwarding address
129: set, and send the message to that address instead
130:
131: returns
132: - in array context a list of results for each message that was sent
133: - in scalar context a space seperated list of results for each
134: message sent
135:
136:
137: =item user_crit_received()
138:
139: Critical message received
140:
141: =item user_normal_msg_raw()
142:
143: Normal communication
144:
145: =item user_normal_msg()
146:
147: New routine that respects "forward" and calls old routine
148:
149: =item * B<user_normal_msg($user, $domain, $subject, $message, $citation,
150: $baseurl, $attachmenturl, $toperm, $sentmessage, $symb, $restitle,
1.238 raeburn 151: $error,$nosentstore,$recipid,$permresults)>:
1.215 jms 152: Sends a message to the $user at $domain, with subject $subject and message $message.
153:
154: Additionally it will check if the user has a Forwarding address
155: set, and send the message to that address instead
156:
157: returns
158: - in array context a list of results for each message that was sent
159: - in scalar context a space seperated list of results for each
160: message sent
161:
162: =item store_sent_mail()
163:
164: =item store_recipients()
165:
166: =item foldersuffix()
167:
168: =item get_user_folders()
169:
170: User-defined folders
171:
172: =item secapply()
173:
174: =item B<decide_receiver($feedurl,$author,$question,$course,$policy,$defaultflag)>:
175:
176: Arguments
177: $feedurl - /res/ url of resource (only need if $author is true)
178: $author,$question,$course,$policy - all true/false parameters
179: if true will attempt to find the addresses of user that should receive
180: this type of feedback (author - feedback to author of resource $feedurl,
181: $question 'Resource Content Questions', $course 'Course Content Question',
182: $policy 'Course Policy')
183: (Additionally it also checks $env for whether the corresponding form.<name>
184: element exists, for ease of use in a html response context)
185:
186: $defaultflag - (internal should be left blank) if true gather addresses
187: that aren't for a section even if I have a section
188: (used for reccursion internally, first we look for
189: addresses for our specific section then we recurse
190: and look for non section addresses)
191:
192: Returns
193: $typestyle - string of html text, describing what addresses were found
194: %to - a hash, which keys are addresses of users to send messages to
195: the keys will look like name:domain
196:
197: =back
1.199 raeburn 198:
199: =cut
200:
1.1 www 201: use strict;
1.140 albertel 202: use Apache::lonnet;
1.242 musolffc 203: use Apache::loncommon;
1.47 albertel 204: use HTML::TokeParser();
1.180 albertel 205: use Apache::lonlocal;
1.226 raeburn 206: use HTML::Entities;
207: use Encode;
1.187 albertel 208: use LONCAPA qw(:DEFAULT :match);
1.180 albertel 209:
210: {
211: my $uniq;
212: sub get_uniq {
213: $uniq++;
214: return $uniq;
215: }
216: }
1.65 www 217:
1.215 jms 218:
1.1 www 219:
1.3 www 220: sub packagemsg {
1.108 www 221: my ($subject,$message,$citation,$baseurl,$attachmenturl,
1.202 raeburn 222: $recuser,$recdomain,$msgid,$type,$crsmsgid,$symb,$error,$recipid)=@_;
1.96 albertel 223: $message =&HTML::Entities::encode($message,'<>&"');
224: $citation=&HTML::Entities::encode($citation,'<>&"');
225: $subject =&HTML::Entities::encode($subject,'<>&"');
1.49 albertel 226: #remove machine specification
1.218 raeburn 227: $baseurl =~ s|^https?://[^/]+/|/|;
1.96 albertel 228: $baseurl =&HTML::Entities::encode($baseurl,'<>&"');
1.51 www 229: #remove machine specification
1.218 raeburn 230: $attachmenturl =~ s|^https?://[^/]+/|/|;
1.96 albertel 231: $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
1.201 raeburn 232: my $course_context = &get_course_context();
1.2 www 233: my $now=time;
1.246 ! raeburn 234: my $ip = &Apache::lonnet::get_requestor_ip();
1.180 albertel 235: my $msgcount = &get_uniq();
1.156 raeburn 236: unless(defined($msgid)) {
1.159 raeburn 237: $msgid = &buildmsgid($now,$subject,$env{'user.name'},$env{'user.domain'},
1.191 raeburn 238: $msgcount,$course_context,$symb,$error,$$);
1.156 raeburn 239: }
1.174 raeburn 240: my $result = '<sendername>'.$env{'user.name'}.'</sendername>'.
1.140 albertel 241: '<senderdomain>'.$env{'user.domain'}.'</senderdomain>'.
1.1 www 242: '<subject>'.$subject.'</subject>'.
1.174 raeburn 243: '<time>'.&Apache::lonlocal::locallocaltime($now).'</time>';
244: if (defined($crsmsgid)) {
245: $result.= '<courseid>'.$course_context.'</courseid>'.
246: '<coursesec>'.$env{'request.course.sec'}.'</coursesec>'.
247: '<msgid>'.$msgid.'</msgid>'.
248: '<coursemsgid>'.$crsmsgid.'</coursemsgid>'.
249: '<message>'.$message.'</message>';
250: return ($msgid,$result);
251: }
252: $result .= '<servername>'.$ENV{'SERVER_NAME'}.'</servername>'.
1.1 www 253: '<host>'.$ENV{'HTTP_HOST'}.'</host>'.
1.246 ! raeburn 254: '<client>'.$ip.'</client>'.
1.140 albertel 255: '<browsertype>'.$env{'browser.type'}.'</browsertype>'.
256: '<browseros>'.$env{'browser.os'}.'</browseros>'.
257: '<browserversion>'.$env{'browser.version'}.'</browserversion>'.
258: '<browsermathml>'.$env{'browser.mathml'}.'</browsermathml>'.
1.1 www 259: '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
1.158 raeburn 260: '<courseid>'.$course_context.'</courseid>'.
1.140 albertel 261: '<coursesec>'.$env{'request.course.sec'}.'</coursesec>'.
262: '<role>'.$env{'request.role'}.'</role>'.
263: '<resource>'.$env{'request.filename'}.'</resource>'.
1.156 raeburn 264: '<msgid>'.$msgid.'</msgid>';
1.214 raeburn 265: if (defined($env{'form.group'})) {
266: $result .= '<group>'.$env{'form.group'}.'</group>';
267: }
1.156 raeburn 268: if (ref($recuser) eq 'ARRAY') {
269: for (my $i=0; $i<@{$recuser}; $i++) {
1.162 raeburn 270: if ($type eq 'dcmail') {
271: my ($username,$email) = split(/:/,$$recuser[$i]);
1.184 www 272: $username = &unescape($username);
273: $email = &unescape($email);
1.162 raeburn 274: $username = &HTML::Entities::encode($username,'<>&"');
275: $email = &HTML::Entities::encode($email,'<>&"');
276: $result .= '<recipient username="'.$username.'">'.
277: $email.'</recipient>';
278: } else {
279: $result .= '<recuser>'.$$recuser[$i].'</recuser>'.
280: '<recdomain>'.$$recdomain[$i].'</recdomain>';
281: }
1.156 raeburn 282: }
283: } else {
284: $result .= '<recuser>'.$recuser.'</recuser>'.
285: '<recdomain>'.$recdomain.'</recdomain>';
286: }
287: $result .= '<message>'.$message.'</message>';
1.49 albertel 288: if (defined($citation)) {
289: $result.='<citation>'.$citation.'</citation>';
290: }
291: if (defined($baseurl)) {
292: $result.= '<baseurl>'.$baseurl.'</baseurl>';
293: }
1.51 www 294: if (defined($attachmenturl)) {
1.52 www 295: $result.= '<attachmenturl>'.$attachmenturl.'</attachmenturl>';
1.51 www 296: }
1.191 raeburn 297: if (defined($symb)) {
298: $result.= '<symb>'.$symb.'</symb>';
1.201 raeburn 299: if ($course_context ne '') {
1.191 raeburn 300: if ($course_context eq $env{'request.course.id'}) {
301: my $resource_title = &Apache::lonnet::gettitle($symb);
302: if (defined($resource_title)) {
303: $result .= '<resource_title>'.$resource_title.'</resource_title>';
304: }
305: }
306: }
307: }
1.202 raeburn 308: if (defined($recipid)) {
309: $result.= '<recipid>'.$recipid.'</recipid>';
310: }
1.204 raeburn 311: if ($env{'form.can_reply'} eq 'N') {
312: $result .= '<noreplies>1</noreplies>';
313: }
314: if ($env{'form.reply_to_addr'}) {
315: my ($replytoname,$replytodom) = split(/:/,$env{'form.reply_to_addr'});
316: if (!($replytoname eq $env{'user.name'} && $replytodom eq $env{'user.domain'})) {
317: if (&Apache::lonnet::homeserver($replytoname,$replytodom) ne 'no_host') {
318: $result .= '<replytoaddr>'.$env{'form.reply_to_addr'}.'</replytoaddr>';
319: }
320: }
321: }
1.191 raeburn 322: return ($msgid,$result);
1.1 www 323: }
324:
1.201 raeburn 325: sub get_course_context {
326: my $course_context;
1.212 raeburn 327: my $msgkey;
1.201 raeburn 328: if (defined($env{'form.replyid'})) {
1.212 raeburn 329: $msgkey = $env{'form.replyid'};
330: } elsif (defined($env{'form.forwid'})) {
331: $msgkey = $env{'form.forwid'}
332: } elsif (defined($env{'form.multiforwid'})) {
333: $msgkey = $env{'form.multiforwid'};
334: }
335: if ($msgkey ne '') {
1.201 raeburn 336: my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
1.212 raeburn 337: split(/\:/,&unescape($msgkey));
1.201 raeburn 338: $course_context = $origcid;
339: }
340: foreach my $key (keys(%env)) {
341: if ($key=~/^form\.(rep)?rec\_(.*)$/) {
342: my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =
343: split(/\:/,&unescape($2));
344: $course_context = $origcid;
345: last;
346: }
347: }
348: if ($course_context eq '') {
349: $course_context = $env{'request.course.id'};
350: }
351: return $course_context;
352: }
353:
1.2 www 354:
1.3 www 355: sub unpackagemsg {
1.212 raeburn 356: my ($message,$notoken,$noattachmentlink)=@_;
1.2 www 357: my %content=();
358: my $parser=HTML::TokeParser->new(\$message);
359: my $token;
360: while ($token=$parser->get_token) {
361: if ($token->[0] eq 'S') {
362: my $entry=$token->[1];
363: my $value=$parser->get_text('/'.$entry);
1.156 raeburn 364: if (($entry eq 'recuser') || ($entry eq 'recdomain')) {
365: push(@{$content{$entry}},$value);
1.162 raeburn 366: } elsif ($entry eq 'recipient') {
367: my $username = $token->[2]{'username'};
368: $username = &HTML::Entities::decode($username,'<>&"');
369: $content{$entry}{$username} = $value;
1.156 raeburn 370: } else {
371: $content{$entry}=$value;
372: }
1.2 www 373: }
374: }
1.168 albertel 375: if (!exists($content{'recuser'})) { $content{'recuser'} = []; }
1.212 raeburn 376: if (($content{'attachmenturl'}) && (!$noattachmentlink)) {
1.100 albertel 377: my ($fname)=($content{'attachmenturl'}=~m|/([^/]+)$|);
1.52 www 378: if ($notoken) {
1.100 albertel 379: $content{'message'}.='<p>'.&mt('Attachment').': <tt>'.$fname.'</tt>';
1.52 www 380: } else {
1.99 albertel 381: &Apache::lonnet::allowuploaded('/adm/msg',
382: $content{'attachmenturl'});
383: $content{'message'}.='<p>'.&mt('Attachment').
384: ': <a href="'.$content{'attachmenturl'}.'"><tt>'.
1.100 albertel 385: $fname.'</tt></a>';
1.52 www 386: }
387: }
1.2 www 388: return %content;
389: }
390:
1.6 www 391:
1.159 raeburn 392: sub buildmsgid {
1.191 raeburn 393: my ($now,$subject,$uname,$udom,$msgcount,$course_context,$symb,$error,$pid) = @_;
1.184 www 394: $subject=&escape($subject);
1.192 raeburn 395: $symb = &escape($symb);
1.184 www 396: return(&escape($now.':'.$subject.':'.$uname.':'.
1.191 raeburn 397: $udom.':'.$msgcount.':'.$course_context.':'.$pid.':'.$symb.':'.$error));
1.159 raeburn 398: }
399:
1.6 www 400: sub unpackmsgid {
1.243 raeburn 401: my ($msgid,$folder,$skipstatus,$status_cache,$onlycid)=@_;
1.184 www 402: $msgid=&unescape($msgid);
1.167 raeburn 403: my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid,
1.191 raeburn 404: $processid,$symb,$error) = split(/\:/,&unescape($msgid));
1.243 raeburn 405: if (!defined($processid)) { $fromcid = ''; }
406: if (($onlycid) && ($onlycid ne $fromcid)) {
407: return ($sendtime,'',$fromname,$fromdomain,'',$fromcid,'',$error);
408: }
1.184 www 409: $shortsubj = &unescape($shortsubj);
1.182 albertel 410: $shortsubj = &HTML::Entities::decode($shortsubj);
1.192 raeburn 411: $symb = &unescape($symb);
1.164 raeburn 412: my %status=();
413: unless ($skipstatus) {
1.169 albertel 414: if (ref($status_cache)) {
415: $status{$msgid} = $status_cache->{$msgid};
416: } else {
417: my $suffix=&foldersuffix($folder);
418: %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
419: }
420: if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
1.164 raeburn 421: unless ($status{$msgid}) { $status{$msgid}='new'; }
422: }
1.191 raeburn 423: return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid,$symb,$error);
1.141 raeburn 424: }
1.6 www 425:
1.53 www 426:
427: sub sendemail {
1.242 musolffc 428: my ($to,$subject,$body,$to_uname,$to_udom,$user_lh,$attachmenturl)=@_;
1.186 www 429: my $senderaddress='';
1.220 raeburn 430: my $replytoaddress='';
1.238 raeburn 431: my $msgsent;
1.220 raeburn 432: if ($env{'form.can_reply'} eq 'N') {
433: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
434: my $hostname = &Apache::lonnet::hostname($lonhost);
435: $replytoaddress = 'do-not-reply@'.$hostname;
436: } else {
437: my %senderemails;
438: my $have_sender;
439: if ($env{'form.reply_to_addr'}) {
440: my ($replytoname,$replytodom) = split(/:/,$env{'form.reply_to_addr'});
441: if (!($replytoname eq $env{'user.name'} && $replytodom eq $env{'user.domain'})) {
442: if (&Apache::lonnet::homeserver($replytoname,$replytodom) ne 'no_host') {
443: %senderemails =
444: &Apache::loncommon::getemails($replytoname,$replytodom);
445: $have_sender = 1;
446: }
447: }
448: }
449: if (!$have_sender) {
450: %senderemails=&Apache::loncommon::getemails();
451: }
452: foreach my $type ('permanentemail','critnotification','notification') {
453: if ($senderemails{$type}) {
454: ($senderaddress) = split(/,/,$senderemails{$type});
455: last if ($senderaddress);
456: }
457: }
1.186 www 458: }
1.53 www 459: $body=
1.217 schafran 460: "*** ".&mt_user($user_lh,'This is an automatic e-mail generated by the LON-CAPA system.')."\n".
461: "*** ".($senderaddress?&mt_user($user_lh,'You can reply to this e-mail'):&mt_user($user_lh,'Please do not reply to this address.')."\n*** ".
1.220 raeburn 462: &mt_user($user_lh,'A reply will not be received by the recipient!'))."\n\n".$body;
1.225 jms 463:
1.242 musolffc 464: $attachmenturl = &Apache::lonnet::filelocation("",$attachmenturl);
465: my $filesize = (stat($attachmenturl))[7];
466: if ($filesize > 1048576) {
467: # Don't send if it exceeds 1 MB.
468: print '<p><span class="LC_error">'
469: .&mt('Email not sent. Attachment exceeds permitted length.')
470: .'</span><br /></p>';
471: } else {
472: # Otherwise build and send the email
473: $subject = '[LON-CAPA] '.$subject;
1.245 raeburn 474: &Apache::loncommon::mime_email($senderaddress,$replytoaddress,$to,
475: $subject,$body,'','',$attachmenturl,'','');
1.238 raeburn 476: $msgsent = 1;
1.68 www 477: }
1.238 raeburn 478: return $msgsent;
1.53 www 479: }
480:
481: # ==================================================== Send notification emails
482:
483: sub sendnotification {
1.242 musolffc 484: my ($to,$touname,$toudom,$subj,$crit,$text,$msgid,$attachmenturl)=@_;
1.140 albertel 485: my $sender=$env{'environment.firstname'}.' '.$env{'environment.lastname'};
1.131 www 486: unless ($sender=~/\w/) {
1.208 raeburn 487: $sender=$env{'user.name'}.':'.$env{'user.domain'};
1.131 www 488: }
1.53 www 489: my $critical=($crit?' critical':'');
1.238 raeburn 490: my $numsent = 0;
1.208 raeburn 491:
1.131 www 492: $text=~s/\<\;/\</gs;
493: $text=~s/\>\;/\>/gs;
1.218 raeburn 494: my $homeserver = &Apache::lonnet::homeserver($touname,$toudom);
1.244 raeburn 495: my $hostname = &Apache::lonnet::hostname($homeserver);
1.218 raeburn 496: my $protocol = $Apache::lonnet::protocol{$homeserver};
497: $protocol = 'http' if ($protocol ne 'https');
1.244 raeburn 498: my $url = $protocol.'://'.$hostname.
1.226 raeburn 499: '/adm/email?username='.$touname.'&domain='.$toudom.
500: '&display='.&escape($msgid);
1.194 raeburn 501: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,
502: $symb,$error) = &Apache::lonmsg::unpackmsgid($msgid);
1.208 raeburn 503: my ($coursetext,$body,$bodybegin,$bodysubj,$bodyend);
1.222 raeburn 504: my $user_lh = &Apache::loncommon::user_lang($touname,$toudom,$fromcid);
1.194 raeburn 505: if ($fromcid ne '') {
1.213 raeburn 506: $coursetext = "\n".&mt_user($user_lh,'Course').': ';
1.194 raeburn 507: if ($env{'course.'.$fromcid.'.description'} ne '') {
508: $coursetext .= $env{'course.'.$fromcid.'.description'};
509: } else {
510: my %coursehash = &Apache::lonnet::coursedescription($fromcid,);
511: if ($coursehash{'description'} ne '') {
512: $coursetext .= $coursehash{'description'};
513: }
514: }
515: $coursetext .= "\n\n";
516: }
1.206 raeburn 517: my @recipients = split(/,/,$to);
1.208 raeburn 518: $bodybegin = $coursetext.
1.213 raeburn 519: &mt_user($user_lh,
520: 'You received a'.$critical.' message from [_1] in LON-CAPA.',$sender).' ';
521: $bodysubj = &mt_user($user_lh,'The subject is
1.53 www 522:
1.195 raeburn 523: [_1]
1.53 www 524:
1.195 raeburn 525: ',$subj)."\n".
1.213 raeburn 526: '=== '.&mt_user($user_lh,'Excerpt')." ============================================================
1.206 raeburn 527: ";
528: $bodyend = "
1.131 www 529: ========================================================================
530:
1.213 raeburn 531: ".&mt_user($user_lh,'Use
1.53 www 532:
1.195 raeburn 533: [_1]
1.53 www 534:
1.195 raeburn 535: to access the full message.',$url);
1.206 raeburn 536: my %userenv = &Apache::lonnet::get('environment',['notifywithhtml'],$toudom,$touname);
1.235 bisitz 537: my $subject = &mt_user($user_lh,"'New'$critical message from [_1]",$sender);
1.232 raeburn 538: unless ($subj eq '') {
539: $subject = $subj;
540: }
1.208 raeburn 541:
542: my ($blocked,$blocktext);
543: if (!$crit) {
544: my %setters;
545: my ($startblock,$endblock) =
546: &Apache::loncommon::blockcheck(\%setters,'com',$touname,$toudom);
547: if ($startblock && $endblock) {
548: $blocked = 1;
1.209 albertel 549: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
550: my $showend = &Apache::lonlocal::locallocaltime($endblock);
1.213 raeburn 551: $blocktext = &mt_user($user_lh,'LON-CAPA messages sent to you between [_1] and [_2] will be inaccessible until the end of this time period, because you are a student in a course with an active communications block.',$showstart,$showend);
1.208 raeburn 552: }
553: }
1.206 raeburn 554: if ($userenv{'notifywithhtml'} ne '') {
555: my @htmlexcerpt = split(/,/,$userenv{'notifywithhtml'});
1.226 raeburn 556: my $htmlfree = &make_htmlfree($text);
1.206 raeburn 557: foreach my $addr (@recipients) {
1.208 raeburn 558: if ($blocked) {
559: $body = $bodybegin."\n".$blocktext."\n".$bodyend;
560: } else {
1.226 raeburn 561: my $sendtext;
1.208 raeburn 562: if (!grep/^\Q$addr\E/,@htmlexcerpt) {
1.227 raeburn 563: $sendtext = $htmlfree;
1.226 raeburn 564: } else {
565: $sendtext = $text;
1.208 raeburn 566: }
567: $body = $bodybegin.$bodysubj.$sendtext.$bodyend;
1.206 raeburn 568: }
1.242 musolffc 569: if (&sendemail($addr,$subject,$body,$touname,$toudom,$user_lh,$attachmenturl)) {
1.238 raeburn 570: $numsent ++;
571: }
1.206 raeburn 572: }
573: } else {
1.208 raeburn 574: if ($blocked) {
575: $body = $bodybegin."\n".$blocktext."\n".$bodyend;
576: } else {
1.226 raeburn 577: my $htmlfree = &make_htmlfree($text);
578: $body = $bodybegin.$bodysubj.$htmlfree.$bodyend;
1.208 raeburn 579: }
1.242 musolffc 580: if (&sendemail($to,$subject,$body,$touname,$toudom,$user_lh,$attachmenturl)) {
1.238 raeburn 581: $numsent ++;
582: }
1.206 raeburn 583: }
1.238 raeburn 584: return $numsent;
1.53 www 585: }
1.215 jms 586:
1.226 raeburn 587: sub make_htmlfree {
588: my ($text) = @_;
589: $text =~ s/\<\/*[^\>]+\>//gs;
590: $text = &HTML::Entities::decode($text);
591: $text = &Encode::encode('utf8',$text);
592: return $text;
593: }
594:
1.223 kaisler 595: sub mynewmail{
596: &newmail();
1.231 raeburn 597: return $env{'user.mailcheck.lastnewmessagetime'} > $env{'user.mailcheck.lastvisit'};
1.223 kaisler 598: }
599:
1.40 www 600:
601: sub newmail {
1.140 albertel 602: if ((time-$env{'user.mailcheck.time'})>300) {
1.40 www 603: my %what=&Apache::lonnet::get('email_status',['recnewemail']);
1.211 raeburn 604: &Apache::lonnet::appenv({'user.mailcheck.time'=>time});
1.231 raeburn 605: &Apache::lonnet::appenv({'user.mailcheck.lastnewmessagetime'=> $what{'recnewemail'}});
1.40 www 606: if ($what{'recnewemail'}>0) { return 1; }
607: }
608: return 0;
609: }
610:
1.1 www 611:
1.58 bowersj2 612:
1.1 www 613: sub author_res_msg {
614: my ($filename,$message)=@_;
1.2 www 615: unless ($message) { return 'empty'; }
1.1 www 616: $filename=&Apache::lonnet::declutter($filename);
1.72 www 617: my ($domain,$author,@dummy)=split(/\//,$filename);
1.1 www 618: my $homeserver=&Apache::lonnet::homeserver($author,$domain);
619: if ($homeserver ne 'no_host') {
620: my $id=unpack("%32C*",$message);
1.181 albertel 621: $message .= " <p>This error occurred on machine ".
622: $Apache::lonnet::perlvar{'lonHostID'}."</p>";
1.2 www 623: my $msgid;
1.72 www 624: ($msgid,$message)=&packagemsg($filename,$message);
1.3 www 625: return &Apache::lonnet::reply('put:'.$domain.':'.$author.
1.72 www 626: ':nohist_res_msgs:'.
1.184 www 627: &escape($filename.'_'.$id).'='.
628: &escape($message),$homeserver);
1.1 www 629: }
1.2 www 630: return 'no_host';
1.73 www 631: }
632:
1.215 jms 633:
1.73 www 634:
635: sub retrieve_author_res_msg {
1.75 www 636: my $url=shift;
1.73 www 637: $url=&Apache::lonnet::declutter($url);
1.187 albertel 638: my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//);
1.76 www 639: my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$domain,$author);
1.73 www 640: my $msgs='';
1.239 raeburn 641: foreach my $msg (keys(%errormsgs)) {
642: if ($msg =~ /^\Q$url\E\_\d+$/) {
643: my %content=&unpackagemsg($errormsgs{$msg});
1.74 www 644: $msgs.='<p><img src="/adm/lonMisc/bomb.gif" /><b>'.
645: $content{'time'}.'</b>: '.$content{'message'}.
646: '<br /></p>';
1.73 www 647: }
648: }
649: return $msgs;
650: }
651:
652:
1.215 jms 653:
654:
1.73 www 655:
656: sub del_url_author_res_msg {
1.75 www 657: my $url=shift;
1.73 www 658: $url=&Apache::lonnet::declutter($url);
1.187 albertel 659: my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//);
1.77 www 660: my @delmsgs=();
1.239 raeburn 661: foreach my $msg (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
662: if ($msg =~ /^\Q$url\E\_\d+$/) {
663: push (@delmsgs,$msg);
1.77 www 664: }
665: }
666: return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
1.73 www 667: }
1.215 jms 668:
1.73 www 669:
1.152 www 670: sub clear_author_res_msg {
671: my $url=shift;
672: $url=&Apache::lonnet::declutter($url);
1.187 albertel 673: my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//);
1.152 www 674: my @delmsgs=();
1.239 raeburn 675: foreach my $msg (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
676: if ($msg =~ /^\Q$url\E/) {
677: push (@delmsgs,$msg);
1.152 www 678: }
679: }
680: return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
681: }
1.215 jms 682:
683:
1.73 www 684:
685: sub all_url_author_res_msg {
686: my ($author,$domain)=@_;
1.75 www 687: my %returnhash=();
1.239 raeburn 688: foreach my $msg (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
689: $msg =~ /^(.+)\_\d+/;
1.75 www 690: $returnhash{$1}=1;
691: }
692: return %returnhash;
1.1 www 693: }
694:
1.185 albertel 695:
696: sub store_instructor_comment {
697: my ($msg,$uname,$udom) = @_;
698: my $cid = $env{'request.course.id'};
699: my $cnum = $env{'course.'.$cid.'.num'};
700: my $cdom = $env{'course.'.$cid.'.domain'};
701: my $subject= &mt('Record').' ['.$uname.':'.$udom.']';
702: my $result = &user_normal_msg_raw($cnum,$cdom,$subject,$msg);
1.201 raeburn 703: if ($result eq 'ok' || $result eq 'con_delayed') {
704:
705: }
1.185 albertel 706: return $result;
707: }
708:
1.1 www 709:
1.38 www 710: sub user_crit_msg_raw {
1.201 raeburn 711: my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
1.238 raeburn 712: $nosentstore,$recipid,$attachmenturl,$permresults)=@_;
1.2 www 713: # Check if allowed missing
1.190 raeburn 714: my ($status,$packed_message);
1.2 www 715: my $msgid='undefined';
716: unless (($message)&&($user)&&($domain)) { $status='empty'; };
1.131 www 717: my $text=$message;
1.2 www 718: my $homeserver=&Apache::lonnet::homeserver($user,$domain);
719: if ($homeserver ne 'no_host') {
1.202 raeburn 720: ($msgid,$packed_message)=&packagemsg($subject,$message,undef,undef,
1.212 raeburn 721: $attachmenturl,undef,undef,undef,undef,undef,
722: undef,undef,$recipid);
1.190 raeburn 723: if ($sendback) { $packed_message.='<sendback>true</sendback>'; }
1.210 albertel 724: $status=&Apache::lonnet::cput('critical', {$msgid => $packed_message},
725: $domain,$user);
1.159 raeburn 726: if (defined($sentmessage)) {
1.190 raeburn 727: $$sentmessage = $packed_message;
1.159 raeburn 728: }
1.201 raeburn 729: if (!$nosentstore) {
1.193 raeburn 730: (undef,my $packed_message_no_citation) =
1.212 raeburn 731: &packagemsg($subject,$message,undef,undef,$attachmenturl,$user,
732: $domain,$msgid);
1.193 raeburn 733: if ($status eq 'ok' || $status eq 'con_delayed') {
734: &store_sent_mail($msgid,$packed_message_no_citation);
735: }
736: }
1.2 www 737: } else {
738: $status='no_host';
739: }
1.190 raeburn 740:
1.53 www 741: # Notifications
1.186 www 742: my %userenv = &Apache::loncommon::getemails($user,$domain);
1.238 raeburn 743: my $critnotify = $userenv{'critnotification'};
744: my $permemail = $userenv{'permanentemail'};
745: my $numcrit = 0;
746: my $numperm = 0;
747: my $permlogmsgstatus;
748: if ($critnotify) {
1.242 musolffc 749: $numcrit = &sendnotification($critnotify,$user,$domain,$subject,1,$text,$msgid,$attachmenturl);
1.238 raeburn 750: }
751: if ($toperm && $permemail) {
752: if ($critnotify && $numcrit) {
753: if (grep(/^\Q$permemail\E/,split(/,/,$critnotify))) {
754: $numperm = 1;
755: }
756: }
757: unless ($numperm) {
1.242 musolffc 758: $numperm = &sendnotification($permemail,$user,$domain,$subject,1,$text,$msgid,$attachmenturl);
1.238 raeburn 759: }
760: }
761: if ($toperm) {
762: $permlogmsgstatus = '. Perm. email log status '.
763: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},$env{'user.home'},
764: "Perm. e-mail count $numperm for $user at $domain");
765: if (ref($permresults) eq 'HASH') {
766: $permresults->{"$user:$domain"} = $numperm;
767: }
1.132 www 768: }
1.53 www 769: # Log this
1.2 www 770: &Apache::lonnet::logthis(
1.238 raeburn 771: 'Sending critical '.$msgid.
1.2 www 772: ', log status: '.
1.140 albertel 773: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
774: $env{'user.home'},
1.238 raeburn 775: 'Sending critical '.$msgid.' to '.$user.' at '.$domain.' with status '
776: .$status).$permlogmsgstatus);
1.2 www 777: return $status;
778: }
779:
1.38 www 780:
1.58 bowersj2 781:
1.38 www 782: sub user_crit_msg {
1.201 raeburn 783: my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
1.238 raeburn 784: $nosentstore,$recipid,$attachmenturl,$permresults)=@_;
1.183 albertel 785: my @status;
1.38 www 786: my %userenv = &Apache::lonnet::get('environment',['msgforward'],
787: $domain,$user);
788: my $msgforward=$userenv{'msgforward'};
789: if ($msgforward) {
1.183 albertel 790: foreach my $addr (split(/\,/,$msgforward)) {
791: my ($forwuser,$forwdomain)=split(/\:/,$addr);
792: push(@status,
793: &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
1.202 raeburn 794: $sendback,$toperm,$sentmessage,$nosentstore,
1.238 raeburn 795: $recipid,$attachmenturl,$permresults));
1.38 www 796: }
797: } else {
1.183 albertel 798: push(@status,
799: &user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
1.212 raeburn 800: $toperm,$sentmessage,$nosentstore,$recipid,
1.238 raeburn 801: $attachmenturl,$permresults));
1.38 www 802: }
1.183 albertel 803: if (wantarray) {
804: return @status;
805: }
806: return join(' ',@status);
1.38 www 807: }
808:
1.2 www 809:
810: sub user_crit_received {
1.12 www 811: my $msgid=shift;
812: my %message=&Apache::lonnet::get('critical',[$msgid]);
1.52 www 813: my %contents=&unpackagemsg($message{$msgid},1);
1.204 raeburn 814: my $destname = $contents{'sendername'};
815: my $destdom = $contents{'senderdomain'};
816: if ($contents{'replytoaddr'}) {
817: my ($repname,$repdom) = split(/:/,$contents{'replytoaddr'});
818: if (&Apache::lonnet::homeserver($repname,$repdom) ne 'no_host') {
819: $destname = $repname;
820: $destdom = $repdom;
821: }
822: }
1.24 www 823: my $status='rec: '.($contents{'sendback'}?
1.204 raeburn 824: &user_normal_msg($destname,$destdom,&mt('Receipt').': '.$env{'user.name'}.
825: ' '.&mt('at').' '.$env{'user.domain'}.', '.
826: $contents{'subject'},&mt('User').' '.$env{'user.name'}.
827: ' '.&mt('at').' '.$env{'user.domain'}.
828: ' acknowledged receipt of message'."\n".' "'.
829: $contents{'subject'}.'"'."\n".&mt('dated').' '.
830: $contents{'time'}.".\n"
831: ):'no msg req');
1.5 www 832: $status.=' trans: '.
1.12 www 833: &Apache::lonnet::put(
834: 'nohist_email',{$contents{'msgid'} => $message{$msgid}});
1.5 www 835: $status.=' del: '.
1.9 albertel 836: &Apache::lonnet::del('critical',[$contents{'msgid'}]);
1.140 albertel 837: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
838: $env{'user.home'},'Received critical message '.
1.5 www 839: $contents{'msgid'}.
840: ', '.$status);
1.12 www 841: return $status;
1.2 www 842: }
843:
1.215 jms 844:
845:
1.2 www 846:
1.38 www 847: sub user_normal_msg_raw {
1.132 www 848: my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
1.191 raeburn 849: $toperm,$currid,$newid,$sentmessage,$crsmsgid,$symb,$restitle,
1.238 raeburn 850: $error,$nosentstore,$recipid,$permresults)=@_;
1.2 www 851: # Check if allowed missing
1.173 albertel 852: my ($status,$packed_message);
1.2 www 853: my $msgid='undefined';
1.131 www 854: my $text=$message;
1.2 www 855: unless (($message)&&($user)&&($domain)) { $status='empty'; };
856: my $homeserver=&Apache::lonnet::homeserver($user,$domain);
857: if ($homeserver ne 'no_host') {
1.173 albertel 858: ($msgid,$packed_message)=
859: &packagemsg($subject,$message,$citation,$baseurl,
1.174 raeburn 860: $attachmenturl,$user,$domain,$currid,
1.202 raeburn 861: undef,$crsmsgid,$symb,$error,$recipid);
1.174 raeburn 862:
1.108 www 863: # Store in user folder
1.210 albertel 864: $status=
865: &Apache::lonnet::cput('nohist_email',{$msgid => $packed_message},
866: $domain,$user);
1.108 www 867: # Save new message received time
1.40 www 868: &Apache::lonnet::put
869: ('email_status',{'recnewemail'=>time},$domain,$user);
1.201 raeburn 870: # Into sent-mail folder if sent mail storage required
871: if (!$nosentstore) {
1.190 raeburn 872: (undef,my $packed_message_no_citation) =
873: &packagemsg($subject,$message,undef,$baseurl,$attachmenturl,
1.191 raeburn 874: $user,$domain,$currid,undef,$crsmsgid,$symb,$error);
1.193 raeburn 875: if ($status eq 'ok' || $status eq 'con_delayed') {
876: &store_sent_mail($msgid,$packed_message_no_citation);
877: }
1.156 raeburn 878: }
1.201 raeburn 879: if (ref($newid) eq 'SCALAR') {
1.196 www 880: $$newid = $msgid;
881: }
1.201 raeburn 882: if (ref($sentmessage) eq 'SCALAR') {
1.196 www 883: $$sentmessage = $packed_message;
884: }
885: # Notifications
1.206 raeburn 886: my %userenv = &Apache::loncommon::getemails($user,$domain);
1.238 raeburn 887: my $notify = $userenv{'notification'};
888: my $permemail = $userenv{'permanentemail'};
889: my $numnotify = 0;
890: my $numperm = 0;
891: my $permlogmsgstatus;
892: if ($notify) {
1.242 musolffc 893: $numnotify = &sendnotification($notify,$user,$domain,$subject,0,$text,$msgid,$attachmenturl);
1.238 raeburn 894: }
895: if ($toperm && $permemail) {
896: if ($notify && $numnotify) {
897: if (grep(/^\Q$permemail\E/,split(/,/,$notify))) {
898: $numperm = 1;
899: }
900: }
901: unless ($numperm) {
902: $numperm = &sendnotification($permemail,$user,$domain,$subject,0,
1.242 musolffc 903: $text,$msgid,$attachmenturl);
1.238 raeburn 904: }
1.196 www 905: }
1.238 raeburn 906: if ($toperm) {
907: $permlogmsgstatus = '. Perm. email log status '.
908: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},$env{'user.home'},
909: "Perm. e-mail count $numperm for $user at $domain");
910: if (ref($permresults) eq 'HASH') {
911: $permresults->{"$user:$domain"} = $numperm;
1.214 raeburn 912: }
1.196 www 913: }
914: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
915: $env{'user.home'},
1.238 raeburn 916: 'Sending '.$msgid.' to '.$user.' at '.$domain.' with status '.$status.
917: $permlogmsgstatus);
1.196 www 918: } else {
1.2 www 919: $status='no_host';
1.196 www 920: }
1.2 www 921: return $status;
922: }
1.38 www 923:
924: sub user_normal_msg {
1.132 www 925: my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
1.238 raeburn 926: $toperm,$sentmessage,$symb,$restitle,$error,$nosentstore,$recipid,
927: $permresults)=@_;
1.199 raeburn 928: my @status;
1.38 www 929: my %userenv = &Apache::lonnet::get('environment',['msgforward'],
930: $domain,$user);
931: my $msgforward=$userenv{'msgforward'};
932: if ($msgforward) {
1.239 raeburn 933: foreach my $fwd (split(/\,/,$msgforward)) {
934: my ($forwuser,$forwdomain)=split(/\:/,$fwd);
1.199 raeburn 935: push(@status,
1.171 banghart 936: &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
1.172 albertel 937: $citation,$baseurl,$attachmenturl,$toperm,
1.201 raeburn 938: undef,undef,$sentmessage,undef,$symb,
1.238 raeburn 939: $restitle,$error,$nosentstore,$recipid,$permresults));
1.171 banghart 940: }
1.191 raeburn 941: } else {
1.199 raeburn 942: push(@status,&user_normal_msg_raw($user,$domain,$subject,$message,
1.172 albertel 943: $citation,$baseurl,$attachmenturl,$toperm,
1.201 raeburn 944: undef,undef,$sentmessage,undef,$symb,
1.238 raeburn 945: $restitle,$error,$nosentstore,$recipid,$permresults));
1.199 raeburn 946: }
947: if (wantarray) {
948: return @status;
1.38 www 949: }
1.199 raeburn 950: return join(' ',@status);
1.38 www 951: }
952:
1.201 raeburn 953: sub process_sent_mail {
1.236 raeburn 954: my ($msgsubj,$subj_prefix,$numsent,$stamp,$msgname,$msgdom,$msgcount,
955: $context,$pid,$savemsg,$recusers,$recudoms,$baseurl,$attachmenturl,
956: $symb,$error,$senderuname,$senderdom,$recipid) = @_;
1.201 raeburn 957: my $sentsubj;
958: if ($numsent > 1) {
959: $sentsubj = $subj_prefix.' ('.$numsent.' sent) '.$msgsubj;
1.205 raeburn 960: } else {
961: if ($subj_prefix) {
962: $sentsubj = $subj_prefix.' ';
963: }
964: $sentsubj .= $msgsubj;
1.201 raeburn 965: }
966: $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
967: my $sentmsgid =
968: &buildmsgid($stamp,$sentsubj,$msgname,$msgdom,$msgcount,$context,$pid);
969: (undef,my $sentmessage) =
970: &packagemsg($msgsubj,$savemsg,undef,$baseurl,$attachmenturl,$recusers,
1.214 raeburn 971: $recudoms,$sentmsgid,undef,undef,$symb,$error,$recipid);
1.201 raeburn 972: my $status = &store_sent_mail($sentmsgid,$sentmessage,$senderuname,
1.210 albertel 973: $senderdom);
1.201 raeburn 974: return $status;
975: }
976:
1.156 raeburn 977: sub store_sent_mail {
1.210 albertel 978: my ($msgid,$message,$senderuname,$senderdom) = @_;
1.201 raeburn 979: if ($senderuname eq '') {
980: $senderuname = $env{'user.name'};
981: }
982: if ($senderdom eq '') {
983: $senderdom = $env{'user.domain'};
984: }
1.210 albertel 985: my $status =' '.&Apache::lonnet::cput('nohist_email_sent',
986: {$msgid => $message},
987: $senderdom,$senderuname);
1.156 raeburn 988: return $status;
989: }
1.2 www 990:
1.202 raeburn 991: sub store_recipients {
992: my ($subject,$sendername,$senderdom,$reciphash) = @_;
993: my $context = &get_course_context();
1.203 albertel 994: my $now = time();
1.202 raeburn 995: my $msgcount = &get_uniq();
996: my $recipid =
997: &buildmsgid($now,$subject,$sendername,$senderdom,$msgcount,$context,$$);
998: my %recipinfo = (
999: $recipid => $reciphash,
1000: );
1001: my $status = &Apache::lonnet::put('nohist_emailrecip',\%recipinfo,
1002: $senderdom,$sendername);
1003: if ($status eq 'ok') {
1004: return ($recipid,$status);
1005: } else {
1006: return (undef,$status);
1007: }
1008: }
1009:
1.106 www 1010:
1011: sub foldersuffix {
1012: my $folder=shift;
1013: unless ($folder) { return ''; }
1.189 raeburn 1014: my $suffix;
1015: my %folderhash = &get_user_folders($folder);
1016: if (ref($folderhash{$folder}) eq 'HASH') {
1017: $suffix = '_'.&escape($folderhash{$folder}{'id'});
1018: } else {
1019: $suffix = '_'.&escape($folder);
1020: }
1021: return $suffix;
1022: }
1023:
1024:
1025: sub get_user_folders {
1026: my ($folder) = @_;
1027: my %userfolders =
1028: &Apache::lonnet::dump('email_folders',undef,undef,$folder);
1029: my $lock = "\0".'lock_counter'; # locks db while counter incremented
1030: my $counter = "\0".'idcount'; # used in suffix for email db files
1031: if (defined($userfolders{$lock})) {
1032: delete($userfolders{$lock});
1033: }
1034: if (defined($userfolders{$counter})) {
1035: delete($userfolders{$counter});
1036: }
1037: return %userfolders;
1.106 www 1038: }
1039:
1.197 albertel 1040: sub secapply {
1041: my $rec=shift;
1042: my $defaultflag=shift;
1043: $rec=~s/\s+//g;
1.229 raeburn 1044: unless ($rec =~ /\:/) {
1045: $rec=~s/\@/\:/g;
1046: }
1.197 albertel 1047: my ($adr,$sections_or_groups)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
1048: if ($sections_or_groups) {
1049: foreach my $item (split(/\;/,$sections_or_groups)) {
1050: if (($item eq $env{'request.course.sec'}) ||
1051: ($defaultflag && ($item eq '*'))) {
1052: return $adr;
1053: } elsif ($env{'request.course.groups'}) {
1054: my @usersgroups = split(/:/,$env{'request.course.groups'});
1055: if (grep(/^\Q$item\E$/,@usersgroups)) {
1056: return $adr;
1057: }
1058: }
1059: }
1060: } else {
1061: return $rec;
1062: }
1063: return '';
1064: }
1065:
1066: sub decide_receiver {
1067: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1068: &Apache::lonenc::check_decrypt(\$feedurl);
1069: my $typestyle='';
1070: my %to=();
1071: if ($env{'form.discuss'} eq 'author' ||$author) {
1072: $typestyle.='Submitting as Author Feedback<br />';
1073: $feedurl=~ m{^/res/($LONCAPA::domain_re)/($LONCAPA::username_re)/};
1074: $to{$2.':'.$1}=1;
1075: }
1076: my $cid = $env{'request.course.id'};
1077: if ($env{'form.discuss'} eq 'question' ||$question) {
1078: $typestyle.=&mt('Submitting as Question').'<br />';
1079: foreach my $item (split(/\,/,$env{'course.'.$cid.'.question.email'})) {
1080: my $rec=&secapply($item,$defaultflag);
1081: if ($rec) { $to{$rec}=1; }
1082: }
1083: }
1084: if ($env{'form.discuss'} eq 'course' ||$course) {
1085: $typestyle.=&mt('Submitting as Comment').'<br />';
1086: foreach my $item (split(/\,/,$env{'course.'.$cid.'.comment.email'})) {
1087: my $rec=&secapply($item,$defaultflag);
1088: if ($rec) { $to{$rec}=1; }
1089: }
1090: }
1091: if ($env{'form.discuss'} eq 'policy' ||$policy) {
1092: $typestyle.=&mt('Submitting as Policy Feedback').'<br />';
1093: foreach my $item (split(/\,/,$env{'course.'.$cid.'.policy.email'})) {
1094: my $rec=&secapply($item,$defaultflag);
1095: if ($rec) { $to{$rec}=1; }
1096: }
1097: }
1098: if ((scalar(%to) eq '0') && (!$defaultflag)) {
1099: ($typestyle,%to)=
1100: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
1101: }
1102: return ($typestyle,%to);
1103: }
1104:
1.180 albertel 1105: 1;
1.1 www 1106: __END__
1107:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>