[LON-CAPA-cvs] cvs: loncom /interface lonfeedback.pm lonmsg.pm lonmsgdisplay.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Fri, 06 Jun 2008 05:24:28 -0000


This is a MIME encoded message

--raeburn1212729868
Content-Type: text/plain

raeburn		Fri Jun  6 01:24:28 2008 EDT

  Modified files:              
    /loncom/interface	lonmsg.pm lonmsgdisplay.pm lonfeedback.pm 
  Log:
  Bugs: 3706 5677 5678.
  - Single attachment allowed in messages (whether sent via COM or FDBK).
  - Warning displayed if uploaded file exceeded maximum size allowed for attachments (and was therefors discarded).
  - Attachments included in forwarded messages (from both single message display, or from forward of multiple messages from folder display).
  - Max size definition moved to a single location in lonmsgdisplay.pm and lonfeedback.pm
  - Some appearance changes in modify_attachments display (for attachements associated with discussion posts).
  - Subdirectory for storage of attachment file in sender's userfiles directory changed from feedback to feedback/$now (i.e., current UNIX time) to lessen likelihood of file being overwritten by a sequent message with an attachment of the same name.       
  
  
--raeburn1212729868
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080606012428.txt"

Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.211 loncom/interface/lonmsg.pm:1.212
--- loncom/interface/lonmsg.pm:1.211	Tue Mar 11 22:45:07 2008
+++ loncom/interface/lonmsg.pm	Fri Jun  6 01:24:28 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging
 #
-# $Id: lonmsg.pm,v 1.211 2008/03/12 02:45:07 raeburn Exp $
+# $Id: lonmsg.pm,v 1.212 2008/06/06 05:24:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -179,9 +179,17 @@
 
 sub get_course_context {
     my $course_context;
+    my $msgkey;
     if (defined($env{'form.replyid'})) {
+        $msgkey = $env{'form.replyid'};
+    } elsif (defined($env{'form.forwid'})) {
+        $msgkey = $env{'form.forwid'}
+    } elsif (defined($env{'form.multiforwid'})) {
+        $msgkey = $env{'form.multiforwid'};
+    }
+    if ($msgkey ne '') {
         my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
-                   split(/\:/,&unescape($env{'form.replyid'}));
+                   split(/\:/,&unescape($msgkey));
         $course_context = $origcid;
     }
     foreach my $key (keys(%env)) {
@@ -201,7 +209,7 @@
 # ================================================== Unpack message into a hash
 
 sub unpackagemsg {
-    my ($message,$notoken)=@_;
+    my ($message,$notoken,$noattachmentlink)=@_;
     my %content=();
     my $parser=HTML::TokeParser->new(\$message);
     my $token;
@@ -221,7 +229,7 @@
        }
     }
     if (!exists($content{'recuser'})) { $content{'recuser'} = []; }
-    if ($content{'attachmenturl'}) {
+    if (($content{'attachmenturl'}) && (!$noattachmentlink)) {
        my ($fname)=($content{'attachmenturl'}=~m|/([^/]+)$|);
        if ($notoken) {
 	   $content{'message'}.='<p>'.&mt('Attachment').': <tt>'.$fname.'</tt>';
@@ -499,7 +507,7 @@
 
 sub user_crit_msg_raw {
     my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
-        $nosentstore,$recipid)=@_;
+        $nosentstore,$recipid,$attachmenturl)=@_;
 # Check if allowed missing
     my ($status,$packed_message);
     my $msgid='undefined';
@@ -508,8 +516,8 @@
     my $homeserver=&Apache::lonnet::homeserver($user,$domain);
     if ($homeserver ne 'no_host') {
        ($msgid,$packed_message)=&packagemsg($subject,$message,undef,undef,
-                                  undef,undef,undef,undef,undef,undef,undef,
-                                  undef,$recipid);
+                                  $attachmenturl,undef,undef,undef,undef,undef,
+                                  undef,undef,$recipid);
        if ($sendback) { $packed_message.='<sendback>true</sendback>'; }
        $status=&Apache::lonnet::cput('critical', {$msgid => $packed_message},
 				     $domain,$user);
@@ -518,8 +526,8 @@
         }
         if (!$nosentstore) {
             (undef,my $packed_message_no_citation) =
-            &packagemsg($subject,$message,undef,undef,undef,$user,$domain,
-                        $msgid);
+            &packagemsg($subject,$message,undef,undef,$attachmenturl,$user,
+                        $domain,$msgid);
             if ($status eq 'ok' || $status eq 'con_delayed') {
                 &store_sent_mail($msgid,$packed_message_no_citation);
             }
@@ -553,7 +561,7 @@
 
 =pod
 
-=item * B<user_crit_msg($user, $domain, $subject, $message, $sendback, $nosentstore,$recipid)>: 
+=item * B<user_crit_msg($user, $domain, $subject, $message, $sendback, $nosentstore,$recipid,$attachmenturl)>: 
     Sends a critical message $message to the $user at $domain.  If $sendback
     is true,  a receipt will be sent to the current user when $user receives 
     the message.
@@ -570,7 +578,7 @@
 
 sub user_crit_msg {
     my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage,
-        $nosentstore,$recipid)=@_;
+        $nosentstore,$recipid,$attachmenturl)=@_;
     my @status;
     my %userenv = &Apache::lonnet::get('environment',['msgforward'],
                                        $domain,$user);
@@ -581,12 +589,13 @@
          push(@status,
 	      &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
 				 $sendback,$toperm,$sentmessage,$nosentstore,
-                                 $recipid));
+                                 $recipid,$attachmenturl));
        }
     } else { 
 	push(@status,
 	     &user_crit_msg_raw($user,$domain,$subject,$message,$sendback,
-				$toperm,$sentmessage,$nosentstore,$recipid));
+				$toperm,$sentmessage,$nosentstore,$recipid,
+                                $attachmenturl));
     }
     if (wantarray) {
 	return @status;
Index: loncom/interface/lonmsgdisplay.pm
diff -u loncom/interface/lonmsgdisplay.pm:1.85 loncom/interface/lonmsgdisplay.pm:1.86
--- loncom/interface/lonmsgdisplay.pm:1.85	Fri Feb 22 13:08:35 2008
+++ loncom/interface/lonmsgdisplay.pm	Fri Jun  6 01:24:28 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging display
 #
-# $Id: lonmsgdisplay.pm,v 1.85 2008/02/22 18:08:35 bisitz Exp $
+# $Id: lonmsgdisplay.pm,v 1.86 2008/06/06 05:24:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1210,6 +1210,7 @@
     my $dissub='';
     my $dismsg='';
     my $disbase='';
+    my $attachrow;
     my $func=&mt('Send New');
     my %lt=&Apache::lonlocal::texthash('us'  => 'Username',
 				       'do'  => 'Domain',
@@ -1224,7 +1225,15 @@
                                        'gmt' => 'General message text',
                                        'tff' => 'The file format for the uploaded portion of the message is',
                                        'uas' => 'Upload and Send',
+                                       'atta' => 'Attachment',
                                       );
+    my %attachmax = (
+                     text => '(128 KB max size)',
+                     num  => 131072,
+                    );
+    if (!$forwarding && !$multiforward) {
+        $attachrow = '<br />'.$lt{'atta'}.' '.$attachmax{'text'}.': <input type="file" name="attachment" />';
+    }
     if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
 	|| &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
 				    '/'.$env{'request.course.sec'})) {
@@ -1418,7 +1427,10 @@
 </table>
 $latexHelp
 <textarea name="message" id="message" cols="80" rows="15" wrap="hard">$dismsg
-</textarea></p><br />
+</textarea>
+$attachrow
+</p>
+<br />
 $dispcrit
 $disbase
 ENDCOMP
@@ -2392,6 +2404,8 @@
     my %msg_status;
     my $numsent = 0;
     my $nosentstore = 1;
+    my $attachmenturl;
+    my $now = time;
     my ($cdom,$cnum,$group);
     if (exists($env{'form.group'})) {
         $group = $env{'form.group'};
@@ -2414,10 +2428,13 @@
 	if ($env{'form.forwid'}) {
 	    my $msgid=$env{'form.forwid'};
 	    my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
-	    %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
+	    %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1,1);
 	    &statuschange($msgid,'forwarded',$folder);
-	    $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
-		$content{'message'};
+            if ($content{'attachmenturl'} ne '') {
+                $attachmenturl = $content{'attachmenturl'};
+            }
+	    $env{'form.message'} .= "\n\n-- Forwarded message --\n\n".
+		                    $content{'message'};
 	}
 	if ($env{'form.replyid'}) {
 	    my $msgid=$env{'form.replyid'};
@@ -2516,7 +2533,18 @@
                                        $env{'user.domain'},\%reciphash);
         if ($recipstatus ne 'ok') {
             &Apache::lonnet::logthis('Failed to store Bcc and Cc recipients for '.$env{'user.name'}.':'.$env{'user.domain'});
-        }  
+        }
+        if ($env{'form.attachment'}) {
+            if (length($env{'form.attachment'})<131072) {
+                $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback/'.$now);
+            } else {
+                $r->print('<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>');
+            }
+        } elsif ($env{'form.multiforward'}) {
+            if ($env{'form.attachmenturl'} ne '') {
+                $attachmenturl = $env{'form.attachmenturl'};
+            }
+        }
         my @recusers;
         my @recudoms;
 	foreach my $address (sort(keys(%toaddr))) {
@@ -2542,7 +2570,7 @@
 		    &Apache::lonmsg::user_normal_msg($recuname,$recdomain,
 						     $msgsubj,$msgtxt,
 						     $content{'citation'},
-						     undef,undef,
+						     undef,$attachmenturl,
 						     $env{'form.permanent'},
 						     \$sentmessage{$address},
                                                      undef,undef,undef,
@@ -2575,7 +2603,7 @@
                 $specialresult = 
                     &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
                         $subj_prefix.' '.$course_str,$savemsg,undef,undef,
-                        undef,undef,undef,\$specialmsgid,undef,undef,undef,
+                        $attachmenturl,undef,undef,\$specialmsgid,undef,undef,undef,
                         undef,undef,1);
                 $specialmsgid = &unescape($specialmsgid);
                 if ($specialresult eq 'ok') {
@@ -2592,7 +2620,7 @@
 							    $pid);
                             &Apache::lonmsg::user_normal_msg_raw($cnum,$cdom,
                                 $subj_prefix.' ['.$recipient.']',$msgsubj,
-                                undef,undef,undef,undef,$usermsgid,undef,
+                                undef,undef,$attachmenturl,undef,$usermsgid,undef,
                                 undef,$specialmsgid,undef,undef,undef,1);
                         }
                     }
@@ -2600,7 +2628,7 @@
                         &Apache::lonmsg::process_sent_mail($msgsubj,
                            $subj_prefix,$numsent,$stamp,$msgname,$msgdom,
                            $msgcount,$context,$pid,$savemsg,\@recusers,
-                           \@recudoms);
+                           \@recudoms,undef,$attachmenturl);
                     }
                 } else {
                     &Apache::lonnet::logthis('Failed to create record of critical, broadcast or archived message in '.$env{'course.'.$env{'request.course.id'}.'.num'}.' '&mt('at').' '.$env{'course.'.$env{'request.course.id'}.'.domain'}.' - no msgid generated');
@@ -2612,7 +2640,7 @@
                 &Apache::lonmsg::process_sent_mail($msgsubj,$subj_prefix,
                        $numsent,$stamp,$env{'user.name'},
                        $env{'user.domain'},$msgcount,$context,
-                       $$,$savemsg,\@recusers,\@recudoms);
+                       $$,$savemsg,\@recusers,\@recudoms,undef,$attachmenturl);
             }
         }
         if (!$env{'form.multiforward'}) { 
@@ -2864,7 +2892,7 @@
             foreach my $item (@to_forward) {
                 my $msgid=&unescape($item);
                 my %message=&Apache::lonnet::get('nohist_email'.$suffix,[$msgid]);
-                my %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1);
+                my %content=&Apache::lonmsg::unpackagemsg($message{$msgid},1,1);
                 if ($env{'form.showorigsubj'}) {
                     $env{'form.subject'} = $fixed_subj.$content{'subject'};
                 } else {
@@ -2878,8 +2906,10 @@
                         &Apache::loncommon::plainname($uname,$udom).' ('.
                                            $uname.':'.$udom.')';
                 }
-                $env{'form.message'} .= "\n\n-- Forwarded message --\n\n".
-                                        $content{'message'};
+                $env{'form.message'}.="\n\n-- Forwarded message --\n\n".
+                                      $content{'message'};
+                $env{'form.attachmenturl'} = $content{'attachmenturl'};
+                $env{'form.multiforwid'} = $item;
                 $fwdcount ++;
                 $r->print($fwdcount.': '); 
                 $sendresult{$msgid} = &sendoffmail($r,$folder);
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.254 loncom/interface/lonfeedback.pm:1.255
--- loncom/interface/lonfeedback.pm:1.254	Wed Jun  4 20:15:24 2008
+++ loncom/interface/lonfeedback.pm	Fri Jun  6 01:24:28 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.254 2008/06/05 00:15:24 bisitz Exp $
+# $Id: lonfeedback.pm,v 1.255 2008/06/06 05:24:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1472,7 +1472,7 @@
 }
 
 sub mail_screen {
-  my ($r,$feedurl,$options,$caller_symb) = @_;
+  my ($r,$feedurl,$options,$caller_symb,$attachmaxtext) = @_;
   if (exists($env{'form.origpage'})) {
       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss','blog','group','ref']);
   }
@@ -1482,7 +1482,7 @@
             'myqu' => 'My question/comment/feedback:',
             'title' => 'Title',
             'reta' => 'Retained attachments',
-            'atta' => 'Attachment (128 KB max size)',
+            'atta' => 'Attachment',
            );
   my $restitle = &get_resource_title($caller_symb,$feedurl);
   my $quote='';
@@ -1721,7 +1721,7 @@
         }
     } else {
         $r->print(<<END);
-$lt{'atta'}: <input type="file" name="attachment" />
+$lt{'atta'} $attachmaxtext: <input type="file" name="attachment" />
 </p>
 END
     }
@@ -2391,7 +2391,7 @@
 }
 
 sub redirect_back {
-  my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group) = @_;
+  my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group,$toolarge) = @_;
   my $sorttag = '';
   my $roletag = '';
   my $statustag = '';
@@ -2505,6 +2505,7 @@
 $typestyle
 <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
 $blog
+$toolarge
 <font color="red">$status</font>
 <form name="reldt" action="$feedurl" target="loncapaclient">
 $prevtag
@@ -2932,7 +2933,8 @@
 }
 
 sub modify_attachments {
-    my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls)=@_;
+    my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls,
+        $attachmaxtext,$toolarge)=@_;
 
     my %lt = &Apache::lonlocal::texthash(
                'subj' => 'Subject',
@@ -2974,10 +2976,12 @@
 				       
     $r->print(<<END);
 $start_page
+$toolarge
 <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
- <table border="2">
+ <br />
+ <table class="LC_data_table">
   <tr>
-   <td>
+   <td colspan="2">
     <b>Subject:</b> $subject</b><br /><br />
 END
     if ($idx) {
@@ -3003,9 +3007,15 @@
         $r->print("<br />"); 
     }
     $r->print(<<END);
-   $lt{'adda'}&nbsp;<input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onClick="this.form.submit()" />    
+   </td></tr>
+   <tr>
+    <td>
+   $lt{'adda'}</td><td><input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onClick="this.form.submit()" />    
    </td>
   </tr>
+  <tr>
+   <td colspan="2">$attachmaxtext</td>
+  </tr>
  </table>
 <input type="hidden" name="subject" value="$env{'form.subject'}" />
 <input type="hidden" name="comment" value="$env{'form.comment'}" />
@@ -3288,6 +3298,10 @@
   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
          ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']);
   my $group = $env{'form.group'};
+  my %attachmax = (
+                    text => '(128 KB max size)',
+                    num  => 131072,
+                  );
   if ($env{'form.editdisc'}) {
       if (!(&editing_allowed($env{'form.editdisc'},$env{'form.group'}))) {
           my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
@@ -3596,13 +3610,15 @@
       &Apache::loncommon::content_type($r,'text/html');
       $r->send_http_header;
       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','discuss','blog']);
-      my (@currnewattach,@currdelold,@keepold);
+      my (@currnewattach,@currdelold,@keepold,$toolarge);
       &process_attachments(\@currnewattach,\@currdelold,\@keepold);
       if (exists($env{'form.addnewattach.filename'})) {
-          unless (length($env{'form.addnewattach'})>131072) {
+          if (length($env{'form.addnewattach'})<=$attachmax{'num'}) {
               my $subdir = 'feedback/'.$env{'form.timestamp'};
               my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
 	      push(@currnewattach, $newattachment);
+          } else {
+              $toolarge = '<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>';
           }
       }
       my $attachmenturls;
@@ -3615,7 +3631,7 @@
           $attachmenturls = $contrib{$idx.':attachmenturl'};
       }
       &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,
-			  $attachmenturls);
+			  $attachmenturls,$attachmax{'text'},$toolarge);
       return OK;
   } elsif ($env{'form.export'}) {
       &Apache::loncommon::content_type($r,'text/html');
@@ -3704,7 +3720,7 @@
           }
 	  my $options=&screen_header($feedurl,$symb);
 	  if ($options) {
-	      &mail_screen($r,$feedurl,$options,$symb);
+	      &mail_screen($r,$feedurl,$options,$symb,$attachmax{'text'});
 	  } else {
 	      &fail_redirect($r,$feedurl);
 	  }
@@ -3730,6 +3746,7 @@
       &Apache::lonnet::delenv('allowed.vgr');
 # Get attachments, if any, and not too large
       my $attachmenturl='';
+      my $toolarge='';
       if (($env{'form.origpage'}) || ($env{'form.editdisc'}) ||
 	  ($env{'form.replydisc'})) {
 	  my ($symb,$idx);
@@ -3748,9 +3765,13 @@
 	  $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
 	  $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
       } elsif ($env{'form.attachment.filename'}) {
-	  unless (length($env{'form.attachment'})>131072) {
-	      $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
-	  }
+	  if (length($env{'form.attachment'})<=$attachmax{'num'}) {
+              my $now = time;
+              my $subdir = 'feedback/'.$now;
+	      $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,$subdir);
+	  } else {
+              $toolarge = '<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>';
+          }
       }
 # Filter HTML out of message (could be nasty)
       my $message=&clear_out_html($env{'form.comment'});
@@ -3793,7 +3814,7 @@
       }
 	  
 # Receipt screen and redirect back to where came from
-      &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'},undef,undef,undef,undef,undef,undef,$group);
+      &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'},undef,undef,undef,undef,undef,undef,$group,$toolarge);
   }
   return OK;
 }

--raeburn1212729868--