* HTML cleaned up a bit
authorfidian <fidian@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 3 Mar 2001 16:20:31 +0000 (16:20 +0000)
committerfidian <fidian@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 3 Mar 2001 16:20:31 +0000 (16:20 +0000)
* Allows for multiple attachments, guaranteed.

Apparently, GenerateRandomString was producing the exact same string for a
second file attached.  This would of course overwrite the currently existing
attachment in both the $attachments array and on disk.  The first one would
be gone.

The code (two lines) fixes this by checking if that $localfilename is
already defined in $attachments, and will generate a new $localfilename if
it does.

What I can't figure out is how in the world did GenerateRandomString produce
the exact same string with two completely different page requests.  We
generate a key based on the time, remote user's information, and Apache's
unique ID that it sends along.  Also, it was supposed to generate 32
characters of lowercase, uppercase, and numbers.  That creates a string with
62^32 different possibilities.  That seems pretty wide open, but apparently
it caused problems.  Well, problems are solved now by simply checking if the
string was used already.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1162 7612ce4b-ef26-0410-bec9-ea0150e637f0

src/compose.php

index abb60da22ca6ceaf3632a460fc0e53c6245433c6..d9110e2ca63851ae1899bb4f3d4394e767f9374b 100644 (file)
    include("../src/load_prefs.php");
 
    if (!isset($attachments))
+   {
        $attachments = array();
-
+   }
+   
    // This function is used when not sending or adding attachments
    function newMail () {
       global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
       }
       
       // This code is for attachments
-      echo "   <tr>\n";
-      echo "     <TD BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n";
-      echo "      <SMALL><BR></SMALL>"._("Attach:");
-      echo "      </td><td ALIGN=left BGCOLOR=\"$color[0]\">\n";
+      echo "   <tr bgcolor=\"$color[0]\">\n";
+      echo "     <TD VALIGN=TOP ALIGN=RIGHT>"._("Attach:");
+      echo "      </td><td ALIGN=left>\n";
       echo "      <INPUT NAME=\"attachfile\" SIZE=48 TYPE=\"file\">\n";
       echo "      &nbsp;&nbsp;<input type=\"submit\" name=\"attach\"";
       echo " value=\"" . _("Add") ."\">\n";
       echo "     </td>\n";
       echo "   </tr>\n";
       if (count($attachments) > 0) {
-         echo "<tr><td bgcolor=\"$color[0]\" align=right>\n";
+         echo "<tr bgcolor=\"$color[0]\"><td align=right>\n";
          echo "&nbsp;";
-         echo "</td><td align=left bgcolor=\"$color[0]\">";
-         while (list($localname, $remotename) = each($attachments)) {
+         echo "</td><td align=left>";
+        foreach ($attachments as $localname => $remotename) {
             echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$localname\">\n";
             echo "$remotename <input type=\"hidden\" name=\"attachments[$localname]\" value=\"$remotename\"><br>\n";
          }
       
       is_logged_in();
       $localfilename = GenerateRandomString(32, '', 7);
+      while (isset($attachments[$localfilename]))
+          $localfilename = GenerateRandomString(32, '', 7);
       
       if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) {
          if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) {