' .
- _("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) {
+ /* FIX ME, this function is kind of big, maybe we can split it up in
+ a couple of functions. Make sure the functions are private and starts with _
+ Also make sure that the error codes are propagated */
+
/**
* Retrieve the UIDSET.
* Setindex is used to be able to store multiple uid sets. That will make it
@@ -866,31 +288,39 @@ function fetchMessageHeaders($imapConnection, &$aMailbox) {
}
}
-
if (is_array($aMailbox['UIDSET'])) {
$aUid =& $aMailbox['UIDSET'][$iSetIndx];
} else {
$aUid = false;
}
+ $aFetchHeaders = $aMailbox['FETCHHEADERS'];
+ $iError = 0;
+ $aFetchItems = $aHeaderItems = array();
// 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';
+ $aHeaderFields = array();
+ foreach ($aFetchHeaders as $v) {
+ switch ($v) {
+ case SQM_COL_DATE: $aHeaderFields[] = 'Date'; break;
+ case SQM_COL_TO: $aHeaderFields[] = 'To'; break;
+ case SQM_COL_CC: $aHeaderFields[] = 'Cc'; break;
+ case SQM_COL_FROM: $aHeaderFields[] = 'From'; break;
+ case SQM_COL_SUBJ: $aHeaderFields[] = 'Subject'; break;
+ case SQM_COL_PRIO: $aHeaderFields[] = 'X-Priority'; break;
+ case SQM_COL_ATTACHMENT: $aHeaderFields[] = 'Content-Type'; break;
+ case SQM_COL_INT_DATE: $aFetchItems[] = 'INTERNALDATE'; break;
+ case SQM_COL_FLAGS: $aFetchItems[] = 'FLAGS'; break;
+ case SQM_COL_SIZE: $aFetchItems[] = 'RFC822.SIZE'; break;
+ default: break;
+ }
}
-
/**
* 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 ) {
-
+ if (isset($aUid) && $aUid ) {
// limit the cache to SQM_MAX_PAGES_IN_CACHE
- if (!$aMailbox['SHOWALL'][$iSetIndx]) {
+ if (!$aMailbox['SHOWALL'][$iSetIndx] && isset($aMailbox['MSG_HEADERS'])) {
$iMaxMsgs = $iLimit * SQM_MAX_PAGES_IN_CACHE;
$iCacheSize = count($aMailbox['MSG_HEADERS']);
if ($iCacheSize > $iMaxMsgs) {
@@ -908,8 +338,20 @@ function fetchMessageHeaders($imapConnection, &$aMailbox) {
$id_slice = array_slice($aUid,$start_msg-1,$iLimit);
/* do some funky cache checks */
- $aUidCached = array_keys($aMailbox['MSG_HEADERS']);
+ if (isset($aMailbox['MSG_HEADERS']) && is_array($aMailbox['MSG_HEADERS'])) {
+ // temp code, read_body del / next links fo not update fields.
+ foreach ($aMailbox['MSG_HEADERS'] as $iUid => $aValue) {
+ if (!isset($aValue['UID'])) {
+ unset($aMailbox['MSG_HEADERS'][$iUid]);
+ }
+ }
+ $aUidCached = array_keys($aMailbox['MSG_HEADERS']);
+ } else {
+ $aMailbox['MSG_HEADERS'] = array();
+ $aUidCached = array();
+ }
$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.
@@ -920,1019 +362,848 @@ function fetchMessageHeaders($imapConnection, &$aMailbox) {
// append the msgs to the existend headers
$aMailbox['MSG_HEADERS'] += $aMsgs;
}
-
} else {
/**
- * Initialize the sorted UID list and fetch the visible message headers
+ * Initialize the sorted UID list or initiate a UID list with search
+ * results 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] != 'ALL') { // in case of a search request
+
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);
+
+ $iError = 0;
+ $iError = _get_sorted_msgs_list($imapConnection,$aMailbox,$iError);
$aUid = $aMailbox['UIDSET'][$iSetIndx];
}
- if ($error === false) {
+ if (!$iError) {
+ /**
+ * Number of messages is the resultset
+ */
+ $aMailbox['TOTAL'][$iSetIndx] = count($aUid);
$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;
- }
- }
+ $iError = 1; // FIX ME, define an error code
}
- $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 { //
+ $iError = 0;
+ $iError = _get_sorted_msgs_list($imapConnection,$aMailbox,$iError);
+ $aUid = $aMailbox['UIDSET'][$iSetIndx];
+
+ if (!$iError) {
+ /**
+ * Number of messages is the resultset
+ */
+ $aMailbox['TOTAL'][$iSetIndx] = count($aUid);
+ $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 {
- $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];
+ $iError = 1; // FIX ME, define an error code
}
}
- $aMailbox['UIDSET'][$iSetIndx] = $aSortedUidList;
- $aMailbox['OFFSET'] = 0;
}
}
- return true;
+ return $iError;
}
/**
- * This function loops through a group of messages in the mailbox
- * and shows them to the user.
+ * Prepares the message headers for display inside a template. The links are calculated,
+ * color for row highlighting is calculated and optionally the strings are truncated.
*
- * @param mixed $imapConnection
- * @param array $aMailbox associative array with mailbox related vars
+ * @param array $aMailbox (reference) mailbox retrieved from sqm_api_mailbox_select
+ * @param array $aProps properties
+ * @return array $aFormattedMessages array with message headers and format info
+ * @since 1.5.1
+ * @author Marc Groot Koerkamp
*/
-function showMessagesForMailbox($imapConnection, &$aMailbox) {
- global $color, $javascript_on, $compact_paginator;
+function prepareMessageList(&$aMailbox, $aProps) {
- // 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;
+ /* Globalize link attributes so plugins can share in modifying them */
+ global $link, $title, $target, $onclick, $link_extra;
- 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']);
+ * TODO 1, retrieve array with identity email addresses in order to match against to,cc and set a flag
+ * $aFormattedMessages[$iUid]['match_identity'] = true
+ * The template can show some image if there is a match.
+ * TODO 2, makes sure the matching is done fast by doing a strpos call on the returned $value
+ */
- /* 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;
+ /**
+ * Only retrieve values for displayable columns
+ */
+ foreach ($aColumnDesc as $k => $v) {
+ switch ($k) {
+ case SQM_COL_FROM: $aCol[SQM_COL_FROM] = 'from'; break;
+ case SQM_COL_DATE: $aCol[SQM_COL_DATE] = 'date'; break;
+ case SQM_COL_SUBJ: $aCol[SQM_COL_SUBJ] = 'subject'; break;
+ case SQM_COL_FLAGS: $aCol[SQM_COL_FLAGS] = 'FLAGS'; break;
+ case SQM_COL_SIZE: $aCol[SQM_COL_SIZE] = 'SIZE'; break;
+ case SQM_COL_PRIO: $aCol[SQM_COL_PRIO] = 'x-priority'; break;
+ case SQM_COL_ATTACHMENT: $aCol[SQM_COL_ATTACHMENT] = 'content-type'; break;
+ case SQM_COL_INT_DATE: $aCol[SQM_COL_INT_DATE] = 'INTERNALDATE'; break;
+ case SQM_COL_TO: $aCol[SQM_COL_TO] = 'to'; break;
+ case SQM_COL_CC: $aCol[SQM_COL_CC] = 'cc'; break;
+ case SQM_COL_BCC: $aCol[SQM_COL_BCC] = 'bcc'; break;
+ default: break;
}
- $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 '