--- loncom/interface/lonmsg.pm 2007/04/22 13:41:22 1.200 +++ loncom/interface/lonmsg.pm 2007/05/01 18:40:57 1.201 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.200 2007/04/22 13:41:22 raeburn Exp $ +# $Id: lonmsg.pm,v 1.201 2007/05/01 18:40:57 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -88,23 +88,7 @@ sub packagemsg { #remove machine specification $attachmenturl =~ s|^http://[^/]+/|/|; $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"'); - my $course_context; - if (defined($env{'form.replyid'})) { - my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)= - split(/\:/,&unescape($env{'form.replyid'})); - $course_context = $origcid; - } - foreach my $key (keys(%env)) { - if ($key=~/^form\.(rep)?rec\_(.*)$/) { - my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) = - split(/\:/,&unescape($2)); - $course_context = $origcid; - last; - } - } - unless(defined($course_context)) { - $course_context = $env{'request.course.id'}; - } + my $course_context = &get_course_context(); my $now=time; my $msgcount = &get_uniq(); unless(defined($msgid)) { @@ -167,7 +151,7 @@ sub packagemsg { } if (defined($symb)) { $result.= ''.$symb.''; - if (defined($course_context)) { + if ($course_context ne '') { if ($course_context eq $env{'request.course.id'}) { my $resource_title = &Apache::lonnet::gettitle($symb); if (defined($resource_title)) { @@ -179,6 +163,27 @@ sub packagemsg { return ($msgid,$result); } +sub get_course_context { + my $course_context; + if (defined($env{'form.replyid'})) { + my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)= + split(/\:/,&unescape($env{'form.replyid'})); + $course_context = $origcid; + } + foreach my $key (keys(%env)) { + if ($key=~/^form\.(rep)?rec\_(.*)$/) { + my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) = + split(/\:/,&unescape($2)); + $course_context = $origcid; + last; + } + } + if ($course_context eq '') { + $course_context = $env{'request.course.id'}; + } + return $course_context; +} + # ================================================== Unpack message into a hash sub unpackagemsg { @@ -430,13 +435,17 @@ sub store_instructor_comment { my $cdom = $env{'course.'.$cid.'.domain'}; my $subject= &mt('Record').' ['.$uname.':'.$udom.']'; my $result = &user_normal_msg_raw($cnum,$cdom,$subject,$msg); + if ($result eq 'ok' || $result eq 'con_delayed') { + + } return $result; } # ================================================== Critical message to a user sub user_crit_msg_raw { - my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_; + my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage, + $nosentstore)=@_; # Check if allowed missing my ($status,$packed_message); my $msgid='undefined'; @@ -453,7 +462,7 @@ sub user_crit_msg_raw { if (defined($sentmessage)) { $$sentmessage = $packed_message; } - if ($env{'request.course.id'} eq '') { + if (!$nosentstore) { (undef,my $packed_message_no_citation) = &packagemsg($subject,$message,undef,undef,undef,$user,$domain, $msgid); @@ -490,9 +499,10 @@ sub user_crit_msg_raw { =pod -=item * B: Sends - a critical message $message to the $user at $domain. If $sendback is true, - a reciept will be sent to the current user when $user recieves the message. +=item * B: + Sends a critical message $message to the $user at $domain. If $sendback + is true, a receipt will be sent to the current user when $user receives + the message. Additionally it will check if the user has a Forwarding address set, and send the message to that address instead @@ -505,7 +515,8 @@ sub user_crit_msg_raw { =cut sub user_crit_msg { - my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_; + my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage, + $nosentstore)=@_; my @status; my %userenv = &Apache::lonnet::get('environment',['msgforward'], $domain,$user); @@ -515,12 +526,12 @@ sub user_crit_msg { my ($forwuser,$forwdomain)=split(/\:/,$addr); push(@status, &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message, - $sendback,$toperm,$sentmessage)); + $sendback,$toperm,$sentmessage,$nosentstore)); } } else { push(@status, &user_crit_msg_raw($user,$domain,$subject,$message,$sendback, - $toperm,$sentmessage)); + $toperm,$sentmessage,$nosentstore)); } if (wantarray) { return @status; @@ -559,7 +570,7 @@ sub user_crit_received { sub user_normal_msg_raw { my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl, $toperm,$currid,$newid,$sentmessage,$crsmsgid,$symb,$restitle, - $error)=@_; + $error,$nosentstore)=@_; # Check if allowed missing my ($status,$packed_message); my $msgid='undefined'; @@ -580,17 +591,8 @@ sub user_normal_msg_raw { # Save new message received time &Apache::lonnet::put ('email_status',{'recnewemail'=>time},$domain,$user); -# Into sent-mail folder unless a broadcast message or critical message - unless (($env{'request.course.id'}) && - (($env{'form.courserecord'}) && - (&Apache::lonnet::allowed('dff',$env{'request.course.id'}) - || &Apache::lonnet::allowed('dff',$env{'request.course.id'}. - '/'.$env{'request.course.sec'}))) || - (($env{'form.sendmode'} eq 'group') || - (($env{'form.critmsg'}) || ($env{'form.sendbck'})) && - (&Apache::lonnet::allowed('srm',$env{'request.course.id'}) - || &Apache::lonnet::allowed('srm',$env{'request.course.id'}. - '/'.$env{'request.course.sec'})))) { +# Into sent-mail folder if sent mail storage required + if (!$nosentstore) { (undef,my $packed_message_no_citation) = &packagemsg($subject,$message,undef,$baseurl,$attachmenturl, $user,$domain,$currid,undef,$crsmsgid,$symb,$error); @@ -598,10 +600,10 @@ sub user_normal_msg_raw { &store_sent_mail($msgid,$packed_message_no_citation); } } - if (defined($newid)) { + if (ref($newid) eq 'SCALAR') { $$newid = $msgid; } - if (defined($sentmessage)) { + if (ref($sentmessage) eq 'SCALAR') { $$sentmessage = $packed_message; } # Notifications @@ -630,7 +632,8 @@ sub user_normal_msg_raw { =pod =item * B: + $baseurl, $attachmenturl, $toperm, $sentmessage, $symb, $restitle, + $error,$nosentstore)>: Sends a message to the $user at $domain, with subject $subject and message $message. Additionally it will check if the user has a Forwarding address @@ -645,7 +648,7 @@ sub user_normal_msg_raw { sub user_normal_msg { my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl, - $toperm,$sentmessage,$symb,$restitle,$error)=@_; + $toperm,$sentmessage,$symb,$restitle,$error,$nosentstore)=@_; my @status; my %userenv = &Apache::lonnet::get('environment',['msgforward'], $domain,$user); @@ -656,12 +659,14 @@ sub user_normal_msg { push(@status, &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message, $citation,$baseurl,$attachmenturl,$toperm, - undef,undef,$sentmessage,undef,$symb,$restitle,$error)); + undef,undef,$sentmessage,undef,$symb, + $restitle,$error,$nosentstore)); } } else { push(@status,&user_normal_msg_raw($user,$domain,$subject,$message, $citation,$baseurl,$attachmenturl,$toperm, - undef,undef,$sentmessage,undef,$symb,$restitle,$error)); + undef,undef,$sentmessage,undef,$symb, + $restitle,$error,$nosentstore)); } if (wantarray) { return @status; @@ -669,13 +674,37 @@ sub user_normal_msg { return join(' ',@status); } +sub process_sent_mail { + my ($msgsubj,$subj_prefix,$numsent,$stamp,$msgname,$msgdom,$msgcount,$context,$pid,$savemsg,$recusers,$recudoms,$baseurl,$attachmenturl,$symb,$error,$senderuname,$senderdom,$senderhome) = @_; + my $sentsubj; + if ($numsent > 1) { + $sentsubj = $subj_prefix.' ('.$numsent.' sent) '.$msgsubj; + } + $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"'); + my $sentmsgid = + &buildmsgid($stamp,$sentsubj,$msgname,$msgdom,$msgcount,$context,$pid); + (undef,my $sentmessage) = + &packagemsg($msgsubj,$savemsg,undef,$baseurl,$attachmenturl,$recusers, + $recudoms,$sentmsgid,undef,undef,$symb,$error); + my $status = &store_sent_mail($sentmsgid,$sentmessage,$senderuname, + $senderdom,$senderhome); + return $status; +} + sub store_sent_mail { - my ($msgid,$message) = @_; + my ($msgid,$message,$senderuname,$senderdom,$senderhome) = @_; + if ($senderuname eq '') { + $senderuname = $env{'user.name'}; + } + if ($senderdom eq '') { + $senderdom = $env{'user.domain'}; + } + if ($senderhome eq '') { + $senderhome = $env{'user.home'}; + } my $status =' '.&Apache::lonnet::critical( - 'put:'.$env{'user.domain'}.':'.$env{'user.name'}. - ':nohist_email_sent:'. - &escape($msgid).'='. - &escape($message),$env{'user.home'}); + 'put:'.$senderdom.':'.$senderuname.':nohist_email_sent:'. + &escape($msgid).'='.&escape($message),$senderhome); return $status; }