* @return void
*/
function sqimap_msgs_list_copy ($imap_stream, $id, $mailbox) {
- $msgs_id = sqimap_message_list_squisher($id);
+ $msgs_id = sqimap_message_list_squisher($id);
$read = sqimap_run_command ($imap_stream, "COPY $msgs_id " . sqimap_encode_mailbox_name($mailbox), true, $response, $message, TRUE);
}
$child = '';
$cutoff = 0;
- /* loop through the threads and take unwanted characters out
- of the thread string then chop it up
+ /* loop through the threads and take unwanted characters out
+ of the thread string then chop it up
*/
for ($i=0;$i<count($thread_new);$i++) {
$thread_new[$i] = preg_replace("/\s\(/", "(", $thread_new[$i]);
$thread_new[$i] = preg_replace("/(\d+)/", "$1|", $thread_new[$i]);
$thread_new[$i] = preg_split("/\|/", $thread_new[$i], -1, PREG_SPLIT_NO_EMPTY);
- }
+ }
$indent_array = array();
if (!$thread_new) {
$thread_new = array();
$thread_list = trim($regs[1]);
break;
}
- }
+ }
}
else {
$thread_list = "";
$maxmsg = sizeof($msg_list);
if ($show_num != '999999') {
$msgs_str = sqimap_message_list_squisher($msg_list);
- } else {
+ } else {
$msgs_str = '1:*';
}
$messages = array();
}
$read_list = sqimap_run_command_list ($imap_stream, $query, true, $response, $message, TRUE);
$i = 0;
-
+
foreach ($read_list as $r) {
/* initialize/reset vars */
$subject = _("(no subject)");
$read = implode('',$r);
- /*
+ /*
* #id<space>FETCH<space>(
*/
-
+
/* extract the message id */
$i_space = strpos($read,' ',2);
$id = substr($read,2,$i_space-2);
} else {
break 3;
}
-
+
break;
case 'INTERNALDATE':
$date = parseString($read,$i);
//if ($tmpdate === false) break 3;
//$tmpdate = str_replace(' ',' ',$tmpdate);
//$tmpdate = explode(' ',$tmpdate);
- //$date = str_replace('-',' ',$tmpdate[0]) . " " .
+ //$date = str_replace('-',' ',$tmpdate[0]) . " " .
// $tmpdate[1] . ' ' . $tmpdate[2];
break;
case 'BODY.PEEK[HEADER.FIELDS':
++$msgi;
}
array_reverse($messages);
- $new_messages = array();
- foreach ($messages as $i =>$message) {
- $new_messages[] = $message;
- }
- return $new_messages;
+// $new_messages = array();
+// foreach ($messages as $i =>$message) {
+// $new_messages[] = $message;
+// }
+ return $messages;
}
/**
- * Returns a message array with all the information about a message.
+ * Returns a message array with all the information about a message.
* See the documentation folder for more information about this array.
*/
function sqimap_get_message ($imap_stream, $id, $mailbox) {
/* this will include a link back to the message list */
error_message($errmessage, $mailbox, $sort, (int) $startMessage, $color);
exit;
- }
+ }
$bodystructure = implode('',$read);
$msg = mime_structure($bodystructure,$flags);
$read = sqimap_run_command ($imap_stream, "FETCH $id BODY[HEADER]", true, $response, $message, TRUE);
* @param mixed $where UNDOCUMENTED
* @param mixed $what UNDOCUMENTED
*/
-function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
+function printMessageInfo($imapConnection, $t, $last=false, $msg, $mailbox,
$start_msg, $where, $what) {
global $checkall,
- $color, $msgs, $msort, $td_str, $msg,
+ $color, $msgs, $msort, $td_str,
$default_use_priority,
$message_highlight_list,
$index_order,
$color_string = $color[12];
}
}
- $msg = $msgs[$key];
if($mailbox == 'None') {
$boxes = sqimap_mailbox_list($imapConnection);
++$col;
}
}
- if ($not_last) {
+ if ($last) {
+ echo '</tr>'."\n";
+ } else {
echo '</tr>' . "\n" . '<tr><td colspan="' . $col . '" bgcolor="' .
$color[0] . '" height="1"></td></tr>' . "\n";
- } else {
- echo '</tr>'."\n";
}
}
$use_cache, $mode='',$mbxresponse) {
global $msgs, $msort, $auto_expunge, $thread_sort_messages,
$allow_server_sort, $server_sort_order;
+ /* if there's no messages in this folder */
+ if ($mbxresponse['EXISTS'] == 0) {
+ $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
+ echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
+ echo ' <tr><td>';
+ echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
+ echo ' <tr><td><br />';
+ echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
+ echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
+ . '</tr>';
+ echo ' </table>';
+ echo ' <br /></td></tr>';
+ echo ' </table></td></tr>';
+ echo ' </table>';
+ return;
+ }
+
+
/*
* For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
$thread_sort_messages = 0;
$msort = $msgs = array();
} else {
- $msort= $msgs;
$sort = 6;
+ $msort = calc_msort($msgs, $sort);
}
break;
case 'serversort':
$msort = $msgs = array();
$id = array();
} else {
- $msort = $msgs;
$sort = 6;
+ $msort = calc_msort($msgs, $sort);
}
break;
default:
- if (!$use_cache) {
- $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
- $num_msgs, $sort, $mbxresponse);
- $msort = calc_msort($msgs, $sort);
- } /* !use cache */
+ $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
+ $num_msgs, $sort, $mbxresponse);
+ $msort = calc_msort($msgs, $sort);
break;
} // switch
sqsession_register($msort, 'msort');
* @return array
*/
function calc_msort($msgs, $sort) {
-
/*
* 0 = Date (up)
* 1 = Date (dn)
if (($sort == 0) || ($sort == 1)) {
foreach ($msgs as $item) {
- $msort[] = $item['TIME_STAMP'];
+ $msort[$item['ID']] = $item['TIME_STAMP'];
}
} elseif (($sort == 2) || ($sort == 3)) {
foreach ($msgs as $item) {
- $msort[] = $item['FROM-SORT'];
+ $msort[$item['ID']] = $item['FROM-SORT'];
}
} elseif (($sort == 4) || ($sort == 5)) {
foreach ($msgs as $item) {
- $msort[] = $item['SUBJECT-SORT'];
+ //echo $item['SUBJECT-SORT'] . "<br />";
+ $msort[$item['ID']] = $item['SUBJECT-SORT'];
}
} else {
- $msort = $msgs;
+ return array_keys($msgs); //array_walk($msort, create_function('&$v,$k', '$v = $v["ID"];'));
}
if ($sort < 6) {
if ($sort % 2) {
} else {
arsort($msort);
}
+ $msort = array_keys($msort);
}
return $msort;
}
/**
* Generic function to convert the msgs array into an HTML table.
*
- * @param mixed $imapConnection
- * @param mixed $num_msgs
- * @param mixed $start_msg
- * @param mixed $msort
+ * @param resource $imapConnection
+ * @param int $num_msgs total number of messages in the mailbox
+ * @param int $start_msg offset in messages to sisplay
+ * @param array $msort sorted array which is used to map the index to the unsorted $msgs index
* @param string $mailbox mail folder name
- * @param mixed $sort
- * @param mixed $color
- * @param mixed $show_num
+ * @param int $sort sort order. 6 means no sorting or server side / thread sort
+ * @param array $color
+ * @param int $show_num number of messages to show
* @param mixed $where
* @param mixed $what
*/
$show_num, $where=0, $what=0) {
global $imapServerAddress, $use_mailbox_cache, $index_order,
$indent_array, $thread_sort_messages, $allow_server_sort,
- $server_sort_order, $PHP_SELF;
+ $server_sort_order, $PHP_SELF, $msgs;
- $res = getEndMessage($start_msg, $show_num, $num_msgs);
- $start_msg = $res[0];
- $end_msg = $res[1];
$urlMailbox = urlencode($mailbox);
/* get indent level for subject display */
+
+ // FIX ME this call is at the wrong place
if ($thread_sort_messages == 1 && $num_msgs) {
$indent_array = get_parent_level($imapConnection);
}
- $real_startMessage = $start_msg;
+ /* messages display */
+
+ // if client side sorting and no sort we only fetch num_msgs so the start_msg in the $msgs
+ // array must be corrected
if ($sort == 6) {
- if ($end_msg - $start_msg < $show_num - 1) {
- $end_msg = $end_msg - $start_msg + 1;
- $start_msg = 1;
- } else if ($start_msg > $show_num) {
- $end_msg = $show_num;
- $start_msg = 1;
- }
+ $i = 0;
+ } else {
+ $i = $start_msg -1;
}
- $endVar = $end_msg + 1;
/*
* Loop through and display the info for each message.
* ($t is used for the checkbox number)
*/
- $t = 0;
-
- /* messages display */
-
- if (!$num_msgs) {
- /* if there's no messages in this folder */
- echo html_tag( 'tr',
- html_tag( 'td',
- "<br /><b>" . _("THIS FOLDER IS EMPTY") . "</b><br /> ",
- 'center',
- $color[4],
- 'colspan="' . count($index_order) . '"'
- )
- );
- } elseif ($start_msg == $end_msg) {
- /* if there's only one message in the box, handle it differently. */
- if ($sort != 6) {
- $i = $start_msg;
+ $iEnd = $i +$show_num;
+ for ($j=$i,$t=0;$j<$iEnd;++$j) {
+ if (isset($msort[$j])) {
+ $msg = $msgs[$msort[$j]];
+ $last = (isset($msort[$j+1]) || $j == $iEnd) ? false : true;
+ printMessageInfo($imapConnection, $t, $last, $msg, $mailbox,
+ $start_msg, $where, $what);
+ $t++;
} else {
- $i = 1;
+ break;
}
- reset($msort);
- $k = 0;
- do {
- $key = key($msort);
- next($msort);
- $k++;
- } while (isset ($key) && ($k < $i));
- printMessageInfo($imapConnection, $t, true, $key, $mailbox,
- $real_startMessage, $where, $what);
- } else {
- $i = $start_msg;
- reset($msort);
- $k = 0;
- do {
- $key = key($msort);
- next($msort);
- $k++;
- } while (isset ($key) && ($k < $i));
- $not_last = true;
- do {
- if (!$i || $i == $endVar-1) $not_last = false;
- printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
- $real_startMessage, $where, $what);
- $key = key($msort);
- $t++;
- $i++;
- next($msort);
- } while ($i && $i < $endVar);
}
}