Diff for /loncom/interface/lonmsg.pm between versions 1.200 and 1.201

version 1.200, 2007/04/22 13:41:22 version 1.201, 2007/05/01 18:40:57
Line 88  sub packagemsg { Line 88  sub packagemsg {
     #remove machine specification      #remove machine specification
     $attachmenturl =~ s|^http://[^/]+/|/|;      $attachmenturl =~ s|^http://[^/]+/|/|;
     $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');      $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
     my $course_context;      my $course_context = &get_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 $now=time;      my $now=time;
     my $msgcount = &get_uniq();      my $msgcount = &get_uniq();
     unless(defined($msgid)) {      unless(defined($msgid)) {
Line 167  sub packagemsg { Line 151  sub packagemsg {
     }      }
     if (defined($symb)) {      if (defined($symb)) {
         $result.= '<symb>'.$symb.'</symb>';          $result.= '<symb>'.$symb.'</symb>';
         if (defined($course_context)) {          if ($course_context ne '') {
             if ($course_context eq $env{'request.course.id'}) {              if ($course_context eq $env{'request.course.id'}) {
                 my $resource_title = &Apache::lonnet::gettitle($symb);                  my $resource_title = &Apache::lonnet::gettitle($symb);
                 if (defined($resource_title)) {                  if (defined($resource_title)) {
Line 179  sub packagemsg { Line 163  sub packagemsg {
     return ($msgid,$result);      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  # ================================================== Unpack message into a hash
   
 sub unpackagemsg {  sub unpackagemsg {
Line 430  sub store_instructor_comment { Line 435  sub store_instructor_comment {
     my $cdom = $env{'course.'.$cid.'.domain'};      my $cdom = $env{'course.'.$cid.'.domain'};
     my $subject= &mt('Record').' ['.$uname.':'.$udom.']';      my $subject= &mt('Record').' ['.$uname.':'.$udom.']';
     my $result = &user_normal_msg_raw($cnum,$cdom,$subject,$msg);      my $result = &user_normal_msg_raw($cnum,$cdom,$subject,$msg);
       if ($result eq 'ok' || $result eq 'con_delayed') {
           
       }
     return $result;      return $result;
 }  }
   
 # ================================================== Critical message to a user  # ================================================== Critical message to a user
   
 sub user_crit_msg_raw {  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  # Check if allowed missing
     my ($status,$packed_message);      my ($status,$packed_message);
     my $msgid='undefined';      my $msgid='undefined';
Line 453  sub user_crit_msg_raw { Line 462  sub user_crit_msg_raw {
         if (defined($sentmessage)) {          if (defined($sentmessage)) {
             $$sentmessage = $packed_message;              $$sentmessage = $packed_message;
         }          }
         if ($env{'request.course.id'} eq '') {          if (!$nosentstore) {
             (undef,my $packed_message_no_citation) =              (undef,my $packed_message_no_citation) =
             &packagemsg($subject,$message,undef,undef,undef,$user,$domain,              &packagemsg($subject,$message,undef,undef,undef,$user,$domain,
                         $msgid);                          $msgid);
Line 490  sub user_crit_msg_raw { Line 499  sub user_crit_msg_raw {
   
 =pod  =pod
   
 =item * B<user_crit_msg($user, $domain, $subject, $message, $sendback)>: Sends  =item * B<user_crit_msg($user, $domain, $subject, $message, $sendback, $nosentstore)>: 
     a critical message $message to the $user at $domain. If $sendback is true,      Sends a critical message $message to the $user at $domain.  If $sendback
     a reciept will be sent to the current user when $user recieves the message.      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      Additionally it will check if the user has a Forwarding address
     set, and send the message to that address instead      set, and send the message to that address instead
Line 505  sub user_crit_msg_raw { Line 515  sub user_crit_msg_raw {
 =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,
           $nosentstore)=@_;
     my @status;      my @status;
     my %userenv = &Apache::lonnet::get('environment',['msgforward'],      my %userenv = &Apache::lonnet::get('environment',['msgforward'],
                                        $domain,$user);                                         $domain,$user);
Line 515  sub user_crit_msg { Line 526  sub user_crit_msg {
  my ($forwuser,$forwdomain)=split(/\:/,$addr);   my ($forwuser,$forwdomain)=split(/\:/,$addr);
          push(@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,$nosentstore));
        }         }
     } else {       } else { 
  push(@status,   push(@status,
      &user_crit_msg_raw($user,$domain,$subject,$message,$sendback,       &user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
  $toperm,$sentmessage));   $toperm,$sentmessage,$nosentstore));
     }      }
     if (wantarray) {      if (wantarray) {
  return @status;   return @status;
Line 559  sub user_crit_received { Line 570  sub user_crit_received {
 sub user_normal_msg_raw {  sub user_normal_msg_raw {
     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,      my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
         $toperm,$currid,$newid,$sentmessage,$crsmsgid,$symb,$restitle,          $toperm,$currid,$newid,$sentmessage,$crsmsgid,$symb,$restitle,
         $error)=@_;          $error,$nosentstore)=@_;
 # Check if allowed missing  # Check if allowed missing
     my ($status,$packed_message);      my ($status,$packed_message);
     my $msgid='undefined';      my $msgid='undefined';
Line 580  sub user_normal_msg_raw { Line 591  sub user_normal_msg_raw {
 # 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);
 # Into sent-mail folder unless a broadcast message or critical message  # Into sent-mail folder if sent mail storage required
        unless (($env{'request.course.id'}) &&         if (!$nosentstore) {
                (($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'})))) {  
            (undef,my $packed_message_no_citation) =             (undef,my $packed_message_no_citation) =
                &packagemsg($subject,$message,undef,$baseurl,$attachmenturl,                 &packagemsg($subject,$message,undef,$baseurl,$attachmenturl,
                            $user,$domain,$currid,undef,$crsmsgid,$symb,$error);                             $user,$domain,$currid,undef,$crsmsgid,$symb,$error);
Line 598  sub user_normal_msg_raw { Line 600  sub user_normal_msg_raw {
                &store_sent_mail($msgid,$packed_message_no_citation);                 &store_sent_mail($msgid,$packed_message_no_citation);
            }             }
        }         }
        if (defined($newid)) {         if (ref($newid) eq 'SCALAR') {
    $$newid = $msgid;     $$newid = $msgid;
        }         }
        if (defined($sentmessage)) {         if (ref($sentmessage) eq 'SCALAR') {
    $$sentmessage = $packed_message;     $$sentmessage = $packed_message;
        }         }
 # Notifications  # Notifications
Line 630  sub user_normal_msg_raw { Line 632  sub user_normal_msg_raw {
 =pod  =pod
   
 =item * B<user_normal_msg($user, $domain, $subject, $message, $citation,  =item * B<user_normal_msg($user, $domain, $subject, $message, $citation,
        $baseurl, $attachmenturl, $toperm, $sentmessage, $symb, $restitle, $error)>:         $baseurl, $attachmenturl, $toperm, $sentmessage, $symb, $restitle,
          $error,$nosentstore)>:
  Sends a message to the  $user at $domain, with subject $subject and message $message.   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      Additionally it will check if the user has a Forwarding address
Line 645  sub user_normal_msg_raw { Line 648  sub user_normal_msg_raw {
   
 sub user_normal_msg {  sub user_normal_msg {
     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,      my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
  $toperm,$sentmessage,$symb,$restitle,$error)=@_;   $toperm,$sentmessage,$symb,$restitle,$error,$nosentstore)=@_;
     my @status;      my @status;
     my %userenv = &Apache::lonnet::get('environment',['msgforward'],      my %userenv = &Apache::lonnet::get('environment',['msgforward'],
                                        $domain,$user);                                         $domain,$user);
Line 656  sub user_normal_msg { Line 659  sub user_normal_msg {
     push(@status,      push(@status,
         &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,          &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
      $citation,$baseurl,$attachmenturl,$toperm,       $citation,$baseurl,$attachmenturl,$toperm,
      undef,undef,$sentmessage,undef,$symb,$restitle,$error));       undef,undef,$sentmessage,undef,$symb,
                                        $restitle,$error,$nosentstore));
         }          }
     } else {      } else {
  push(@status,&user_normal_msg_raw($user,$domain,$subject,$message,   push(@status,&user_normal_msg_raw($user,$domain,$subject,$message,
      $citation,$baseurl,$attachmenturl,$toperm,       $citation,$baseurl,$attachmenturl,$toperm,
      undef,undef,$sentmessage,undef,$symb,$restitle,$error));       undef,undef,$sentmessage,undef,$symb,
                                        $restitle,$error,$nosentstore));
     }      }
     if (wantarray) {      if (wantarray) {
         return @status;          return @status;
Line 669  sub user_normal_msg { Line 674  sub user_normal_msg {
     return join(' ',@status);      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 {  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(      my $status =' '.&Apache::lonnet::critical(
                'put:'.$env{'user.domain'}.':'.$env{'user.name'}.                 'put:'.$senderdom.':'.$senderuname.':nohist_email_sent:'.
                                           ':nohist_email_sent:'.                 &escape($msgid).'='.&escape($message),$senderhome);
                &escape($msgid).'='.  
                &escape($message),$env{'user.home'});  
     return $status;      return $status;
 }  }
   

Removed from v.1.200  
changed lines
  Added in v.1.201


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