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;
}
Exemplo n.º 2
0
/**
 * 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;
}