+ }
+ sqsession_register($thread_new, 'thread_new');
+ $thread_new = array_reverse($thread_new);
+ $thread_list = implode(" ", $thread_new);
+ $thread_list = str_replace("(", " ", $thread_list);
+ $thread_list = str_replace(")", " ", $thread_list);
+ $thread_list = preg_split("/\s/", $thread_list, -1, PREG_SPLIT_NO_EMPTY);
+ $server_sort_array = $thread_list;
+ sqsession_register($server_sort_array, 'server_sort_array');
+ return $thread_list;
+}
+
+
+function elapsedTime($start) {
+ $stop = gettimeofday();
+ $timepassed = 1000000 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec'];
+ return $timepassed;
+}
+
+// only used in sqimap_get_small_header_list
+function parseString($read,&$i) {
+ $char = $read{$i};
+ $s = '';
+ if ($char == '"') {
+ $iPos = ++$i;
+ while (true) {
+ $iPos = strpos($read,'"',$iPos);
+ if (!$iPos) break;
+ if ($iPos && $read{$iPos -1} != '\\') {
+ $s = substr($read,$i,($iPos-$i));
+ $i = $iPos;
+ break;
+ }
+ $iPos++;
+ if ($iPos > strlen($read)) {
+ break;
+ }
+ }
+ } else if ($char == '{') {
+ $lit_cnt = '';
+ ++$i;
+ $iPos = strpos($read,'}',$i);
+ if ($iPos) {
+ $lit_cnt = substr($read, $i, $iPos - $i);
+ $i += strlen($lit_cnt) + 3; /* skip } + \r + \n */
+ /* Now read the literal */
+ $s = ($lit_cnt ? substr($read,$i,$lit_cnt): '');
+ $i += $lit_cnt;
+ /* temp bugfix (SM 1.5 will have a working clean version)
+ too much work to implement that version right now */
+ --$i;
+ } else { /* should never happen */
+ $i += 3; /* } + \r + \n */
+ $s = '';
+ }
+ } else {
+ return false;
+ }
+ ++$i;
+ return $s;
+}
+
+// only used in sqimap_get_small_header_list
+function parseArray($read,&$i) {
+ $i = strpos($read,'(',$i);
+ $i_pos = strpos($read,')',$i);
+ $s = substr($read,$i+1,$i_pos - $i -1);
+ $a = explode(' ',$s);
+ if ($i_pos) {
+ $i = $i_pos+1;
+ return $a;
+ } else {
+ return false;
+ }
+}
+
+function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false) {
+ global $squirrelmail_language, $color, $data_dir, $username, $imap_server_type;
+ global $uid_support, $allow_server_sort;
+ /* Get the small headers for each message in $msg_list */
+ $maxmsg = sizeof($msg_list);
+ if ($show_num != '999999') {
+ $msgs_str = sqimap_message_list_squisher($msg_list);
+ } else {
+ $msgs_str = '1:*';
+ }
+ $messages = array();
+ $read_list = array();
+
+ /*
+ * We need to return the data in the same order as the caller supplied
+ * in $msg_list, but IMAP servers are free to return responses in
+ * whatever order they wish... So we need to re-sort manually
+ */
+ for ($i = 0; $i < sizeof($msg_list); $i++) {
+ $messages["$msg_list[$i]"] = array();
+ }
+
+ $internaldate = getPref($data_dir, $username, 'internal_date_sort');
+ if ($internaldate) {
+ $query = "FETCH $msgs_str (FLAGS UID RFC822.SIZE INTERNALDATE BODY.PEEK[HEADER.FIELDS (Date To Cc From Subject X-Priority Content-Type)])";
+ } else {
+ $query = "FETCH $msgs_str (FLAGS UID RFC822.SIZE BODY.PEEK[HEADER.FIELDS (Date To Cc From Subject X-Priority Content-Type)])";
+ }
+ $read_list = sqimap_run_command_list ($imap_stream, $query, true, $response, $message, $uid_support);
+ $i = 0;
+
+ foreach ($read_list as $r) {
+ $subject = _("(no subject)");
+ $from = _("Unknown Sender");
+ $priority = 0;
+ $messageid = '<>';
+ $cc = $to = $date = $type[0] = $type[1] = $inrepto = '';
+ $flag_seen = $flag_answered = $flag_deleted = $flag_flagged = false;
+
+ $read = implode('',$r);
+
+ /*
+ * #id<space>FETCH<space>(
+ */
+
+ /* extract the message id */
+ $i_space = strpos($read,' ',2);
+ $id = substr($read,2,$i_space-2);
+ $fetch = substr($read,$i_space+1,5);
+ if (!is_numeric($id) && $fetch !== 'FETCH') {
+ set_up_language($squirrelmail_language);
+ echo '<br><b><font color=$color[2]>' .
+ _("ERROR : Could not complete request.") .
+ '</b><br>' .
+ _("Unknown response from IMAP server: ") . ' 1.' .
+ htmlspecialchars($read) . "</font><br>\n";
+ break;