More cleanups.
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 23 May 2004 08:52:39 +0000 (08:52 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 23 May 2004 08:52:39 +0000 (08:52 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@7524 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/imap_mailbox.php
functions/imap_messages.php
functions/mailbox_display.php
src/read_body.php
src/right_main.php

index cd13eeb3915a31234a462f8df603728c47c159d1..13eab2d4d868c18907c3d77753023506c1d1d58b 100755 (executable)
@@ -249,53 +249,39 @@ function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true,
 
 
 /**
- * Expunge specified message, updated $msgs and $msort
+ * Expunge specified message
  *
- * Until Marc and I come up with a better way to maintain
- * these stupid arrays, we'll use this wrapper function to
+ * We'll use this wrapper function to
  * remove the message with the matching UID .. the order
  * won't be changed - the array element for the message
  * will just be removed.
  */
-function sqimap_mailbox_expunge_dmn($message_id, $aMbxResponse, &$server_sort_array)
-{
-    global $msgs, $msort, $sort, $imapConnection,
-           $mailbox, $auto_expunge,
-           $sort, $allow_server_sort, $thread_sort_messages, $allow_thread_sort,
-           $username, $data_dir;
-    $cnt = 0;
 
-    if (!isset($sort) || $sort === false) {
-        sqgetGlobalVar('sort',$sort,SQ_GET);
-    }
+function sqimap_mailbox_expunge_dmn($imapConnection, &$aMailbox, $message_id) {
+    $cnt = 0;
 
-    if ($auto_expunge) {
-         $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
+    if ($aMailbox['AUTO_EXPUNGE']) {
+         $cnt = sqimap_mailbox_expunge($imapConnection, $aMailbox['NAME'], true);
     } else {
          return $cnt;
     }
-
-    // Got to grab this out of prefs, since it isn't saved from mailbox_view.php
-    if ($allow_thread_sort && getPref($data_dir, $username, "thread_$mailbox",0)) {
-        $mode = 'THREAD';
-    } else if ($allow_server_sort) {
-        $mode = 'SERVER';
-    } else {
-        $mode = 'SQUIRREL';
-    }
     $error = '';
-    if (is_array($server_sort_array)) {
-        $key = array_search($message_id,$server_sort_array,true);
+    $message_id = (int) $message_id; // we use strickt array_search
+    if (is_array($aMailbox['UIDSET'])) {
+        $key = array_search($message_id,$aMailbox['UIDSET'],true);
         if ($key !== false) {
-            unset($server_sort_array[$key]);
-            $server_sort_array = array_values($server_sort_array);
+            unset($aMailbox['UIDSET'][$key]);
+            $aMailbox['UIDSET'] = array_values($aMailbox['UIDSET']);
+            // adapt the exists count to avoid triggering of a new sort
+            $aMailbox['EXISTS'] -= 1;
         } else {
-            $server_sort_array = get_sorted_msgs_list($imapConnection,$sort,$mode,$error);
+            $aMailbox['UIDSET'] = get_sorted_msgs_list($imapConnection,$aMailbox,$error);
         }
     } else {
-        $server_sort_array = get_sorted_msgs_list($imapConnection,$sort,$mode,$error);
+        $aMailbox['UIDSET'] = get_sorted_msgs_list($imapConnection,$aMailbox,$error);
     }
-    sqsession_register($server_sort_array,'server_sort_array');
+    sqsession_register($aMailbox,'aLastSelectedMailbox');
+    sqsession_register($aMailbox['UIDSET'],'server_sort_array'); //fix me, use aMailbox instead
     return $cnt;
 }
 
index 6dfb53b5807af8886dd8437a6f5ff41b0c0e3380..c321beb9240b47fa025c584ec2c23384100d5aef 100755 (executable)
@@ -137,7 +137,7 @@ function sqimap_message_list_squisher($messages_array) {
 * @param bool $reverse Reverse order search
 * @return array $id sorted uid list
 */
-function sqimap_get_sort_order ($imap_stream, $sSortField = 'UID',$reverse) {
+function sqimap_get_sort_order ($imap_stream, $sSortField,$reverse) {
     global  $default_charset,
             $sent_folder;
 
@@ -145,20 +145,6 @@ function sqimap_get_sort_order ($imap_stream, $sSortField = 'UID',$reverse) {
     $sort_test = array();
     $sort_query = '';
 
-    if ($sSortField == 'UID') {
-        $query = "SEARCH UID 1:*";
-        $uids = sqimap_run_command ($imap_stream, $query, true, $response, $message, true);
-        if (isset($uids[0])) {
-            if (preg_match("/^\* SEARCH (.+)$/", $uids[0], $regs)) {
-                $id = preg_split("/ /", trim($regs[1]));
-            }
-        }
-        if (!preg_match("/OK/", $response)) {
-            $id = false;
-        }
-        $id = array_reverse($id);
-        return $id;
-    }
     if ($sSortField) {
         if ($reverse) {
             $sSortField = 'REVERSE '.$sSortField;
@@ -190,25 +176,12 @@ function sqimap_get_sort_order ($imap_stream, $sSortField = 'UID',$reverse) {
 * @return array $aUid sorted uid list
 */
 function get_squirrel_sort ($imap_stream, $sSortField, $reverse = false) {
-
-    if ($sSortField == 'UID') {
-        // FIX ME: this is not needed. Try to find another way to solve this
-        $query = "SEARCH UID 1:*";
-        $uids = sqimap_run_command ($imap_stream, $query, true, $response, $message, true);
-        if (isset($uids[0])) {
-            if (preg_match("/^\* SEARCH (.+)$/", $uids[0], $regs)) {
-                $msgs = preg_split("/ /", trim($regs[1]));
-            }
-        }
-        if (!preg_match("/OK/", $response)) {
-            $msgs = false;
-        }
-    } else if ($sSortField != 'RFC822.SIZE' && $sSortField != 'INTERNALDATE') {
+    if ($sSortField != 'RFC822.SIZE' && $sSortField != 'INTERNALDATE') {
         $msgs = sqimap_get_small_header_list($imap_stream, false, '*',
-                                      array($sSortField), array('UID'));
+                                      array($sSortField), array());
     } else {
         $msgs = sqimap_get_small_header_list($imap_stream, false, '*',
-                                      array(), array('UID', $sSortField));
+                                      array(), array($sSortField));
     }
     $aUid = array();
     $walk = false;
index 1865b09553ff4d2bde0d432398a62a01b2d3e0e2..5871b33ff681e6d88e1968032f34e75009c2c814 100644 (file)
@@ -45,6 +45,7 @@ define('SQSORT_CC_ASC',11);
 define('SQSORT_CC_DEC',12);
 define('SQSORT_INT_DATE_ASC',13);
 define('SQSORT_INT_DATE_DEC',14);
+define('SQSORT_THREAD',42);
 /**
 * @param mixed $start UNDOCUMENTED
 */
@@ -70,15 +71,13 @@ function elapsed($start) {
 */
 
 function printMessageInfo($aMsg) {
+    // FIX ME, remove these globals as well by adding an array as argument for the user settings
+    // specificly meant for header display
     global $checkall,
-        $color, $td_str,
+        $color,
         $default_use_priority,
         $message_highlight_list,
         $index_order,
-        $indent_array,         /* indent subject by */
-        $pos,                  /* Search postion (if any)  */
-        $thread_sort_messages, /* thread sorting on/off */
-        $row_count,
         $truncate_sender,      /* number of characters for From/To field (<= 0 for unchanged) */
         $email_address,
         $show_recipient_instead,       /* show recipient name instead of default identity */
@@ -100,6 +99,7 @@ function printMessageInfo($aMsg) {
         $where = false;
         $what = false;
     }
+    $iIndent  = $aMsg['INDENT'];
 
     $sSubject = (isset($msg['SUBJECT']) && $msg['SUBJECT'] != '') ? $msg['SUBJECT'] : _("(no subject)");
     $sFrom    = (isset($msg['FROM'])) ? $msg['FROM'] : _("Unknown sender");
@@ -110,20 +110,19 @@ function printMessageInfo($aMsg) {
     $iSize    = (isset($msg['SIZE'])) ? $msg['SIZE'] : 0;
     $sType0   = (isset($msg['TYPE0'])) ? $msg['TYPE0'] : 'text';
     $sType1   = (isset($msg['TYPE1'])) ? $msg['TYPE1'] : 'plain';
-    $sDate    = (isset($msg['DATE'])) ? getDateString(getTimeStamp(explode(' ',$msg['DATE']))) : '';
+    if (isset($msg['INTERNALDATE'])) {
+       $sDate = getDateString(getTimeStamp(explode(' ',$msg['INTERNALDATE'])));
+    } else {
+       $sDate = (isset($msg['DATE'])) ? getDateString(getTimeStamp(explode(' ',$msg['DATE']))) : '';
+    }
     $iId      = (isset($msg['ID'])) ? $msg['ID'] : false;
 
-    sqgetGlobalVar('indent_array',$indent_array,SQ_SESSION);
     if (!$iId) {
         return;
     }
 
     if ($GLOBALS['alt_index_colors']) {
-        if (!isset($row_count)) {
-            $row_count = 0;
-        }
-        $row_count++;
-        if ($row_count % 2) {
+        if (!($t % 2)) {
             if (!isset($color[12])) {
                 $color[12] = '#EAEAEA';
             }
@@ -133,6 +132,10 @@ function printMessageInfo($aMsg) {
 
     $urlMailbox = urlencode($mailbox);
 
+    // FIXME, foldertype should be set in right_main.php
+    // in other words, handle as sent is obsoleted from now.
+    // We replace that by providing an array to aMailbox with the to shown headers
+    // that way we are free to show the user different layouts for different folders
     $bSentFolder = handleAsSent($mailbox);
     if ((!$bSentFolder) && ($show_recipient_instead)) {
         // If the From address is the same as $email_address, then handle as Sent
@@ -182,6 +185,14 @@ function printMessageInfo($aMsg) {
         $senderAddress = _("To:") . ' ' . $senderAddress;
     }
 
+    // this is a column property which can apply to multiple columns. Do not use vars for one column
+    // only. instead we should use something like this:
+    // 1ed column $aMailbox['columns']['SUBJECT'] value: aray with properties ...
+    // 2ed column $aMailbox['columns']['FROM'] value: aray with properties ...
+    //            NB in case of the sentfolder this could be the TO field
+    // properties array example:
+    //      'truncate' => length (0 is no truncate)
+    //      'prefix    => if (x in b then do that )
     if ($truncate_sender > 0) {
         $senderName = truncateWithEntities($senderName, $truncate_sender);
     }
@@ -190,8 +201,6 @@ function printMessageInfo($aMsg) {
     $bold = '<b>';
     $bold_end = '</b>';
 
-
-
     foreach ($aFlags as $sFlag => $value) {
         switch ($sFlag) {
           case '\\flagged':
@@ -273,11 +282,7 @@ function printMessageInfo($aMsg) {
     }
     $col = 0;
     $sSubject = str_replace('&nbsp;', ' ', decodeHeader($sSubject));
-    if (isset($indent_array[$iId])) { /* Thread sort */
-        $subject = processSubject($sSubject, $indent_array[$iId]);
-    } else {
-        $subject = processSubject($sSubject, 0);
-    }
+    $subject = processSubject($sSubject, $iIndent);
 
     echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
 
@@ -316,10 +321,8 @@ function printMessageInfo($aMsg) {
                 break;
             case 4: /* subject */
                 $td_str = $bold;
-                if ($thread_sort_messages == 1) {
-                    if (isset($indent_array[$iId])) {
-                        $td_str .= str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;",$indent_array[$iId]);
-                    }
+                if ($iIndent) {
+                    $td_str .= str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;",$iIndent);
                 }
                 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
                         .  '&amp;passed_id='. $msg["ID"]
@@ -487,16 +490,19 @@ function getSortField($sort,$bServerSort) {
         case SQSORT_INT_DATE_DEC:
             $sSortField = ($bServerSort) ? 'ARRIVAL' : 'INTERNALDATE';
             break;
-        default: $sSortField = 'DATE';
+        case SQSORT_THREAD:
             break;
+        default: $sSortField = 'UID';
+            break;
+
     }
     return $sSortField;
 }
 
-function get_sorted_msgs_list($imapConnection,$sort,$mode,&$error) {
-    $bDirection = ($sort % 2);
+function get_sorted_msgs_list($imapConnection,$aMailbox,&$error) {
+    $bDirection = ($aMailbox['SORT'] % 2);
     $error = false;
-    switch ($mode) {
+    switch ($aMailbox['SORT_METHOD']) {
       case 'THREAD':
         $id = get_thread_sort($imapConnection);
         if ($id === false) {
@@ -507,7 +513,7 @@ function get_sorted_msgs_list($imapConnection,$sort,$mode,&$error) {
         }
         break;
       case 'SERVER':
-        $sSortField = getSortField($sort,true);
+        $sSortField = getSortField($aMailbox['SORT'],true);
         $id = sqimap_get_sort_order($imapConnection, $sSortField, $bDirection);
         if ($id === false) {
             $error =  '<b><small><center><font color=red>' .
@@ -517,7 +523,7 @@ function get_sorted_msgs_list($imapConnection,$sort,$mode,&$error) {
         }
         break;
       default:
-        $sSortField = getSortField($sort,false);
+        $sSortField = getSortField($aMailbox['SORT'],false);
         $id = get_squirrel_sort($imapConnection, $sSortField, $bDirection);
         break;
     }
@@ -532,12 +538,15 @@ function get_sorted_msgs_list($imapConnection,$sort,$mode,&$error) {
 * @param array $aMailbox associative array with mailbox related vars
 */
 function showMessagesForMailbox($imapConnection, $aMailbox) {
-    global $msgs, $server_sort_array;
+    global $msgs, $server_sort_array,$indent_array;
 
     // to retrieve the internaldate pref: (I know this is not the right place to do that, move up in front
     // and use a properties array as function argument to provide user preferences
     global $data_dir, $username;
 
+    // retrieve indent array for thread sort
+
+
     /* if there's no messages in this folder */
     if ($aMailbox['EXISTS'] == 0) {
         $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
@@ -576,7 +585,7 @@ function showMessagesForMailbox($imapConnection, $aMailbox) {
         if ($internaldate) {
             $aFetchItems[] = 'INTERNALDATE';
         }
-        if ($aMailbox['SORT'] === SQSORT_NONE) {
+        if ($aMailbox['SORT'] == SQSORT_NONE) {
             /**
              * retrieve messages by sequence id's and fetch the UID to retrieve
              * the UID. for sorted lists this is not needed because a UID FETCH
@@ -591,15 +600,17 @@ function showMessagesForMailbox($imapConnection, $aMailbox) {
         * SM internal sorting
         */
 
-        if ($aMailbox['SORT'] !== SQSORT_NONE && isset($aMailbox['UIDSET']) && //['SORT_ARRAY']) &&
-                      $aMailbox['UIDSET'] ) {//is_array($mbxresponse['SORT_ARRAY'])) {
-            $id = $aMailbox['UIDSET'];//$mbxresponse['SORT_ARRAY'];
+        if ($aMailbox['SORT'] != SQSORT_NONE && isset($aMailbox['UIDSET']) &&
+                      $aMailbox['UIDSET'] ) {
+            $id = $aMailbox['UIDSET'];
             if (sqsession_is_registered('msgs')) {
                 sqsession_unregister('msgs');
             }
             $id_slice = array_slice($id,$start_msg-1,$aMailbox['LIMIT']);
             if (count($id_slice)) {
-                $msgs = sqimap_get_small_header_list($imapConnection,$id_slice,$aMailbox['LIMIT']);
+                $msgs = sqimap_get_small_header_list($imapConnection,$id_slice,$aMailbox['LIMIT'],
+                                                     $aHeaderFields,$aFetchItems);
+
             } else {
                 return false;
             }
@@ -609,8 +620,9 @@ function showMessagesForMailbox($imapConnection, $aMailbox) {
             if (sqsession_is_registered('server_sort_array')) {
                 sqsession_unregister('server_sort_array');
             }
-            if ($aMailbox['SORT'] !== SQSORT_NONE) {
-                $id = get_sorted_msgs_list($imapConnection,$aMailbox['SORT'],$aMailbox['SORT_METHOD'],$error);
+
+            if ($aMailbox['SORT'] != SQSORT_NONE  || $aMailbox['SORT_METHOD'] == 'THREAD') {
+                $id = get_sorted_msgs_list($imapConnection,$aMailbox,$error);
                 if ($id !== false) {
                     $id_slice = array_slice($id,$aMailbox['OFFSET'], $aMailbox['LIMIT']);
                     if (count($id_slice)) {
@@ -644,16 +656,19 @@ function showMessagesForMailbox($imapConnection, $aMailbox) {
         }
         $aMailbox['UIDSET'] =& $id;
         $aMailbox['MSG_HEADERS'] =& $msgs;
+        if ($aMailbox['SORT_METHOD'] == 'THREAD') {
+            sqgetGlobalVar('indent_array',$indent_array,SQ_SESSION);
+            $aMailbox['THREAD_INDENT'] =& $indent_array;
+        }
     } /* if exists > 0 */
 
-    $res = getEndMessage($aMailbox['PAGEOFFSET'], $aMailbox['LIMIT'], $aMailbox['EXISTS']);
-    //    $start_msg = $res[0];
-    $end_msg   = $res[1];
+    $iEnd = ($aMailbox['PAGEOFFSET'] + ($aMailbox['LIMIT'] - 1) < $aMailbox['EXISTS']) ?
+             $aMailbox['PAGEOFFSET'] + $aMailbox['LIMIT'] - 1 : $aMailbox['EXISTS'];
 
-    $paginator_str = get_paginator_str($aMailbox['NAME'], $aMailbox['PAGEOFFSET'], $end_msg,
+    $paginator_str = get_paginator_str($aMailbox['NAME'], $aMailbox['PAGEOFFSET'], $iEnd,
                                     $aMailbox['EXISTS'], $aMailbox['LIMIT'], $aMailbox['SORT']);
 
-    $msg_cnt_str = get_msgcnt_str($aMailbox['PAGEOFFSET'], $aMailbox['PAGEOFFSET']+$aMailbox['LIMIT'],$aMailbox['EXISTS']);
+    $msg_cnt_str = get_msgcnt_str($aMailbox['PAGEOFFSET'], $iEnd,$aMailbox['EXISTS']);
 
     do_hook('mailbox_index_before');
 ?>
@@ -712,7 +727,12 @@ function displayMessageArray($imapConnection, $aMailbox) {
     $iPageOffset = $aMailbox['PAGEOFFSET'];
     $sMailbox    = $aMailbox['NAME'];
     $aSearch     = (isset($aMailbox['SEARCH'])) ? $aMailbox['SEARCH'] : false;
-
+    if ($aMailbox['SORT_METHOD'] == 'THREAD') {
+        $aIndentArray =& $aMailbox['THREAD_INDENT'];
+        $bThread = true;
+    } else {
+        $bThread = false;
+    }
     /*
     * Loop through and display the info for each message.
     * ($t is used for the checkbox number)
@@ -722,6 +742,11 @@ function displayMessageArray($imapConnection, $aMailbox) {
         if (isset($aId[$i])) {
             $bLast = ((isset($aId[$i+1]) && isset($aHeaders[$aId[$i+1]]))
                                  || ($i == $iEnd )) ? false : true;
+            if ($bThread) {
+               $indent = (isset($aIndentArray[$aId[$i]])) ? $aIndentArray[$aId[$i]] : 0;
+            } else {
+               $indent = 0;
+            }
             $aMsg = array(
                       'HEADER'     => $aHeaders[$aId[$i]],
                       'INDX'       => $t,
@@ -730,6 +755,7 @@ function displayMessageArray($imapConnection, $aMailbox) {
                       'SORT'       => $sort,
                       'SEARCH'     => $aSearch,
                       'MAILBOX'    => $sMailbox,
+                      'INDENT'     => $indent,
                       'LAST'       => $bLast
                     );
             printMessageInfo($aMsg);
@@ -882,7 +908,8 @@ function mail_message_listing_beginning ($imapConnection,
 }
 
 /**
-* FIXME: Undocumented function
+* Function to add the last row in a message list, it contains the paginator and info about
+* the number of messages.
 *
 * @param integer $num_msgs number of messages in a mailbox
 * @param string  $paginator_str Paginator string  [Prev | Next]  [ 1 2 3 ... 91 92 94 ]  [Show all]
@@ -1442,29 +1469,6 @@ function getSmallStringCell($string, $align) {
                     'nowrap' );
 }
 
-/**
-* FIXME: Undocumented function
-*
-* @param integer $start_msg
-* @param integer $show_num
-* @param integer $num_msgs
-*/
-function getEndMessage($start_msg, $show_num, $num_msgs) {
-    if ($start_msg + ($show_num - 1) < $num_msgs){
-        $end_msg = $start_msg + ($show_num - 1);
-    } else {
-        $end_msg = $num_msgs;
-    }
-
-    if ($end_msg < $start_msg) {
-        $start_msg = $start_msg - $show_num;
-        if ($start_msg < 1) {
-            $start_msg = 1;
-        }
-    }
-    return (array($start_msg,$end_msg));
-}
-
 /**
 * This should go in imap_mailbox.php
 * @param string $mailbox
index 75f478e8b25468586756934d8c46ac6d32a0a78c..fde71ed722babcaf0d3ed38331462b024a8f6dd2 100644 (file)
@@ -37,16 +37,20 @@ require_once(SM_PATH . 'functions/mailbox_display.php');
  * @param int $passed_id The current message UID
  * @return the index of the next valid message from the array
  */
-function findNextMessage($passed_id) {
-    global $server_sort_array;
+function findNextMessage($uidset,$passed_id='backwards') {
+    if ($passed_id=='backwards' || !is_array($uidset)) { // check for backwards compattibilty gpg plugin
+        $passed_id = $uidset;
+        sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
+        $uidset = $server_sort_array;
+    }
     $result = -1;
-    $count = count($server_sort_array) - 1;
-    foreach($server_sort_array as $key=>$value) {
+    $count = count($uidset) - 1;
+    foreach($uidset as $key=>$value) {
         if ($passed_id == $value) {
             if ($key == $count) {
                 break;
             }
-            $result = $server_sort_array[$key + 1];
+            $result = $uidset[$key + 1];
             break;
         }
     }
@@ -60,13 +64,17 @@ function findNextMessage($passed_id) {
  * @param int $passed_id The current message UID
  * @return the index of the next valid message from the array
  */
-function findPreviousMessage($numMessages, $passed_id) {
-    global $server_sort_array;
+
+function findPreviousMessage($uidset, $passed_id) {
+    if (!is_array($uidset)) { //obsolete check
+        sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
+        $uidset = $server_sort_array;
+    }
     $result = -1;
-    foreach($server_sort_array as $key=>$value) {
+    foreach($uidset as $key=>$value) {
         if ($passed_id == $value) {
             if ($key != 0) {
-                $result = $server_sort_array[$key - 1];
+                $result = $uidset[$key - 1];
             }
             break;
         }
@@ -359,12 +367,14 @@ function formatRecipientString($recipients, $item ) {
     return $string;
 }
 
-function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
+function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
                          $color, $FirstTimeSee) {
     global $msn_user_support, $default_use_mdn, $default_use_priority,
            $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
           $squirrelmail_language;
 
+    $mailbox = $aMailbox['NAME']       ;
+
     $header = $message->rfc822_header;
     $env = array();
     $env[_("Subject")] = str_replace("&nbsp;"," ",decodeHeader($header->subject));
@@ -448,13 +458,16 @@ function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
  * @param object $message Current message object
  * @param object $mbx_response
  */
-function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
+function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
     global $base_uri, $draft_folder, $where, $what, $color, $sort,
            $startMessage, $PHP_SELF, $save_as_draft,
            $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
            $data_dir, $username, $delete_prev_next_display,
            $compose_new_win, $javascript_on;
 
+    //FIXME cleanup argument list, use $aMailbox where possible
+    $mailbox = $aMailbox['NAME'];
+
     $topbar_delimiter = '&nbsp;|&nbsp;';
     $double_delimiter = '&nbsp;&nbsp;&nbsp;&nbsp;';
     $urlMailbox = urlencode($mailbox);
@@ -513,8 +526,8 @@ function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_resp
 
     // Prev/Next links for regular messages
     } else if ( !(isset($where) && isset($what)) ) {
-        $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
-        $next = findNextMessage($passed_id);
+        $prev = findPreviousMessage($aMailbox['UIDSET'], $passed_id);
+        $next = findNextMessage($aMailbox['UIDSET'],$passed_id);
 
         $prev_link = _("Previous");
         if ($prev >= 0) {
@@ -788,13 +801,31 @@ global $sqimap_capabilities, $lastTargetMailbox;
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
 $mbx_response   = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
 
+global $allow_thread_sort, $auto_expunge;
+
+if ($allow_thread_sort && getPref($data_dir, $username, "thread_$mailbox",0)) {
+    $aMailbox['SORT_METHOD'] = 'THREAD';
+} else if ($allow_server_sort) {
+    $aMailbox['SORT_METHOD'] = 'SERVER';
+} else {
+    $aMailbox['SORT_METHOD'] = 'SQUIRREL';
+}
+sqgetGlobalVar('aLastSelectedMailbox',$aMailbox,SQ_SESSION);
+$aMailbox['UIDSET'] = $server_sort_array;
+$aMailbox['SORT'] = $sort;
+$aMailbox['NAME'] = $mailbox;
+$aMailbox['EXISTS'] = $mbx_response['EXISTS'];
+$aMailbox['AUTO_EXPUNGE'] = $auto_expunge;
+$aMailbox['MSG_HEADERS'] = $msgs;
+
+
 /**
  * Process Delete from delete-move-next
  * but only if delete_id was set
  */
 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
     sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
-    sqimap_mailbox_expunge_dmn($delete_id,$mbx_response,$server_sort_array);
+    sqimap_mailbox_expunge_dmn($imapConnection,$aMailbox,$delete_id);
 }
 
 /**
@@ -876,8 +907,8 @@ for ($i = 0; $i < $cnt; $i++) {
 }
 
 displayPageHeader($color, $mailbox);
-formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
-formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
+formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
+formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
 echo '  <tr><td>';
 echo '    <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
index f77c21aa1b1a4e0246e783d6af9d35fd3bf528bb..47f488a380b2f8c9ab662d64aa26489ac5119814 100644 (file)
@@ -54,11 +54,10 @@ sqgetGlobalVar('base_uri',  $base_uri,      SQ_SESSION);
 
 sqgetGlobalVar('mailbox',   $mailbox);
 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
-sqgetGlobalVar('numMessages'      , $numMessages,       SQ_SESSION);
+sqgetGlobalVar('sort'             , $sort,              SQ_SESSION);
 sqgetGlobalVar('session',           $session,           SQ_GET);
 sqgetGlobalVar('note',              $note,              SQ_GET);
 sqgetGlobalVar('mail_sent',         $mail_sent,         SQ_GET);
-sqgetGlobalVar('use_mailbox_cache', $use_mailbox_cache, SQ_GET);
 
 if ( sqgetGlobalVar('startMessage', $temp) ) {
   $startMessage = (int) $temp;
@@ -84,7 +83,7 @@ if ( !sqgetGlobalVar('composenew', $composenew, SQ_GET) ) {
 /* end of get globals */
 
 
-/* Open a connection on the imap port (143) */
+/* Open an imap connection */
 
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
 
@@ -102,32 +101,22 @@ if (isset($PG_SHOWALL)) {
 else if( isset( $PG_SHOWNUM ) ) {
     $show_num = $PG_SHOWNUM;
 }
+$mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX';
+/* compensate for the UW vulnerability. */
+if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
+                                  substr($mailbox, 0, 1) == '/')) {
+   $mailbox = 'INBOX';
+}
 
 if (isset($newsort) ) {
-    if ( $newsort != $sort )
+    if ( $newsort != $sort ) {
         setPref($data_dir, $username, 'sort', $newsort);
-
+    }
+    $oldsort = $sort;
     $sort = $newsort;
     sqsession_register($sort, 'sort');
 }
 
-/* If the page has been loaded without a specific mailbox, */
-/* send them to the inbox                                  */
-//if (!isset($mailbox)) {
-//    $mailbox = 'INBOX';
-//    $startMessage = 1;
-//}
-
-//if (!isset($startMessage) || ($startMessage == '')) {
-//    $startMessage = 1;
-//}
-
-/* compensate for the UW vulnerability. */
-if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
-                                  substr($mailbox, 0, 1) == '/')) {
-   $mailbox = 'INBOX';
-}
-
 do_hook ('generic_header');
 
 $aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox);
@@ -145,16 +134,25 @@ if (!isset($aMbxResponse['UIDNEXT']) || !isset($aMbxResponse['UIDVALIDITY'])) {
     $aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY'];
 }
 
-if ($aLastSelectedMailbox && !isset($newsort)) {
+if ($aLastSelectedMailbox) {
     // check if we deal with the same mailbox
     if ($aLastSelectedMailbox['NAME'] == $mailbox) {
        if ($aLastSelectedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] &&
            $aLastSelectedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] &&
            $aLastSelectedMailbox['UIDNEXT']  == $aMbxResponse['UIDNEXT']) {
-           // sort is still valid
            sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
            if ($server_sort_array && is_array($server_sort_array)) {
                $aMbxResponse['SORT_ARRAY'] = $server_sort_array;
+               // check if oldsort can be used in case we changed the sort order of the same column
+               if (isset($newsort) ) {
+                    if ((($newsort % 2) && ($newsort + 1 == $oldsort)) ||
+                        (!($newsort % 2) && ($newsort - 1 == $oldsort))) {
+                        $server_sort_array = array_reverse($server_sort_array);
+                    } else {
+                        $server_sort_array = false;
+                    }
+               }
+               $aMbxResponse['SORT_ARRAY'] = $server_sort_array;
            }
        }
     }
@@ -168,7 +166,7 @@ $aLastSelectedMailbox['PERMANENTFLAGS'] = $aMbxResponse['PERMANENTFLAGS'];
 $aLastSelectedMailbox['OFFSET'] = (isset($startMessage) && $startMessage) ? $startMessage -1 : 0;
 $aLastSelectedMailbox['PAGEOFFSET'] = (isset($startMessage) && $startMessage) ? $startMessage : 1;
 $aLastSelectedMailbox['SORT'] = ($sort !== false) ? $sort : 0;
-$aLastSelectedMailbox['LIMIT'] = $show_num;
+$aLastSelectedMailbox['LIMIT'] = ($show_num != 999999) ? $show_num : $aMbxResponse['EXISTS'];
 
 $aLastSelectedMailbox['UIDSET'] = $aMbxResponse['SORT_ARRAY'];
 $aLastSelectedMailbox['SEEN'] = (isset($aMbxResponse['SEEN'])) ? $aMbxResponse['SEEN'] : $aMbxResponse['EXISTS'];
@@ -246,52 +244,8 @@ if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) {
     }
 }
 
+showMessagesForMailbox($imapConnection,$aLastSelectedMailbox);
 
-/*********************************************************************
- * Check to see if we can use cache or not. Currently the only time  *
- * when you will not use it is when a link on the left hand frame is *
- * used. Also check to make sure we actually have the array in the   *
- * registered session data.  :)                                      *
- *********************************************************************/
-if (! isset($use_mailbox_cache)) {
-    $use_mailbox_cache = 0;
-}
-
-if ($use_mailbox_cache && sqsession_is_registered('msgs')) {
-    showMessagesForMailbox($imapConnection,$aLastSelectedMailbox);
-//    showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
-//                           $startMessage, $sort, $color, $show_num,
-//                           $use_mailbox_cache, '',$aMbxResponse);
-} else {
-    if (sqsession_is_registered('msgs')) {
-        unset($msgs);
-    }
-
-    if (sqsession_is_registered('msort')) {
-        unset($msort);
-    }
-
-    if (sqsession_is_registered('numMessages')) {
-        unset($numMessages);
-    }
-
-    $numMessages = $aMbxResponse['EXISTS'];
-
-    showMessagesForMailbox($imapConnection,$aLastSelectedMailbox);
-//    showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
-//                           $startMessage, $sort, $color, $show_num,
-//                           $use_mailbox_cache,'',$aMbxResponse);
-
-    if (sqsession_is_registered('msgs') && isset($msgs)) {
-        sqsession_register($msgs, 'msgs');
-    }
-
-    if (sqsession_is_registered('msort') && isset($msort)) {
-        sqsession_register($msort, 'msort');
-    }
-
-    sqsession_register($numMessages, 'numMessages');
-}
 do_hook('right_main_bottom');
 sqimap_logout ($imapConnection);
 echo '</body></html>';