Fix for situation when mailbox cache was invalidated while iterating through
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 8 Nov 2005 22:26:37 +0000 (22:26 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 8 Nov 2005 22:26:37 +0000 (22:26 +0000)
the messages with the next/prev links from read_body.php

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

functions/mailbox_display.php
src/read_body.php

index b0dae7b2371ac7d342e571b0709cf402dfd790d5..8a6b608ce25946182c8d4a24ab0831d188e6b07f 100644 (file)
@@ -105,6 +105,7 @@ function sqm_api_mailbox_select($imapConnection,$account,$mailbox,$aConfig,$aPro
     $aMailbox['UIDSET'][$iSetIndx] = false;
     $aMailbox['ID'] = false;
     $aMailbox['SETINDEX'] = $iSetIndx;
+    $aMailbox['MSG_HEADERS'] = false;
 
     if ($aCachedMailbox) {
         /**
@@ -601,8 +602,8 @@ function prepareMessageList(&$aMailbox, $aProps) {
                                          'answered'=>false,
                                          'flagged' => false,
                                          'draft' => false);
-                                         
-                    if(!is_array($value)) $value = array();                     
+
+                    if(!is_array($value)) $value = array();
                     foreach ($value as $sFlag => $value) {
                         switch ($sFlag) {
                           case '\\seen'    : $aFlagColumn['seen']     = true; break;
@@ -798,7 +799,52 @@ function _getSortField($sort,$bServerSort) {
     return $sSortField;
 }
 
+function calcFetchColumns(&$aMailbox, &$aProps) {
+
+    $highlight_list    = (isset($aProps['config']['highlight_list'])) ? $aProps['config']['highlight_list'] : false;
+    $aColumnsDesc      = (isset($aProps['columns'])) ? $aProps['columns'] : false;
+
+    $aFetchColumns = $aColumnsDesc;
+    if (isset($aFetchColumns[SQM_COL_CHECK])) {
+        unset($aFetchColumns[SQM_COL_CHECK]);
+    }
+
+    /*
+     * Before we fetch the message headers, check if we need to fetch extra columns
+     * to make the message highlighting work
+     */
+    if (is_array($highlight_list) && count($highlight_list)) {
+        $aHighlightColumns = array();
+        foreach ($highlight_list as $highlight_list_part) {
+            if (trim($highlight_list_part['value'])) {
+                $match_type = strtoupper($highlight_list_part['match_type']);
+                switch ($match_type) {
+                    case 'TO_CC':
+                        $aHighlightColumns[SQM_COL_TO] = true;
+                        $aHighlightColumns[SQM_COL_CC] = true;
+                        break;
+                    case 'TO':     $aHighlightColumns[SQM_COL_TO] = true; break;
+                    case 'CC':     $aHighlightColumns[SQM_COL_CC] = true; break;
+                    case 'FROM':   $aHighlightColumns[SQM_COL_FROM] = true; break;
+                    case 'SUBJECT':$aHighlightColumns[SQM_COL_SUBJ] = true; break;
+                }
+            }
+        }
+        $aExtraColumns = array();
+        foreach ($aHighlightColumns as $k => $v) {
+            if (!isset($aFetchColumns[$k])) {
+                $aExtraColumns[]  = $k;
+                $aFetchColumns[$k] = true;
+            }
+        }
+        if (count($aExtraColumns)) {
+            $aProps['extra_columns'] = $aExtraColumns;
+        }
+    }
+    $aMailbox['FETCHHEADERS'] =  array_keys($aFetchColumns);
 
+    ;
+}
 
 
 /**
@@ -844,50 +890,9 @@ function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) {
     } else {
         ++$iFormId;
     }
-    /*
-     * Remove the checkbox column because we cannot fetch it from the imap server
-     */
-    $aFetchColumns = $aColumnsDesc;
-    if (isset($aFetchColumns[SQM_COL_CHECK])) {
-        unset($aFetchColumns[SQM_COL_CHECK]);
-    }
-
-    /*
-     * Before we fetch the message headers, check if we need to fetch extra columns
-     * to make the message highlighting work
-     */
-    if (is_array($highlight_list) && count($highlight_list)) {
-        $aHighlightColumns = array();
-        foreach ($highlight_list as $highlight_list_part) {
-            if (trim($highlight_list_part['value'])) {
-                $match_type = strtoupper($highlight_list_part['match_type']);
-                switch ($match_type) {
-                    case 'TO_CC':
-                        $aHighlightColumns[SQM_COL_TO] = true;
-                        $aHighlightColumns[SQM_COL_CC] = true;
-                        break;
-                    case 'TO':     $aHighlightColumns[SQM_COL_TO] = true; break;
-                    case 'CC':     $aHighlightColumns[SQM_COL_CC] = true; break;
-                    case 'FROM':   $aHighlightColumns[SQM_COL_FROM] = true; break;
-                    case 'SUBJECT':$aHighlightColumns[SQM_COL_SUBJ] = true; break;
-                }
-            }
-        }
-        $aExtraColumns = array();
-        foreach ($aHighlightColumns as $k => $v) {
-            if (!isset($aFetchColumns[$k])) {
-                $aExtraColumns[]  = $k;
-                $aFetchColumns[$k] = true;
-            }
-        }
-        if (count($aExtraColumns)) {
-            $aProps['extra_columns'] = $aExtraColumns;
-        }
-    }
-    $aFetchColumns = array_keys($aFetchColumns);
     // store the columns to fetch so we can pick them up in read_body
     // where we validate the cache.
-    $aMailbox['FETCHHEADERS'] = $aFetchColumns;
+    calcFetchColumns($aMailbox  ,$aProps);
 
     $iError = fetchMessageHeaders($imapConnection, $aMailbox);
     if ($iError) {
index 1b484286b3758573cc6b76acdbded1e23fc02efb..e15be367f74b0803cb593dee27b1e9c0de12eeb3 100644 (file)
@@ -29,7 +29,7 @@ require_once(SM_PATH . 'functions/html.php');
 require_once(SM_PATH . 'functions/global.php');
 require_once(SM_PATH . 'functions/identity.php');
 include_once(SM_PATH . 'functions/arrays.php');
-require_once(SM_PATH . 'functions/mailbox_display.php');
+include_once(SM_PATH . 'functions/mailbox_display.php');
 
 /**
  * Given an IMAP message id number, this will look it up in the cached
@@ -826,15 +826,57 @@ global $sqimap_capabilities, $lastTargetMailbox;
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
 $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mailbox,array('setindex' => $what, 'offset' => $startMessage),array());
 
+
+/**
+ Start code to set the columns to fetch in case of hitting the next/prev link
+ The reason for this is the fact that the cache can be invalidated which means that the headers
+ to fetch aren't there anymore. Before they got calculated when the messagelist was shown.
+
+ Todo, better central handling of setting the mailbox options so we do not need to do the stuff below
+*/
+
+/**
+ * Replace From => To  in case it concerns a draft or sent folder
+ */
+if (($mailbox == $sent_folder || $mailbox == $draft_folder) &&
+    !in_array(SQM_COL_TO,$index_order)) {
+    $aNewOrder = array(); // nice var name ;)
+    foreach($index_order as $iCol) {
+        if ($iCol == SQM_COL_FROM) {
+            $iCol = SQM_COL_TO;
+        }
+        $aNewOrder[] = $iCol;
+   }
+   $aColumns = $aNewOrder;
+} else {
+   $aColumns = $index_order;
+}
+
+$aProps = array(
+    'columns' => $aColumns, // columns bound settings
+    'config'  => array(
+                        'highlight_list'        => $message_highlight_list, // row highlighting rules
+                        'trash_folder'          => $trash_folder,
+                        'sent_folder'           => $sent_folder,
+                        'draft_folder'          => $draft_folder));
+
+calcFetchColumns($aMailbox,$aProps);
+
 /**
-    * Check if cache is still valid, $what contains the key
-    * which gives us acces to the array with uid's. At this moment
-    * 0 is used for a normal message list and search uses 1 as key. This can be
-    * changed / extended in the future.
-    * If on a select of a mailbox we detect that the cache should be invalidated due to
-    * the delete of messages or due to new messages we empty the list with uid's and
-    * that's what we detect below.
-    */
+ End code to set the columns to fetch in case of hitting the next/prev link
+*/
+
+
+
+/**
+ * Check if cache is still valid, $what contains the key
+ * which gives us acces to the array with uid's. At this moment
+ * 0 is used for a normal message list and search uses 1 as key. This can be
+ * changed / extended in the future.
+ * If on a select of a mailbox we detect that the cache should be invalidated due to
+ * the delete of messages or due to new messages we empty the list with uid's and
+ * that's what we detect below.
+ */
 if (!is_array($aMailbox['UIDSET'][$what])) {
     fetchMessageHeaders($imapConnection, $aMailbox);
 }