f8cc0792fdc390729803afc8170fa8eaae31a8ad
6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This implements functions that manipulate messages
10 * NOTE: Quite a few functions in this file are obsolete
13 * @package squirrelmail
18 * Copies specified messages to specified folder
19 * @param int $imap_stream The resource ID for the IMAP connection
20 * @param string $start Beginning of range to copy
21 * @param string $end End of the range to copy
22 * @param string $mailbox Which box to copy to
23 * @deprecated This function is obsolete and should not be used
25 function sqimap_messages_copy ($imap_stream, $start, $end, $mailbox) {
26 $read = sqimap_run_command ($imap_stream, "COPY $start:$end " . sqimap_encode_mailbox_name($mailbox), true, $response, $message, TRUE);
30 * copy a range of messages ($id) to another mailbox ($mailbox)
31 * @param int $imap_stream The resource ID for the IMAP socket
32 * @param string $id The list of messages to copy
33 * @param string $mailbox The destination to copy to
36 function sqimap_msgs_list_copy ($imap_stream, $id, $mailbox) {
37 $msgs_id = sqimap_message_list_squisher($id);
38 $read = sqimap_run_command ($imap_stream, "COPY $msgs_id " . sqimap_encode_mailbox_name($mailbox), true, $response, $message, TRUE);
39 if ($response == 'OK') {
47 * move a range of messages ($id) to another mailbox. Deletes the originals.
48 * @param int $imap_stream The resource ID for the IMAP socket
49 * @param string $id The list of messages to move
50 * @param string $mailbox The destination to move to
53 function sqimap_msgs_list_move ($imap_stream, $id, $mailbox) {
54 $msgs_id = sqimap_message_list_squisher($id);
55 if (sqimap_msgs_list_copy ($imap_stream, $id, $mailbox)) {
56 return sqimap_toggle_flag($imap_stream, $id, '\\Deleted', true, true);
64 * Deletes specified messages and moves them to trash if possible
65 * @deprecated This function is obsolete and should no longer be used
66 * @param int $imap_steam The resource ID for the IMAP connection
67 * @param string $start Start of range
68 * @param string $end End of range
69 * @param string $mailbox Mailbox messages are being deleted from
72 function sqimap_messages_delete ($imap_stream, $start, $end, $mailbox, $bypass_trash=false) {
73 global $move_to_trash, $trash_folder, $auto_expunge;
75 if (($move_to_trash == true) && ($bypass_trash != true) &&
76 (sqimap_mailbox_exists($imap_stream, $trash_folder) && ($mailbox != $trash_folder))) {
77 sqimap_messages_copy ($imap_stream, $start, $end, $trash_folder);
79 sqimap_messages_flag ($imap_stream, $start, $end, "Deleted", true);
82 function sqimap_msgs_list_delete ($imap_stream, $mailbox, $id, $bypass_trash=false) {
83 // FIX ME, remove globals by introducing an associative array with properties
84 // as 4th argument as replacement for the bypass_trash var
85 global $move_to_trash, $trash_folder;
87 if (($move_to_trash == true) && ($bypass_trash != true) &&
88 (sqimap_mailbox_exists($imap_stream, $trash_folder) && ($mailbox != $trash_folder)) ) {
89 $bRes = sqimap_msgs_list_copy ($imap_stream, $id, $trash_folder);
92 return sqimap_toggle_flag($imap_stream, $id, '\\Deleted', true, true);
100 * Sets the specified messages with specified flag
102 function sqimap_messages_flag ($imap_stream, $start, $end, $flag, $handle_errors) {
103 $read = sqimap_run_command ($imap_stream, "STORE $start:$end +FLAGS (\\$flag)", $handle_errors, $response, $message, TRUE);
106 function sqimap_toggle_flag($imap_stream, $id, $flag, $set, $handle_errors) {
107 $msgs_id = sqimap_message_list_squisher($id);
108 $set_string = ($set ?
'+' : '-');
109 $aResponse = sqimap_run_command_list($imap_stream, "STORE $msgs_id ".$set_string."FLAGS ($flag)", $handle_errors, $response, $message, TRUE);
110 // parse the fetch response
111 return parseFetch($aResponse);
115 function sqimap_get_small_header ($imap_stream, $id, $sent) {
116 $res = sqimap_get_small_header_list($imap_stream, $id, $sent);
121 * Sort the message list and crunch to be as small as possible
122 * (overflow could happen, so make it small if possible)
124 function sqimap_message_list_squisher($messages_array) {
125 if( !is_array( $messages_array ) ) {
126 return $messages_array;
129 sort($messages_array, SORT_NUMERIC
);
131 while ($messages_array) {
132 $start = array_shift($messages_array);
134 while (isset($messages_array[0]) && $messages_array[0] == $end +
1) {
135 $end = array_shift($messages_array);
137 if ($msgs_str != '') {
141 if ($start != $end) {
142 $msgs_str .= ':' . $end;
149 * Retrieves an array with a sorted uid list. Sorting is done on the imap server
150 * @link http://www.ietf.org/internet-drafts/draft-ietf-imapext-sort-13.txt
151 * @param resource $imap_stream IMAP socket connection
152 * @param string $sSortField Field to sort on
153 * @param bool $reverse Reverse order search
154 * @return array $id sorted uid list
156 function sqimap_get_sort_order ($imap_stream, $sSortField, $reverse, $search='ALL') {
157 global $default_charset,
161 $sort_test = array();
166 $sSortField = 'REVERSE '.$sSortField;
168 $query = "SORT ($sSortField) ".strtoupper($default_charset)." $search";
169 // FIX ME sqimap_run_command should return the parsed data accessible by $aDATA['SORT']
170 $aData = sqimap_run_command ($imap_stream, $query, false, $response, $message, TRUE);
171 /* fallback to default charset */
172 if ($response == 'NO' && strpos($message,'[BADCHARSET]') !== false) {
173 $query = "SORT ($sSortField) US-ASCII $search";
174 $aData = sqimap_run_command ($imap_stream, $query, true, $response, $message, TRUE);
178 if ($response == 'OK') {
179 return parseUidList($aData,'SORT');
185 function parseUidList($aData,$sCommand) {
187 if (isset($aData) && count($aData)) {
188 for ($i=0,$iCnt=count($aData);$i<$iCnt;++
$i) {
189 if (preg_match("/^\* $sCommand (.+)$/", $aData[$i], $aMatch)) {
190 $aUid +
= preg_split("/ /", trim($aMatch[1]));
194 return array_unique($aUid);
198 * Retrieves an array with a sorted uid list. Sorting is done by SquirrelMail
200 * @param resource $imap_stream IMAP socket connection
201 * @param string $sSortField Field to sort on
202 * @param bool $reverse Reverse order search
203 * @return array $aUid sorted uid list
205 function get_squirrel_sort ($imap_stream, $sSortField, $reverse = false, $aUid = NULL) {
206 if ($aUID === NULL) {
209 if ($sSortField != 'RFC822.SIZE' && $sSortField != 'INTERNALDATE') {
210 $msgs = sqimap_get_small_header_list($imap_stream, $aUid,
211 array($sSortField), array());
213 $msgs = sqimap_get_small_header_list($imap_stream, $aUid,
214 array(), array($sSortField));
218 switch ($sSortField) {
219 // natcasesort section
224 array_walk($msgs, create_function('&$v,&$k,$f',
225 '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
226 $addr = reset(parseRFC822Address($v[$f],1));
227 $sPersonal = (isset($addr[SQM_ADDR_PERSONAL]) && $addr[SQM_ADDR_PERSONAL]) ?
228 $addr[SQM_ADDR_PERSONAL] : "";
229 $sEmail = ($addr[SQM_ADDR_HOST]) ?
230 $addr[SQM_ADDR_HOST] . "@".$addr[SQM_ADDR_HOST] :
231 $addr[SQM_ADDR_HOST];
232 $v[$f] = ($sPersonal) ? decodeHeader($sPersonal):$sEmail;'),$sSortField);
238 array_walk($msgs, create_function('&$v,&$k,$f',
239 '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
240 $v[$f] = strtolower(decodeHeader(trim($v[$f])));
241 $v[$f] = (preg_match("/^(vedr|sv|re|aw|\[\w\]):\s*(.*)$/si", $v[$f], $matches)) ?
242 $matches[2] : $v[$f];'),$sSortField);
245 foreach ($msgs as $item) {
246 $aUid[$item['UID']] = $item[$sSortField];
249 $aUid = array_keys($aUid);
251 $aUid = array_reverse($aUid);
254 // \natcasesort section
255 // sort_numeric section
259 array_walk($msgs, create_function('&$v,$k,$f',
260 '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
261 $v[$f] = getTimeStamp(explode(" ",$v[$f]));'),$sSortField);
267 // redefine $sSortField to maintain the same namespace between
268 // server-side sorting and squirrelmail sorting
269 $sSortField = 'SIZE';
271 foreach ($msgs as $item) {
272 $aUid[$item['UID']] = (isset($item[$sSortField])) ?
$item[$sSortField] : 0;
275 arsort($aUid,SORT_NUMERIC
);
277 asort($aUid, SORT_NUMERIC
);
279 $aUid = array_keys($aUid);
281 // \sort_numeric section
283 $aUid = array_reverse($msgs);
290 * Returns an indent array for printMessageinfo()
291 * This represents the amount of indent needed (value),
292 * for this message number (key)
296 * Notes for future work:
297 * indent_array should contain: indent_level, parent and flags,
299 * To achieve that we need to define the following flags:
304 * a node has sibling nodes if it's not the last node
305 * a node has no sibling nodes if it's the last node
306 * By using binary comparations we can store the flag in one var
309 * -1 par = 0, level = 0, flag = 1 + 2 + 4 = 7 (haschildren, isfirst, islast)
310 * \-2 par = 1, level = 1, flag = 0 + 2 = 2 (hasnochildren, isfirst)
311 * |-3 par = 1, level = 1, flag = 1 + 4 = 5 (haschildren, islast)
312 * \-4 par = 3, level = 2, flag = 1 + 2 + 4 = 7 (haschildren, isfirst, islast)
313 * \-5 par = 4, level = 3, flag = 0 + 2 + 4 = 6 (hasnochildren, isfirst, islast)
315 function get_parent_level ($thread_new) {
321 * loop through the threads and take unwanted characters out
322 * of the thread string then chop it up
324 for ($i=0;$i<count($thread_new);$i++
) {
325 $thread_new[$i] = preg_replace("/\s\(/", "(", $thread_new[$i]);
326 $thread_new[$i] = preg_replace("/(\d+)/", "$1|", $thread_new[$i]);
327 $thread_new[$i] = preg_split("/\|/", $thread_new[$i], -1, PREG_SPLIT_NO_EMPTY
);
329 $indent_array = array();
331 $thread_new = array();
333 /* looping through the parts of one message thread */
335 for ($i=0;$i<count($thread_new);$i++
) {
336 /* first grab the parent, it does not indent */
338 if (isset($thread_new[$i][0])) {
339 if (preg_match("/(\d+)/", $thread_new[$i][0], $regs)) {
343 $indent_array[$parent] = 0;
346 * now the children, checking each thread portion for
347 * ),(, and space, adjusting the level and space values
348 * to get the indent level
355 for ($k=1,$iCnt=count($thread_new[$i])-1;$k<$iCnt;++
$k) {
356 $chars = count_chars($thread_new[$i][$k], 1);
357 if (isset($chars['40'])) { /* testing for ( */
358 $level +
= $chars['40'];
360 if (isset($chars['41'])) { /* testing for ) */
361 $level -= $chars['41'];
363 /* if we were faking lets stop, this portion
364 * of the thread is over
366 if ($level == $cutoff) {
370 if (isset($chars['32'])) { /* testing for space */
371 if (!isset($spaces[$level])) {
374 $spaces[$level] +
= $chars['32'];
376 for ($x=0;$x<=$level;$x++
) {
377 if (isset($spaces[$x])) {
378 $spaces_total +
= $spaces[$x];
381 $indent = $level +
$spaces_total;
382 /* must have run into a message that broke the thread
383 * so we are adjusting for that portion
386 $indent = $indent +
1;
388 if (preg_match("/(\d+)/", $thread_new[$i][$k], $regs)) {
391 /* the thread must be broken if $indent == 0
392 * so indent the message once and start faking it
399 /* dont need abs but if indent was negative
402 $indent_array[$child] = ($indent < 0) ?
0 : $indent;
406 return $indent_array;
411 * Returns an array with each element as a string representing one
412 * message-thread as returned by the IMAP server.
413 * @link http://www.ietf.org/internet-drafts/draft-ietf-imapext-sort-13.txt
415 function get_thread_sort ($imap_stream, $search='ALL') {
416 global $thread_new, $sort_by_ref, $default_charset, $server_sort_array, $indent_array;
418 $thread_temp = array ();
419 if ($sort_by_ref == 1) {
420 $sort_type = 'REFERENCES';
422 $sort_type = 'ORDEREDSUBJECT';
424 $query = "THREAD $sort_type ".strtoupper($default_charset)." $search";
426 $thread_test = sqimap_run_command ($imap_stream, $query, false, $response, $message, TRUE);
427 /* fallback to default charset */
428 if ($response == 'NO' && strpos($message,'[BADCHARSET]') !== false) {
429 $query = "THREAD $sort_type US-ASCII $search";
430 $thread_test = sqimap_run_command ($imap_stream, $query, true, $response, $message, TRUE);
432 if (isset($thread_test[0])) {
433 for ($i=0,$iCnt=count($thread_test);$i<$iCnt;++
$i) {
434 if (preg_match("/^\* THREAD (.+)$/", $thread_test[$i], $regs)) {
435 $thread_list = trim($regs[1]);
442 if (!preg_match("/OK/", $response)) {
443 $server_sort_array = 'no';
444 return $server_sort_array;
446 if (isset($thread_list)) {
447 $thread_temp = preg_split("//", $thread_list, -1, PREG_SPLIT_NO_EMPTY
);
450 $char_count = count($thread_temp);
452 $thread_new = array();
456 * parse the thread response into separate threads
461 * [2] => (1599 759 959 37)
463 * [4] => ((933)(1891))
464 * [5] => (1030 (1497)(845)(1637))
466 for ($i=0,$iCnt=count($thread_temp);$i<$iCnt;$i++
) {
467 if ($thread_temp[$i] != ')' && $thread_temp[$i] != '(') {
468 $thread_new[$k] = $thread_new[$k] . $thread_temp[$i];
469 } elseif ($thread_temp[$i] == '(') {
470 $thread_new[$k] .= $thread_temp[$i];
472 } elseif ($thread_temp[$i] == ')') {
474 $thread_new[$k] .= $thread_temp[$i];
475 $counter = $counter - 1;
477 $thread_new[$k] .= $thread_temp[$i];
479 $thread_new[$k] = "";
480 $counter = $counter - 1;
485 $thread_new = array_reverse($thread_new);
486 /* place the threads after each other in one string */
487 $thread_list = implode(" ", $thread_new);
488 $thread_list = str_replace("(", " ", $thread_list);
489 $thread_list = str_replace(")", " ", $thread_list);
490 $thread_list = preg_split("/\s/", $thread_list, -1, PREG_SPLIT_NO_EMPTY
);
491 $server_sort_array = $thread_list;
493 $indent_array = get_parent_level ($thread_new);
494 return array($thread_list,$indent_array);
498 function elapsedTime($start) {
499 $stop = gettimeofday();
500 $timepassed = 1000000 * ($stop['sec'] - $start['sec']) +
$stop['usec'] - $start['usec'];
504 // only used in sqimap_get_small_header_list
505 function parseString($read,&$i) {
511 $iPos = strpos($read,'"',$iPos);
513 if ($iPos && $read{$iPos -1} != '\\') {
514 $s = substr($read,$i,($iPos-$i));
519 if ($iPos > strlen($read)) {
523 } else if ($char == '{') {
526 $iPos = strpos($read,'}',$i);
528 $lit_cnt = substr($read, $i, $iPos - $i);
529 $i +
= strlen($lit_cnt) +
3; /* skip } + \r + \n */
530 /* Now read the literal */
531 $s = ($lit_cnt ?
substr($read,$i,$lit_cnt): '');
533 /* temp bugfix (SM 1.5 will have a working clean version)
534 too much work to implement that version right now */
536 } else { /* should never happen */
537 $i +
= 3; /* } + \r + \n */
547 // only used in sqimap_get_small_header_list
548 function parseArray($read,&$i) {
549 $i = strpos($read,'(',$i);
550 $i_pos = strpos($read,')',$i);
551 $s = substr($read,$i+
1,$i_pos - $i -1);
552 $a = explode(' ',$s);
561 function sqimap_get_small_header_list ($imap_stream, $msg_list,
562 $aHeaderFields = array('Date', 'To', 'Cc', 'From', 'Subject', 'X-Priority', 'Content-Type'),
563 $aFetchItems = array('FLAGS', 'RFC822.SIZE', 'INTERNALDATE')) {
565 $aMessageList = array();
566 $read_list = array();
568 $bUidFetch = ! in_array('UID', $aFetchItems, true);
570 /* Get the small headers for each message in $msg_list */
571 if ($msg_list !== NULL) {//$show_num != -1 && $show_num != '*' ) {
572 $msgs_str = sqimap_message_list_squisher($msg_list);
574 * We need to return the data in the same order as the caller supplied
575 * in $msg_list, but IMAP servers are free to return responses in
576 * whatever order they wish... So we need to re-sort manually
579 for ($i = 0; $i < sizeof($msg_list); $i++
) {
580 $aMessageList["$msg_list[$i]"] = array();
593 $query = "FETCH $msgs_str (";
594 if (count($aFetchItems)) {
595 $sFetchItems = implode(' ',$aFetchItems);
597 if (count($aHeaderFields)) {
598 $sHeaderFields = implode(' ',$aHeaderFields);
599 $sFetchItems .= ' BODY.PEEK[HEADER.FIELDS ('.$sHeaderFields.')]';
601 $query .= trim($sFetchItems) . ')';
602 $aResponse = sqimap_run_command_list ($imap_stream, $query, true, $response, $message, $bUidFetch);
603 $aMessages = parseFetch($aResponse,$aMessageList);
604 array_reverse($aMessages);
608 function parseFetch($aResponse,$aMessageList = array()) {
609 foreach ($aResponse as $r) {
611 // use unset because we do isset below
612 $read = implode('',$r);
615 * #id<space>FETCH<space>(
618 /* extract the message id */
619 $i_space = strpos($read,' ',2);
620 $id = substr($read,2,$i_space-2);
622 $fetch = substr($read,$i_space+
1,5);
623 if (!is_numeric($id) && $fetch !== 'FETCH') {
624 $msg['ERROR'] = $read; // htmlspecialchars should be done just before display. this is backend code
627 $i = strpos($read,'(',$i_space+
5);
628 $read = substr($read,$i+
1);
629 $i_len = strlen($read);
631 while ($i < $i_len && $i !== false) {
633 $read = trim(substr($read,$i));
634 $i_len = strlen($read);
635 $i = strpos($read,' ');
636 $arg = substr($read,0,$i);
641 $i_pos = strpos($read,' ',$i);
643 $i_pos = strpos($read,')',$i);
646 $unique_id = substr($read,$i,$i_pos-$i);
653 $flags = parseArray($read,$i);
654 if (!$flags) break 3;
656 foreach ($flags as $flag) {
657 $flag = strtolower($flag);
658 $aFlags[$flag] = true;
660 $msg['FLAGS'] = $aFlags;
663 $i_pos = strpos($read,' ',$i);
665 $i_pos = strpos($read,')',$i);
668 $msg['SIZE'] = substr($read,$i,$i_pos-$i);
676 break; // to be implemented, moving imap code out of the nessages class
677 sqimap_parse_address($read,$i,$msg);
678 break; // to be implemented, moving imap code out of the nessages class
679 case 'BODYSTRUCTURE':
682 $msg['INTERNALDATE'] = str_replace(' ', ' ',parseString($read,$i));
684 case 'BODY.PEEK[HEADER.FIELDS':
685 case 'BODY[HEADER.FIELDS':
686 $i = strpos($read,'{',$i);
687 $header = parseString($read,$i);
688 if ($header === false) break 2;
689 /* First we replace all \r\n by \n, and unfold the header */
690 $hdr = trim(str_replace(array("\r\n", "\n\t", "\n "),array("\n", ' ', ' '), $header));
691 /* Now we can make a new header array with */
692 /* each element representing a headerline */
693 $hdr = explode("\n" , $hdr);
694 $aReceived = array();
695 foreach ($hdr as $line) {
696 $pos = strpos($line, ':');
698 $field = strtolower(substr($line, 0, $pos));
699 if (!strstr($field,' ')) { /* valid field */
700 $value = trim(substr($line, $pos+
1));
703 case 'to': $msg['TO'] = $value; break;
704 case 'cc': $msg['CC'] = $value; break;
705 case 'from': $msg['FROM'] = $value; break;
707 $msg['DATE'] = str_replace(' ', ' ', $value);
709 case 'x-priority': $msg['PRIORITY'] = $value; break;
710 case 'subject': $msg['SUBJECT'] = $value; break;
713 if ($pos = strpos($type, ";")) {
714 $type = substr($type, 0, $pos);
716 $type = explode("/", $type);
717 if(!is_array($type) ||
count($type) < 2) {
718 $msg['TYPE0'] = 'text';
719 $msg['TYPE1'] = 'plain';
721 $msg['TYPE0'] = strtolower($type[0]);
722 $msg['TYPE1'] = strtolower($type[1]);
726 $aReceived[] = $value;
733 if (count($aReceived)) {
734 $msg['RECEIVED'] = $aReceived;
743 $msg['UID'] = $unique_id;
745 $aMessageList[$msgi] = $msg;
748 return $aMessageList;
752 function sqimap_parse_envelope($read, &$i, &$msg) {
756 for ($cnt = strlen($read); ($i < $cnt) && ($read{$i} != ')'); ++
$i) {
757 $char = strtoupper($read{$i});
761 $arg_a[] = parseString($read,$i);
765 /* probably NIL argument */
766 if (strtoupper(substr($read, $i, 3)) == 'NIL') {
773 /* Address structure (with group support)
774 * Note: Group support is useless on SMTP connections
775 * because the protocol doesn't support it
780 for (; $i < $cnt && $read{$i} != ')'; ++
$i) {
781 if ($read{$i} == '(') {
782 $addr = sqimap_parse_address($read, $i);
783 if (($addr[3] == '') && ($addr[2] != '')) {
788 } else if ($group && ($addr[3] == '') && ($addr[2] == '')) {
790 if ($a == ($j+
1)) { /* no group members */
791 $group_addr[4] = $group;
793 $group_addr[0] = "$group: Undisclosed recipients;";
794 $addr_a[] = $group_addr;
810 if (count($arg_a) > 9) {
811 $d = strtr($arg_a[0], array(' ' => ' '));
812 $d = explode(' ', $d);
813 if (!$arg_a[1]) $arg_1[1] = '';
814 $msg['DATE'] = $d; /* argument 1: date */
815 $msg['SUBJECT'] = $arg_a[1]; /* argument 2: subject */
816 $msg['FROM'] = is_array($arg_a[2]) ?
$arg_a[2][0] : ''; /* argument 3: from */
817 $msg['SENDER'] = is_array($arg_a[3]) ?
$arg_a[3][0] : ''; /* argument 4: sender */
818 $msg['REPLY-TO'] = is_array($arg_a[4]) ?
$arg_a[4][0] : ''; /* argument 5: reply-to */
819 $msg['TO'] = $arg_a[5]; /* argument 6: to */
820 $msg['CC'] = $arg_a[6]; /* argument 7: cc */
821 $msg['BCC'] = $arg_a[7]; /* argument 8: bcc */
822 $msg['IN-REPLY-TO'] = $arg_a[8]; /* argument 9: in-reply-to */
823 $msg['MESSAGE-ID'] = $arg_a[9]; /* argument 10: message-id */
827 function sqimap_parse_address($read, &$i) {
829 for (; $read{$i} != ')'; ++
$i) {
830 $char = strtoupper($read{$i});
833 case '"': $arg_a[] = parseString($read,$i); break;
836 if (strtoupper(substr($read, $i, 3)) == 'NIL') {
845 if (count($arg_a) == 4) {
848 // $adr = new AddressStructure();
849 // $adr->personal = $arg_a[0];
850 // $adr->adl = $arg_a[1];
851 // $adr->mailbox = $arg_a[2];
852 // $adr->host = $arg_a[3];
860 * Returns a message array with all the information about a message.
861 * See the documentation folder for more information about this array.
863 function sqimap_get_message ($imap_stream, $id, $mailbox) {
864 // typecast to int to prohibit 1:* msgs sets
867 $read = sqimap_run_command ($imap_stream, "FETCH $id (FLAGS BODYSTRUCTURE)", true, $response, $message, TRUE);
869 if (preg_match('/.+FLAGS\s\((.*)\)\s/AUi',$read[0],$regs)) {
870 if (trim($regs[1])) {
871 $flags = preg_split('/ /', $regs[1],-1,'PREG_SPLIT_NI_EMPTY');
875 /* the message was not found, maybe the mailbox was modified? */
876 global $sort, $startMessage, $color;
878 $errmessage = _("The server couldn't find the message you requested.") .
879 '<p>'._("Most probably your message list was out of date and the message has been moved away or deleted (perhaps by another program accessing the same mailbox).");
880 /* this will include a link back to the message list */
881 error_message($errmessage, $mailbox, $sort, (int) $startMessage, $color);
884 $bodystructure = implode('',$read);
885 $msg = mime_structure($bodystructure,$flags);
886 $read = sqimap_run_command ($imap_stream, "FETCH $id BODY[HEADER]", true, $response, $message, TRUE);
887 $rfc822_header = new Rfc822Header();
888 $rfc822_header->parseHeader($read);
889 $msg->rfc822_header
= $rfc822_header;