Diff for /loncom/interface/lonmsg.pm between versions 1.213 and 1.214.2.5

version 1.213, 2008/09/13 02:37:26 version 1.214.2.5, 2009/01/05 20:08:25
Line 83  sub packagemsg { Line 83  sub packagemsg {
     $citation=&HTML::Entities::encode($citation,'<>&"');      $citation=&HTML::Entities::encode($citation,'<>&"');
     $subject =&HTML::Entities::encode($subject,'<>&"');      $subject =&HTML::Entities::encode($subject,'<>&"');
     #remove machine specification      #remove machine specification
     $baseurl =~ s|^http://[^/]+/|/|;      $baseurl =~ s|^https?\://[^/]+/|/|;
     $baseurl =&HTML::Entities::encode($baseurl,'<>&"');      $baseurl =&HTML::Entities::encode($baseurl,'<>&"');
     #remove machine specification      #remove machine specification
     $attachmenturl =~ s|^http://[^/]+/|/|;      $attachmenturl =~ s|^https?\://[^/]+/|/|;
     $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');      $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
     my $course_context = &get_course_context();      my $course_context = &get_course_context();
     my $now=time;      my $now=time;
Line 120  sub packagemsg { Line 120  sub packagemsg {
    '<role>'.$env{'request.role'}.'</role>'.     '<role>'.$env{'request.role'}.'</role>'.
    '<resource>'.$env{'request.filename'}.'</resource>'.     '<resource>'.$env{'request.filename'}.'</resource>'.
            '<msgid>'.$msgid.'</msgid>';             '<msgid>'.$msgid.'</msgid>';
       if (defined($env{'form.group'})) {
           $result .= '<group>'.$env{'form.group'}.'</group>';
       }
     if (ref($recuser) eq 'ARRAY') {      if (ref($recuser) eq 'ARRAY') {
         for (my $i=0; $i<@{$recuser}; $i++) {          for (my $i=0; $i<@{$recuser}; $i++) {
             if ($type eq 'dcmail') {              if ($type eq 'dcmail') {
Line 280  sub unpackmsgid { Line 283  sub unpackmsgid {
   
 sub sendemail {  sub sendemail {
     my ($to,$subject,$body,$to_uname,$to_udom,$user_lh)=@_;      my ($to,$subject,$body,$to_uname,$to_udom,$user_lh)=@_;
     my %senderemails=&Apache::loncommon::getemails();  
     my $senderaddress='';      my $senderaddress='';
     foreach my $type ('notification','permanentemail','critnotification') {      my $replytoaddress='';
  if ($senderemails{$type}) {      if ($env{'form.can_reply'} eq 'N') {
     $senderaddress=$senderemails{$type};          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=      $body=
     "*** ".&mt_user($user_lh,'This is an automatic message generated by the LON-CAPA system.')."\n".      "*** ".&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*** ".      "*** ".($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,'A reply will not be received by the recipient!'))."\n\n".$body;
     my $msg = new Mail::Send;      my $msg = new Mail::Send;
     $msg->to($to);      $msg->to($to);
     $msg->subject('[LON-CAPA] '.$subject);      $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()) {      if (my $fh = $msg->open()) {
  print $fh $body;   print $fh $body;
  $fh->close;   $fh->close;
Line 313  sub sendnotification { Line 343  sub sendnotification {
   
     $text=~s/\&lt\;/\</gs;      $text=~s/\&lt\;/\</gs;
     $text=~s/\&gt\;/\>/gs;      $text=~s/\&gt\;/\>/gs;
     my $url='http://'.      my $homeserver = &Apache::lonnet::homeserver($touname,$toudom);
  &Apache::lonnet::hostname(&Apache::lonnet::homeserver($touname,$toudom)).      my $protocol = $Apache::lonnet::protocol{$homeserver};
       '/adm/email?username='.$touname.'&domain='.$toudom;      $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,      my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,
         $symb,$error) = &Apache::lonmsg::unpackmsgid($msgid);          $symb,$error) = &Apache::lonmsg::unpackmsgid($msgid);
     my ($coursetext,$body,$bodybegin,$bodysubj,$bodyend);      my ($coursetext,$body,$bodybegin,$bodysubj,$bodyend);
Line 688  sub user_normal_msg_raw { Line 720  sub user_normal_msg_raw {
      $text,$msgid);       $text,$msgid);
        }         }
        if ($toperm && $userenv{'permanentemail'}) {         if ($toperm && $userenv{'permanentemail'}) {
    &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,0,             if ((!$userenv{'notification'}) || ($userenv{'notification'} ne $userenv{'permanentemail'})) {
      $text,$msgid);         &sendnotification($userenv{'permanentemail'},$user,$domain,$subject,0,
              $text,$msgid);
              }
        }         }
        &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},         &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
     $env{'user.home'},      $env{'user.home'},
Line 748  sub user_normal_msg { Line 782  sub user_normal_msg {
 }  }
   
 sub process_sent_mail {  sub process_sent_mail {
     my ($msgsubj,$subj_prefix,$numsent,$stamp,$msgname,$msgdom,$msgcount,$context,$pid,$savemsg,$recusers,$recudoms,$baseurl,$attachmenturl,$symb,$error,$senderuname,$senderdom) = @_;      my ($msgsubj,$subj_prefix,$numsent,$stamp,$msgname,$msgdom,$msgcount,$context,$pid,$savemsg,$recusers,$recudoms,$baseurl,$attachmenturl,$symb,$error,$senderuname,$senderdom,$recipid) = @_;
     my $sentsubj;      my $sentsubj;
     if ($numsent > 1) {      if ($numsent > 1) {
         $sentsubj = $subj_prefix.' ('.$numsent.' sent) '.$msgsubj;          $sentsubj = $subj_prefix.' ('.$numsent.' sent) '.$msgsubj;
Line 763  sub process_sent_mail { Line 797  sub process_sent_mail {
         &buildmsgid($stamp,$sentsubj,$msgname,$msgdom,$msgcount,$context,$pid);          &buildmsgid($stamp,$sentsubj,$msgname,$msgdom,$msgcount,$context,$pid);
     (undef,my $sentmessage) =      (undef,my $sentmessage) =
         &packagemsg($msgsubj,$savemsg,undef,$baseurl,$attachmenturl,$recusers,          &packagemsg($msgsubj,$savemsg,undef,$baseurl,$attachmenturl,$recusers,
                     $recudoms,$sentmsgid,undef,undef,$symb,$error);                      $recudoms,$sentmsgid,undef,undef,$symb,$error,$recipid);
     my $status = &store_sent_mail($sentmsgid,$sentmessage,$senderuname,      my $status = &store_sent_mail($sentmsgid,$sentmessage,$senderuname,
                                   $senderdom);                                    $senderdom);
     return $status;      return $status;
Line 931  sub user_lang { Line 965  sub user_lang {
         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,          @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                     $env{'course.'.$fromcid.'.languages'}));                      $env{'course.'.$fromcid.'.languages'}));
     } else {      } else {
         my %langhash = &Apache::lonnet::get('environment',['languages'],$toudom,$touname);          my %langhash = &Apache::loncommon::getlangs($touname,$toudom);
         if ($langhash{'languages'} ne '') {          if ($langhash{'languages'} ne '') {
             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});                @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});  
         } else {          } else {
Line 941  sub user_lang { Line 975  sub user_lang {
             }              }
         }          }
     }      }
     my @languages=&Apache::loncommon::get_genlanguages(@userlangs);      my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
     my $user_lh = Apache::localize->get_handle(@languages);      my $user_lh = Apache::localize->get_handle(@languages);
     return $user_lh;      return $user_lh;
 }  }

Removed from v.1.213  
changed lines
  Added in v.1.214.2.5


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>