--- loncom/interface/lonmsg.pm 2003/10/04 20:49:40 1.66 +++ loncom/interface/lonmsg.pm 2004/03/01 23:06:17 1.71.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging # -# $Id: lonmsg.pm,v 1.66 2003/10/04 20:49:40 www Exp $ +# $Id: lonmsg.pm,v 1.71.2.1 2004/03/01 23:06:17 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -115,6 +115,7 @@ use Apache::loncommon(); use Apache::lontexconvert(); use HTML::Entities(); use Mail::Send; +use Apache::lonlocal; # Querystring component with sorting type my $sqs; @@ -143,7 +144,7 @@ sub packagemsg { my $result=''.$ENV{'user.name'}.''. ''.$ENV{'user.domain'}.''. ''.$subject.''. - ''. + ''. ''.$ENV{'SERVER_NAME'}.''. ''.$ENV{'HTTP_HOST'}.''. ''.$ENV{'REMOTE_ADDR'}.''. @@ -186,9 +187,9 @@ sub unpackagemsg { if ($content{'attachmenturl'}) { my ($fname,$ft)=($content{'attachmenturl'}=~/\/(\w+)\.(\w+)$/); if ($notoken) { - $content{'message'}.='

Attachment: '.$fname.'.'.$ft.''; + $content{'message'}.='

'.&mt('Attachment').': '.$fname.'.'.$ft.''; } else { - $content{'message'}.='

Attachment: '.$fname.'.'.$ft.''; } @@ -212,14 +213,15 @@ sub unpackmsgid { sub sendemail { my ($to,$subject,$body)=@_; $body= - "*** This is an automatic message generated by the LON-CAPA system.\n". - "*** Please do not reply to this address.\n\n".$body; + "*** ".&mt('This is an automatic message generated by the LON-CAPA system.')."\n". + "*** ".&mt('Please do not reply to this address.')."\n\n".$body; my $msg = new Mail::Send; $msg->to($to); $msg->subject('[LON-CAPA] '.$subject); - my $fh = $msg->open('smtp',Server => 'localhost'); - print $fh $body; - $fh->close; + if (my $fh = $msg->open('smtp',Server => 'localhost')) { + print $fh $body; + $fh->close; + } } # ==================================================== Send notification emails @@ -268,16 +270,22 @@ sub author_res_msg { my ($filename,$message)=@_; unless ($message) { return 'empty'; } $filename=&Apache::lonnet::declutter($filename); - my ($domain,$author,@dummy)=split(/\//,$filename); + my ($domain,$author)=split(/\//,$filename); my $homeserver=&Apache::lonnet::homeserver($author,$domain); if ($homeserver ne 'no_host') { my $id=unpack("%32C*",$message); my $msgid; - ($msgid,$message)=&packagemsg($filename,$message); + ($msgid,$message)=&packagemsg("Error: [$filename]",$message); + #FIXME this should be nohist_res_msg, we need to provide an interface + # to this hash BUG#2444 + #return &Apache::lonnet::reply('put:'.$domain.':'.$author. + # ':nohist_res_msg:'. + # &Apache::lonnet::escape($filename.'_'.$id).'='. + # &Apache::lonnet::escape($message),$homeserver); return &Apache::lonnet::reply('put:'.$domain.':'.$author. - ':nohist_res_msgs:'. - &Apache::lonnet::escape($filename.'_'.$id).'='. - &Apache::lonnet::escape($message),$homeserver); + ':nohist_email:'. + &Apache::lonnet::escape($msgid).'='. + &Apache::lonnet::escape($message),$homeserver); } return 'no_host'; } @@ -362,10 +370,10 @@ sub user_crit_received { my %contents=&unpackagemsg($message{$msgid},1); my $status='rec: '.($contents{'sendback'}? &user_normal_msg($contents{'sendername'},$contents{'senderdomain'}, - 'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}, - 'User '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}. + &mt('Receipt').': '.$ENV{'user.name'}.' at '.$ENV{'user.domain'}, + &mt('User').' '.$ENV{'user.name'}.' '.&mt('at').' '.$ENV{'user.domain'}. ' acknowledged receipt of message'."\n".' "'. - $contents{'subject'}.'"'."\n".'dated '. + $contents{'subject'}.'"'."\n".&mt('dated').' '. $contents{'time'}.".\n" ):'no msg req'); $status.=' trans: '. @@ -469,6 +477,9 @@ sub discourse { $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); my $now=time; + my %lt=&Apache::lonlocal::texthash('cfa' => 'Check for All', + 'cfs' => 'Check for Section/Group', + 'cfn' => 'Check for None'); $r->print(< -  - +  +   - +

ENDDISHEADER my %coursepersonnel= @@ -545,7 +556,7 @@ ENDDISHEADER sub discrit { my $r=shift; - my $header = '

Critical Messages

'. + my $header = '

'.&mt('Critical Messages').'

'. '
'. ''; my %what=&Apache::lonnet::dump('critical'); @@ -554,23 +565,23 @@ sub discrit { my %content=&unpackagemsg($what{$_}); next if ($content{'senderdomain'} eq ''); $content{'message'}=~s/\n/\/g; - $result.='
From: '. + $result.='
'.&mt('From').': '. &Apache::loncommon::aboutmewrapper( &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('. $content{'sendername'}.'@'. $content{'senderdomain'}.') '.$content{'time'}. - '
Subject: '.$content{'subject'}. + '
'.&mt('Subject').': '.$content{'subject'}. '
'. &Apache::lontexconvert::msgtexconverted($content{'message'}). '
'. - ''. + ''. ''; + 'value="'.&mt('Confirm Receipt and Reply').'">'; } # Check to see if there were any messages. if ($result eq '') { - $result = "

You have no critical messages.

". - 'Select a course'; + $result = "

".&mt('You have no critical messages.')."

". + ''.&mt('Select a course').''; } else { $r->print($header); } @@ -592,26 +603,33 @@ sub comprep { &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('. $content{'sendername'}.'@'. $content{'senderdomain'}.')'; - my $subject='Re: '.$content{'subject'}; + my $subject=&mt('Re').': '.$content{'subject'}; my $dispcrit=''; if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message"); $dispcrit= - ' Send as critical message ' . $crithelp . + ' '.&mt('Send as critical message').' ' . $crithelp . '
'. - ' Send as critical message ' . - ' and return receipt' . $crithelp . '

'; + ' '.&mt('Send as critical message').' ' . + &mt('and return receipt') . $crithelp . '

'; } + my %lt=&Apache::lonlocal::texthash( + 'to' => 'To', + 'sb' => 'Subject', + 'sr' => 'Send Reply', + 'ca' => 'Cancel' + ); $r->print(<<"ENDREPLY"); - - -To: $torepl
-Subject:

-

+


$dispcrit - + + ENDREPLY } @@ -688,37 +706,37 @@ sub disall { } ENDDISHEADER - $r->print('

Display All Messages

print('

'.&mt('Display All Messages').'

'. ''); + $r->print(''.&mt('Date').''); } else { - $r->print('Date'); + $r->print(''.&mt('Date').''); } $r->print(''); + $r->print(''.&mt('Status').''); } else { - $r->print('Status'); + $r->print(''.&mt('Status').''); } $r->print(''); my @temp=sortedmessages(); @@ -735,8 +753,8 @@ ENDDISHEADER $r->print(''); } $r->print(''. + '">'.&mt('Open').''. '
 '); if ($ENV{'form.sortedby'} eq "revdate") { - $r->print('Date'); if ($ENV{'form.sortedby'} eq "revuser") { - $r->print('Username'); + $r->print(''.&mt('Username').''); } else { - $r->print('Username'); + $r->print(''.&mt('Username').''); } $r->print(''); if ($ENV{'form.sortedby'} eq "revdomain") { - $r->print('Domain'); + $r->print(''.&mt('Domain').''); } else { - $r->print('Domain'); + $r->print(''.&mt('Domain').''); } $r->print(''); if ($ENV{'form.sortedby'} eq "revsubject") { - $r->print('Subject'); + $r->print(''.&mt('Subject').''); } else { - $r->print('Subject'); + $r->print(''.&mt('Subject').''); } $r->print(''); if ($ENV{'form.sortedby'} eq "revstatus") { - $r->print('Status
OpenDelete'.&mt('Delete').''.&Apache::lonlocal::locallocaltime($sendtime).''. $fromname.''.$fromdomain.''. &Apache::lonnet::unescape($shortsubj).''. @@ -744,10 +762,10 @@ ENDDISHEADER } } $r->print('

'. - 'Check All '. - 'Uncheck All

'. + ''.&mt('Check All').' '. + ''.&mt('Uncheck All').'

'. ''. - ''. + ''. '

'); } @@ -758,25 +776,32 @@ sub compout { my $dispcrit=''; my $dissub=''; my $dismsg=''; - my $func='Send New'; - if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { + my $func=&mt('Send New'); + my %lt=&Apache::lonlocal::texthash('us' => 'Username', + 'do' => 'Domain', + 'ad' => 'Additional Recipients', + 'sb' => 'Subject', + 'ca' => 'Cancel', + 'ma' => 'Mail'); + + if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { my $crithelp = Apache::loncommon::help_open_topic("Course_Critical_Message"); $dispcrit= - ' Send as critical message ' . $crithelp . + ' '.&mt('Send as critical message').' ' . $crithelp . '
'. - ' Send as critical message ' . - ' and return receipt' . $crithelp . '

'; + ' '.&mt('Send as critical message').' ' . + &mt('and return receipt') . $crithelp . '

'; } if ($forwarding) { - $dispcrit.=''; - $func='Forward'; + $func=&mt('Forward'); my %message=&Apache::lonnet::get('nohist_email',[$forwarding]); my %content=&unpackagemsg($message{$forwarding}); - $dissub='Forwarding: '.$content{'subject'}; - $dismsg='Forwarded message from '. - $content{'sendername'}.' at '.$content{'senderdomain'}; + $dissub=&mt('Forwarding').': '.$content{'subject'}; + $dismsg=&mt('Forwarded message from').' '. + $content{'sendername'}.' '.&mt('at').' '.$content{'senderdomain'}; } my $defdom=$ENV{'user.domain'}; if ($ENV{'form.recdom'}) { $defdom=$ENV{'form.recdom'}; } @@ -791,28 +816,30 @@ sub compout { ('compemail','recuname','recdomain'); $r->print(<<"ENDREC"); - - + + ENDREC } my $latexHelp = Apache::loncommon::helpLatexCheatsheet(); if ($broadcast ne 'upload') { $r->print(<<"ENDCOMP"); - - +
Username:$selectlink
Domain:
$lt{'us'}:$selectlink
$lt{'do'}: $domform
Additional Recipients
username\@domain,username\@domain, ... +
$lt{'ad'}
username\@domain,username\@domain, ...
-
Subject: +
$lt{'sb'}:
$latexHelp -

+


$dispcrit - + + ENDCOMP } else { # $broadcast is 'upload' $r->print(< +

Generate messages from a file

Subject: @@ -861,15 +888,15 @@ sub disfacetoface { next if ($content{'senderdomain'} eq ''); $content{'message'}=~s/\n/\/g; if ($content{'subject'}=~/^Record/) { - $result.='

Record

'; + $result.='

'.&mt('Record').'

'; } else { - $result.='

Sent Message

'; + $result.='

'.&mt('Sent Message').'

'; %content=&unpackagemsg($content{'message'}); $content{'message'}= 'Subject: '.$content{'subject'}.'
'. $content{'message'}; } - $result.='By: '. + $result.=&mt('By').': '. &Apache::loncommon::aboutmewrapper( &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}),$content{'sendername'},$content{'senderdomain'}).' ('. $content{'sendername'}.'@'. @@ -955,7 +982,7 @@ sub handler { # ----------------------------------------------------------- Set document type - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK if $r->header_only; @@ -1000,32 +1027,32 @@ sub handler { $r->print(&Apache::loncommon::studentbrowser_javascript(). ''. &Apache::loncommon::bodytag('EMail and Messages')); - $r->print('Subject: '.$content{'subject'}. - '
From: '. + $r->print(''.&mt('Subject').': '.$content{'subject'}. + '
'.&mt('From').': '. &Apache::loncommon::aboutmewrapper( &Apache::loncommon::plainname($content{'sendername'},$content{'senderdomain'}), $content{'sendername'},$content{'senderdomain'}).' ('. $content{'sendername'}.' at '. $content{'senderdomain'}.') '. - '
Time: '.$content{'time'}.'

'. - ''. + '
'.&mt('Time').': '.$content{'time'}.'

'. + '

Functions:
'. ''. + '">'.&mt('Reply').''. ''. + '">'.&mt('Forward').''. ''. + '">'.&mt('Mark Unread').''. ''. ''); + '">'.&mt('Display all Messages').''); if ($counter > 0){ $r->print(''); + '">'.&mt('Previous').''); } if ($counter < $number_of_messages - 1){ $r->print(''); + '">'.&mt('Next').''); } $r->print('
'.&mt('Functions').':ReplyForwardMark UnreadDeleteDisplay all MessagesPreviousNext

'.
              &Apache::lontexconvert::msgtexconverted($content{'message'}).
@@ -1033,23 +1060,25 @@ $content{'sendername'},$content{'senderd
   } elsif ($ENV{'form.replyto'}) {
       &comprep($r,$ENV{'form.replyto'});
   } elsif ($ENV{'form.sendreply'}) {
-      my $msgid=$ENV{'form.sendreply'};
-      my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
-      my %content=&unpackagemsg($message{$msgid},1);
-      &statuschange($msgid,'replied');
-      if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
-          (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
-         $r->print('Sending critical: '.
-                &user_crit_msg($content{'sendername'},
-                                 $content{'senderdomain'},
-                                 &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
-                                 &Apache::lonfeedback::clear_out_html($ENV{'form.message'}),
-                                 $ENV{'form.sendbck'}));
-      } else {
-         $r->print('Sending: '.&user_normal_msg($content{'sendername'},
-                                 $content{'senderdomain'},
-                                 &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
-                                 &Apache::lonfeedback::clear_out_html($ENV{'form.message'})));
+      if ($ENV{'form.send'}) {
+	  my $msgid=$ENV{'form.sendreply'};
+	  my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
+	  my %content=&unpackagemsg($message{$msgid},1);
+	  &statuschange($msgid,'replied');
+	  if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && 
+	      (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
+	      $r->print(&mt('Sending critical message').': '.
+			&user_crit_msg($content{'sendername'},
+				       $content{'senderdomain'},
+				       &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
+				       &Apache::lonfeedback::clear_out_html($ENV{'form.message'}),
+				       $ENV{'form.sendbck'}));
+	  } else {
+	      $r->print(&mt('Sending').': '.&user_normal_msg($content{'sendername'},
+							     $content{'senderdomain'},
+							     &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}),
+							     &Apache::lonfeedback::clear_out_html($ENV{'form.message'})));
+	  }
       }
       if ($ENV{'form.displayedcrit'}) {
           &discrit($r);
@@ -1096,64 +1125,75 @@ $content{'sendername'},$content{'senderd
   } elsif ($ENV{'form.recordftf'}) {
       &facetoface($r,$ENV{'form.recordftf'});
   } elsif ($ENV{'form.sendmail'}) {
-      my %content=();
-      undef %content;
-      if ($ENV{'form.forwid'}) {
-        my $msgid=$ENV{'form.forwid'};
-        my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
-        %content=&unpackagemsg($message{$msgid},1);
-        &statuschange($msgid,'forwarded');
-        $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
-	                       $content{'message'};
+      my $sendstatus='';
+      if ($ENV{'form.send'}) {
+	  my %content=();
+	  undef %content;
+	  if ($ENV{'form.forwid'}) {
+	      my $msgid=$ENV{'form.forwid'};
+	      my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
+	      %content=&unpackagemsg($message{$msgid},1);
+	      &statuschange($msgid,'forwarded');
+	      $ENV{'form.message'}.="\n\n-- Forwarded message --\n\n".
+		  $content{'message'};
+	  }
+	  my %toaddr=();
+	  undef %toaddr;
+	  if ($ENV{'form.sendmode'} eq 'group') {
+	      foreach (keys %ENV) {
+		  if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) {
+		      $toaddr{$1}='';
+		  }
+	      }
+	  } elsif ($ENV{'form.sendmode'} eq 'upload') {
+	      foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) {
+		  my ($rec,$txt)=split(/\s*\:\s*/,$_);
+		  if ($txt) {
+		      $rec=~s/\@/\:/;
+		      $toaddr{$rec}.=$txt."\n";
+		  }
+	      }
+	  } else {
+	      $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}='';
+	  }
+	  if ($ENV{'form.additionalrec'}) {
+	      foreach (split(/\,/,$ENV{'form.additionalrec'})) {
+		  my ($auname,$audom)=split(/\@/,$_);
+		  $toaddr{$auname.':'.$audom}='';
+	      }
+	  }
+	  foreach (keys %toaddr) {
+	      my ($recuname,$recdomain)=split(/\:/,$_);
+	      my $msgtxt=&Apache::lonfeedback::clear_out_html($ENV{'form.message'});
+	      if ($toaddr{$_}) { $msgtxt.='
'.$toaddr{$_}; } + if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && + (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) { + $r->print(&mt('Sending critical message').' ...'); + $sendstatus.=' '.&user_crit_msg($recuname,$recdomain, + &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), + $msgtxt, + $ENV{'form.sendbck'}); + } else { + $r->print(&mt('Sending').' ...'); + $sendstatus.=' '.&user_normal_msg($recuname,$recdomain, + &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), + $msgtxt, + $content{'citation'}); + } + $r->print('
'); + } } - my %toaddr=(); - undef %toaddr; - if ($ENV{'form.sendmode'} eq 'group') { - foreach (keys %ENV) { - if ($_=~/^form\.send\_to\_\&\&\&[^\&]*\&\&\&\_(.+)$/) { - $toaddr{$1}=''; - } - } - } elsif ($ENV{'form.sendmode'} eq 'upload') { - foreach (split(/[\n\r\f]+/,$ENV{'form.upfile'})) { - my ($rec,$txt)=split(/\s*\:\s*/,$_); - if ($txt) { - $rec=~s/\@/\:/; - $toaddr{$rec}.=$txt."\n"; - } - } + if ($sendstatus=~/^(\s*(?:ok|con_delayed)\s*)*$/) { + if ($ENV{'form.displayedcrit'}) { + &discrit($r); + } else { + &disall($r); + } } else { - $toaddr{$ENV{'form.recuname'}.':'.$ENV{'form.recdomain'}}=''; - } - if ($ENV{'form.additionalrec'}) { - foreach (split(/\,/,$ENV{'form.additionalrec'})) { - my ($auname,$audom)=split(/\@/,$_); - $toaddr{$auname.':'.$audom}=''; - } - } - foreach (keys %toaddr) { - my ($recuname,$recdomain)=split(/\:/,$_); - my $msgtxt=&Apache::lonfeedback::clear_out_html($ENV{'form.message'}); - if ($toaddr{$_}) { $msgtxt.='
'.$toaddr{$_}; } - if ((($ENV{'form.critmsg'}) || ($ENV{'form.sendbck'})) && - (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) { - $r->print('Sending critical: '. - &user_crit_msg($recuname,$recdomain, - &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), - $msgtxt, - $ENV{'form.sendbck'})); - } else { - $r->print('Sending: '.&user_normal_msg($recuname,$recdomain, - &Apache::lonfeedback::clear_out_html($ENV{'form.subject'}), - $msgtxt, - $content{'citation'})); - } - $r->print('
'); - } - if ($ENV{'form.displayedcrit'}) { - &discrit($r); - } else { - &disall($r); + $r->print( + '

'.&mt('Could not deliver message').'

'. + &mt('Please use the browser "Back" button and correct the recipient addresses') + ); } } else { &disall($r);