";
$flag_end = '';
} else {
$flag = '';
$flag_end = '';
}
if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
$bold = '';
$bold_end = '';
} else {
$bold = '';
$bold_end = '';
}
if (handleAsSent($mailbox)) {
$italic = '';
$italic_end = '';
} else {
$italic = '';
$italic_end = '';
}
if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
$fontstr = "";
$fontstr_end = '';
} else {
$fontstr = '';
$fontstr_end = '';
}
/**
* AAAAH! Make my eyes stop bleeding!
* Who wrote this?!
*/
if (sizeof($message_highlight_list)){
foreach ($message_highlight_list as $message_highlight_list_part) {
if (trim($message_highlight_list_part['value']) != '') {
if ($message_highlight_list_part['match_type'] == 'to_cc') {
if (strstr('^^' . strtolower($msg['TO']),
strtolower($message_highlight_list_part['value']))
|| strstr('^^'.strtolower($msg['CC']),
strtolower($message_highlight_list_part['value']))) {
$hlt_color = $message_highlight_list_part['color'];
continue;
}
} else
if (strstr('^^' . strtolower($msg[strtoupper($message_highlight_list_part['match_type'])]),
strtolower($message_highlight_list_part['value']))) {
$hlt_color = $message_highlight_list_part['color'];
continue;
}
}
}
}
if (!isset($hlt_color)) {
$hlt_color = $color_string;
}
if ($where && $what) {
if(!isset($pos) || $pos == '') {
$pos = '0';
}
$search_stuff = "&pos=" . urlencode($pos)
. "&where=" . urlencode($where) . '&what=' . urlencode($what);
} else {
$search_stuff = '';
}
$checked = ($checkall == 1) ? ' checked' : '';
if (sizeof($index_order)){
foreach ($index_order as $index_order_part) {
switch ($index_order_part) {
case 1: /* checkbox */
echo html_tag( 'td',
"",
'center',
$hlt_color );
break;
case 2: /* from */
echo html_tag( 'td',
$italic . $bold . $flag . $fontstr . $senderName .
$fontstr_end . $flag_end . $bold_end . $italic_end,
'left',
$hlt_color );
break;
case 3: /* date */
echo html_tag( 'td',
$bold . $flag . $fontstr . $msg['DATE_STRING'] .
$fontstr_end . $flag_end . $bold_end,
'center',
$hlt_color,
'nowrap' );
break;
case 4: /* subject */
$td_str = $bold;
if ($thread_sort_messages == 1) {
if (isset($indent_array[$msg["ID"]])) {
$td_str .= str_repeat(" ",$indent_array[$msg['ID']]);
}
}
$td_str .= "";
if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
$td_str .= _("A");
$stuff = true;
}
if ($msg['TYPE0'] == 'multipart') {
$td_str .= '+';
$stuff = true;
}
if ($default_use_priority) {
if ( ($msg['PRIORITY'] == 1) || ($msg['PRIORITY'] == 2) ) {
$td_str .= "!";
$stuff = true;
}
if ($msg['PRIORITY'] == 5) {
$td_str .= "?";
$stuff = true;
}
}
if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
$td_str .= "D";
$stuff = true;
}
if (!$stuff) {
$td_str .= ' ';
}
$td_str .= '';
echo html_tag( 'td',
$td_str,
'center',
$hlt_color,
'nowrap' );
break;
case 6: /* size */
echo html_tag( 'td',
$bold . $fontstr . show_readable_size($msg['SIZE']) .
$fontstr_end . $bold_end,
'right',
$hlt_color );
break;
}
}
}
echo "\n";
}
/*
* This function loops through a group of messages in the mailbox
* and shows them to the user.
*/
function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
$start_msg, $sort, $color, $show_num,
$use_cache) {
global $msgs, $msort,
$sent_folder, $draft_folder,
$message_highlight_list,
$auto_expunge, $thread_sort_messages, $allow_server_sort,
$data_dir, $username, $server_sort_order, $php_sort_order;
/* If autoexpunge is turned on, then do it now. */
$mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
$issent = handleAsSent($mailbox);
/* 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;
}
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) {
$id = get_thread_sort($imapConnection);
if ($id == 'no') {
echo '' .
_("Thread sorting is not supported by your IMAP server.
Please report this to the system administrator.").
'';
$thread_sort_messages = 0;
$id = array();
} else {
$sort = 6;
if ($start_msg + ($show_num - 1) < $num_msgs) {
$end_msg = $start_msg + ($show_num-1);
} else {
$end_msg = $num_msgs;
}
$id = array_slice($id, ($start_msg-1), ($end_msg));
}
}
if ($allow_server_sort == TRUE && $thread_sort_messages != 1) {
$server_sort_order = $sort;
$id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
if ($id == 'no') {
echo '' .
_( "Server-side sorting is not supported by your IMAP server.
Please report this to the system administrator.").
'';
$sort = $server_sort_order;
$allow_server_sort = FALSE;
$id = array();
} else {
$sort = 6;
if ($start_msg + ($show_num - 1) < $num_msgs) {
$end_msg = $start_msg + ($show_num-1);
} else {
$end_msg = $num_msgs;
}
$id = array_slice($id, ($start_msg-1), ($end_msg));
}
}
if (!$use_cache) {
/* If it is sorted... */
if ($num_msgs >= 1) {
if ($sort < 6 ) {
$id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
} elseif ($thread_sort_messages != 1 && $allow_server_sort != TRUE && $sort == 6) {
/* if it's not sorted */
$id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
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;
}
}
$real_startMessage = $num_msgs - $start_msg + 1;
$real_endMessage = $num_msgs - $start_msg - $show_num + 2;
if ($real_endMessage <= 0) {
$real_endMessage = 1;
}
$id = array_slice(array_reverse($id), ($start_msg-1), ($end_msg));
}
}
if ($sort == 6) {
$end = $start_msg + $show_num - 1;
if ($num_msgs < $show_num) {
$end_loop = $num_msgs;
} else if ($end > $num_msgs) {
$end_loop = $num_msgs - $start_msg + 1;
} else {
$end_loop = $show_num;
}
} else {
$end = $num_msgs;
$end_loop = $end;
}
$messages = fillMessageArray($imapConnection,$id,$issent,$end_loop);
if (!isset($messages)) {
$messages = array();
}
$msgs = $messages;
}
$msort = calc_msort($msgs, $sort, $num_msgs, $use_cache);
/* There's gotta be messages in the array for it to sort them. */
} /* if exists > 0 */
displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs,
$msort, $mailbox, $sort, $color,$show_num);
/**
* TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
*/
session_register('msgs');
}
function calc_msort($msgs, $sort, $num_msgs, $use_cache) {
global $thread_sort_messages, $allow_server_sort;
if (($num_msgs > 0) && (!$use_cache)) {
/*
* 0 = Date (up)
* 1 = Date (dn)
* 2 = Name (up)
* 3 = Name (dn)
* 4 = Subject (up)
* 5 = Subject (dn)
*/
session_unregister('msgs');
if (($sort == 0) || ($sort == 1)) {
$msort = array_cleave ($msgs, 'TIME_STAMP');
} elseif (($sort == 2) || ($sort == 3)) {
$msort = array_cleave ($msgs, 'FROM-SORT');
} elseif (($sort == 4) || ($sort == 5)) {
$msort = array_cleave ($msgs, 'SUBJECT-SORT');
} else {
$msort = $msgs;
}
if ($sort < 6) {
if ($sort % 2) {
asort($msort);
} else {
arsort($msort);
}
}
session_register('msort');
} elseif ($thread_sort_messages == 1 || $allow_server_sort == TRUE) {
$msort = $msgs;
session_unregister('msgs');
session_register('msort');
}
return $msort;
}
function fillMessageArray($imapConnection,$id,$issent,$count) {
$msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
$messages = array();
if (sizeof($msgs_list)){
foreach ($msgs_list as $hdr) {
$unique_id[] = $hdr->uid;
$from[] = $hdr->from;
$date[] = $hdr->date;
$subject[] = $hdr->subject;
$to[] = $hdr->to;
$priority[] = $hdr->priority;
$cc[] = $hdr->cc;
$size[] = $hdr->size;
$type[] = $hdr->type0;
$flag_deleted[] = $hdr->flag_deleted;
$flag_answered[] = $hdr->flag_answered;
$flag_seen[] = $hdr->flag_seen;
$flag_flagged[] = $hdr->flag_flagged;
}
}
$j = 0;
while ($j < $count) {
if (isset($date[$j])) {
$date[$j] = str_replace(' ', ' ', $date[$j]);
$tmpdate = explode(' ', trim($date[$j]));
} else {
$tmpdate = $date = array('', '', '', '', '', '');
}
$messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
$messages[$j]['DATE_STRING'] =
getDateString($messages[$j]['TIME_STAMP']);
$messages[$j]['ID'] = $unique_id[$j];
$messages[$j]['FROM'] = decodeHeader($from[$j]);
$messages[$j]['FROM-SORT'] =
strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
$messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
$messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
$messages[$j]['TO'] = decodeHeader($to[$j]);
$messages[$j]['PRIORITY'] = $priority[$j];
$messages[$j]['CC'] = $cc[$j];
$messages[$j]['SIZE'] = $size[$j];
$messages[$j]['TYPE0'] = $type[$j];
$messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
$messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
$messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
$messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
/*
* fix SUBJECT-SORT to remove Re:
* vedr|sv (Danish)
* re|aw (English)
*
* TODO: i18n should be incorporated here. E.g. we catch the ones
* we know about, but also define in i18n what the localized
* "Re: " is for this or that locale.
*/
if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
$messages[$j]['SUBJECT-SORT'], $matches)){
$messages[$j]['SUBJECT-SORT'] = $matches[2];
}
$j++;
}
return $messages;
}
/* Generic function to convert the msgs array into an HTML table. */
function displayMessageArray($imapConnection, $num_msgs, $start_msg,
&$msgs, $msort, $mailbox, $sort, $color,
$show_num, $search=false) {
global $folder_prefix, $sent_folder,
$imapServerAddress, $data_dir, $username, $use_mailbox_cache,
$index_order, $real_endMessage, $real_startMessage, $checkall,
$indent_array, $thread_sort_messages, $allow_server_sort,
$server_sort_order, $PHP_SELF;
/* If cache isn't already set, do it now. */
if (!session_is_registered('msgs')) {
session_register('msgs');
}
if (!session_is_registered('msort')) {
session_register('msort');
}
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;
}
}
$urlMailbox = urlencode($mailbox);
do_hook('mailbox_index_before');
if (preg_match('/.+search\.php.*/',$PHP_SELF,$regs)) {
$paginator_str = get_selectall_link($start_msg, $sort);
} else {
$paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg,
$num_msgs, $show_num, $sort);
}
$msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
if (!isset($msg)) {
$msg = '';
}
/* get indent level for subject display */
if ($thread_sort_messages == 1 ) {
$indent_array = get_parent_level($imapConnection);
}
$fstring = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
. "&startMessage=$start_msg";
/* messages display header */
if ($num_msgs) {
mail_message_listing_beginning($imapConnection, $fstring,
$mailbox, $sort, $msg_cnt_str,
$paginator_str, $start_msg);
}
$groupNum = $start_msg % ($show_num - 1);
$real_startMessage = $start_msg;
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;
}
}
$endVar = $end_msg + 1;
/*
* Loop through and display the info for each message.
* ($t is used for the checkbox number)
*/
$t = 0;
/* messages display */
echo html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
if ($num_msgs == 0) {
/* if there's no messages in this folder */
echo html_tag( 'tr',
html_tag( 'td',
"
" . _("THIS FOLDER IS EMPTY") . "
",
'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;
} else {
$i = 1;
}
reset($msort);
$k = 0;
do {
$key = key($msort);
next($msort);
$k++;
} while (isset ($key) && ($k < $i));
printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
$real_startMessage, 0, 0);
} else {
$i = $start_msg;
reset($msort);
$k = 0;
do {
$key = key($msort);
next($msort);
$k++;
} while (isset ($key) && ($k < $i));
do {
printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
$sort, $real_startMessage, 0, 0);
$key = key($msort);
$t++;
$i++;
next($msort);
} while ($i && $i < $endVar);
}
echo '';
/* messages display footer */
if ($num_msgs) {
echo html_tag( 'table',
html_tag( 'tr',
html_tag( 'td',
html_tag( 'table',
html_tag( 'tr',
html_tag( 'td', $paginator_str ) .
html_tag( 'td', $msg_cnt_str, 'right' )
)
, '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
)
, '', $color[4] )
, '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
}
/* End of message-list table */
do_hook('mailbox_index_after');
echo "\n";
}
/*
* Displays the standard message list header. To finish the table,
* you need to do a "";
*
* $moveURL is the URL to submit the delete/move form to
* $mailbox is the current mailbox
* $sort is the current sorting method (-1 for no sorting available [searches])
* $Message is a message that is centered on top of the list
* $More is a second line that is left aligned
*/
function mail_message_listing_beginning ($imapConnection, $moveURL,
$mailbox = '', $sort = -1,
$msg_cnt_str = '',
$paginator = ' ',
$start_msg = 1) {
global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
$checkall, $sent_folder, $draft_folder, $thread_sort_messages,
$allow_thread_sort, $allow_server_sort, $server_sort_order,
$lastTargetMailbox, $PHP_SELF;
$urlMailbox = urlencode($mailbox);
if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
$source_url = $regs[1];
} else {
$source_url = $PHP_SELF;
}
/*
* This is the beginning of the message list table.
* It wraps around all messages
*/
echo "