' .
+ _("Server-side sorting is not supported by your IMAP server.") . ' ' .
+ _("Please contact your system administrator and report this error.") .
+ '
';
} else {
- arsort($msort);
+ $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 $msort;
+ return $error;
}
-function fillMessageArray($imapConnection, $id, $count) {
- $msgs_list = sqimap_get_small_header_list($imapConnection, $id);
- $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;
+
+
+
+function fetchMessageHeaders($imapConnection, &$aMailbox) {
+
+ /**
+ * Retrieve the UIDSET.
+ * Setindex is used to be able to store multiple uid sets. That will make it
+ * possible to display the mailbox multiple times in different sort order
+ * or to store serach results separate from normal mailbox view.
+ */
+ $iSetIndx = (isset($aMailbox['SETINDEX'])) ? $aMailbox['SETINDEX'] : 0;
+
+ $iLimit = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $aMailbox['LIMIT'];
+ /**
+ * Adjust the start_msg
+ */
+ $start_msg = $aMailbox['PAGEOFFSET'];
+ if($aMailbox['PAGEOFFSET'] > $aMailbox['EXISTS']) {
+ $start_msg -= $aMailbox['LIMIT'];
+ if($start_msg < 1) {
+ $start_msg = 1;
}
}
- for($j = 0; $j < $count; ++$j) {
- if (isset($date[$j])) {
- $date[$j] = str_replace(' ', ' ', $date[$j]);
- $tmpdate = explode(' ', trim($date[$j]));
- } else {
- $tmpdate = $date = array('', '', '', '', '', '');
+
+ if (is_array($aMailbox['UIDSET'])) {
+ $aUid =& $aMailbox['UIDSET'][$iSetIndx];
+ } else {
+ $aUid = false;
+ }
+
+ // 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
+ if ($aMailbox['INTERNALDATE']) {
+ $aFetchItems[] = 'INTERNALDATE';
+ }
+
+
+ /**
+ * 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 ) {
+
+ // limit the cache to SQM_MAX_PAGES_IN_CACHE
+ if (!$aMailbox['SHOWALL'][$iSetIndx]) {
+ $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) {
+ unset($aMailbox['MSG_HEADERS'][$iUid]);
+ } else {
+ break;
+ }
+ --$iReduce;
+ }
+ }
}
- $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.
+
+ $id_slice = array_slice($aUid,$start_msg-1,$iLimit);
+ /* do some funky cache checks */
+ $aUidCached = array_keys($aMailbox['MSG_HEADERS']);
+ $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.
*/
- if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
- $messages[$j]['SUBJECT-SORT'], $matches)){
- $messages[$j]['SUBJECT-SORT'] = $matches[2];
+ if (count($aUidNotCached)) {
+ $aMsgs = sqimap_get_small_header_list($imapConnection,$aUidNotCached,
+ $aHeaderFields,$aFetchItems);
+ // append the msgs to the existend headers
+ $aMailbox['MSG_HEADERS'] += $aMsgs;
+ }
+
+ } else {
+ /**
+ * Initialize the sorted UID list 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] && $aMailbox['SORT'] == 0) {
+ $aUid = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]);
+ } else {
+ $error = get_sorted_msgs_list($imapConnection,$aMailbox,$error);
+ $aUid = $aMailbox['UIDSET'][$iSetIndx];
+ }
+ if ($error === false) {
+ $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;
+ }
+ }
+ }
+ $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 {
+ $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];
+ }
+ }
+ $aMailbox['UIDSET'][$iSetIndx] = $aSortedUidList;
+ $aMailbox['OFFSET'] = 0;
}
}
- return $messages;
+ return true;
}
+/**
+ * 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 $color, $javascript_on, $compact_paginator;
-/* Generic function to convert the msgs array into an HTML table. */
-function displayMessageArray($imapConnection, $num_msgs, $start_msg,
- $msort, $mailbox, $sort, $color,
- $show_num, $where=0, $what=0) {
- global $imapServerAddress, $use_mailbox_cache,
- $index_order, $checkall,
- $indent_array, $thread_sort_messages, $allow_server_sort,
- $server_sort_order, $PHP_SELF;
+ // 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;
- $res = getEndMessage($start_msg, $show_num, $num_msgs);
- $start_msg = $res[0];
- $end_msg = $res[1];
+ 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'];
- $urlMailbox = urlencode($mailbox);
+ $paginator_str = get_paginator_str($aMailbox['NAME'], $aMailbox['PAGEOFFSET'],
+ $aMailbox['EXISTS'], $aMailbox['LIMIT'], $aMailbox['SHOWALL'][$iSetIndx]);
- /* get indent level for subject display */
- if ($thread_sort_messages == 1 ) {
- $indent_array = get_parent_level($imapConnection);
- }
+ $msg_cnt_str = get_msgcnt_str($aMailbox['PAGEOFFSET'], $iEnd,$aMailbox['EXISTS']);
- $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;
- }
+ do_hook('mailbox_index_before');
+
+ if ($javascript_on && $compact_paginator) {
+ // Insert compact paginator javascript
+ echo "\n\n"
+ . "\n"
+ . "\n";
}
- $endVar = $end_msg + 1;
+ mail_message_listing_beginning($imapConnection, $aMailbox, $msg_cnt_str, $paginator_str);
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+" . _("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;
+ * Loop through and display the info for each message.
+ * ($t is used for the checkbox number)
+ */
+ $iEnd = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $iOffset + $aMailbox['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 {
+ $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 {
- $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);
}
}
-/*
- * Displays the standard message list header. To finish the table,
- * you need to do a "";
+/**
+ * Displays the standard message list header.
*
- * $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
+ * 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,
- $mailbox = '', $sort = -1,
+ $aMailbox,
$msg_cnt_str = '',
- $paginator = ' ',
- $start_msg = 1) {
- global $color, $auto_expunge, $base_uri, $thread_sort_messages,
- $allow_thread_sort, $allow_server_sort, $server_sort_order,
- $PHP_SELF;
+ $paginator = ' '
+ ) {
+ global $color, $show_flag_buttons, $PHP_SELF;
+ global $lastTargetMailbox, $boxes;
$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($mailbox);
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 = '';
}
- $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox"
- . "&startMessage=$start_msg";
- /*
- * This is the beginning of the message list table.
- * It wraps around all messages
- */
- echo "\n";
}
-function printHeader($mailbox, $sort, $color, $showsort=true) {
- global $index_order;
+/**
+ * Prints the table header for the messages list view
+ *
+ * @param array $aMailbox
+ */
+function printHeader($aMailbox) {
+ global $index_order, $internal_date_sort, $color;
+
+ if ($aMailbox['SORT_METHOD'] != 'THREAD') {
+ $showsort = true;
+ } else {
+ $showsort = false;
+ }
+
echo html_tag( 'tr' ,'' , 'center', $color[5] );
- for ($i = 1; $i <= count($index_order); $i++) {
- switch ($index_order[$i]) {
+
+ /* calculate the width of the subject column based on the
+ * widths of the other columns */
+ $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
+ $subjectwidth = 100;
+ foreach($index_order as $item) {
+ $subjectwidth -= $widths[$item];
+ }
+
+ foreach ($index_order as $item) {
+ switch ($item) {
case 1: /* checkbox */
+ echo html_tag( 'td',get_selectall_link($aMailbox) , '', '', 'width="1%"' );
+ break;
case 5: /* flags */
- echo html_tag( 'td' ,' ' , '', '', 'width="1%"' );
+ echo html_tag( 'td',' ' , '', '', 'width="1%"' );
break;
case 2: /* from */
- if (handleAsSent($mailbox)) {
+ if (handleAsSent($aMailbox['NAME'])) {
echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
- . '' . _("To") . '';
+ . '' . _("To") . '';
+ if ($showsort) {
+ ShowSortButton($aMailbox, SQSORT_TO_ASC, SQSORT_TO_DEC);
+ }
} else {
echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
- . '' . _("From") . '';
- }
- if ($showsort) {
- ShowSortButton($sort, $mailbox, 2, 3);
+ . '' . _("From") . '';
+ if ($showsort) {
+ ShowSortButton($aMailbox, SQSORT_FROM_ASC, SQSORT_FROM_DEC);
+ }
}
echo "\n";
break;
case 3: /* date */
- echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
- . '' . _("Date") . '';
+ echo html_tag( 'td' ,'' , 'left', '', 'width="5%" style="white-space: nowrap;"' )
+ . '' . _("Date") . '';
if ($showsort) {
- ShowSortButton($sort, $mailbox, 0, 1);
+ if ($internal_date_sort) {
+ ShowSortButton($aMailbox, SQSORT_INT_DATE_ASC, SQSORT_INT_DATE_DEC);
+ } else {
+ ShowSortButton($aMailbox, SQSORT_DATE_ASC, SQSORT_DATE_DEC);
+ }
}
echo "\n";
break;
case 4: /* subject */
- echo html_tag( 'td' ,'' , 'left', '', '' )
- . '' . _("Subject") . '';
+ echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
+ . '' . _("Subject") . '';
if ($showsort) {
- ShowSortButton($sort, $mailbox, 4, 5);
+ ShowSortButton($aMailbox, SQSORT_SUBJ_ASC, SQSORT_SUBJ_DEC);
}
echo "\n";
break;
case 6: /* size */
- echo html_tag( 'td', '' . _("Size") . '', 'center', '', 'width="5%"' );
+ echo html_tag( 'td', '', 'center','','width="5%" style="white-space: nowrap;"')
+ . '' . _("Size") . '';
+ if ($showsort) {
+ ShowSortButton($aMailbox, SQSORT_SIZE_ASC, SQSORT_SIZE_DEC);
+ }
+ echo "\n";
break;
}
}
@@ -829,21 +1382,26 @@ function printHeader($mailbox, $sort, $color, $showsort=true) {
}
-/*
+/**
* This function shows the sort button. Isn't this a good comment?
+ *
+ * @param array $aMailbox
+ * @param integer $Down
+ * @param integer $Up
*/
-function ShowSortButton($sort, $mailbox, $Up, $Down ) {
+function ShowSortButton($aMailbox, $Down, $Up ) {
global $PHP_SELF;
+
/* Figure out which image we want to use. */
- if ($sort != $Up && $sort != $Down) {
+ if ($aMailbox['SORT'] != $Up && $aMailbox['SORT'] != $Down) {
$img = 'sort_none.png';
$which = $Up;
- } elseif ($sort == $Up) {
+ } elseif ($aMailbox['SORT'] == $Up) {
$img = 'up_pointer.png';
$which = $Down;
} else {
$img = 'down_pointer.png';
- $which = 6;
+ $which = 0;
}
if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
@@ -853,118 +1411,159 @@ function ShowSortButton($sort, $mailbox, $Up, $Down ) {
}
/* Now that we have everything figured out, show the actual button. */
- echo ' ';
+ echo ' ';
}
-function get_selectall_link($start_msg, $sort) {
- global $checkall, $what, $where, $mailbox, $javascript_on;
- global $PHP_SELF, $PG_SHOWNUM;
+/**
+ * FIXME: Undocumented function
+ *
+ * @param array $aMailbox
+ */
+function get_selectall_link($aMailbox) {
+ global $checkall, $javascript_on;
+ global $PHP_SELF;
$result = '';
if ($javascript_on) {
+ $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']);
+ $func_name = "CheckAll" . $safe_name;
+ $form_name = "FormMsgs" . $safe_name;
$result = '' . _("Toggle All")
- . "\n";
+ . ''
+ . '';
+// . ' . _("Toggle All")
+// . "\n";
} else {
+ $result .= "";
- if (isset($checkall) && ($checkall == '1')) {
- $result .= _("Unselect All");
- } else {
- $result .= _("Select All");
+ // FIXME: I suspect that search pages use different variables in 1.5.1cvs
+ // and these variables are present in $PHP_SELF.
+ if (isset($aMailbox['SEARCH']) && isset($aMailbox['SEARCH'][0]) && ! sqgetGlobalVar('where',$tmp,SQ_GET)) {
+ $result .= '&where=' . urlencode($aMailbox['SEARCH'][0]);
+ if (isset($aMailbox['SEARCH'][1]) && ! sqgetGlobalVar('what',$tmp,SQ_GET)) {
+ $result .= '&what=' . urlencode($aMailbox['SEARCH'][1]);
+ }
}
- $result .= "\n";
+ $result .= "\">";
+ $result .= _("All");
+ $result .= "\n";
}
/* Return our final result. */
return ($result);
}
-/*
+/**
* This function computes the "Viewing Messages..." string.
+ *
+ * @param integer $start_msg first message number
+ * @param integer $end_msg last message number
+ * @param integer $num_msgs total number of message in folder
+ * @return string
*/
function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
/* Compute the $msg_cnt_str. */
$result = '';
if ($start_msg < $end_msg) {
- $result = sprintf(_("Viewing Messages: %s to %s (%s total)"),
- $start_msg, $end_msg, $num_msgs);
+ $result = sprintf(_("Viewing Messages: %s to %s (%s total)"),
+ ''.$start_msg.'', ''.$end_msg.'', $num_msgs);
} else if ($start_msg == $end_msg) {
- $result = sprintf(_("Viewing Message: %s (1 total)"), $start_msg);
+ $result = sprintf(_("Viewing Message: %s (%s total)"), ''.$start_msg.'', $num_msgs);
} else {
- $result = ' ';
+ $result = ' ';
}
/* Return our result string. */
return ($result);
}
-/*
+/**
* Generate a paginator link.
+ *
+ * @param mixed $box Mailbox name
+ * @param mixed $start_msg Message Offset
+ * @param mixed $use
+ * @param string $text text used for paginator link
+ * @return string
*/
-function get_paginator_link($box, $start_msg, $use, $text) {
- global $PHP_SELF;
+function get_paginator_link($box, $start_msg, $text) {
+ sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER);
+ $result = "$text";
- $result = "$text";
return ($result);
-/*
- if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
- $source_url = $regs[1];
- } else {
- $source_url = $PHP_SELF;
- }
-
- $result = '$text";
- return ($result);
-*/
}
-/*
+/**
* This function computes the paginator string.
+ *
+ * @param string $box mailbox name
+ * @param integer $iOffset offset in total number of messages
+ * @param integer $iTotal total number of messages
+ * @param integer $iLimit maximum number of messages to show on a page
+ * @param bool $bShowAll show all messages at once (non paginate mode)
+ * @return string $result paginate string with links to pages
*/
-function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
- $show_num, $sort) {
- global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
+function get_paginator_str($box, $iOffset, $iTotal, $iLimit, $bShowAll) {
+ global $username, $data_dir, $javascript_on;
+ // page selector globals
+ global $page_selector, $page_selector_max, $compact_paginator;
+ sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER);
/* Initialize paginator string chunks. */
$prv_str = '';
$nxt_str = '';
$pg_str = '';
$all_str = '';
- $tgl_str = '';
$box = urlencode($box);
@@ -972,284 +1571,573 @@ function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
$spc = ' '; /* This will be used as a space. */
$sep = '|'; /* This will be used as a seperator. */
- /* Get some paginator preference values. */
- $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
- $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
-
/* Make sure that our start message number is not too big. */
- $start_msg = min($start_msg, $num_msgs);
-
- /* Decide whether or not we will use the mailbox cache. */
- /* Not sure why $use_mailbox_cache is even passed in. */
- if ($sort == 6) {
- $use = 0;
- } else {
- $use = 1;
- }
+ $iOffset = min($iOffset, $iTotal);
/* Compute the starting message of the previous and next page group. */
- $next_grp = $start_msg + $show_num;
- $prev_grp = $start_msg - $show_num;
-
- /* Compute the basic previous and next strings. */
- if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
- $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
- $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
- } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
- $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
- $nxt_str = ""._("Next")."\n";
- } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
- $prv_str = ""._("Previous") . '';
- $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
- }
-
- /* Page selector block. Following code computes page links. */
- if ($pg_sel && ($num_msgs > $show_num)) {
- /* Most importantly, what is the current page!!! */
- $cur_pg = intval($start_msg / $show_num) + 1;
-
- /* Compute total # of pages and # of paginator page links. */
- $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
- $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
-
- /* Compute the size of the four quarters of the page links. */
-
- /* If we can, just show all the pages. */
- if (($tot_pgs - 1) <= $pg_max) {
- $q1_pgs = $cur_pg - 1;
- $q2_pgs = $q3_pgs = 0;
- $q4_pgs = $tot_pgs - $cur_pg;
-
- /* Otherwise, compute some magic to choose the four quarters. */
+ $next_grp = $iOffset + $iLimit;
+ $prev_grp = $iOffset - $iLimit;
+
+ if (!$bShowAll) {
+ /* Compute the basic previous and next strings. */
+ if ($compact_paginator) {
+ if (($next_grp <= $iTotal) && ($prev_grp >= 0)) {
+ $prv_str = get_paginator_link($box, $prev_grp, '<');
+ $nxt_str = get_paginator_link($box, $next_grp, '>');
+ } else if (($next_grp > $iTotal) && ($prev_grp >= 0)) {
+ $prv_str = get_paginator_link($box, $prev_grp, '<');
+ $nxt_str = '>';
+ } else if (($next_grp <= $iTotal) && ($prev_grp < 0)) {
+ $prv_str = '<';
+ $nxt_str = get_paginator_link($box, $next_grp, '>');
+ }
} else {
- /*
- * Compute the magic base values. Added together,
- * these values will always equal to the $pag_pgs.
- * NOTE: These are DEFAULT values and do not take
- * the current page into account. That is below.
- */
- $q1_pgs = floor($vis_pgs/4);
- $q2_pgs = round($vis_pgs/4, 0);
- $q3_pgs = ceil($vis_pgs/4);
- $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
-
- /* Adjust if the first quarter contains the current page. */
- if (($cur_pg - $q1_pgs) < 1) {
- $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
- $q1_pgs = $cur_pg - 1;
- $q2_pgs = 0;
- $q3_pgs += ceil($extra_pgs / 2);
- $q4_pgs += floor($extra_pgs / 2);
-
- /* Adjust if the first and second quarters intersect. */
- } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
- $extra_pgs = $q2_pgs;
- $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
- $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
- $q3_pgs += ceil($extra_pgs / 2);
- $q4_pgs += floor($extra_pgs / 2);
-
- /* Adjust if the fourth quarter contains the current page. */
- } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
- $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
- $q3_pgs = 0;
- $q4_pgs = $tot_pgs - $cur_pg;
- $q1_pgs += floor($extra_pgs / 2);
- $q2_pgs += ceil($extra_pgs / 2);
-
- /* Adjust if the third and fourth quarter intersect. */
- } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
- $extra_pgs = $q3_pgs;
- $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
- $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
- $q1_pgs += floor($extra_pgs / 2);
- $q2_pgs += ceil($extra_pgs / 2);
+ if (($next_grp <= $iTotal) && ($prev_grp >= 0)) {
+ $prv_str = get_paginator_link($box, $prev_grp, _("Previous"));
+ $nxt_str = get_paginator_link($box, $next_grp, _("Next"));
+ } else if (($next_grp > $iTotal) && ($prev_grp >= 0)) {
+ $prv_str = get_paginator_link($box, $prev_grp, _("Previous"));
+ $nxt_str = _("Next");
+ } else if (($next_grp <= $iTotal) && ($prev_grp < 0)) {
+ $prv_str = _("Previous");
+ $nxt_str = get_paginator_link($box, $next_grp, _("Next"));
}
}
- /*
- * I am leaving this debug code here, commented out, because
- * it is a really nice way to see what the above code is doing.
- * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
- * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . ' ';
- */
+ /* Page selector block. Following code computes page links. */
+ if ($iLimit != 0 && $page_selector && ($iTotal > $iLimit)) {
+ /* Most importantly, what is the current page!!! */
+ $cur_pg = intval($iOffset / $iLimit) + 1;
- /* Print out the page links from the compute page quarters. */
+ /* Compute total # of pages and # of paginator page links. */
+ $tot_pgs = ceil($iTotal / $iLimit); /* Total number of Pages */
- /* Start with the first quarter. */
- if (($q1_pgs == 0) && ($cur_pg > 1)) {
- $pg_str .= "...$spc";
- } else {
- for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
- $start = (($pg-1) * $show_num) + 1;
- $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
- }
- if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
- $pg_str .= "...$spc";
- }
- }
+ if (!$compact_paginator) {
+ $vis_pgs = min($page_selector_max, $tot_pgs - 1); /* Visible Pages */
- /* Continue with the second quarter. */
- for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
- $start = (($pg-1) * $show_num) + 1;
- $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
- }
+ /* Compute the size of the four quarters of the page links. */
- /* Now print the current page. */
- $pg_str .= $cur_pg . $spc;
+ /* If we can, just show all the pages. */
+ if (($tot_pgs - 1) <= $page_selector_max) {
+ $q1_pgs = $cur_pg - 1;
+ $q2_pgs = $q3_pgs = 0;
+ $q4_pgs = $tot_pgs - $cur_pg;
- /* Next comes the third quarter. */
- for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
- $start = (($pg-1) * $show_num) + 1;
- $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
- }
+ /* Otherwise, compute some magic to choose the four quarters. */
+ } else {
+ /*
+ * Compute the magic base values. Added together,
+ * these values will always equal to the $pag_pgs.
+ * NOTE: These are DEFAULT values and do not take
+ * the current page into account. That is below.
+ */
+ $q1_pgs = floor($vis_pgs/4);
+ $q2_pgs = round($vis_pgs/4, 0);
+ $q3_pgs = ceil($vis_pgs/4);
+ $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
+
+ /* Adjust if the first quarter contains the current page. */
+ if (($cur_pg - $q1_pgs) < 1) {
+ $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
+ $q1_pgs = $cur_pg - 1;
+ $q2_pgs = 0;
+ $q3_pgs += ceil($extra_pgs / 2);
+ $q4_pgs += floor($extra_pgs / 2);
+
+ /* Adjust if the first and second quarters intersect. */
+ } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
+ $extra_pgs = $q2_pgs;
+ $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4);
+ $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4);
+ $q3_pgs += ceil($extra_pgs / 2);
+ $q4_pgs += floor($extra_pgs / 2);
+
+ /* Adjust if the fourth quarter contains the current page. */
+ } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
+ $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
+ $q3_pgs = 0;
+ $q4_pgs = $tot_pgs - $cur_pg;
+ $q1_pgs += floor($extra_pgs / 2);
+ $q2_pgs += ceil($extra_pgs / 2);
+
+ /* Adjust if the third and fourth quarter intersect. */
+ } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
+ $extra_pgs = $q3_pgs;
+ $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
+ $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
+ $q1_pgs += floor($extra_pgs / 2);
+ $q2_pgs += ceil($extra_pgs / 2);
+ }
+ }
- /* And last, print the forth quarter page links. */
- if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
- $pg_str .= "...$spc";
- } else {
- if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
- $pg_str .= "...$spc";
- }
- for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
- $start = (($pg-1) * $show_num) + 1;
- $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
+ /*
+ * I am leaving this debug code here, commented out, because
+ * it is a really nice way to see what the above code is doing.
+ * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
+ * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . ' ';
+ */
+
+ /* Print out the page links from the compute page quarters. */
+
+ /* Start with the first quarter. */
+ if (($q1_pgs == 0) && ($cur_pg > 1)) {
+ $pg_str .= "...$spc";
+ } else {
+ for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
+ $start = (($pg-1) * $iLimit) + 1;
+ $pg_str .= get_paginator_link($box, $start, $pg) . $spc;
+ }
+ if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
+ $pg_str .= "...$spc";
+ }
+ }
+
+ /* Continue with the second quarter. */
+ for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
+ $start = (($pg-1) * $iLimit) + 1;
+ $pg_str .= get_paginator_link($box, $start, $pg) . $spc;
+ }
+
+ /* Now print the current page. */
+ $pg_str .= $cur_pg . $spc;
+
+ /* Next comes the third quarter. */
+ for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
+ $start = (($pg-1) * $iLimit) + 1;
+ $pg_str .= get_paginator_link($box, $start, $pg) . $spc;
+ }
+
+ /* And last, print the forth quarter page links. */
+ if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
+ $pg_str .= "...$spc";
+ } else {
+ if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
+ $pg_str .= "...$spc";
+ }
+ for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
+ $start = (($pg-1) * $iLimit) + 1;
+ $pg_str .= get_paginator_link($box, $start,$pg) . $spc;
+ }
+ }
}
+ $last_grp = (($tot_pgs - 1) * $iLimit) + 1;
}
- } else if ($PG_SHOWNUM == 999999) {
- $pg_str = "" ._("Paginate") . '' . $spc;
- }
-
- /* If necessary, compute the 'show all' string. */
- if (($prv_str != '') || ($nxt_str != '')) {
- $all_str = "" . _("Show All") . '';
+ } else {
+ $pg_str = "" ._("Paginate") . '';
}
- /* Last but not least, get the value for the toggle all link. */
- $tgl_str = get_selectall_link($start_msg, $sort);
-
/* Put all the pieces of the paginator string together. */
/**
* Hairy code... But let's leave it like it is since I am not certain
* a different approach would be any easier to read. ;)
*/
$result = '';
- $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
- $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
- $result .= ($pg_str != '' ? $pg_str : '');
- $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
- $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
+ if ( $prv_str || $nxt_str ) {
+
+ /* Compute the 'show all' string. */
+ $all_str = "" . _("Show All") . '';
+ }
+
+ if ($compact_paginator) {
+ if ( $prv_str || $nxt_str ) {
+ $result .= '[' . get_paginator_link($box, 1, '<<') . ']';
+ $result .= '[' . $prv_str . ']';
+
+ $pg_url = $php_self . '?mailbox=' . $box;
+
+ $result .= '[' . $nxt_str . ']';
+ $result .= '[' . get_paginator_link($box, $last_grp, '>>') . ']';
+ if ($page_selector) {
+ $result .= $spc . '';
+
+ if ($javascript_on) {
+ $result .= '';
+ } else {
+ $result .= addSubmit(_("Go"));
+ }
+ }
+ }
+
+ $result .= ($pg_str != '' ? '['.$pg_str.']' . $spc : '');
+ $result .= ($all_str != '' ? $spc . '['.$all_str.']' . $spc . $spc : '');
+ } else {
+ if ( $prv_str || $nxt_str ) {
+ $result .= '[';
+ $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
+ $result .= ($nxt_str != '' ? $nxt_str : '');
+ $result .= ']' . $spc ;
+ }
+
+ $result .= ($pg_str != '' ? $spc . '['.$spc.$pg_str.']' . $spc : '');
+ $result .= ($all_str != '' ? $spc . '['.$all_str.']' . $spc . $spc : '');
+ }
/* If the resulting string is blank, return a non-breaking space. */
if ($result == '') {
$result = ' ';
}
-
/* Return our final magical paginator string. */
return ($result);
}
-function processSubject($subject) {
- global $languages, $squirrelmail_language;
- /* Shouldn't ever happen -- caught too many times in the IMAP functions */
- if ($subject == '')
- return _("(no subject)");
-
- if (strlen($subject) <= 55)
+/**
+ * FIXME: Undocumented function
+ */
+function truncateWithEntities($subject, $trim_at)
+{
+ $ent_strlen = strlen($subject);
+ if (($trim_at <= 0) || ($ent_strlen <= $trim_at))
return $subject;
- $ent_strlen = strlen($subject);
- $trim_val=50;
- $ent_offset=0;
+ global $languages, $squirrelmail_language;
+
/*
* see if this is entities-encoded string
* If so, Iterate through the whole string, find out
* the real number of characters, and if more
- * than 55, substr with an updated trim value.
+ * than $trim_at, substr with an updated trim value.
*/
- while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
- (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
- $trim_val += ($ent_loc_end-$ent_loc)+1;
- $ent_strlen -= $ent_loc_end-$ent_loc;
+ $trim_val = $trim_at;
+ $ent_offset = 0;
+ $ent_loc = 0;
+ while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
+ (($ent_loc_end = strpos($subject, ';', $ent_loc+3)) !== false) ) {
+ $trim_val += ($ent_loc_end-$ent_loc);
$ent_offset = $ent_loc_end+1;
}
-
- if ($ent_strlen <= 55){
- return $subject;
+ if (($trim_val > $trim_at) && ($ent_strlen > $trim_val) && (strpos($subject,';',$trim_val) < ($trim_val + 6))) {
+ $i = strpos($subject,';',$trim_val);
+ if ($i) {
+ $trim_val = strpos($subject,';',$trim_val);
+ }
}
+ // only print '...' when we're actually dropping part of the subject
+ if ($ent_strlen <= $trim_val)
+ return $subject;
if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
- function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
- return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
+ function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_strimwidth')) {
+ return call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_strimwidth', $subject, $trim_val);
}
- return substr($subject, 0, $trim_val) . '...';
+ return substr_replace($subject, '...', $trim_val + 1);
}
-function getMbxList($imapConnection) {
- global $lastTargetMailbox;
- echo ' ';
+
+ global $truncate_subject; /* number of characters for Subject field (<= 0 for unchanged) */
+ $trim_at = $truncate_subject;
+
+ /* if this is threaded, subtract two chars per indentlevel */
+ if (($threadlevel > 0) && ($threadlevel <= 10))
+ $trim_at -= (2*$threadlevel);
+
+ return truncateWithEntities($subject, $trim_at);
}
-function getButton($type, $name, $value) {
- return '';
+
+/**
+ * Creates button
+ *
+ * @deprecated see form functions available in 1.5.1 and 1.4.3.
+ * @param string $type
+ * @param string $name
+ * @param string $value
+ * @param string $js
+ * @param bool $enabled
+ */
+function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
+ $disabled = ( $enabled ? '' : 'disabled ' );
+ $js = ( $js ? $js.' ' : '' );
+ return '';
}
+/**
+ * Puts string into cell, aligns it and adds tag
+ *
+ * @param string $string string
+ * @param string $align alignment
+ */
function getSmallStringCell($string, $align) {
return html_tag('td',
'' . $string . ': ',
$align,
'',
- 'nowrap' );
-}
-
-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));
+ 'style="white-space: nowrap;"' );
}
+/**
+ * This should go in imap_mailbox.php
+ * @param string $mailbox
+ */
function handleAsSent($mailbox) {
- global $sent_folder, $draft_folder, $handleAsSent_result;
+ global $handleAsSent_result;
/* First check if this is the sent or draft folder. */
- $handleAsSent_result = (($mailbox == $sent_folder)
- || ($mailbox == $draft_folder));
+ $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox);
/* Then check the result of the handleAsSent hook. */
do_hook('check_handleAsSent_result', $mailbox);
/* And return the result. */
- return ($handleAsSent_result);
+ return $handleAsSent_result;
}
-?>
+
+/**
+ * Process messages list form and handle the cache gracefully. If $sButton and
+ * $aUid are provided as argument then you can fake a message list submit and
+ * use it i.e. in read_body.php for del move next and update the cache
+ *
+ * @param resource $imapConnection imap connection
+ * @param array $aMailbox (reference) cached mailbox
+ * @param string $sButton fake a submit button
+ * @param array $aUid fake the $msg array
+ * @return string $sError error string in case of an error
+ * @author Marc Groot Koerkamp
+ */
+function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = array()) {
+
+ /* incoming formdata */
+ $sButton = (sqgetGlobalVar('moveButton', $sTmp, SQ_POST)) ? 'move' : $sButton;
+ $sButton = (sqgetGlobalVar('expungeButton', $sTmp, SQ_POST)) ? 'expunge' : $sButton;
+ $sButton = (sqgetGlobalVar('attache', $sTmp, SQ_POST)) ? 'attache' : $sButton;
+ $sButton = (sqgetGlobalVar('delete', $sTmp, SQ_POST)) ? 'setDeleted' : $sButton;
+ $sButton = (sqgetGlobalVar('undeleteButton', $sTmp, SQ_POST)) ? 'setDeleted' : $sButton;
+ $sButton = (sqgetGlobalVar('markRead', $sTmp, SQ_POST)) ? 'setSeen' : $sButton;
+ $sButton = (sqgetGlobalVar('markUnread', $sTmp, SQ_POST)) ? 'unsetSeen' : $sButton;
+ $sButton = (sqgetGlobalVar('markFlagged', $sTmp, SQ_POST)) ? 'setFlagged' : $sButton;
+ $sButton = (sqgetGlobalVar('markUnflagged', $sTmp, SQ_POST)) ? 'unsetFlagged' : $sButton;
+ sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST);
+ sqgetGlobalVar('bypass_trash', $bypass_trash, SQ_POST);
+ sqgetGlobalVar('msg', $msg, SQ_POST);
+
+ $sError = '';
+ $mailbox = $aMailbox['NAME'];
+
+ /* retrieve the check boxes */
+ $aUid = (isset($msg) && is_array($msg)) ? array_values($msg) : $aUid;
+
+ if (count($aUid) && $sButton != 'expunge') {
+ $aUpdatedMsgs = false;
+ $bExpunge = false;
+ switch ($sButton) {
+ case 'setDeleted':
+ // check if id exists in case we come from read_body
+ if (count($aUid) == 1 && is_array($aMailbox['UIDSET'][$aMailbox['SETINDEX']]) &&
+ !in_array($aUid[0],$aMailbox['UIDSET'][$aMailbox['SETINDEX']])) {
+ break;
+ }
+ $aUpdatedMsgs = sqimap_msgs_list_delete($imapConnection, $mailbox, $aUid,$bypass_trash);
+ $bExpunge = true;
+ break;
+ case 'unsetDeleted':
+ case 'setSeen':
+ case 'unsetSeen':
+ case 'setFlagged':
+ case 'unsetFlagged':
+ // get flag
+ $sFlag = (substr($sButton,0,3) == 'set') ? '\\'.substr($sButton,3) : '\\'.substr($sButton,5);
+ $bSet = (substr($sButton,0,3) == 'set') ? true : false;
+ $aUpdatedMsgs = sqimap_toggle_flag($imapConnection, $aUid, $sFlag, $bSet, true);
+ break;
+ case 'move':
+ $aUpdatedMsgs = sqimap_msgs_list_move($imapConnection,$aUid,$targetMailbox);
+ sqsession_register($targetMailbox,'lastTargetMailbox');
+ $bExpunge = true;
+ break;
+ case 'attache':
+ $aMsgHeaders = array();
+ foreach ($aUid as $iUid) {
+ $aMsgHeaders[$iUid] = $aMailbox['MSG_HEADERS'][$iUid];
+ }
+ if (count($aMsgHeaders)) {
+ $composesession = attachSelectedMessages($imapConnection,$aMsgHeaders);
+ // dirty hack, add info to $aMailbox
+ $aMailbox['FORWARD_SESSION'] = $composesession;
+ }
+ break;
+ default:
+ // Hook for plugin buttons
+ do_hook_function('mailbox_display_button_action', $aUid);
+ break;
+ }
+ /**
+ * Updates messages is an array containing the result of the untagged
+ * fetch responses send by the imap server due to a flag change. That
+ * response is parsed in a array with msg arrays by the parseFetch function
+ */
+ if ($aUpdatedMsgs) {
+ // Update the message headers cache
+ $aDeleted = array();
+ foreach ($aUpdatedMsgs as $iUid => $aMsg) {
+ if (isset($aMsg['FLAGS'])) {
+ /**
+ * Only update the cached headers if the header is
+ * cached.
+ */
+ if (isset($aMailbox['MSG_HEADERS'][$iUid])) {
+ $aMailbox['MSG_HEADERS'][$iUid]['FLAGS'] = $aMsg['FLAGS'];
+ }
+ /**
+ * Count the messages with the \Delete flag set so we can determine
+ * if the number of expunged messages equals the number of flagged
+ * messages for deletion.
+ */
+ if (isset($aMsg['FLAGS']['\\deleted']) && $aMsg['FLAGS']['\\deleted']) {
+ $aDeleted[] = $iUid;
+ }
+ }
+ }
+ if ($bExpunge && $aMailbox['AUTO_EXPUNGE'] &&
+ $iExpungedMessages = sqimap_mailbox_expunge($imapConnection, $aMailbox['NAME'], true))
+ {
+ if (count($aDeleted) != $iExpungedMessages) {
+ // there are more messages deleted permanently then we expected
+ // invalidate the cache
+ $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = false;
+ $aMailbox['MSG_HEADERS'] = false;
+ } else {
+ // remove expunged messages from cache
+ $aUidSet = $aMailbox['UIDSET'][$aMailbox['SETINDEX']];
+ if (is_array($aUidSet)) {
+ // create a UID => array index temp array
+ $aUidSetDummy = array_flip($aUidSet);
+ foreach ($aDeleted as $iUid) {
+ // get the id as well in case of SQM_SORT_NONE
+ if ($aMailbox['SORT'] == SQSORT_NONE) {
+ $aMailbox['ID'] = false;
+ //$iId = $aMailbox['MSG_HEADERS'][$iUid]['ID'];
+ //unset($aMailbox['ID'][$iId]);
+ }
+ // unset the UID and message header
+ unset($aUidSetDummy[$iUid]);
+ unset($aMailbox['MSG_HEADERS'][$iUid]);
+ }
+ $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = array_keys($aUidSetDummy);
+ }
+ }
+ // update EXISTS info
+ if ($iExpungedMessages) {
+ $aMailbox['EXISTS'] -= (int) $iExpungedMessages;
+ }
+ // Change the startMessage number if the mailbox was changed
+ if (($aMailbox['PAGEOFFSET']-1) >= $aMailbox['EXISTS']) {
+ $aMailbox['PAGEOFFSET'] = ($aMailbox['PAGEOFFSET'] > $aMailbox['LIMIT']) ?
+ $aMailbox['PAGEOFFSET'] - $aMailbox['LIMIT'] : 1;
+ $aMailbox['OFFSET'] = $aMailbox['PAGEOFFSET'] - 1 ;
+ }
+ }
+ }
+ } else {
+ if ($sButton == 'expunge') {
+ /**
+ * on expunge we do not know which messages will be deleted
+ * so it's useless to try to sync the cache
+
+ * Close the mailbox so we do not need to parse the untagged expunge
+ * responses which do not contain uid info.
+ * NB: Closing a mailbox is faster then expunge because the imap
+ * server does not need to generate the untagged expunge responses
+ */
+ sqimap_run_command($imapConnection,'CLOSE',false,$result,$message);
+ $aMbxResponse = sqimap_mailbox_select($imapConnection,$aMailbox['NAME']);
+ // update the $aMailbox array
+ $aMailbox['EXISTS'] = $aMbxResponse['EXISTS'];
+ $aMailbox['UIDSET'] = false;
+ } else {
+ if ($sButton) {
+ $sError = _("No messages were selected.");
+ }
+ }
+ }
+ return $sError;
+}
+
+function attachSelectedMessages($imapConnection,$aMsgHeaders) {
+ global $username, $attachment_dir,
+ $data_dir, $composesession,
+ $compose_messages;
+
+ if (!isset($compose_messages)) {
+ $compose_messages = array();
+ sqsession_register($compose_messages,'compose_messages');
+ }
+
+ if (!$composesession) {
+ $composesession = 1;
+ sqsession_register($composesession,'composesession');
+ } else {
+ $composesession++;
+ sqsession_register($composesession,'composesession');
+ }
+
+ $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+
+ $composeMessage = new Message();
+ $rfc822_header = new Rfc822Header();
+ $composeMessage->rfc822_header = $rfc822_header;
+ $composeMessage->reply_rfc822_header = '';
+
+ foreach($aMsgHeaders as $iUid => $aMsgHeader) {
+ /**
+ * Retrieve the full message
+ */
+ $body_a = sqimap_run_command($imapConnection, "FETCH $iUid RFC822", true, $response, $readmessage, TRUE);
+
+ if ($response == 'OK') {
+ $subject = (isset($aMsgHeader['SUBJECT'])) ? $aMsgHeader['SUBJECT'] : $iUid;
+
+ array_shift($body_a);
+ array_pop($body_a);
+ $body = implode('', $body_a);
+ $body .= "\r\n";
+
+ $localfilename = GenerateRandomString(32, 'FILE', 7);
+ $full_localfilename = "$hashed_attachment_dir/$localfilename";
+
+ $fp = fopen( $full_localfilename, 'wb');
+ fwrite ($fp, $body);
+ fclose($fp);
+ $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
+ $full_localfilename);
+ }
+ }
+
+ $compose_messages[$composesession] = $composeMessage;
+ sqsession_register($compose_messages,'compose_messages');
+ return $composesession;
+}
+
+// vim: et ts=4
+?>
\ No newline at end of file