From: lkehresman Date: Wed, 1 Dec 1999 18:22:30 +0000 (+0000) Subject: Bug fix in date sorting X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=0e9193688e63baac3636e58a909acb3a7483f5c8 Bug fix in date sorting git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@44 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/date.php b/functions/date.php index 4760d029..ea95e891 100644 --- a/functions/date.php +++ b/functions/date.php @@ -127,35 +127,35 @@ **/ /* 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]); } ?> diff --git a/functions/mailbox.php b/functions/mailbox.php index 83b77feb..49ccc0fa 100644 --- a/functions/mailbox.php +++ b/functions/mailbox.php @@ -20,10 +20,16 @@ } } + /** 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
"; exit; @@ -70,6 +76,12 @@ 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"); diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 84025faa..b9d8c23c 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -40,10 +40,13 @@ $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; @@ -90,10 +93,48 @@ // 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) { @@ -140,13 +181,30 @@ echo ""; echo ""; echo " "; - echo " "; + /** FROM HEADER **/ + echo " \n"; + else if ($sort == 3) + echo " \n"; + else + echo " \n"; + /** DATE HEADER **/ echo " \n"; - else + else if ($sort == 1) echo " \n"; - echo " \n"; + else + echo " \n"; + /** SUBJECT HEADER **/ + echo " \n"; + else if ($sort == 5) + echo " \n"; + else + echo " \n"; echo ""; // loop through and display the info for each message.
NumFromFrom"; + if ($sort == 2) + echo " Date"; if ($sort == 0) echo " SubjectSubject\n"; + if ($sort == 4) + echo "