+ /**
+ * Replace From => To in case it concerns a draft or sent folder
+ */
+ if (($mbx == $sent_folder || $mbx == $draft_folder) &&
+ !in_array(SQM_COL_TO,$aMailboxPref[MBX_PREF_COLUMNS])) {
+ $aNewOrder = array(); // nice var name ;)
+ foreach($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
+ if ($iCol == SQM_COL_FROM) {
+ $iCol = SQM_COL_TO;
+ }
+ $aNewOrder[] = $iCol;
+ }
+ $aMailboxPref[MBX_PREF_COLUMNS] = $aNewOrder;
+ setUserPref($username,'pref_'.$iAccount.'_'.$mbx,serialize($aMailboxPref));
+ }
+
+ $aConfig['search'] = $search['search'];
+ $aConfig['charset'] = $search['charset'];
+
+ /**
+ * Set the max cache size to the number of mailboxes to avoid cache cleanups
+ * when searching all mailboxes
+ */
+ $aConfig['max_cache_size'] = count($mboxes_mailbox) +1;
+ if (isset($startMessage) && $targetmailbox == $mbx) {
+ $aConfig['offset'] = $startMessage;
+ } else {
+ $aConfig['offset'] = 0;
+ }
+ if (isset($showall) && $targetmailbox == $mbx) {
+ $aConfig['showall'] = $showall;
+ } else {
+ if (isset($aConfig['showall'])) {
+ unset($aConfig['showall']);
+ }
+ $showall = false;
+ }
+
+ /**
+ * Set the config options for the messages list
+ */
+ $aColumns = array();
+ foreach ($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
+ $aColumns[$iCol] = array();
+ switch ($iCol) {
+ case SQM_COL_SUBJ:
+ if ($truncate_subject) {
+ $aColumns[$iCol]['truncate'] = $truncate_subject;
+ }
+ break;
+ case SQM_COL_FROM:
+ case SQM_COL_TO:
+ case SQM_COL_CC:
+ case SQM_COL_BCC:
+ if ($truncate_sender) {
+ $aColumns[$iCol]['truncate'] = $truncate_sender;
+ }
+ break;
+ }
+ }
+
+
+ $aProps = array(
+ 'columns' => $aColumns,
+ 'config' => array('alt_index_colors' => $alt_index_colors,
+ 'highlight_list' => $message_highlight_list,
+ 'fancy_index_highlite' => $fancy_index_highlite,
+ 'show_flag_buttons' => (isset($show_flag_buttons)) ? $show_flag_buttons : true,
+ 'lastTargetMailbox' => (isset($lastTargetMailbox)) ? $lastTargetMailbox : '',
+ 'trash_folder' => $trash_folder,
+ 'sent_folder' => $sent_folder,
+ 'draft_folder' => $draft_folder,
+ 'enablesort' => true,
+ 'color' => $color
+ ),
+ 'mailbox' => $mbx,
+ 'account' => (isset($iAccount)) ? $iAccount : 0,
+ 'module' => 'read_body',
+ 'email' => false);
+
+
+ $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mbx,$aConfig,$aMailboxPref);
+
+ $iError = 0;
+ $aTemplate = showMessagesForMailbox($imapConnection, $aMailbox,$aProps, $iError);
+
+ // in th future we can make use of multiple message sets, now set it to 1 for search.
+ $iSetIndex = 1;
+ if (isset($aMailbox['UIDSET'][$iSetIndex])) {
+ $iMsgCnt += count($aMailbox['UIDSET'][$iSetIndex]);
+ }
+ if ($iError) {
+ // error handling
+ } else {
+ /**
+ * In the future, move this the the initialisation area
+ */
+ sqgetGlobalVar('align',$align,SQ_SESSION);
+
+ $oTemplate = new Template($sTplDir);
+
+ if ($aMailbox['EXISTS'] > 0) {
+ if ($iError) {
+ // TODO
+ echo "ERROR occured, errorhandler will be implemented very soon";
+ } else {
+ foreach ($aTemplate as $k => $v) {
+ $oTemplate->assign($k, $v);
+ }
+ $oTemplate->assign('page_selector', $page_selector);
+ $oTemplate->assign('page_selector_max', $page_selector_max);
+ $oTemplate->assign('compact_paginator', $compact_paginator);
+ $oTemplate->assign('javascript_on', $javascript_on);
+ $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false);
+ // Aaaaaahhhhhhh FIX ME DO NOT USE the string "none" for a var when you mean the boolean false or null
+ $oTemplate->assign('icon_theme', (isset($icon_theme) && $icon_theme !== 'none') ? $icon_theme : false);
+ $oTemplate->assign('use_icons', (isset($use_icons)) ? $use_icons : false);
+ $oTemplate->assign('aOrder', array_keys($aColumns));
+ $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ? $alt_index_colors: false);
+ $oTemplate->assign('color', $color);
+ $oTemplate->assign('align', $align);
+
+ $mailbox_display = asearch_get_mailbox_display($aMailbox['NAME']);
+ if (strtoupper($mbx) == 'INBOX') {
+ $mailbox_display = _("INBOX");
+ } else {
+ $mailbox_display = imap_utf7_decode_local($mbx);
+ }
+
+ echo '<br /><b><big>' . _("Folder:") . ' '. htmlspecialchars($mailbox_display) . ' </big></b>';
+
+ $oTemplate->display('message_list.tpl');
+ }
+ }
+ }
+
+ /* add the mailbox to the cache */
+ $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
+
+ }
+ }
+ if(!$iMsgCnt) {
+ echo '<br />' . html_tag('div', asearch_get_error_display($color, _("No Messages Found")), 'center') . "\n";
+ }
+}