Diff for /loncom/interface/lonmsg.pm between versions 1.181 and 1.188

version 1.181, 2006/04/11 14:17:23 version 1.188, 2006/12/06 17:14:50
Line 33  use Apache::lonnet; Line 33  use Apache::lonnet;
 use HTML::TokeParser();  use HTML::TokeParser();
 use Apache::lonlocal;  use Apache::lonlocal;
 use Mail::Send;  use Mail::Send;
   use LONCAPA qw(:DEFAULT :match);
   
 {  {
     my $uniq;      my $uniq;
Line 59  sub packagemsg { Line 60  sub packagemsg {
     my $course_context;      my $course_context;
     if (defined($env{'form.replyid'})) {      if (defined($env{'form.replyid'})) {
         my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=          my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
                    split(/\:/,&Apache::lonnet::unescape($env{'form.replyid'}));                     split(/\:/,&unescape($env{'form.replyid'}));
         $course_context = $origcid;          $course_context = $origcid;
     }      }
     foreach my $key (keys(%env)) {      foreach my $key (keys(%env)) {
         if ($key=~/^form\.(rep)?rec\_(.*)$/) {          if ($key=~/^form\.(rep)?rec\_(.*)$/) {
             my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =              my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =
                                     split(/\:/,&Apache::lonnet::unescape($2));                                      split(/\:/,&unescape($2));
             $course_context = $origcid;              $course_context = $origcid;
             last;              last;
         }          }
Line 108  sub packagemsg { Line 109  sub packagemsg {
         for (my $i=0; $i<@{$recuser}; $i++) {          for (my $i=0; $i<@{$recuser}; $i++) {
             if ($type eq 'dcmail') {              if ($type eq 'dcmail') {
                 my ($username,$email) = split(/:/,$$recuser[$i]);                  my ($username,$email) = split(/:/,$$recuser[$i]);
                 $username = &Apache::lonnet::unescape($username);                  $username = &unescape($username);
                 $email = &Apache::lonnet::unescape($email);                  $email = &unescape($email);
                 $username = &HTML::Entities::encode($username,'<>&"');                  $username = &HTML::Entities::encode($username,'<>&"');
                 $email = &HTML::Entities::encode($email,'<>&"');                  $email = &HTML::Entities::encode($email,'<>&"');
                 $result .= '<recipient username="'.$username.'">'.                  $result .= '<recipient username="'.$username.'">'.
Line 178  sub unpackagemsg { Line 179  sub unpackagemsg {
   
 sub buildmsgid {  sub buildmsgid {
     my ($now,$subject,$uname,$udom,$msgcount,$course_context,$pid) = @_;      my ($now,$subject,$uname,$udom,$msgcount,$course_context,$pid) = @_;
     $subject=&Apache::lonnet::escape($subject);      $subject=&escape($subject);
     return(&Apache::lonnet::escape($now.':'.$subject.':'.$uname.':'.      return(&escape($now.':'.$subject.':'.$uname.':'.
            $udom.':'.$msgcount.':'.$course_context.':'.$pid));             $udom.':'.$msgcount.':'.$course_context.':'.$pid));
 }  }
   
 sub unpackmsgid {  sub unpackmsgid {
     my ($msgid,$folder,$skipstatus,$status_cache)=@_;      my ($msgid,$folder,$skipstatus,$status_cache)=@_;
     $msgid=&Apache::lonnet::unescape($msgid);      $msgid=&unescape($msgid);
     my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid,      my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid,
                      $processid)=split(/\:/,&Apache::lonnet::unescape($msgid));                       $processid)=split(/\:/,&unescape($msgid));
       $shortsubj = &unescape($shortsubj);
       $shortsubj = &HTML::Entities::decode($shortsubj);
     if (!defined($processid)) { $fromcid = ''; }      if (!defined($processid)) { $fromcid = ''; }
     my %status=();      my %status=();
     unless ($skipstatus) {      unless ($skipstatus) {
Line 206  sub unpackmsgid { Line 209  sub unpackmsgid {
   
 sub sendemail {  sub sendemail {
     my ($to,$subject,$body)=@_;      my ($to,$subject,$body)=@_;
       my %senderemails=&Apache::loncommon::getemails();
       my $senderaddress='';
       foreach my $type ('notification','permanentemail','critnotification') {
    if ($senderemails{$type}) {
       $senderaddress=$senderemails{$type};
    }
       }
     $body=      $body=
     "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n".      "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n".
     "*** ".&mt('Please do not reply to this address.')."\n\n".$body;      "*** ".($senderaddress?&mt('You can reply to this message'):&mt('Please do not reply to this address.')."\n*** ".
       &mt('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 (my $fh = $msg->open()) {      if (my $fh = $msg->open()) {
  print $fh $body;   print $fh $body;
  $fh->close;   $fh->close;
Line 284  sub author_res_msg { Line 296  sub author_res_msg {
        ($msgid,$message)=&packagemsg($filename,$message);         ($msgid,$message)=&packagemsg($filename,$message);
        return &Apache::lonnet::reply('put:'.$domain.':'.$author.         return &Apache::lonnet::reply('put:'.$domain.':'.$author.
          ':nohist_res_msgs:'.           ':nohist_res_msgs:'.
           &Apache::lonnet::escape($filename.'_'.$id).'='.            &escape($filename.'_'.$id).'='.
           &Apache::lonnet::escape($message),$homeserver);            &escape($message),$homeserver);
     }      }
     return 'no_host';      return 'no_host';
 }  }
Line 295  sub author_res_msg { Line 307  sub author_res_msg {
 sub retrieve_author_res_msg {  sub retrieve_author_res_msg {
     my $url=shift;      my $url=shift;
     $url=&Apache::lonnet::declutter($url);      $url=&Apache::lonnet::declutter($url);
     my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);      my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//);
     my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$domain,$author);      my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$domain,$author);
     my $msgs='';      my $msgs='';
     foreach (keys %errormsgs) {      foreach (keys %errormsgs) {
Line 315  sub retrieve_author_res_msg { Line 327  sub retrieve_author_res_msg {
 sub del_url_author_res_msg {  sub del_url_author_res_msg {
     my $url=shift;      my $url=shift;
     $url=&Apache::lonnet::declutter($url);      $url=&Apache::lonnet::declutter($url);
     my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);      my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//);
     my @delmsgs=();      my @delmsgs=();
     foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {      foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
  if ($_=~/^\Q$url\E\_\d+$/) {   if ($_=~/^\Q$url\E\_\d+$/) {
Line 329  sub del_url_author_res_msg { Line 341  sub del_url_author_res_msg {
 sub clear_author_res_msg {  sub clear_author_res_msg {
     my $url=shift;      my $url=shift;
     $url=&Apache::lonnet::declutter($url);      $url=&Apache::lonnet::declutter($url);
     my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);      my ($domain,$author)=($url=~/^($match_domain)\/($match_username)\//);
     my @delmsgs=();      my @delmsgs=();
     foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {      foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
  if ($_=~/^\Q$url\E/) {   if ($_=~/^\Q$url\E/) {
Line 350  sub all_url_author_res_msg { Line 362  sub all_url_author_res_msg {
     return %returnhash;      return %returnhash;
 }  }
   
   # ====================================== Add a comment to the User Notes screen
   
   sub store_instructor_comment {
       my ($msg,$uname,$udom) = @_;
       my $cid  = $env{'request.course.id'};
       my $cnum = $env{'course.'.$cid.'.num'};
       my $cdom = $env{'course.'.$cid.'.domain'};
       my $subject= &mt('Record').' ['.$uname.':'.$udom.']';
       my $result = &user_normal_msg_raw($cnum,$cdom,$subject,$msg);
       return $result;
   }
   
 # ================================================== Critical message to a user  # ================================================== Critical message to a user
   
 sub user_crit_msg_raw {  sub user_crit_msg_raw {
Line 365  sub user_crit_msg_raw { Line 389  sub user_crit_msg_raw {
        if ($sendback) { $message.='<sendback>true</sendback>'; }         if ($sendback) { $message.='<sendback>true</sendback>'; }
        $status=&Apache::lonnet::critical(         $status=&Apache::lonnet::critical(
            'put:'.$domain.':'.$user.':critical:'.             'put:'.$domain.':'.$user.':critical:'.
            &Apache::lonnet::escape($msgid).'='.             &escape($msgid).'='.
            &Apache::lonnet::escape($message),$homeserver);             &escape($message),$homeserver);
         if (defined($sentmessage)) {          if (defined($sentmessage)) {
             $$sentmessage = $message;              $$sentmessage = $message;
         }          }
Line 374  sub user_crit_msg_raw { Line 398  sub user_crit_msg_raw {
        $status='no_host';         $status='no_host';
     }      }
 # Notifications  # Notifications
     my %userenv = &Apache::lonnet::get('environment',['critnotification',      my %userenv = &Apache::loncommon::getemails($user,$domain);
                                                       'permanentemail'],  
                                        $domain,$user);  
     if ($userenv{'critnotification'}) {      if ($userenv{'critnotification'}) {
       &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1,        &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1,
  $text);   $text);
Line 404  sub user_crit_msg_raw { Line 426  sub user_crit_msg_raw {
     a critical message $message to the $user at $domain. If $sendback is true,      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.      a reciept will be sent to the current user when $user recieves the message.
   
       Additionally it will check if the user has a Forwarding address
       set, and send the message to that address instead
   
       returns 
         - in array context a list of results for each message that was sent
         - in scalar context a space seperated list of results for each 
              message sent
   
 =cut  =cut
   
 sub user_crit_msg {  sub user_crit_msg {
     my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;      my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
     my $status='';      my @status;
     my %userenv = &Apache::lonnet::get('environment',['msgforward'],      my %userenv = &Apache::lonnet::get('environment',['msgforward'],
                                        $domain,$user);                                         $domain,$user);
     my $msgforward=$userenv{'msgforward'};      my $msgforward=$userenv{'msgforward'};
     if ($msgforward) {      if ($msgforward) {
        foreach (split(/\,/,$msgforward)) {         foreach my $addr (split(/\,/,$msgforward)) {
  my ($forwuser,$forwdomain)=split(/\:/,$_);   my ($forwuser,$forwdomain)=split(/\:/,$addr);
          $status.=           push(@status,
    &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,        &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
                 $sendback,$toperm,$sentmessage).' ';   $sendback,$toperm,$sentmessage));
        }         }
     } else {       } else { 
  $status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage);   push(@status,
        &user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
    $toperm,$sentmessage));
     }      }
     return $status;      if (wantarray) {
    return @status;
       }
       return join(' ',@status);
 }  }
   
 # =================================================== Critical message received  # =================================================== Critical message received
Line 471  sub user_normal_msg_raw { Line 506  sub user_normal_msg_raw {
 # Store in user folder  # Store in user folder
        $status=&Apache::lonnet::critical(         $status=&Apache::lonnet::critical(
            'put:'.$domain.':'.$user.':nohist_email:'.             'put:'.$domain.':'.$user.':nohist_email:'.
            &Apache::lonnet::escape($msgid).'='.             &escape($msgid).'='.
            &Apache::lonnet::escape($packed_message),$homeserver);             &escape($packed_message),$homeserver);
 # Save new message received time  # Save new message received time
        &Apache::lonnet::put         &Apache::lonnet::put
                          ('email_status',{'recnewemail'=>time},$domain,$user);                           ('email_status',{'recnewemail'=>time},$domain,$user);
Line 556  sub store_sent_mail { Line 591  sub store_sent_mail {
     my $status =' '.&Apache::lonnet::critical(      my $status =' '.&Apache::lonnet::critical(
                'put:'.$env{'user.domain'}.':'.$env{'user.name'}.                 'put:'.$env{'user.domain'}.':'.$env{'user.name'}.
                                           ':nohist_email_sent:'.                                            ':nohist_email_sent:'.
                &Apache::lonnet::escape($msgid).'='.                 &escape($msgid).'='.
                &Apache::lonnet::escape($message),$env{'user.home'});                 &escape($message),$env{'user.home'});
     return $status;      return $status;
 }  }
   
Line 566  sub store_sent_mail { Line 601  sub store_sent_mail {
 sub foldersuffix {  sub foldersuffix {
     my $folder=shift;      my $folder=shift;
     unless ($folder) { return ''; }      unless ($folder) { return ''; }
     return '_'.&Apache::lonnet::escape($folder);      return '_'.&escape($folder);
 }  }
   
 1;  1;

Removed from v.1.181  
changed lines
  Added in v.1.188


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