Bug fix in date sorting
authorlkehresman <lkehresman@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 1 Dec 1999 18:22:30 +0000 (18:22 +0000)
committerlkehresman <lkehresman@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 1 Dec 1999 18:22:30 +0000 (18:22 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@44 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/date.php
functions/mailbox.php
functions/mailbox_display.php

index 4760d02..ea95e89 100644 (file)
        **/
 
       /* if the first part is a day */
-      if (eregi("mon|tue|wed|thu|fri|sat|sun", $dateParts[0], $tmp)) {
-         $dateParts[0] = getDayOfWeek($dateParts[0]);
-         $dateParts[1] = getDayOfMonth($dateParts[1]);
-         $dateParts[2] = getMonth($dateParts[2]);
-         $dateParts[3] = getYear($dateParts[3]);
+      if (eregi("mon|tue|wed|thu|fri|sat|sun", trim($dateParts[0]), $tmp)) {
+         $dateParts[0] = getDayOfWeek(trim($dateParts[0]));
+         $dateParts[1] = getDayOfMonth(trim($dateParts[1]));
+         $dateParts[2] = getMonth(trim($dateParts[2]));
+         $dateParts[3] = getYear(trim($dateParts[3]));
          return "$dateParts[2] $dateParts[1], $dateParts[3]";
       }
-      $dateParts[0] = getDayOfMonth($dateParts[0]);
-      $dateParts[1] = getMonth($dateParts[1]);
-      $dateParts[2] = getYear($dateParts[2]);
+      $dateParts[0] = getDayOfMonth(trim($dateParts[0]));
+      $dateParts[1] = getMonth(trim($dateParts[1]));
+      $dateParts[2] = getYear(trim($dateParts[2]));
       return "$dateParts[1] $dateParts[0], $dateParts[2]";
    }
 
    function getTimeStamp($dateParts) {
       if (eregi("mon|tue|wed|thu|fri|sat|sun", $dateParts[0], $tmp)) {
-         $d[0] = getHour($dateParts[4]);
-         $d[1] = getMinute($dateParts[4]);
-         $d[2] = getSecond($dateParts[4]);
-         $d[3] = getMonthNum($dateParts[2]);
-         $d[4] = getDayOfMonth($dateParts[1]);
-         $d[5] = getYear($dateParts[3]);
+         $d[0] = getHour(trim($dateParts[4]));
+         $d[1] = getMinute(trim($dateParts[4]));
+         $d[2] = getSecond(trim($dateParts[4]));
+         $d[3] = getMonthNum(trim($dateParts[2]));
+         $d[4] = getDayOfMonth(trim($dateParts[1]));
+         $d[5] = getYear(trim($dateParts[3]));
          return mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]);
       }
-      $d[0] = getHour($dateParts[3]);
-      $d[1] = getMinute($dateParts[3]);
-      $d[2] = getSecond($dateParts[3]);
-      $d[3] = getMonthNum($dateParts[1]);
-      $d[4] = getDayOfMonth($dateParts[0]);
-      $d[5] = getYear($dateParts[2]);
+      $d[0] = getHour(trim($dateParts[3]));
+      $d[1] = getMinute(trim($dateParts[3]));
+      $d[2] = getSecond(trim($dateParts[3]));
+      $d[3] = getMonthNum(trim($dateParts[1]));
+      $d[4] = getDayOfMonth(trim($dateParts[0]));
+      $d[5] = getYear(trim($dateParts[2]));
       return mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]);
    }
 ?>
index 83b77fe..49ccc0f 100644 (file)
       }
    }
 
+   /**  This function sends a request to the IMAP server for headers, 50 at a time
+    **  until $end is reached.  I originally had it do them all at one time, but found
+    **  it slightly faster to do it this way.
+    **
+    **  Originally we had getMessageHeaders get the headers for one message at a time.
+    **  Doing it in bunches gave us a speed increase from 9 seconds (for a box of 800
+    **  messages) to about 3.5 seconds.
+    **/
    function getMessageHeaders($imapConnection, $start, $end, &$from, &$subject, &$date) {
-
       $rel_start = $start;
-
       if (($start > $end) || ($start < 1)) {
          echo "Error in message header fetching.  Start message: $start, End message: $end<BR>";
          exit;
       fputs($imapConnection, "messageStore STORE $i:$q +FLAGS (\\$flag)\n");
    }
 
+   /**  This function gets the flags for message $j.  It does only one message at a
+    **  time, rather than doing groups of messages (like getMessageHeaders does).
+    **  I found it one or two seconds quicker (on a box of 800 messages) to do it
+    **  individually.  I'm not sure why it happens like that, but that's what my
+    **  testing found.  Perhaps later I will be proven wrong and this will change.
+    **/
    function getMessageFlags($imapConnection, $j, &$flags) {
       /**   * 2 FETCH (FLAGS (\Answered \Seen))   */
       fputs($imapConnection, "messageFetch FETCH $j:$j FLAGS\n");
index 84025fa..b9d8c23 100644 (file)
 
       $j = 0;
       while ($j < $numMessages) {
-         $messages[$j]["TIME_STAMP"] = getTimeStamp(explode(" ", trim($date[$j])));
-         $messages[$j]["DATE_STRING"] = getDateString(explode(" ", trim($date[$j])));
+         $date[$j] = ereg_replace("  ", " ", $date[$j]);
+         $tmpdate = explode(" ", trim($date[$j]));
+
+         $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
+         $messages[$j]["DATE_STRING"] = getDateString($tmpdate);
          $messages[$j]["ID"] = $j+1;
-         $messages[$j]["FROM"] = $from[$j];
+         $messages[$j]["FROM"] = getSenderName($from[$j]);
          $messages[$j]["SUBJECT"] = $subject[$j];
          $messages[$j]["FLAG_DELETED"] = false;
          $messages[$j]["FLAG_ANSWERED"] = false;
 
       // There's gotta be messages in the array for it to sort them.
       if ($numMessages > 0) {
+         /** 0 = Date (up)      4 = Subject (up)
+          ** 1 = Date (dn)      5 = Subject (dn)
+          ** 2 = Name (up)
+          ** 3 = Name (dn)
+          **/
          if ($sort == 0)
             $msgs = ary_sort($msgs, "TIME_STAMP", -1);
-         else
+         else if ($sort == 1)
             $msgs = ary_sort($msgs, "TIME_STAMP", 1);
+         else {
+            $original = $msgs;
+            $i = 0;
+            while ($i < count($msgs)) {
+               $msgs[$i]["FROM"] = strtolower($msgs[$i]["FROM"]);
+               $msgs[$i]["SUBJECT"] = strtolower($msgs[$i]["SUBJECT"]);
+               $i++;
+            }
+
+            if ($sort == 2)
+               $msgs = ary_sort($msgs, "FROM", -1);
+            else if ($sort == 3)
+               $msgs = ary_sort($msgs, "FROM", 1);
+            else if ($sort == 4)
+               $msgs = ary_sort($msgs, "SUBJECT", -1);
+            else if ($sort == 5)
+               $msgs = ary_sort($msgs, "SUBJECT", 1);
+            else
+               $msgs = ary_sort($msgs, "TIME_STAMP", -1);
+
+            $i = 0;
+            while ($i < count($msgs)) {
+               $j = 0;
+               while ($j < count($original)) {
+                  if ($msgs[$i]["ID"] == $original[$j]["ID"]) {
+                     $msgs[$i]["FROM"] = $original[$j]["FROM"];
+                     $msgs[$i]["SUBJECT"] = $original[$j]["SUBJECT"];
+                  }
+                  $j++;
+               }
+               $i++;
+            }
+         }
       }
 
       if ($startMessage + 24 < $numMessages) {
       echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=FFFFFF>";
       echo "<TR BGCOLOR=FFFFCC ALIGN=\"center\">";
       echo "   <TD WIDTH=5%><FONT FACE=\"Arial,Helvetica\"><B>Num</B></FONT></TD>";
-      echo "   <TD WIDTH=25%><FONT FACE=\"Arial,Helvetica\"><B>From</B></FONT></TD>";
+      /** FROM HEADER **/
+      echo "   <TD WIDTH=25%><FONT FACE=\"Arial,Helvetica\"><B>From</B></FONT>";
+      if ($sort == 2)
+         echo "   <A HREF=\"right_main.php?sort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
+      else if ($sort == 3)
+         echo "   <A HREF=\"right_main.php?sort=2&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
+      else
+         echo "   <A HREF=\"right_main.php?sort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
+      /** DATE HEADER **/
       echo "   <TD WIDTH=15%><FONT FACE=\"Arial,Helvetica\"><B>Date</B></FONT>";
       if ($sort == 0)
          echo "   <A HREF=\"right_main.php?sort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
-      else
+      else if ($sort == 1)
          echo "   <A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
-      echo "   <TD WIDTH=*><FONT FACE=\"Arial,Helvetica\"><B>Subject</B></FONT></TD>\n";
+      else
+         echo "   <A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
+      /** SUBJECT HEADER **/
+      echo "   <TD WIDTH=*><FONT FACE=\"Arial,Helvetica\"><B>Subject</B></FONT>\n";
+      if ($sort == 4)
+         echo "   <A HREF=\"right_main.php?sort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
+      else if ($sort == 5)
+         echo "   <A HREF=\"right_main.php?sort=4&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
+      else
+         echo "   <A HREF=\"right_main.php?sort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
       echo "</TR>";
 
       // loop through and display the info for each message.