--- loncom/interface/lonmsg.pm 2008/11/28 14:36:50 1.216 +++ loncom/interface/lonmsg.pm 2009/03/31 21:04:12 1.224 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.216 2008/11/28 14:36:50 raeburn Exp $ +# $Id: lonmsg.pm,v 1.224 2009/03/31 21:04:12 kaisler Exp $ # # Copyright Michigan State University Board of Trustees # @@ -194,8 +194,6 @@ Returns %to - a hash, which keys are addresses of users to send messages to the keys will look like name:domain -=item user_lang() - =back =cut @@ -224,10 +222,10 @@ sub packagemsg { $citation=&HTML::Entities::encode($citation,'<>&"'); $subject =&HTML::Entities::encode($subject,'<>&"'); #remove machine specification - $baseurl =~ s|^http://[^/]+/|/|; + $baseurl =~ s|^https?://[^/]+/|/|; $baseurl =&HTML::Entities::encode($baseurl,'<>&"'); #remove machine specification - $attachmenturl =~ s|^http://[^/]+/|/|; + $attachmenturl =~ s|^https?://[^/]+/|/|; $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"'); my $course_context = &get_course_context(); my $now=time; @@ -422,21 +420,48 @@ sub unpackmsgid { sub sendemail { my ($to,$subject,$body,$to_uname,$to_udom,$user_lh)=@_; - my %senderemails=&Apache::loncommon::getemails(); my $senderaddress=''; - foreach my $type ('notification','permanentemail','critnotification') { - if ($senderemails{$type}) { - $senderaddress=$senderemails{$type}; - } + my $replytoaddress=''; + if ($env{'form.can_reply'} eq 'N') { + my $lonhost = $Apache::lonnet::perlvar{'lonHostID'}; + my $hostname = &Apache::lonnet::hostname($lonhost); + $replytoaddress = 'do-not-reply@'.$hostname; + } else { + my %senderemails; + my $have_sender; + if ($env{'form.reply_to_addr'}) { + my ($replytoname,$replytodom) = split(/:/,$env{'form.reply_to_addr'}); + if (!($replytoname eq $env{'user.name'} && $replytodom eq $env{'user.domain'})) { + if (&Apache::lonnet::homeserver($replytoname,$replytodom) ne 'no_host') { + %senderemails = + &Apache::loncommon::getemails($replytoname,$replytodom); + $have_sender = 1; + } + } + } + if (!$have_sender) { + %senderemails=&Apache::loncommon::getemails(); + } + foreach my $type ('permanentemail','critnotification','notification') { + if ($senderemails{$type}) { + ($senderaddress) = split(/,/,$senderemails{$type}); + last if ($senderaddress); + } + } } $body= - "*** ".&mt_user($user_lh,'This is an automatic message generated by the LON-CAPA system.')."\n". - "*** ".($senderaddress?&mt_user($user_lh,'You can reply to this message'):&mt_user($user_lh,'Please do not reply to this address.')."\n*** ". - &mt_user($user_lh,'A reply will not be received by the recipient!'))."\n\n".$body; + "*** ".&mt_user($user_lh,'This is an automatic e-mail generated by the LON-CAPA system.')."\n". + "*** ".($senderaddress?&mt_user($user_lh,'You can reply to this e-mail'):&mt_user($user_lh,'Please do not reply to this address.')."\n*** ". + &mt_user($user_lh,'A reply will not be received by the recipient!'))."\n\n".$body; my $msg = new Mail::Send; $msg->to($to); $msg->subject('[LON-CAPA] '.$subject); - if ($senderaddress) { $msg->add('Reply-to',$senderaddress); $msg->add('From',$senderaddress); } + if ($replytoaddress) { + $msg->add('Reply-to',$replytoaddress); + } + if ($senderaddress) { + $msg->add('From',$senderaddress); + } if (my $fh = $msg->open()) { print $fh $body; $fh->close; @@ -455,13 +480,15 @@ sub sendnotification { $text=~s/\<\;/\/gs; - my $url='http://'. - &Apache::lonnet::hostname(&Apache::lonnet::homeserver($touname,$toudom)). - '/adm/email?username='.$touname.'&domain='.$toudom; + my $homeserver = &Apache::lonnet::homeserver($touname,$toudom); + my $protocol = $Apache::lonnet::protocol{$homeserver}; + $protocol = 'http' if ($protocol ne 'https'); + my $url = $protocol.'://'.&Apache::lonnet::hostname($homeserver). + '/adm/email?username='.$touname.'&domain='.$toudom; my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid, $symb,$error) = &Apache::lonmsg::unpackmsgid($msgid); my ($coursetext,$body,$bodybegin,$bodysubj,$bodyend); - my $user_lh = &user_lang($touname,$toudom,$fromcid); + my $user_lh = &Apache::loncommon::user_lang($touname,$toudom,$fromcid); if ($fromcid ne '') { $coursetext = "\n".&mt_user($user_lh,'Course').': '; if ($env{'course.'.$fromcid.'.description'} ne '') { @@ -533,11 +560,17 @@ to access the full message.',$url); } } +sub mynewmail{ + &newmail(); + return $env{'user.mailcheck.lastnewmassagetime'} > $env{'user.mailcheck.lastvisit'}; +} + sub newmail { if ((time-$env{'user.mailcheck.time'})>300) { my %what=&Apache::lonnet::get('email_status',['recnewemail']); &Apache::lonnet::appenv({'user.mailcheck.time'=>time}); + &Apache::lonnet::appenv({'user.mailcheck.lastnewmassagetime'=> $what{'recnewemail'}}); if ($what{'recnewemail'}>0) { return 1; } } return 0; @@ -996,28 +1029,6 @@ sub decide_receiver { return ($typestyle,%to); } -sub user_lang { - my ($touname,$toudom,$fromcid) = @_; - my @userlangs; - if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) { - @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/, - $env{'course.'.$fromcid.'.languages'})); - } else { - my %langhash = &Apache::lonnet::get('environment',['languages'],$toudom,$touname); - if ($langhash{'languages'} ne '') { - @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'}); - } else { - my %domdefs = &Apache::lonnet::get_domain_defaults($toudom); - if ($domdefs{'lang_def'} ne '') { - @userlangs = ($domdefs{'lang_def'}); - } - } - } - my @languages=&Apache::lonlocal::get_genlanguages(@userlangs); - my $user_lh = Apache::localize->get_handle(@languages); - return $user_lh; -} - 1; __END__