\n";
+/**
+* Does the $sort $_GET var to field mapping
+*
+* @param int $sort Field to sort on
+* @param bool $bServerSort Server sorting is true
+* @param mixed $key UNDOCUMENTED
+* @return string $sSortField Field tosort on
+*/
+function getSortField($sort,$bServerSort) {
+ switch($sort) {
+ case SQSORT_NONE:
+ $sSortField = 'UID';
break;
- case 2: /* from */
- echo "
' .
+ _( "Server-side sorting is not supported by your IMAP server.") . ' ' .
+ _("Please report this to the system administrator.").
+ '
';
}
+ break;
+ default:
+ $sSortField = getSortField($aMailbox['SORT'],false);
+ $id = get_squirrel_sort($imapConnection, $sSortField, $bDirection);
+ break;
}
- echo "\n";
+ return $id;
}
/**
- * 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;
- global $sent_folder, $draft_folder;
- global $message_highlight_list;
- global $auto_expunge;
-
- /* If autoexpunge is turned on, then do it now. */
- if ($auto_expunge == true) {
- sqimap_mailbox_expunge($imapConnection, $mailbox, false);
- }
- sqimap_mailbox_select($imapConnection, $mailbox);
-
- $issent = handleAsSent($mailbox);
- if (!$use_cache) {
- /* If it is sorted... */
- if ($num_msgs >= 1) {
- if ($sort < 6) {
- $id = range(1, $num_msgs);
- } else {
- // if it's not sorted
- 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_reverse(range($real_endMessage, $real_startMessage));
+* 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 $msgs, $server_sort_array, $indent_array, $color;
+
+ // 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 there's no messages in this folder */
+ if ($aMailbox['EXISTS'] == 0) {
+ $string = '' . _("THIS FOLDER IS EMPTY") . '';
+ echo '
';
+ echo '
';
+ echo '
';
+ echo '
';
+ echo '
';
+ echo '
' . html_tag( 'td', $string."\n", 'left')
+ . '
';
+ echo '
';
+ echo '
';
+ echo '
';
+ echo '
';
+ return;
+ } else {
+ /*
+ * Adjust the start_msg
+ */
+ $start_msg = $aMailbox['PAGEOFFSET'];
+ if($aMailbox['PAGEOFFSET'] > $aMailbox['EXISTS']) {
+ $start_msg -= $aMailbox['LIMIT'];
+ if($start_msg < 1) {
+ $start_msg = 1;
}
+ }
+ $aMailbox['SEARCH'] = array(); // Alex maybe you can change this so that you can use it from a search
+
+ // initialize the fields we want to retrieve:
+ $aHeaderFields = array('Date', 'To', 'Cc', 'From', 'Subject', 'X-Priority', 'Content-Type');
+ $aFetchItems = array('FLAGS', 'RFC822.SIZE');
+ // Are we sorting on internaldate then retrieve the internaldate value as well
+ $internaldate = getPref($data_dir, $username, 'internal_date_sort');
+ if ($internaldate) {
+ $aFetchItems[] = 'INTERNALDATE';
+ }
- $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
- $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
- foreach ($msgs_list as $hdr) {
- $from[] = $hdr->from;
- $date[] = $hdr->date;
- $subject[] = $hdr->subject;
- $to[] = $hdr->to;
- $priority[] = $hdr->priority;
- $cc[] = $hdr->cc;
- $size[] = $hdr->size;
- $type[] = $hdr->type0;
+ 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'],
+ $aHeaderFields,$aFetchItems);
- $j = 0;
- 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;
+ return false;
}
+ // FIX ME, move to msgs cache bound to a mailbox
+ sqsession_register($msgs, 'msgs');
} else {
- $end = $num_msgs;
- $end_loop = $end;
- }
+ if (sqsession_is_registered('server_sort_array')) {
+ sqsession_unregister('server_sort_array');
+ }
- while ($j < $end_loop) {
- if (isset($date[$j])) {
- $date[$j] = ereg_replace(' ', ' ', $date[$j]);
- $tmpdate = explode(' ', trim($date[$j]));
+ 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)) {
+ $msgs = sqimap_get_small_header_list($imapConnection,$id_slice,$aMailbox['LIMIT'],
+ $aHeaderFields,$aFetchItems);
+ } else {
+ // FIX ME do error handling
+ return false;
+ }
+ } else {
+ // FIX ME, format message and fallback to squirrel sort
+ if ($error) {
+ echo $error;
+ }
+ }
} else {
- $tmpdate = $date = array('', '', '', '', '', '');
+ /**
+ * 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
+ $iRangeEnd = (($aMailbox['EXISTS'] - $aMailbox['OFFSET']) > $aMailbox['LIMIT']) ?
+ $aMailbox['EXISTS'] - $aMailbox['OFFSET'] +1 - $aMailbox['LIMIT']:
+ $aMailbox['EXISTS'] - $aMailbox['OFFSET'];
+ $iRangeStart = (($aMailbox['EXISTS'] - $aMailbox['OFFSET']) > $aMailbox['LIMIT']) ?
+ $aMailbox['EXISTS']-$aMailbox['OFFSET'] +1:1;
+ $id_slice = range($iRangeStart, $iRangeEnd);
+ $msgs = sqimap_get_small_header_list($imapConnection,$id_slice,$aMailbox['LIMIT'],
+ $aHeaderFields,$aFetchItems);
+ $msgs = array_reverse($msgs,true /* preserve key */);
+ // generate id array
+ $id = array_keys($msgs);
+ $aMailbox['OFFSET'] = 0;
}
-
- $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
- $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
- $messages[$j]['ID'] = $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];
-
- # fix SUBJECT-SORT to remove Re:
- $re_abbr = /* Add more here! */
- 'vedr|sv|' . /* Danish */
- 're|aw'; /* English */
-
- if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) {
- $messages[$j]['SUBJECT-SORT'] = $regs[2];
+ // FIX ME, use an id list bound to a mailbox
+ if ($id !== false) {
+ sqsession_register($id, 'server_sort_array');
}
- $num = 0;
- while ($num < count($flags[$j])) {
- if ($flags[$j][$num] == 'Deleted') {
- $messages[$j]['FLAG_DELETED'] = true;
- } else if ($flags[$j][$num] == 'Answered') {
- $messages[$j]['FLAG_ANSWERED'] = true;
- } else if ($flags[$j][$num] == 'Seen') {
- $messages[$j]['FLAG_SEEN'] = true;
- } else if ($flags[$j][$num] == 'Flagged') {
- $messages[$j]['FLAG_FLAGGED'] = true;
- }
- $num++;
- }
- $j++;
+ sqsession_register($msgs, 'msgs');
+ }
+ $aMailbox['UIDSET'] =& $id;
+ $aMailbox['MSG_HEADERS'] =& $msgs;
+ if ($aMailbox['SORT_METHOD'] == 'THREAD') {
+ // retrieve indent array for thread sort
+ sqgetGlobalVar('indent_array',$indent_array,SQ_SESSION);
+ $aMailbox['THREAD_INDENT'] =& $indent_array;
}
+ } /* if exists > 0 */
- /* Only ignore messages flagged as deleted if we are using a
- * trash folder or auto_expunge */
- if (((isset($move_to_trash) && $move_to_trash)
- || (isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
+ $iEnd = ($aMailbox['PAGEOFFSET'] + ($aMailbox['LIMIT'] - 1) < $aMailbox['EXISTS']) ?
+ $aMailbox['PAGEOFFSET'] + $aMailbox['LIMIT'] - 1 : $aMailbox['EXISTS'];
- /** Find and remove the ones that are deleted */
- $i = 0;
- $j = 0;
+ $paginator_str = get_paginator_str($aMailbox['NAME'], $aMailbox['PAGEOFFSET'], $iEnd,
+ $aMailbox['EXISTS'], $aMailbox['LIMIT'], $aMailbox['SORT']);
- while ($j < $num_msgs) {
- if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
- $j++;
- continue;
- }
- $msgs[$i] = $messages[$j];
+ $msg_cnt_str = get_msgcnt_str($aMailbox['PAGEOFFSET'], $iEnd,$aMailbox['EXISTS']);
- $i++;
- $j++;
- }
- $num_msgs = $i;
- } else {
- if (!isset($messages)) {
- $messages = array();
- }
- $msgs = $messages;
- }
- }
+ do_hook('mailbox_index_before');
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0 && ! $use_cache) {
- /** 0 = Date (up) 4 = Subject (up)
- ** 1 = Date (dn) 5 = Subject (dn)
- ** 2 = Name (up)
- ** 3 = Name (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 // ($sort == 6)
- $msort = $msgs;
-
- if ($sort < 6) {
- if ($sort % 2) {
- asort($msort);
+/**
+* Function to map an uid list with a msg header array by uid
+* The mapped headers are printed with printMessage
+* aMailbox parameters contains info about the page we are on, the
+* used search criteria, the number of messages to show
+*
+* @param resource $imapConnection socket handle to imap
+* @param array $aMailbox array with required elements MSG_HEADERS, UIDSET, OFFSET, LIMIT
+* @return void
+**/
+function displayMessageArray($imapConnection, $aMailbox) {
+
+ $aId = $aMailbox['UIDSET'];
+ $aHeaders = $aMailbox['MSG_HEADERS'];
+ $iOffset = $aMailbox['OFFSET'];
+ $sort = $aMailbox['SORT'];
+ $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)
+ */
+ $iEnd = ($aMailbox['LIMIT']) ? $iOffset + $aMailbox['LIMIT'] : 99999999 /* no limit */;
+ for ($i=$iOffset,$t=0;$i<$iEnd;++$i) {
+ 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 {
- arsort($msort);
+ $indent = 0;
}
+ $aMsg = array(
+ 'HEADER' => $aHeaders[$aId[$i]],
+ 'INDX' => $t,
+ 'OFFSET' => $iOffset,
+ 'PAGEOFFSET' => $iPageOffset,
+ 'SORT' => $sort,
+ 'SEARCH' => $aSearch,
+ 'MAILBOX' => $sMailbox,
+ 'INDENT' => $indent,
+ 'LAST' => $bLast
+ );
+ printMessageInfo($aMsg);
+ ++$t;
+ } else {
+ break;
}
- session_register('msort');
}
- displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
- session_register('msgs');
}
/**
- * 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) {
- global $folder_prefix, $sent_folder;
- global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
- global $index_order, $real_endMessage, $real_startMessage, $checkall;
-
- /* 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;
- }
+* 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, $base_uri, $show_flag_buttons, $PHP_SELF;
- 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');
+ $php_self = $PHP_SELF;
+ /* fix for incorrect $PHP_SELF */
+ if (strpos($php_self, 'move_messages.php')) {
+ $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
+ }
+ $urlMailbox = urlencode($aMailbox['NAME']);
- $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
- $paginator_str = get_paginator_str
- ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort);
+ if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
+ $source_url = $regs[1];
+ } else {
+ $source_url = $php_self;
+ }
- if (! isset($msg)) {
+ if (!isset($msg)) {
$msg = '';
}
- mail_message_listing_beginning( $imapConnection,
- "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg",
- $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;
- }
+ if (!strpos($php_self,'?')) {
+ $location = $php_self.'?mailbox=INBOX&startMessage=1';
+ } else {
+ $location = $php_self;
}
- $endVar = $end_msg + 1;
-
- /* Loop through and display the info for each message. */
- $t = 0; // $t is used for the checkbox number
- if ($num_msgs == 0) { // if there's no messages in this folder
- echo "
";
- /** End of message-list table */
+ $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 '\n";
+ 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;
- global $checkall, $sent_folder, $draft_folder;
- $urlMailbox = urlencode($mailbox);
+* Prints the table header for the messages list view
+*
+* @param array $aMailbox
+*/
+function printHeader($aMailbox) {
+ global $index_order, $internal_date_sort, $color;
- /*
- * This is the beginning of the message list table.
- * It wraps around all messages
- */
- echo "