From c3731db510a99031918324062045e4883fb53df4 Mon Sep 17 00:00:00 2001 From: stekkel Date: Tue, 8 Nov 2005 22:26:37 +0000 Subject: [PATCH] Fix for situation when mailbox cache was invalidated while iterating through 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 | 93 ++++++++++++++++++----------------- src/read_body.php | 60 ++++++++++++++++++---- 2 files changed, 100 insertions(+), 53 deletions(-) diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index b0dae7b2..8a6b608c 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -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) { diff --git a/src/read_body.php b/src/read_body.php index 1b484286..e15be367 100644 --- a/src/read_body.php +++ b/src/read_body.php @@ -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); } -- 2.25.1