function fix_sort_array() { global $username, $data_dir, $allow_server_sort, $allow_thread_sort, $thread_sort_messages, $mailbox, $imapConnection, $sort, $uid_support, $mbx_response; // Got to grab this out of prefs, since it isn't saved from mailbox_view.php if ($allow_thread_sort) { $thread_sort_messages = getPref($data_dir, $username, "thread_{$mailbox}", 0); } switch (true) { case $allow_thread_sort && $thread_sort_messages: $server_sort_array = get_thread_sort($imapConnection); break; case $allow_server_sort: $server_sort_array = sqimap_get_sort_order($imapConnection, $sort, $mbx_response); break; case $uid_support: $server_sort_array = sqimap_get_php_sort_order($imapConnection, $mbx_response); break; default: break; } }
function get_sorted_msgs_list($imapConnection, &$aMailbox, &$error) { $iSetIndx = isset($aMailbox['SETINDEX']) ? $aMailbox['SETINDEX'] : 0; $bDirection = $aMailbox['SORT'] % 2; $error = false; if (!$aMailbox['SEARCH'][$iSetIndx]) { $aMailbox['SEARCH'][$iSetIndx] = 'ALL'; } switch ($aMailbox['SORT_METHOD']) { case 'THREAD': $aRes = get_thread_sort($imapConnection, $aMailbox['SEARCH'][$iSetIndx]); if ($aRes === false) { $error = '<b><small><center><font color=red>' . _("Thread sorting is not supported by your IMAP server.") . '<br />' . _("Please contact your system administrator and report this error.") . '</center></small></b>'; $aMailbox['SORT'] -= SQSORT_THREAD; } else { $aMailbox['UIDSET'][$iSetIndx] = $aRes[0]; $aMailbox['THREAD_INDENT'][$iSetIndx] = $aRes[1]; } break; case 'SERVER': $sSortField = getSortField($aMailbox['SORT'], true); $id = sqimap_get_sort_order($imapConnection, $sSortField, $bDirection, $aMailbox['SEARCH'][$iSetIndx]); if ($id === false) { $error = '<b><small><center><font color=red>' . _("Server-side sorting is not supported by your IMAP server.") . '<br />' . _("Please contact your system administrator and report this error.") . '</center></small></b>'; } else { $aMailbox['UIDSET'][$iSetIndx] = $id; } break; default: $id = NULL; if ($aMailbox['SEARCH'][$iSetIndx] != 'ALL') { $id = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]); } $sSortField = getSortField($aMailbox['SORT'], false); $aMailbox['UIDSET'][$iSetIndx] = get_squirrel_sort($imapConnection, $sSortField, $bDirection, $id); break; } return $error; }
function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, $start_msg, $sort, $color, $show_num, $use_cache, $mode = '') { global $msgs, $msort, $auto_expunge, $thread_sort_messages, $allow_server_sort, $server_sort_order; /* * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc * so setting it to an empty array beforehand seems to clean up the issue, and stopping the * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error */ if (!isset($msort)) { $msort = array(); } if (!isset($msgs)) { $msgs = array(); } //$start = microtime(); /* If autoexpunge is turned on, then do it now. */ $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox); $srt = $sort; /* If autoexpunge is turned on, then do it now. */ if ($auto_expunge == true) { $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, ''); $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt; $num_msgs = $mbxresponse['EXISTS']; } if ($mbxresponse['EXISTS'] > 0) { /* if $start_msg is lower than $num_msgs, we probably deleted all messages * in the last page. We need to re-adjust the start_msg */ if ($start_msg > $num_msgs) { $start_msg -= $show_num; if ($start_msg < 1) { $start_msg = 1; } } /* This code and the next if() block check for * server-side sorting methods. The $id array is * formatted and $sort is set to 6 to disable * SM internal sorting */ if ($thread_sort_messages == 1) { $mode = 'thread'; } elseif ($allow_server_sort == 1) { $mode = 'serversort'; } else { $mode = ''; } if ($use_cache) { sqgetGlobalVar('msgs', $msgs, SQ_SESSION); sqgetGlobalVar('msort', $msort, SQ_SESSION); } else { sqsession_unregister('msort'); sqsession_unregister('msgs'); } switch ($mode) { case 'thread': $id = get_thread_sort($imapConnection); $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id); if ($msgs === false) { echo '<b><small><center><font color="red">' . _("Thread sorting is not supported by your IMAP server.") . '<br />' . _("Please contact your system administrator and report this error.") . '</font></center></small></b>'; $thread_sort_messages = 0; $msort = $msgs = array(); } else { $msort = $msgs; $sort = 6; } break; case 'serversort': $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse); $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id); if ($msgs === false) { echo '<b><small><center><font color="red">' . _("Server-side sorting is not supported by your IMAP server.") . '<br />' . _("Please contact your system administrator and report this error.") . '</font></center></small></b>'; $sort = $server_sort_order; $allow_server_sort = FALSE; $msort = $msgs = array(); $id = array(); } else { $msort = $msgs; $sort = 6; } break; default: if (!$use_cache) { $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num, $num_msgs, $sort, $mbxresponse); $msort = calc_msort($msgs, $sort); } /* !use cache */ break; } // switch sqsession_register($msort, 'msort'); sqsession_register($msgs, 'msgs'); } /* if exists > 0 */ $res = getEndMessage($start_msg, $show_num, $num_msgs); $start_msg = $res[0]; $end_msg = $res[1]; if ($num_msgs > 0) { $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort); } else { $paginator_str = ''; } $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs); do_hook('mailbox_index_before'); $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox); $form_name = "FormMsgs" . $safe_name; echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' . "\n" . '<input type="hidden" name="mailbox" value="' . htmlspecialchars($mailbox) . '">' . "\n" . '<input type="hidden" name="startMessage" value="' . htmlspecialchars($start_msg) . '">' . "\n"; echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">'; echo '<tr><td>'; mail_message_listing_beginning($imapConnection, $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg); /* line between the button area and the list */ echo '<tr><td height="5" bgcolor="' . $color[4] . '"></td></tr>'; echo '<tr><td>'; echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"' . ' border="0" bgcolor="' . $color[9] . '">'; echo ' <tr><td>'; echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="' . $color[5] . '">'; printHeader($mailbox, $srt, $color, !$thread_sort_messages); displayMessageArray($imapConnection, $num_msgs, $start_msg, $msort, $mailbox, $sort, $color, $show_num, 0, 0); echo '</table></td></tr></table>'; mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color); echo '</table>'; echo "\n</form>\n\n"; //$t = elapsed($start); //echo("elapsed time = $t seconds\n"); }
/** * Execute the sorting for a mailbox * * @param resource $imapConnection Imap connection * @param array $aMailbox (reference) Mailbox retrieved with sqm_api_mailbox_select * @return int $error (reference) Error number * @private * @since 1.5.1 * @author Marc Groot Koerkamp */ function _get_sorted_msgs_list($imapConnection, &$aMailbox) { $iSetIndx = isset($aMailbox['SETINDEX']) ? $aMailbox['SETINDEX'] : 0; $bDirection = !($aMailbox['SORT'] % 2); $error = 0; if (!$aMailbox['SEARCH'][$iSetIndx]) { $aMailbox['SEARCH'][$iSetIndx] = 'ALL'; } if ($aMailbox['SORT'] & SQSORT_THREAD && sqimap_capability($imapConnection, 'THREAD')) { $aRes = get_thread_sort($imapConnection, $aMailbox['SEARCH'][$iSetIndx]); if ($aRes === false) { $aMailbox['SORT'] -= SQSORT_THREAD; $error = 1; // fix me, define an error code; } else { $aMailbox['UIDSET'][$iSetIndx] = $aRes[0]; $aMailbox['THREAD_INDENT'][$iSetIndx] = $aRes[1]; } } else { if ($aMailbox['SORT'] === SQSORT_NONE) { $id = sqimap_run_search($imapConnection, 'ALL', ''); if ($id === false) { $error = 1; // fix me, define an error code } else { $aMailbox['UIDSET'][$iSetIndx] = array_reverse($id); $aMailbox['TOTAL'][$iSetIndx] = $aMailbox['EXISTS']; } } else { if (sqimap_capability($imapConnection, 'SORT')) { $sSortField = _getSortField($aMailbox['SORT'], true); $id = sqimap_get_sort_order($imapConnection, $sSortField, $bDirection, $aMailbox['SEARCH'][$iSetIndx]); if ($id === false) { $error = 1; // fix me, define an error code } else { $aMailbox['UIDSET'][$iSetIndx] = $id; } } else { $id = NULL; if ($aMailbox['SEARCH'][$iSetIndx] != 'ALL') { $id = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]); } $sSortField = _getSortField($aMailbox['SORT'], false); $aMailbox['UIDSET'][$iSetIndx] = get_squirrel_sort($imapConnection, $sSortField, $bDirection, $id); } } } return $error; }