Fix bug #534795 concerning logo height broken
[squirrelmail.git] / functions / imap_messages.php
1 <?php
2
3 /**
4 * imap_messages.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This implements functions that manipulate messages
10 *
11 * $Id$
12 */
13
14 /* Copies specified messages to specified folder */
15 function sqimap_messages_copy ($imap_stream, $start, $end, $mailbox) {
16 $read = sqimap_run_command ($imap_stream, "COPY $start:$end \"$mailbox\"", true, $response, $message);
17 }
18
19 /* Deletes specified messages and moves them to trash if possible */
20 function sqimap_messages_delete ($imap_stream, $start, $end, $mailbox) {
21 global $move_to_trash, $trash_folder, $auto_expunge;
22
23 if (($move_to_trash == true) && (sqimap_mailbox_exists($imap_stream, $trash_folder) && ($mailbox != $trash_folder))) {
24 sqimap_messages_copy ($imap_stream, $start, $end, $trash_folder);
25 }
26 sqimap_messages_flag ($imap_stream, $start, $end, "Deleted");
27 }
28
29 /* Sets the specified messages with specified flag */
30 function sqimap_messages_flag ($imap_stream, $start, $end, $flag) {
31 $read = sqimap_run_command ($imap_stream, "STORE $start:$end +FLAGS (\\$flag)", true, $response, $message);
32 }
33
34 /* Remove specified flag from specified messages */
35 function sqimap_messages_remove_flag ($imap_stream, $start, $end, $flag) {
36 $read = sqimap_run_command ($imap_stream, "STORE $start:$end -FLAGS (\\$flag)", true, $response, $message);
37 }
38
39 /* Returns some general header information -- FROM, DATE, and SUBJECT */
40 class small_header {
41 var $from = '', $subject = '', $date = '', $to = '',
42 $priority = 0, $message_id = 0, $cc = '';
43 }
44
45 function sqimap_get_small_header ($imap_stream, $id, $sent) {
46 $res = sqimap_get_small_header_list($imap_stream, array($id), $sent);
47 return $res[0];
48 }
49
50 /*
51 * Sort the message list and crunch to be as small as possible
52 * (overflow could happen, so make it small if possible)
53 */
54 function sqimap_message_list_squisher($messages_array) {
55 if( !is_array( $messages_array ) ) {
56 return;
57 }
58 sort($messages_array, SORT_NUMERIC);
59 $msgs_str = '';
60 while ($messages_array) {
61 $start = array_shift($messages_array);
62 $end = $start;
63 while (isset($messages_array[0]) && $messages_array[0] == $end + 1) {
64 $end = array_shift($messages_array);
65 }
66 if ($msgs_str != '') {
67 $msgs_str .= ',';
68 }
69 $msgs_str .= $start;
70 if ($start != $end) {
71 $msgs_str .= ':' . $end;
72 }
73 }
74
75 return $msgs_str;
76 }
77
78 /* returns the references header lines */
79 function get_reference_header ($imap_stream, $message) {
80 $responses = array ();
81 $sid = sqimap_session_id();
82 $results = array();
83 $references = "";
84 $query = "$sid FETCH $message BODY.PEEK[HEADER.FIELDS (References)]\r\n";
85 fputs ($imap_stream, $query);
86 $responses = sqimap_read_data_list($imap_stream, $sid, true, $responses, $message);
87 if (!eregi("^\\* ([0-9]+) FETCH", $responses[0][0], $regs)) {
88 $responses = array ();
89 }
90 return $responses;
91 }
92
93
94 /* get sort order from server and
95 * return it as the $id array for
96 * mailbox_display
97 */
98
99 function sqimap_get_sort_order ($imap_stream, $sort) {
100 global $default_charset, $thread_sort_messages, $internal_date_sort;
101 $sid = sqimap_session_id();
102 $sort_on = array();
103 $reverse = 0;
104 $server_sort_array = array();
105 $sort_test = array();
106 $sort_query = '';
107 $sort_on = array (0=> 'DATE',
108 1=> 'DATE',
109 2=> 'FROM',
110 3=> 'FROM',
111 4=> 'SUBJECT',
112 5=> 'SUBJECT',
113 6=> 'DATE');
114 if ($internal_date_sort == true) {
115 $sort_on[0] = 'ARRIVAL';
116 $sort_on[1] = 'ARRIVAL';
117 }
118 if (!empty($sort_on[$sort])) {
119 $sort_query = "$sid SORT ($sort_on[$sort]) ".strtoupper($default_charset)." ALL\r\n";
120 fputs($imap_stream, $sort_query);
121 $sort_test = sqimap_read_data($imap_stream, $sid, true, $response, $message);
122 }
123 if (preg_match("/^\* SORT (.+)$/", $sort_test[0], $regs)) {
124 $server_sort_array = preg_split("/ /", trim($regs[1]));
125 }
126 if ($sort == 0 || $sort == 2 || $sort == 4) {
127 $server_sort_array = array_reverse($server_sort_array);
128 }
129 return $server_sort_array;
130 }
131
132 /* returns an indent array for printMessageinfo()
133 this represents the amount of indent needed
134 for this message number
135 */
136
137 function get_parent_level ($imap_stream) {
138 global $sort_by_ref, $default_charset, $thread_new;
139 $parent = "";
140 $child = "";
141 for ($i=0;$i<count($thread_new);$i++) {
142 $thread_new[$i] = preg_replace("/\s\(/", "(", $thread_new[$i]);
143 $thread_new[$i] = preg_replace("/(\d+)/", "$1|", $thread_new[$i]);
144 $thread_new[$i] = preg_split("/\|/", $thread_new[$i], -1, PREG_SPLIT_NO_EMPTY);
145 }
146 $indent_array = array();
147 if (!$thread_new) {
148 $thread_new = array();
149 }
150 for ($i=0;$i<count($thread_new);$i++) {
151 if (isset($thread_new[$i][0])) {
152 if (preg_match("/(\d+)/", $thread_new[$i][0], $regs)) {
153 $parent = $regs[1];
154 }
155 }
156 $indent_array[$parent] = 0;
157 $indent = 0;
158 $go = 'stop';
159 $spaces = array ();
160 $l = 0;
161 for ($k=1;$k<(count($thread_new[$i]))-1;$k++) {
162 $chars = count_chars($thread_new[$i][$k], 1);
163 if (isset($chars['40']) && isset($chars['41'])) {
164 $l--;
165 }
166 if (isset($chars['40'])) { // (
167 $indent = $indent + $chars[40];
168 $go = 'start';
169 $l++;
170 }
171 if (isset($chars['41'])) { // )
172 if ($go == 'start') {
173 if (!isset($spaces[$l])) {
174 $spaces[$l] = 0;
175 }
176 $indent = $indent - $spaces[$l];
177 $indent = $indent - $chars[41] ;
178 $go = 'stop';
179 $l--;
180 }
181 else {
182 $indent = $indent - $chars[41];
183 }
184 }
185 if (isset($chars['32'])) { // space
186 $indent = $indent + $chars[32];
187 if ($go == 'start') {
188 if (!isset($spaces[$l])) {
189 $spaces[$l] = 0;
190 }
191 $spaces[$l] = $spaces[$l] + $chars[32];
192 }
193 }
194 if (preg_match("/(\d+)/", $thread_new[$i][$k], $regs)) {
195 $child = $regs[1];
196 }
197 $indent_array[$child] = abs($indent);
198 }
199 }
200 return $indent_array;
201 }
202
203
204 /* returns an array with each element as a string
205 representing one message thread as returned by
206 the IMAP server
207 */
208
209 function get_thread_sort ($imap_stream) {
210 global $thread_new, $sort_by_ref, $default_charset;
211
212 if (session_register('thread_new')) {
213 session_unregister('thread_new');
214 }
215 $sid = sqimap_session_id();
216 $thread_temp = array ();
217 if ($sort_by_ref == 1) {
218 $sort_type = 'REFERENCES';
219 }
220 else {
221 $sort_type = 'ORDEREDSUBJECT';
222 }
223 $thread_query = "$sid THREAD $sort_type ".strtoupper($default_charset)." ALL\r\n";
224 fputs($imap_stream, $thread_query);
225 $thread_test = sqimap_read_data($imap_stream, $sid, true, $response, $message);
226 if (preg_match("/^\* THREAD (.+)$/", $thread_test[0], $regs)) {
227 $thread_list = trim($regs[1]);
228 }
229 else {
230 $thread_list = "";
231 }
232 $thread_temp = preg_split("//", $thread_list, -1, PREG_SPLIT_NO_EMPTY);
233 $char_count = count($thread_temp);
234 $counter = 0;
235 $thread_new = array();
236 $k = 0;
237 $thread_new[0] = "";
238 for ($i=0;$i<$char_count;$i++) {
239 if ($thread_temp[$i] != ')' && $thread_temp[$i] != '(') {
240 $thread_new[$k] = $thread_new[$k] . $thread_temp[$i];
241 }
242 elseif ($thread_temp[$i] == '(') {
243 $thread_new[$k] .= $thread_temp[$i];
244 $counter++;
245 }
246 elseif ($thread_temp[$i] == ')') {
247 if ($counter > 1) {
248 $thread_new[$k] .= $thread_temp[$i];
249 $counter = $counter - 1;
250 }
251 else {
252 $thread_new[$k] .= $thread_temp[$i];
253 $k++;
254 $thread_new[$k] = "";
255 $counter = $counter - 1;
256 }
257 }
258 }
259 session_register('$thread_new');
260 $thread_new = array_reverse($thread_new);
261 $thread_list = implode(" ", $thread_new);
262 $thread_list = str_replace("(", " ", $thread_list);
263 $thread_list = str_replace(")", " ", $thread_list);
264 $thread_list = preg_split("/\s/", $thread_list, -1, PREG_SPLIT_NO_EMPTY);
265 return $thread_list;
266 }
267
268
269
270 function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
271 global $squirrelmail_language, $color, $data_dir, $username;
272
273 /* Get the small headers for each message in $msg_list */
274 $sid = sqimap_session_id();
275 $maxmsg = sizeof($msg_list);
276 $msgs_str = sqimap_message_list_squisher($msg_list);
277 $results = array();
278 $read_list = array();
279 $sizes_list = array();
280 /*
281 * We need to return the data in the same order as the caller supplied
282 * in $msg_list, but IMAP servers are free to return responses in
283 * whatever order they wish... So we need to re-sort manually
284 */
285 for ($i = 0; $i < sizeof($msg_list); $i++) {
286 $id2index[$msg_list[$i]] = $i;
287 }
288
289 $query = "$sid FETCH $msgs_str BODY.PEEK[HEADER.FIELDS (Date To From Cc Subject Message-Id X-Priority Content-Type In-Reply-To)]\r\n";
290 fputs ($imap_stream, $query);
291 $readin_list = sqimap_read_data_list($imap_stream, $sid, true, $response, $message);
292
293 foreach ($readin_list as $r) {
294 if (!eregi("^\\* ([0-9]+) FETCH", $r[0], $regs)) {
295 set_up_language($squirrelmail_language);
296 echo '<br><b><font color=$color[2]>' .
297 _("ERROR : Could not complete request.") .
298 '</b><br>' .
299 _("Unknown response from IMAP server: ") . ' 1.' .
300 $r[0] . "</font><br>\n";
301 } else if (! isset($id2index[$regs[1]]) || !count($id2index[$regs[1]])) {
302 set_up_language($squirrelmail_language);
303 echo '<br><b><font color=$color[2]>' .
304 _("ERROR : Could not complete request.") .
305 '</b><br>' .
306 _("Unknown message number in reply from server: ") .
307 $regs[1] . "</font><br>\n";
308 } else {
309 $read_list[$id2index[$regs[1]]] = $r;
310 }
311 }
312 arsort($read_list);
313
314 $query = "$sid FETCH $msgs_str RFC822.SIZE\r\n";
315 fputs ($imap_stream, $query);
316 $sizesin_list = sqimap_read_data_list($imap_stream, $sid, true, $response, $message);
317
318 foreach ($sizesin_list as $r) {
319 if (!eregi("^\\* ([0-9]+) FETCH", $r[0], $regs)) {
320 set_up_language($squirrelmail_language);
321 echo "<br><b><font color=$color[2]>\n";
322 echo _("ERROR : Could not complete request.");
323 echo "</b><br>\n";
324 echo _("Unknown response from IMAP server: ") . ' 2.';
325 echo $r[0] . "</font><br>\n";
326 exit;
327 }
328 if (!count($id2index[$regs[1]])) {
329 set_up_language($squirrelmail_language);
330 echo "<br><b><font color=$color[2]>\n";
331 echo _("ERROR : Could not complete request.");
332 echo "</b><br>\n";
333 echo _("Unknown messagenumber in reply from server: ");
334 echo $regs[1] . "</font><br>\n";
335 exit;
336 }
337 $sizes_list[$id2index[$regs[1]]] = $r;
338 }
339 arsort($sizes_list);
340
341 for ($msgi = 0; $msgi < $maxmsg; $msgi++) {
342 $subject = _("(no subject)");
343 $from = _("Unknown Sender");
344 $priority = 0;
345 $messageid = "<>";
346 $cc = "";
347 $to = "";
348 $date = "";
349 $type[0] = "";
350 $type[1] = "";
351 $inrepto = "";
352 $read = $read_list[$msgi];
353
354 $prevline = false;
355 foreach ($read as $read_part) {
356 //unfold multi-line headers
357 while ($prevline && strspn($read_part, "\t ") > 0) {
358 $read_part = substr($prevline, 0, -2) . ' ' . ltrim($read_part);
359 }
360 $prevline = $read_part;
361 if (eregi ("^to:(.*)$", $read_part, $regs)) {
362 $to = $regs[1];
363 } else if (eregi ("^from:(.*)$", $read_part, $regs)) {
364 $from = $regs[1];
365 } else if (eregi ("^x-priority:(.*)$", $read_part, $regs)) {
366 $priority = trim($regs[1]);
367 } else if (eregi ("^message-id:(.*)$", $read_part, $regs)) {
368 $messageid = trim($regs[1]);
369 } else if (eregi ("^cc:(.*)$", $read_part, $regs)) {
370 $cc = $regs[1];
371 } else if (eregi ("^date:(.*)$", $read_part, $regs)) {
372 $date = $regs[1];
373 } else if (eregi ("^subject:(.*)$", $read_part, $regs)) {
374 $subject = htmlspecialchars(trim($regs[1]));
375 if ($subject == "") {
376 $subject = _("(no subject)");
377 }
378 } else if (eregi ("^content-type:(.*)$", $read_part, $regs)) {
379 $type = strtolower(trim($regs[1]));
380 if ($pos = strpos($type, ";")) {
381 $type = substr($type, 0, $pos);
382 }
383 $type = explode("/", $type);
384 if (!isset($type[1])) {
385 $type[1] = '';
386 }
387 } else if (eregi ("^in-reply-to:(.*)$", $read_part, $regs)) {
388 $inrepto = trim($regs[1]);
389 }
390 }
391 $internaldate = getPref($data_dir, $username, 'internal_date_sort');
392 if (trim($date) == "" || $internaldate) {
393 fputs($imap_stream, "$sid FETCH $msg_list[$msgi] INTERNALDATE\r\n");
394 $readdate = sqimap_read_data($imap_stream, $sid, true, $response, $message);
395 if (eregi(".*INTERNALDATE \"(.*)\".*", $readdate[0], $regs)) {
396 $date_list = explode(' ', trim($regs[1]));
397 $date_list[0] = str_replace("-", ' ', $date_list[0]);
398 $date = implode(' ', $date_list);
399 }
400 }
401 eregi("([0-9]+)[^0-9]*$", $sizes_list[$msgi][0], $regs);
402 $size = $regs[1];
403
404 $header = new small_header;
405 if ($issent) {
406 $header->from = (trim($to) != '' ? $to : '(' ._("No To Address") . ')');
407 } else {
408 $header->from = $from;
409 }
410
411 $header->date = $date;
412 $header->subject = $subject;
413 $header->to = $to;
414 $header->priority = $priority;
415 $header->message_id = $messageid;
416 $header->cc = $cc;
417 $header->size = $size;
418 $header->type0 = $type[0];
419 $header->type1 = $type[1];
420 $header->inrepto = $inrepto;
421 $result[] = $header;
422 }
423 return $result;
424 }
425
426 /* Returns the flags for the specified messages */
427 function sqimap_get_flags ($imap_stream, $i) {
428 $read = sqimap_run_command ($imap_stream, "FETCH $i:$i FLAGS", true, $response, $message);
429 if (ereg('FLAGS(.*)', $read[0], $regs)) {
430 return explode(' ', trim(ereg_replace('[\\(\\)\\\\]', '', $regs[1])));
431 }
432 return array('None');
433 }
434
435 function sqimap_get_flags_list ($imap_stream, $msg_list) {
436 $msgs_str = sqimap_message_list_squisher($msg_list);
437 for ($i = 0; $i < sizeof($msg_list); $i++) {
438 $id2index[$msg_list[$i]] = $i;
439 }
440 $result_list = sqimap_run_command_list ($imap_stream, "FETCH $msgs_str FLAGS", true, $response, $message);
441 $result_flags = array();
442
443 for ($i = 0; $i < sizeof($result_list); $i++) {
444 if (eregi('^\* ([0-9]+).*FETCH.*FLAGS(.*)', $result_list[$i][0], $regs)
445 && isset($id2index[$regs[1]]) && count($id2index[$regs[1]])) {
446 $result_flags[$id2index[$regs[1]]] = explode(" ", trim(ereg_replace('[\\(\\)\\\\]', '', $regs[2])));
447 } else {
448 set_up_language($squirrelmail_language);
449 echo "<br><b><font color=$color[2]>\n" .
450 _("ERROR : Could not complete request.") .
451 "</b><br>\n" .
452 _("Unknown response from IMAP server: ") .
453 $result_list[$i][0] . "</font><br>\n";
454 exit;
455 }
456 }
457 arsort($result_flags);
458 return $result_flags;
459 }
460
461 /*
462 * Returns a message array with all the information about a message.
463 * See the documentation folder for more information about this array.
464 */
465 function sqimap_get_message ($imap_stream, $id, $mailbox) {
466 $header = sqimap_get_message_header($imap_stream, $id, $mailbox);
467 return sqimap_get_message_body($imap_stream, $header);
468 }
469
470 /* Wrapper function that reformats the header information. */
471 function sqimap_get_message_header ($imap_stream, $id, $mailbox) {
472 $read = sqimap_run_command ($imap_stream, "FETCH $id:$id BODY[HEADER]", true, $response, $message);
473 $header = sqimap_get_header($imap_stream, $read);
474 $header->id = $id;
475 $header->mailbox = $mailbox;
476 return $header;
477 }
478
479 /* Wrapper function that reformats the entity header information. */
480 function sqimap_get_ent_header ($imap_stream, $id, $mailbox, $ent) {
481 $read = sqimap_run_command ($imap_stream, "FETCH $id:$id BODY[$ent.HEADER]", true, $response, $message);
482 $header = sqimap_get_header($imap_stream, $read);
483 $header->id = $id;
484 $header->mailbox = $mailbox;
485 return $header;
486 }
487
488
489 /* Wrapper function that returns entity headers for use by decodeMime */
490 /*
491 function sqimap_get_entity_header ($imap_stream, &$read, &$type0, &$type1, &$bound, &$encoding, &$charset, &$filename) {
492 $header = sqimap_get_header($imap_stream, $read);
493 $type0 = $header["TYPE0"];
494 $type1 = $header["TYPE1"];
495 $bound = $header["BOUNDARY"];
496 $encoding = $header["ENCODING"];
497 $charset = $header["CHARSET"];
498 $filename = $header["FILENAME"];
499 }
500 */
501 /* Queries the IMAP server and gets all header information. */
502 function sqimap_get_header ($imap_stream, $read) {
503 global $where, $what;
504
505 $hdr = new msg_header();
506 $i = 0;
507
508 /* Set up some defaults */
509 $hdr->type0 = "text";
510 $hdr->type1 = "plain";
511 $hdr->charset = "us-ascii";
512
513 while ($i < count($read)) {
514 //unfold multi-line headers
515 while ($i + 1 < count($read) && strspn($read[$i + 1], "\t ") > 0) {
516 $read[$i + 1] = substr($read[$i], 0, -2) . ' ' . ltrim($read[$i + 1]);
517 array_splice($read, $i, 1);
518 }
519
520 if (substr($read[$i], 0, 17) == "MIME-Version: 1.0") {
521 $hdr->mime = true;
522 $i++;
523 }
524 /* ENCODING TYPE */
525 else if (substr(strtolower($read[$i]), 0, 26) == "content-transfer-encoding:") {
526 $hdr->encoding = strtolower(trim(substr($read[$i], 26)));
527 $i++;
528 }
529 /* CONTENT-TYPE */
530 else if (strtolower(substr($read[$i], 0, 13)) == "content-type:") {
531 $cont = strtolower(trim(substr($read[$i], 13)));
532 if (strpos($cont, ";")) {
533 $cont = substr($cont, 0, strpos($cont, ";"));
534 }
535
536 if (strpos($cont, "/")) {
537 $hdr->type0 = substr($cont, 0, strpos($cont, "/"));
538 $hdr->type1 = substr($cont, strpos($cont, "/")+1);
539 } else {
540 $hdr->type0 = $cont;
541 }
542
543 $line = $read[$i];
544 $i++;
545 while ( (substr(substr($read[$i], 0, strpos($read[$i], " ")), -1) != ":") && (trim($read[$i]) != "") && (trim($read[$i]) != ")")) {
546 str_replace("\n", "", $line);
547 str_replace("\n", "", $read[$i]);
548 $line = "$line $read[$i]";
549 $i++;
550 }
551
552 /* Detect the boundary of a multipart message */
553 if (eregi('boundary="([^"]+)"', $line, $regs)) {
554 $hdr->boundary = $regs[1];
555 }
556
557 /* Detect the charset */
558 if (strpos(strtolower(trim($line)), "charset=")) {
559 $pos = strpos($line, "charset=") + 8;
560 $charset = trim($line);
561 if (strpos($line, ";", $pos) > 0) {
562 $charset = substr($charset, $pos, strpos($line, ";", $pos)-$pos);
563 } else {
564 $charset = substr($charset, $pos);
565 }
566 $charset = str_replace("\"", "", $charset);
567 $hdr->charset = $charset;
568 } else {
569 $hdr->charset = "us-ascii";
570 }
571 }
572 else if (strtolower(substr($read[$i], 0, 20)) == "content-disposition:") {
573 /* Add better content-disposition support */
574 $line = $read[$i];
575 $i++;
576 while ( (substr(substr($read[$i], 0, strpos($read[$i], " ")), -1) != ":") && (trim($read[$i]) != "") && (trim($read[$i]) != ")")) {
577 str_replace("\n", "", $line);
578 str_replace("\n", "", $read[$i]);
579 $line = "$line $read[$i]";
580 $i++;
581 }
582
583 /* Detects filename if any */
584 if (strpos(strtolower(trim($line)), "filename=")) {
585 $pos = strpos($line, "filename=") + 9;
586 $name = trim($line);
587 if (strpos($line, " ", $pos) > 0) {
588 $name = substr($name, $pos, strpos($line, " ", $pos));
589 } else {
590 $name = substr($name, $pos);
591 }
592 $name = str_replace("\"", "", $name);
593 $hdr->filename = $name;
594 }
595 }
596 /* REPLY-TO */
597 else if (strtolower(substr($read[$i], 0, 9)) == "reply-to:") {
598 $hdr->replyto = trim(substr($read[$i], 9, strlen($read[$i])));
599 $i++;
600 }
601 /* FROM */
602 else if (strtolower(substr($read[$i], 0, 5)) == "from:") {
603 $hdr->from = trim(substr($read[$i], 5, strlen($read[$i]) - 6));
604 if (! isset($hdr->replyto) || $hdr->replyto == "") {
605 $hdr->replyto = $hdr->from;
606 }
607 $i++;
608 }
609 /* DATE */
610 else if (strtolower(substr($read[$i], 0, 5)) == "date:") {
611 $d = substr($read[$i], 5);
612 $d = trim($d);
613 $d = strtr($d, array(' ' => ' '));
614 $d = explode(' ', $d);
615 $hdr->date = getTimeStamp($d);
616 $i++;
617 }
618 /* SUBJECT */
619 else if (strtolower(substr($read[$i], 0, 8)) == "subject:") {
620 $hdr->subject = trim(substr($read[$i], 8, strlen($read[$i]) - 9));
621 if (strlen(Chop($hdr->subject)) == 0) {
622 $hdr->subject = _("(no subject)");
623 }
624 /*
625 if ($where == 'SUBJECT') {
626 $hdr->subject = $what;
627 // $hdr->subject = eregi_replace($what, "<b>\\0</b>", $hdr->subject);
628 }
629 */
630 $i++;
631 }
632 /* CC */
633 else if (strtolower(substr($read[$i], 0, 3)) == "cc:") {
634 $pos = 0;
635 $hdr->cc[$pos] = trim(substr($read[$i], 4));
636 $i++;
637 while (((substr($read[$i], 0, 1) == " ") || (substr($read[$i], 0, 1) == "\t")) && (trim($read[$i]) != "")){
638 $pos++;
639 $hdr->cc[$pos] = trim($read[$i]);
640 $i++;
641 }
642 }
643 /* BCC */
644 else if (strtolower(substr($read[$i], 0, 4)) == "bcc:") {
645 $pos = 0;
646 $hdr->bcc[$pos] = trim(substr($read[$i], 5));
647 $i++;
648 while (((substr($read[$i], 0, 1) == " ") || (substr($read[$i], 0, 1) == "\t")) && (trim($read[$i]) != "")){
649 $pos++;
650 $hdr->bcc[$pos] = trim($read[$i]);
651 $i++;
652 }
653 }
654 /* TO */
655 else if (strtolower(substr($read[$i], 0, 3)) == "to:") {
656 $pos = 0;
657 $hdr->to[$pos] = trim(substr($read[$i], 4));
658 $i++;
659 while (((substr($read[$i], 0, 1) == " ") || (substr($read[$i], 0, 1) == "\t")) && (trim($read[$i]) != "")){
660 $pos++;
661 $hdr->to[$pos] = trim($read[$i]);
662 $i++;
663 }
664 }
665 /* MESSAGE ID */
666 else if (strtolower(substr($read[$i], 0, 11)) == "message-id:") {
667 $hdr->message_id = trim(substr($read[$i], 11));
668 $i++;
669 }
670 /* ERROR CORRECTION */
671 else if (substr($read[$i], 0, 1) == ")") {
672 if (strlen(trim($hdr->subject)) == 0) {
673 $hdr->subject = _("(no subject)");
674 }
675 if (strlen(trim($hdr->from)) == 0) {
676 $hdr->from = _("(unknown sender)");
677 }
678 if (strlen(trim($hdr->date)) == 0) {
679 $hdr->date = time();
680 }
681 $i++;
682 }
683 /* X-PRIORITY */
684 else if (strtolower(substr($read[$i], 0, 11)) == "x-priority:") {
685 $hdr->priority = trim(substr($read[$i], 11));
686 $i++;
687 }
688 else {
689 $i++;
690 }
691 }
692 return $hdr;
693 }
694
695 /* Returns the body of a message. */
696 function sqimap_get_message_body ($imap_stream, &$header) {
697 $id = $header->id;
698 return decodeMime($imap_stream, $header);
699 }
700
701 ?>