' .
_("Server-side sorting is not supported by your IMAP server.") . ' ' .
_("Please contact your system administrator and report this error.") .
'
';
} 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 fetchMessageHeaders($imapConnection, &$aMailbox) {
/**
* Retrieve the UIDSET.
* Setindex is used to be able to store multiple uid sets. That will make it
* possible to display the mailbox multiple times in different sort order
* or to store serach results separate from normal mailbox view.
*/
$iSetIndx = (isset($aMailbox['SETINDEX'])) ? $aMailbox['SETINDEX'] : 0;
$iLimit = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $aMailbox['LIMIT'];
/**
* Adjust the start_msg
*/
$start_msg = $aMailbox['PAGEOFFSET'];
if($aMailbox['PAGEOFFSET'] > $aMailbox['EXISTS']) {
$start_msg -= $aMailbox['LIMIT'];
if($start_msg < 1) {
$start_msg = 1;
}
}
if (is_array($aMailbox['UIDSET'])) {
$aUid =& $aMailbox['UIDSET'][$iSetIndx];
} else {
$aUid = false;
}
// initialize the fields we want to retrieve:
$aHeaderFields = array('Date', 'To', 'Cc', 'From', 'Subject', 'X-Priority', 'Importance', 'Priority', 'Content-Type');
$aFetchItems = array('FLAGS', 'RFC822.SIZE');
// Are we sorting on internaldate then retrieve the internaldate value as well
if ($aMailbox['INTERNALDATE']) {
$aFetchItems[] = 'INTERNALDATE';
}
/**
* A uidset with sorted uid's is available. We can use the cache
*/
if (($aMailbox['SORT'] != SQSORT_NONE || $aMailbox['SEARCH'][$iSetIndx] != 'ALL') &&
isset($aUid) && $aUid ) {
// limit the cache to SQM_MAX_PAGES_IN_CACHE
if (!$aMailbox['SHOWALL'][$iSetIndx]) {
$iMaxMsgs = $iLimit * SQM_MAX_PAGES_IN_CACHE;
$iCacheSize = count($aMailbox['MSG_HEADERS']);
if ($iCacheSize > $iMaxMsgs) {
$iReduce = $iCacheSize - $iMaxMsgs;
foreach ($aMailbox['MSG_HEADERS'] as $iUid => $value) {
if ($iReduce) {
unset($aMailbox['MSG_HEADERS'][$iUid]);
} else {
break;
}
--$iReduce;
}
}
}
$id_slice = array_slice($aUid,$start_msg-1,$iLimit);
/* do some funky cache checks */
$aUidCached = array_keys($aMailbox['MSG_HEADERS']);
$aUidNotCached = array_values(array_diff($id_slice,$aUidCached));
/**
* $aUidNotCached contains an array with UID's which need to be fetched to
* complete the needed message headers.
*/
if (count($aUidNotCached)) {
$aMsgs = sqimap_get_small_header_list($imapConnection,$aUidNotCached,
$aHeaderFields,$aFetchItems);
// append the msgs to the existend headers
$aMailbox['MSG_HEADERS'] += $aMsgs;
}
} else {
/**
* Initialize the sorted UID list and fetch the visible message headers
*/
if ($aMailbox['SORT'] != SQSORT_NONE || $aMailbox['SEARCH'][$iSetIndx] != 'ALL') {// || $aMailbox['SORT_METHOD'] & SQSORT_THREAD 'THREAD') {
$error = false;
if ($aMailbox['SEARCH'][$iSetIndx] && $aMailbox['SORT'] == 0) {
$aUid = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]);
} else {
$error = get_sorted_msgs_list($imapConnection,$aMailbox,$error);
$aUid = $aMailbox['UIDSET'][$iSetIndx];
}
if ($error === false) {
$id_slice = array_slice($aUid,$aMailbox['OFFSET'], $iLimit);
if (count($id_slice)) {
$aMailbox['MSG_HEADERS'] = sqimap_get_small_header_list($imapConnection,$id_slice,
$aHeaderFields,$aFetchItems);
} else {
return false;
}
} else {
// FIX ME, format message and fallback to squirrel sort
if ($error) {
echo $error;
}
}
} else {
// limit the cache to SQM_MAX_PAGES_IN_CACHE
if (!$aMailbox['SHOWALL'][$iSetIndx] && isset($aMailbox['MSG_HEADERS']) && is_array($aMailbox['MSG_HEADERS'])) {
$iMaxMsgs = $iLimit * SQM_MAX_PAGES_IN_CACHE;
$iCacheSize = count($aMailbox['MSG_HEADERS']);
if ($iCacheSize > $iMaxMsgs) {
$iReduce = $iCacheSize - $iMaxMsgs;
foreach ($aMailbox['MSG_HEADERS'] as $iUid => $value) {
if ($iReduce) {
$iId = $aMailbox['MSG_HEADERS'][$iUid]['ID'];
unset($aMailbox['MSG_HEADERS'][$iUid]);
unset($aMailbox['ID'][$iId]);
} else {
break;
}
--$iReduce;
}
}
}
/**
* retrieve messages by sequence id's and fetch the UID to retrieve
* the UID. for sorted lists this is not needed because a UID FETCH
* automaticly add the UID value in fetch results
**/
$aFetchItems[] = 'UID';
//create id range
$iRangeStart = $aMailbox['EXISTS'] - $aMailbox['OFFSET'];
$iRangeEnd = ($iRangeStart > $iLimit) ?
($iRangeStart - $iLimit+1):1;
$id_slice = range($iRangeStart, $iRangeEnd);
/**
* Non sorted mailbox with cached message headers
*/
if (isset($aMailbox['ID']) && is_array($aMailbox['ID'])) {
// the fetched id => uid relation
$aId = $aMailbox['ID'];
$aIdCached = array();
foreach ($aId as $iId => $iUid) {
if (isset($aMailbox['MSG_HEADERS'][$iUid])) {
if ($iId <= $iRangeStart && $iId >= $iRangeEnd) {
$aIdCached[] = $iId;
}
}
}
$aIdNotCached = array_diff($id_slice,$aIdCached);
} else {
$aIdNotCached = $id_slice;
}
if (count($aIdNotCached)) {
$aMsgs = sqimap_get_small_header_list($imapConnection,$aIdNotCached,
$aHeaderFields,$aFetchItems);
// append the msgs to the existend headers
if (isset($aMailbox['MSG_HEADERS']) && is_array($aMailbox['MSG_HEADERS'])) {
$aMailbox['MSG_HEADERS'] += $aMsgs;
} else {
$aMailbox['MSG_HEADERS'] = $aMsgs;
}
// update the ID array
foreach ($aMsgs as $iUid => $aMsg) {
if (isset($aMsg['ID'])) {
$aMailbox['ID'][$aMsg['ID']] = $iUid;
}
}
}
/**
* In unsorted state we show newest messages first which means
* that the UIDSET which represents the order of the messages
* should contain a high to low ordered UID list
*/
$aSortedUidList = array();
foreach ($id_slice as $iId) {
if (isset($aMailbox['ID'][$iId])) {
$aSortedUidList[] = $aMailbox['ID'][$iId];
}
}
$aMailbox['UIDSET'][$iSetIndx] = $aSortedUidList;
$aMailbox['OFFSET'] = 0;
}
}
return true;
}
/**
* This function loops through a group of messages in the mailbox
* and shows them to the user.
*
* @param mixed $imapConnection
* @param array $aMailbox associative array with mailbox related vars
*/
function showMessagesForMailbox($imapConnection, &$aMailbox) {
global $color, $javascript_on, $compact_paginator;
// to retrieve the internaldate pref: (I know this is not the right place to do that, move up in front
// and use a properties array as function argument to provide user preferences
global $data_dir, $username;
if (!fetchMessageHeaders($imapConnection, $aMailbox)) {
return false;
}
$iSetIndx = $aMailbox['SETINDEX'];
$iLimit = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $aMailbox['LIMIT'];
$iEnd = ($aMailbox['PAGEOFFSET'] + ($iLimit - 1) < $aMailbox['EXISTS']) ?
$aMailbox['PAGEOFFSET'] + $iLimit - 1 : $aMailbox['EXISTS'];
$paginator_str = get_paginator_str($aMailbox['NAME'], $aMailbox['PAGEOFFSET'],
$aMailbox['EXISTS'], $aMailbox['LIMIT'], $aMailbox['SHOWALL'][$iSetIndx]);
$msg_cnt_str = get_msgcnt_str($aMailbox['PAGEOFFSET'], $iEnd,$aMailbox['EXISTS']);
do_hook('mailbox_index_before');
if ($javascript_on && $compact_paginator) {
// Insert compact paginator javascript
echo "\n\n"
. "\n"
. "\n";
}
mail_message_listing_beginning($imapConnection, $aMailbox, $msg_cnt_str, $paginator_str);
?>
$aHeaders[$aId[$i]],
'INDX' => $t,
'OFFSET' => $iOffset,
'PAGEOFFSET' => $iPageOffset,
'SORT' => $sort,
'SEARCH' => $aSearch,
'MAILBOX' => $sMailbox,
'INDENT' => $indent,
'LAST' => $bLast
);
printMessageInfo($aMsg);
++$t;
} else {
break;
}
}
}
/**
* Displays the standard message list header.
*
* To finish the table, you need to do a "";
*
* @param resource $imapConnection
* @param array $aMailbox associative array with mailbox related information
* @param string $msg_cnt_str
* @param string $paginator Paginator string
*/
function mail_message_listing_beginning ($imapConnection,
$aMailbox,
$msg_cnt_str = '',
$paginator = ' '
) {
global $color, $show_flag_buttons, $PHP_SELF;
global $lastTargetMailbox, $boxes;
$php_self = $PHP_SELF;
if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
$source_url = $regs[1];
} else {
$source_url = $php_self;
}
$php_self = str_replace('&', '&', $php_self);
if (!isset($msg)) {
$msg = '';
}
$moveFields = addHidden('msg', $msg).
addHidden('mailbox', $aMailbox['NAME']).
addHidden('startMessage', $aMailbox['PAGEOFFSET']);
/* build thread sorting links */
$sort = $aMailbox['SORT'];
if ($aMailbox['ALLOW_THREAD']) {
if ($aMailbox['SORT'] & SQSORT_THREAD) {
$sort -= SQSORT_THREAD;
$thread_name = _("Unthread View");
} else {
$thread_name = _("Thread View");
$sort = $aMailbox['SORT'] + SQSORT_THREAD;
}
$thread_link_str = '[' . $thread_name
. ']';
} else {
$thread_link_str ='';
}
/*
* This is the beginning of the message list table.
* It wraps around all messages
*/
$safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']);
$form_name = "FormMsgs" . $safe_name;
echo '