/**
- * Expunge specified message, updated $msgs and $msort
+ * Expunge specified message
*
- * Until Marc and I come up with a better way to maintain
- * these stupid arrays, we'll use this wrapper function to
+ * We'll use this wrapper function to
* remove the message with the matching UID .. the order
* won't be changed - the array element for the message
* will just be removed.
*/
-function sqimap_mailbox_expunge_dmn($message_id, $aMbxResponse, &$server_sort_array)
-{
- global $msgs, $msort, $sort, $imapConnection,
- $mailbox, $auto_expunge,
- $sort, $allow_server_sort, $thread_sort_messages, $allow_thread_sort,
- $username, $data_dir;
- $cnt = 0;
- if (!isset($sort) || $sort === false) {
- sqgetGlobalVar('sort',$sort,SQ_GET);
- }
+function sqimap_mailbox_expunge_dmn($imapConnection, &$aMailbox, $message_id) {
+ $cnt = 0;
- if ($auto_expunge) {
- $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
+ if ($aMailbox['AUTO_EXPUNGE']) {
+ $cnt = sqimap_mailbox_expunge($imapConnection, $aMailbox['NAME'], true);
} else {
return $cnt;
}
-
- // Got to grab this out of prefs, since it isn't saved from mailbox_view.php
- if ($allow_thread_sort && getPref($data_dir, $username, "thread_$mailbox",0)) {
- $mode = 'THREAD';
- } else if ($allow_server_sort) {
- $mode = 'SERVER';
- } else {
- $mode = 'SQUIRREL';
- }
$error = '';
- if (is_array($server_sort_array)) {
- $key = array_search($message_id,$server_sort_array,true);
+ $message_id = (int) $message_id; // we use strickt array_search
+ if (is_array($aMailbox['UIDSET'])) {
+ $key = array_search($message_id,$aMailbox['UIDSET'],true);
if ($key !== false) {
- unset($server_sort_array[$key]);
- $server_sort_array = array_values($server_sort_array);
+ unset($aMailbox['UIDSET'][$key]);
+ $aMailbox['UIDSET'] = array_values($aMailbox['UIDSET']);
+ // adapt the exists count to avoid triggering of a new sort
+ $aMailbox['EXISTS'] -= 1;
} else {
- $server_sort_array = get_sorted_msgs_list($imapConnection,$sort,$mode,$error);
+ $aMailbox['UIDSET'] = get_sorted_msgs_list($imapConnection,$aMailbox,$error);
}
} else {
- $server_sort_array = get_sorted_msgs_list($imapConnection,$sort,$mode,$error);
+ $aMailbox['UIDSET'] = get_sorted_msgs_list($imapConnection,$aMailbox,$error);
}
- sqsession_register($server_sort_array,'server_sort_array');
+ sqsession_register($aMailbox,'aLastSelectedMailbox');
+ sqsession_register($aMailbox['UIDSET'],'server_sort_array'); //fix me, use aMailbox instead
return $cnt;
}
* @param bool $reverse Reverse order search
* @return array $id sorted uid list
*/
-function sqimap_get_sort_order ($imap_stream, $sSortField = 'UID',$reverse) {
+function sqimap_get_sort_order ($imap_stream, $sSortField,$reverse) {
global $default_charset,
$sent_folder;
$sort_test = array();
$sort_query = '';
- if ($sSortField == 'UID') {
- $query = "SEARCH UID 1:*";
- $uids = sqimap_run_command ($imap_stream, $query, true, $response, $message, true);
- if (isset($uids[0])) {
- if (preg_match("/^\* SEARCH (.+)$/", $uids[0], $regs)) {
- $id = preg_split("/ /", trim($regs[1]));
- }
- }
- if (!preg_match("/OK/", $response)) {
- $id = false;
- }
- $id = array_reverse($id);
- return $id;
- }
if ($sSortField) {
if ($reverse) {
$sSortField = 'REVERSE '.$sSortField;
* @return array $aUid sorted uid list
*/
function get_squirrel_sort ($imap_stream, $sSortField, $reverse = false) {
-
- if ($sSortField == 'UID') {
- // FIX ME: this is not needed. Try to find another way to solve this
- $query = "SEARCH UID 1:*";
- $uids = sqimap_run_command ($imap_stream, $query, true, $response, $message, true);
- if (isset($uids[0])) {
- if (preg_match("/^\* SEARCH (.+)$/", $uids[0], $regs)) {
- $msgs = preg_split("/ /", trim($regs[1]));
- }
- }
- if (!preg_match("/OK/", $response)) {
- $msgs = false;
- }
- } else if ($sSortField != 'RFC822.SIZE' && $sSortField != 'INTERNALDATE') {
+ if ($sSortField != 'RFC822.SIZE' && $sSortField != 'INTERNALDATE') {
$msgs = sqimap_get_small_header_list($imap_stream, false, '*',
- array($sSortField), array('UID'));
+ array($sSortField), array());
} else {
$msgs = sqimap_get_small_header_list($imap_stream, false, '*',
- array(), array('UID', $sSortField));
+ array(), array($sSortField));
}
$aUid = array();
$walk = false;
define('SQSORT_CC_DEC',12);
define('SQSORT_INT_DATE_ASC',13);
define('SQSORT_INT_DATE_DEC',14);
+define('SQSORT_THREAD',42);
/**
* @param mixed $start UNDOCUMENTED
*/
*/
function printMessageInfo($aMsg) {
+ // FIX ME, remove these globals as well by adding an array as argument for the user settings
+ // specificly meant for header display
global $checkall,
- $color, $td_str,
+ $color,
$default_use_priority,
$message_highlight_list,
$index_order,
- $indent_array, /* indent subject by */
- $pos, /* Search postion (if any) */
- $thread_sort_messages, /* thread sorting on/off */
- $row_count,
$truncate_sender, /* number of characters for From/To field (<= 0 for unchanged) */
$email_address,
$show_recipient_instead, /* show recipient name instead of default identity */
$where = false;
$what = false;
}
+ $iIndent = $aMsg['INDENT'];
$sSubject = (isset($msg['SUBJECT']) && $msg['SUBJECT'] != '') ? $msg['SUBJECT'] : _("(no subject)");
$sFrom = (isset($msg['FROM'])) ? $msg['FROM'] : _("Unknown sender");
$iSize = (isset($msg['SIZE'])) ? $msg['SIZE'] : 0;
$sType0 = (isset($msg['TYPE0'])) ? $msg['TYPE0'] : 'text';
$sType1 = (isset($msg['TYPE1'])) ? $msg['TYPE1'] : 'plain';
- $sDate = (isset($msg['DATE'])) ? getDateString(getTimeStamp(explode(' ',$msg['DATE']))) : '';
+ if (isset($msg['INTERNALDATE'])) {
+ $sDate = getDateString(getTimeStamp(explode(' ',$msg['INTERNALDATE'])));
+ } else {
+ $sDate = (isset($msg['DATE'])) ? getDateString(getTimeStamp(explode(' ',$msg['DATE']))) : '';
+ }
$iId = (isset($msg['ID'])) ? $msg['ID'] : false;
- sqgetGlobalVar('indent_array',$indent_array,SQ_SESSION);
if (!$iId) {
return;
}
if ($GLOBALS['alt_index_colors']) {
- if (!isset($row_count)) {
- $row_count = 0;
- }
- $row_count++;
- if ($row_count % 2) {
+ if (!($t % 2)) {
if (!isset($color[12])) {
$color[12] = '#EAEAEA';
}
$urlMailbox = urlencode($mailbox);
+ // FIXME, foldertype should be set in right_main.php
+ // in other words, handle as sent is obsoleted from now.
+ // We replace that by providing an array to aMailbox with the to shown headers
+ // that way we are free to show the user different layouts for different folders
$bSentFolder = handleAsSent($mailbox);
if ((!$bSentFolder) && ($show_recipient_instead)) {
// If the From address is the same as $email_address, then handle as Sent
$senderAddress = _("To:") . ' ' . $senderAddress;
}
+ // this is a column property which can apply to multiple columns. Do not use vars for one column
+ // only. instead we should use something like this:
+ // 1ed column $aMailbox['columns']['SUBJECT'] value: aray with properties ...
+ // 2ed column $aMailbox['columns']['FROM'] value: aray with properties ...
+ // NB in case of the sentfolder this could be the TO field
+ // properties array example:
+ // 'truncate' => length (0 is no truncate)
+ // 'prefix => if (x in b then do that )
if ($truncate_sender > 0) {
$senderName = truncateWithEntities($senderName, $truncate_sender);
}
$bold = '<b>';
$bold_end = '</b>';
-
-
foreach ($aFlags as $sFlag => $value) {
switch ($sFlag) {
case '\\flagged':
}
$col = 0;
$sSubject = str_replace(' ', ' ', decodeHeader($sSubject));
- if (isset($indent_array[$iId])) { /* Thread sort */
- $subject = processSubject($sSubject, $indent_array[$iId]);
- } else {
- $subject = processSubject($sSubject, 0);
- }
+ $subject = processSubject($sSubject, $iIndent);
echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
break;
case 4: /* subject */
$td_str = $bold;
- if ($thread_sort_messages == 1) {
- if (isset($indent_array[$iId])) {
- $td_str .= str_repeat(" ",$indent_array[$iId]);
- }
+ if ($iIndent) {
+ $td_str .= str_repeat(" ",$iIndent);
}
$td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
. '&passed_id='. $msg["ID"]
case SQSORT_INT_DATE_DEC:
$sSortField = ($bServerSort) ? 'ARRIVAL' : 'INTERNALDATE';
break;
- default: $sSortField = 'DATE';
+ case SQSORT_THREAD:
break;
+ default: $sSortField = 'UID';
+ break;
+
}
return $sSortField;
}
-function get_sorted_msgs_list($imapConnection,$sort,$mode,&$error) {
- $bDirection = ($sort % 2);
+function get_sorted_msgs_list($imapConnection,$aMailbox,&$error) {
+ $bDirection = ($aMailbox['SORT'] % 2);
$error = false;
- switch ($mode) {
+ switch ($aMailbox['SORT_METHOD']) {
case 'THREAD':
$id = get_thread_sort($imapConnection);
if ($id === false) {
}
break;
case 'SERVER':
- $sSortField = getSortField($sort,true);
+ $sSortField = getSortField($aMailbox['SORT'],true);
$id = sqimap_get_sort_order($imapConnection, $sSortField, $bDirection);
if ($id === false) {
$error = '<b><small><center><font color=red>' .
}
break;
default:
- $sSortField = getSortField($sort,false);
+ $sSortField = getSortField($aMailbox['SORT'],false);
$id = get_squirrel_sort($imapConnection, $sSortField, $bDirection);
break;
}
* @param array $aMailbox associative array with mailbox related vars
*/
function showMessagesForMailbox($imapConnection, $aMailbox) {
- global $msgs, $server_sort_array;
+ global $msgs, $server_sort_array,$indent_array;
// 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;
+ // retrieve indent array for thread sort
+
+
/* if there's no messages in this folder */
if ($aMailbox['EXISTS'] == 0) {
$string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
if ($internaldate) {
$aFetchItems[] = 'INTERNALDATE';
}
- if ($aMailbox['SORT'] === SQSORT_NONE) {
+ if ($aMailbox['SORT'] == SQSORT_NONE) {
/**
* 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
* SM internal sorting
*/
- if ($aMailbox['SORT'] !== SQSORT_NONE && isset($aMailbox['UIDSET']) && //['SORT_ARRAY']) &&
- $aMailbox['UIDSET'] ) {//is_array($mbxresponse['SORT_ARRAY'])) {
- $id = $aMailbox['UIDSET'];//$mbxresponse['SORT_ARRAY'];
+ if ($aMailbox['SORT'] != SQSORT_NONE && isset($aMailbox['UIDSET']) &&
+ $aMailbox['UIDSET'] ) {
+ $id = $aMailbox['UIDSET'];
if (sqsession_is_registered('msgs')) {
sqsession_unregister('msgs');
}
$id_slice = array_slice($id,$start_msg-1,$aMailbox['LIMIT']);
if (count($id_slice)) {
- $msgs = sqimap_get_small_header_list($imapConnection,$id_slice,$aMailbox['LIMIT']);
+ $msgs = sqimap_get_small_header_list($imapConnection,$id_slice,$aMailbox['LIMIT'],
+ $aHeaderFields,$aFetchItems);
+
} else {
return false;
}
if (sqsession_is_registered('server_sort_array')) {
sqsession_unregister('server_sort_array');
}
- if ($aMailbox['SORT'] !== SQSORT_NONE) {
- $id = get_sorted_msgs_list($imapConnection,$aMailbox['SORT'],$aMailbox['SORT_METHOD'],$error);
+
+ if ($aMailbox['SORT'] != SQSORT_NONE || $aMailbox['SORT_METHOD'] == 'THREAD') {
+ $id = get_sorted_msgs_list($imapConnection,$aMailbox,$error);
if ($id !== false) {
$id_slice = array_slice($id,$aMailbox['OFFSET'], $aMailbox['LIMIT']);
if (count($id_slice)) {
}
$aMailbox['UIDSET'] =& $id;
$aMailbox['MSG_HEADERS'] =& $msgs;
+ if ($aMailbox['SORT_METHOD'] == 'THREAD') {
+ sqgetGlobalVar('indent_array',$indent_array,SQ_SESSION);
+ $aMailbox['THREAD_INDENT'] =& $indent_array;
+ }
} /* if exists > 0 */
- $res = getEndMessage($aMailbox['PAGEOFFSET'], $aMailbox['LIMIT'], $aMailbox['EXISTS']);
- // $start_msg = $res[0];
- $end_msg = $res[1];
+ $iEnd = ($aMailbox['PAGEOFFSET'] + ($aMailbox['LIMIT'] - 1) < $aMailbox['EXISTS']) ?
+ $aMailbox['PAGEOFFSET'] + $aMailbox['LIMIT'] - 1 : $aMailbox['EXISTS'];
- $paginator_str = get_paginator_str($aMailbox['NAME'], $aMailbox['PAGEOFFSET'], $end_msg,
+ $paginator_str = get_paginator_str($aMailbox['NAME'], $aMailbox['PAGEOFFSET'], $iEnd,
$aMailbox['EXISTS'], $aMailbox['LIMIT'], $aMailbox['SORT']);
- $msg_cnt_str = get_msgcnt_str($aMailbox['PAGEOFFSET'], $aMailbox['PAGEOFFSET']+$aMailbox['LIMIT'],$aMailbox['EXISTS']);
+ $msg_cnt_str = get_msgcnt_str($aMailbox['PAGEOFFSET'], $iEnd,$aMailbox['EXISTS']);
do_hook('mailbox_index_before');
?>
$iPageOffset = $aMailbox['PAGEOFFSET'];
$sMailbox = $aMailbox['NAME'];
$aSearch = (isset($aMailbox['SEARCH'])) ? $aMailbox['SEARCH'] : false;
-
+ if ($aMailbox['SORT_METHOD'] == 'THREAD') {
+ $aIndentArray =& $aMailbox['THREAD_INDENT'];
+ $bThread = true;
+ } else {
+ $bThread = false;
+ }
/*
* Loop through and display the info for each message.
* ($t is used for the checkbox number)
if (isset($aId[$i])) {
$bLast = ((isset($aId[$i+1]) && isset($aHeaders[$aId[$i+1]]))
|| ($i == $iEnd )) ? false : true;
+ if ($bThread) {
+ $indent = (isset($aIndentArray[$aId[$i]])) ? $aIndentArray[$aId[$i]] : 0;
+ } else {
+ $indent = 0;
+ }
$aMsg = array(
'HEADER' => $aHeaders[$aId[$i]],
'INDX' => $t,
'SORT' => $sort,
'SEARCH' => $aSearch,
'MAILBOX' => $sMailbox,
+ 'INDENT' => $indent,
'LAST' => $bLast
);
printMessageInfo($aMsg);
}
/**
-* FIXME: Undocumented function
+* Function to add the last row in a message list, it contains the paginator and info about
+* the number of messages.
*
* @param integer $num_msgs number of messages in a mailbox
* @param string $paginator_str Paginator string [Prev | Next] [ 1 2 3 ... 91 92 94 ] [Show all]
'nowrap' );
}
-/**
-* FIXME: Undocumented function
-*
-* @param integer $start_msg
-* @param integer $show_num
-* @param integer $num_msgs
-*/
-function getEndMessage($start_msg, $show_num, $num_msgs) {
- if ($start_msg + ($show_num - 1) < $num_msgs){
- $end_msg = $start_msg + ($show_num - 1);
- } else {
- $end_msg = $num_msgs;
- }
-
- if ($end_msg < $start_msg) {
- $start_msg = $start_msg - $show_num;
- if ($start_msg < 1) {
- $start_msg = 1;
- }
- }
- return (array($start_msg,$end_msg));
-}
-
/**
* This should go in imap_mailbox.php
* @param string $mailbox
* @param int $passed_id The current message UID
* @return the index of the next valid message from the array
*/
-function findNextMessage($passed_id) {
- global $server_sort_array;
+function findNextMessage($uidset,$passed_id='backwards') {
+ if ($passed_id=='backwards' || !is_array($uidset)) { // check for backwards compattibilty gpg plugin
+ $passed_id = $uidset;
+ sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
+ $uidset = $server_sort_array;
+ }
$result = -1;
- $count = count($server_sort_array) - 1;
- foreach($server_sort_array as $key=>$value) {
+ $count = count($uidset) - 1;
+ foreach($uidset as $key=>$value) {
if ($passed_id == $value) {
if ($key == $count) {
break;
}
- $result = $server_sort_array[$key + 1];
+ $result = $uidset[$key + 1];
break;
}
}
* @param int $passed_id The current message UID
* @return the index of the next valid message from the array
*/
-function findPreviousMessage($numMessages, $passed_id) {
- global $server_sort_array;
+
+function findPreviousMessage($uidset, $passed_id) {
+ if (!is_array($uidset)) { //obsolete check
+ sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
+ $uidset = $server_sort_array;
+ }
$result = -1;
- foreach($server_sort_array as $key=>$value) {
+ foreach($uidset as $key=>$value) {
if ($passed_id == $value) {
if ($key != 0) {
- $result = $server_sort_array[$key - 1];
+ $result = $uidset[$key - 1];
}
break;
}
return $string;
}
-function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
+function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
$color, $FirstTimeSee) {
global $msn_user_support, $default_use_mdn, $default_use_priority,
$show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
$squirrelmail_language;
+ $mailbox = $aMailbox['NAME'] ;
+
$header = $message->rfc822_header;
$env = array();
$env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject));
* @param object $message Current message object
* @param object $mbx_response
*/
-function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
+function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
global $base_uri, $draft_folder, $where, $what, $color, $sort,
$startMessage, $PHP_SELF, $save_as_draft,
$enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
$data_dir, $username, $delete_prev_next_display,
$compose_new_win, $javascript_on;
+ //FIXME cleanup argument list, use $aMailbox where possible
+ $mailbox = $aMailbox['NAME'];
+
$topbar_delimiter = ' | ';
$double_delimiter = ' ';
$urlMailbox = urlencode($mailbox);
// Prev/Next links for regular messages
} else if ( !(isset($where) && isset($what)) ) {
- $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
- $next = findNextMessage($passed_id);
+ $prev = findPreviousMessage($aMailbox['UIDSET'], $passed_id);
+ $next = findNextMessage($aMailbox['UIDSET'],$passed_id);
$prev_link = _("Previous");
if ($prev >= 0) {
$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
+global $allow_thread_sort, $auto_expunge;
+
+if ($allow_thread_sort && getPref($data_dir, $username, "thread_$mailbox",0)) {
+ $aMailbox['SORT_METHOD'] = 'THREAD';
+} else if ($allow_server_sort) {
+ $aMailbox['SORT_METHOD'] = 'SERVER';
+} else {
+ $aMailbox['SORT_METHOD'] = 'SQUIRREL';
+}
+sqgetGlobalVar('aLastSelectedMailbox',$aMailbox,SQ_SESSION);
+$aMailbox['UIDSET'] = $server_sort_array;
+$aMailbox['SORT'] = $sort;
+$aMailbox['NAME'] = $mailbox;
+$aMailbox['EXISTS'] = $mbx_response['EXISTS'];
+$aMailbox['AUTO_EXPUNGE'] = $auto_expunge;
+$aMailbox['MSG_HEADERS'] = $msgs;
+
+
/**
* Process Delete from delete-move-next
* but only if delete_id was set
*/
if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
- sqimap_mailbox_expunge_dmn($delete_id,$mbx_response,$server_sort_array);
+ sqimap_mailbox_expunge_dmn($imapConnection,$aMailbox,$delete_id);
}
/**
}
displayPageHeader($color, $mailbox);
-formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
-formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
+formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
+formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
echo ' <tr><td>';
echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
sqgetGlobalVar('mailbox', $mailbox);
sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
-sqgetGlobalVar('numMessages' , $numMessages, SQ_SESSION);
+sqgetGlobalVar('sort' , $sort, SQ_SESSION);
sqgetGlobalVar('session', $session, SQ_GET);
sqgetGlobalVar('note', $note, SQ_GET);
sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET);
-sqgetGlobalVar('use_mailbox_cache', $use_mailbox_cache, SQ_GET);
if ( sqgetGlobalVar('startMessage', $temp) ) {
$startMessage = (int) $temp;
/* end of get globals */
-/* Open a connection on the imap port (143) */
+/* Open an imap connection */
$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
else if( isset( $PG_SHOWNUM ) ) {
$show_num = $PG_SHOWNUM;
}
+$mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX';
+/* compensate for the UW vulnerability. */
+if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
+ substr($mailbox, 0, 1) == '/')) {
+ $mailbox = 'INBOX';
+}
if (isset($newsort) ) {
- if ( $newsort != $sort )
+ if ( $newsort != $sort ) {
setPref($data_dir, $username, 'sort', $newsort);
-
+ }
+ $oldsort = $sort;
$sort = $newsort;
sqsession_register($sort, 'sort');
}
-/* If the page has been loaded without a specific mailbox, */
-/* send them to the inbox */
-//if (!isset($mailbox)) {
-// $mailbox = 'INBOX';
-// $startMessage = 1;
-//}
-
-//if (!isset($startMessage) || ($startMessage == '')) {
-// $startMessage = 1;
-//}
-
-/* compensate for the UW vulnerability. */
-if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
- substr($mailbox, 0, 1) == '/')) {
- $mailbox = 'INBOX';
-}
-
do_hook ('generic_header');
$aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox);
$aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY'];
}
-if ($aLastSelectedMailbox && !isset($newsort)) {
+if ($aLastSelectedMailbox) {
// check if we deal with the same mailbox
if ($aLastSelectedMailbox['NAME'] == $mailbox) {
if ($aLastSelectedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] &&
$aLastSelectedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] &&
$aLastSelectedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT']) {
- // sort is still valid
sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
if ($server_sort_array && is_array($server_sort_array)) {
$aMbxResponse['SORT_ARRAY'] = $server_sort_array;
+ // check if oldsort can be used in case we changed the sort order of the same column
+ if (isset($newsort) ) {
+ if ((($newsort % 2) && ($newsort + 1 == $oldsort)) ||
+ (!($newsort % 2) && ($newsort - 1 == $oldsort))) {
+ $server_sort_array = array_reverse($server_sort_array);
+ } else {
+ $server_sort_array = false;
+ }
+ }
+ $aMbxResponse['SORT_ARRAY'] = $server_sort_array;
}
}
}
$aLastSelectedMailbox['OFFSET'] = (isset($startMessage) && $startMessage) ? $startMessage -1 : 0;
$aLastSelectedMailbox['PAGEOFFSET'] = (isset($startMessage) && $startMessage) ? $startMessage : 1;
$aLastSelectedMailbox['SORT'] = ($sort !== false) ? $sort : 0;
-$aLastSelectedMailbox['LIMIT'] = $show_num;
+$aLastSelectedMailbox['LIMIT'] = ($show_num != 999999) ? $show_num : $aMbxResponse['EXISTS'];
$aLastSelectedMailbox['UIDSET'] = $aMbxResponse['SORT_ARRAY'];
$aLastSelectedMailbox['SEEN'] = (isset($aMbxResponse['SEEN'])) ? $aMbxResponse['SEEN'] : $aMbxResponse['EXISTS'];
}
}
+showMessagesForMailbox($imapConnection,$aLastSelectedMailbox);
-/*********************************************************************
- * Check to see if we can use cache or not. Currently the only time *
- * when you will not use it is when a link on the left hand frame is *
- * used. Also check to make sure we actually have the array in the *
- * registered session data. :) *
- *********************************************************************/
-if (! isset($use_mailbox_cache)) {
- $use_mailbox_cache = 0;
-}
-
-if ($use_mailbox_cache && sqsession_is_registered('msgs')) {
- showMessagesForMailbox($imapConnection,$aLastSelectedMailbox);
-// showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
-// $startMessage, $sort, $color, $show_num,
-// $use_mailbox_cache, '',$aMbxResponse);
-} else {
- if (sqsession_is_registered('msgs')) {
- unset($msgs);
- }
-
- if (sqsession_is_registered('msort')) {
- unset($msort);
- }
-
- if (sqsession_is_registered('numMessages')) {
- unset($numMessages);
- }
-
- $numMessages = $aMbxResponse['EXISTS'];
-
- showMessagesForMailbox($imapConnection,$aLastSelectedMailbox);
-// showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
-// $startMessage, $sort, $color, $show_num,
-// $use_mailbox_cache,'',$aMbxResponse);
-
- if (sqsession_is_registered('msgs') && isset($msgs)) {
- sqsession_register($msgs, 'msgs');
- }
-
- if (sqsession_is_registered('msort') && isset($msort)) {
- sqsession_register($msort, 'msort');
- }
-
- sqsession_register($numMessages, 'numMessages');
-}
do_hook('right_main_bottom');
sqimap_logout ($imapConnection);
echo '</body></html>';