Little bit of tidying up
[squirrelmail.git] / functions / imap_messages.php
CommitLineData
59177427 1<?php
7350889b 2
35586184 3/**
4 * imap_messages.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 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 */
052e0c26 13
3411d4ec 14/* Copies specified messages to specified folder */
35586184 15function sqimap_messages_copy ($imap_stream, $start, $end, $mailbox) {
1c72b151 16 $read = sqimap_run_command ($imap_stream, "COPY $start:$end \"$mailbox\"", true, $response, $message);
97f7ddf2 17}
18
3411d4ec 19/* Deletes specified messages and moves them to trash if possible */
97f7ddf2 20function 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);
97f7ddf2 25 }
3411d4ec 26 sqimap_messages_flag ($imap_stream, $start, $end, "Deleted");
97f7ddf2 27}
28
3411d4ec 29/* Sets the specified messages with specified flag */
97f7ddf2 30function sqimap_messages_flag ($imap_stream, $start, $end, $flag) {
1c72b151 31 $read = sqimap_run_command ($imap_stream, "STORE $start:$end +FLAGS (\\$flag)", true, $response, $message);
97f7ddf2 32}
33
3411d4ec 34/* Remove specified flag from specified messages */
97f7ddf2 35function sqimap_messages_remove_flag ($imap_stream, $start, $end, $flag) {
1c72b151 36 $read = sqimap_run_command ($imap_stream, "STORE $start:$end -FLAGS (\\$flag)", true, $response, $message);
97f7ddf2 37}
38
3411d4ec 39/* Returns some general header information -- FROM, DATE, and SUBJECT */
97f7ddf2 40class small_header {
41 var $from = '', $subject = '', $date = '', $to = '',
42 $priority = 0, $message_id = 0, $cc = '';
43}
44
45function 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}
3411d4ec 49
50/*
51 * Sort the message list and crunch to be as small as possible
97f7ddf2 52 * (overflow could happen, so make it small if possible)
53 */
54function 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 }
3411d4ec 74
97f7ddf2 75 return $msgs_str;
3411d4ec 76}
97f7ddf2 77
67c2f5ea 78/* returns the references header lines */
79function 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
97f7ddf2 93function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
9735cf27 94 global $squirrelmail_language, $color, $data_dir, $username;
97f7ddf2 95
96 /* Get the small headers for each message in $msg_list */
97 $sid = sqimap_session_id();
98 $maxmsg = sizeof($msg_list);
99 $msgs_str = sqimap_message_list_squisher($msg_list);
100 $results = array();
101 $read_list = array();
102 $sizes_list = array();
103
3411d4ec 104 /*
97f7ddf2 105 * We need to return the data in the same order as the caller supplied
106 * in $msg_list, but IMAP servers are free to return responses in
107 * whatever order they wish... So we need to re-sort manually
108 */
109 for ($i = 0; $i < sizeof($msg_list); $i++) {
110 $id2index[$msg_list[$i]] = $i;
111 }
112
67c2f5ea 113 $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";
97f7ddf2 114 fputs ($imap_stream, $query);
115 $readin_list = sqimap_read_data_list($imap_stream, $sid, true, $response, $message);
116
117 foreach ($readin_list as $r) {
118 if (!eregi("^\\* ([0-9]+) FETCH", $r[0], $regs)) {
91f68e94 119 set_up_language($squirrelmail_language);
0fbbda83 120 echo '<br><b><font color=$color[2]>' .
97f7ddf2 121 _("ERROR : Could not complete request.") .
122 '</b><br>' .
123 _("Unknown response from IMAP server: ") . ' 1.' .
124 $r[0] . "</font><br>\n";
97f7ddf2 125 } else if (! isset($id2index[$regs[1]]) || !count($id2index[$regs[1]])) {
126 set_up_language($squirrelmail_language);
127 echo '<br><b><font color=$color[2]>' .
128 _("ERROR : Could not complete request.") .
129 '</b><br>' .
130 _("Unknown message number in reply from server: ") .
131 $regs[1] . "</font><br>\n";
97f7ddf2 132 } else {
133 $read_list[$id2index[$regs[1]]] = $r;
134 }
135 }
136 arsort($read_list);
3411d4ec 137
97f7ddf2 138 $query = "$sid FETCH $msgs_str RFC822.SIZE\r\n";
139 fputs ($imap_stream, $query);
140 $sizesin_list = sqimap_read_data_list($imap_stream, $sid, true, $response, $message);
3411d4ec 141
97f7ddf2 142 foreach ($sizesin_list as $r) {
143 if (!eregi("^\\* ([0-9]+) FETCH", $r[0], $regs)) {
91f68e94 144 set_up_language($squirrelmail_language);
145 echo "<br><b><font color=$color[2]>\n";
146 echo _("ERROR : Could not complete request.");
147 echo "</b><br>\n";
0fbbda83 148 echo _("Unknown response from IMAP server: ") . ' 2.';
91f68e94 149 echo $r[0] . "</font><br>\n";
150 exit;
97f7ddf2 151 }
152 if (!count($id2index[$regs[1]])) {
91f68e94 153 set_up_language($squirrelmail_language);
154 echo "<br><b><font color=$color[2]>\n";
155 echo _("ERROR : Could not complete request.");
156 echo "</b><br>\n";
157 echo _("Unknown messagenumber in reply from server: ");
158 echo $regs[1] . "</font><br>\n";
159 exit;
97f7ddf2 160 }
161 $sizes_list[$id2index[$regs[1]]] = $r;
162 }
163 arsort($sizes_list);
3411d4ec 164
97f7ddf2 165 for ($msgi = 0; $msgi < $maxmsg; $msgi++) {
166 $subject = _("(no subject)");
167 $from = _("Unknown Sender");
168 $priority = 0;
169 $messageid = "<>";
170 $cc = "";
171 $to = "";
172 $date = "";
173 $type[0] = "";
174 $type[1] = "";
67c2f5ea 175 $inrepto = "";
97f7ddf2 176 $read = $read_list[$msgi];
177
ec91fad4 178 $prevline = false;
3411d4ec 179 foreach ($read as $read_part) {
ec91fad4 180 //unfold multi-line headers
181 while ($prevline && strspn($read_part, "\t ") > 0) {
11505466 182 $read_part = substr($prevline, 0, -2) . ' ' . ltrim($read_part);
ec91fad4 183 }
184 $prevline = $read_part;
3411d4ec 185 if (eregi ("^to:(.*)$", $read_part, $regs)) {
97f7ddf2 186 $to = $regs[1];
3411d4ec 187 } else if (eregi ("^from:(.*)$", $read_part, $regs)) {
97f7ddf2 188 $from = $regs[1];
3411d4ec 189 } else if (eregi ("^x-priority:(.*)$", $read_part, $regs)) {
97f7ddf2 190 $priority = trim($regs[1]);
3411d4ec 191 } else if (eregi ("^message-id:(.*)$", $read_part, $regs)) {
97f7ddf2 192 $messageid = trim($regs[1]);
3411d4ec 193 } else if (eregi ("^cc:(.*)$", $read_part, $regs)) {
97f7ddf2 194 $cc = $regs[1];
3411d4ec 195 } else if (eregi ("^date:(.*)$", $read_part, $regs)) {
97f7ddf2 196 $date = $regs[1];
3411d4ec 197 } else if (eregi ("^subject:(.*)$", $read_part, $regs)) {
97f7ddf2 198 $subject = htmlspecialchars(trim($regs[1]));
199 if ($subject == "") {
200 $subject = _("(no subject)");
201 }
3411d4ec 202 } else if (eregi ("^content-type:(.*)$", $read_part, $regs)) {
97f7ddf2 203 $type = strtolower(trim($regs[1]));
204 if ($pos = strpos($type, ";")) {
205 $type = substr($type, 0, $pos);
206 }
207 $type = explode("/", $type);
3411d4ec 208 if (!isset($type[1])) {
97f7ddf2 209 $type[1] = '';
210 }
b288e71e 211 } else if (eregi ("^in-reply-to:(.*)$", $read_part, $regs)) {
67c2f5ea 212 $inrepto = trim($regs[1]);
91f68e94 213 }
97f7ddf2 214 }
3411d4ec 215 $internaldate = getPref($data_dir, $username, 'internal_date_sort');
9735cf27 216 if (trim($date) == "" || $internaldate) {
0fbbda83 217 fputs($imap_stream, "$sid FETCH $msg_list[$msgi] INTERNALDATE\r\n");
218 $readdate = sqimap_read_data($imap_stream, $sid, true, $response, $message);
91f68e94 219 if (eregi(".*INTERNALDATE \"(.*)\".*", $readdate[0], $regs)) {
3411d4ec 220 $date_list = explode(' ', trim($regs[1]));
221 $date_list[0] = str_replace("-", ' ', $date_list[0]);
222 $date = implode(' ', $date_list);
91f68e94 223 }
97f7ddf2 224 }
225 eregi("([0-9]+)[^0-9]*$", $sizes_list[$msgi][0], $regs);
226 $size = $regs[1];
3411d4ec 227
97f7ddf2 228 $header = new small_header;
3411d4ec 229 if ($issent) {
f7b1b3b1 230 $header->from = (trim($to) != '' ? $to : '(' ._("No To Address") . ')');
97f7ddf2 231 } else {
91f68e94 232 $header->from = $from;
97f7ddf2 233 }
234
235 $header->date = $date;
236 $header->subject = $subject;
237 $header->to = $to;
238 $header->priority = $priority;
239 $header->message_id = $messageid;
240 $header->cc = $cc;
241 $header->size = $size;
242 $header->type0 = $type[0];
243 $header->type1 = $type[1];
67c2f5ea 244 $header->inrepto = $inrepto;
97f7ddf2 245 $result[] = $header;
246 }
247 return $result;
248}
249
3411d4ec 250/* Returns the flags for the specified messages */
97f7ddf2 251function sqimap_get_flags ($imap_stream, $i) {
1c72b151 252 $read = sqimap_run_command ($imap_stream, "FETCH $i:$i FLAGS", true, $response, $message);
3411d4ec 253 if (ereg('FLAGS(.*)', $read[0], $regs)) {
0f8a1ce9 254 return explode(' ', trim(ereg_replace('[\\(\\)\\\\]', '', $regs[1])));
97f7ddf2 255 }
3411d4ec 256 return array('None');
97f7ddf2 257}
258
259function sqimap_get_flags_list ($imap_stream, $msg_list) {
260 $msgs_str = sqimap_message_list_squisher($msg_list);
261 for ($i = 0; $i < sizeof($msg_list); $i++) {
262 $id2index[$msg_list[$i]] = $i;
263 }
1c72b151 264 $result_list = sqimap_run_command_list ($imap_stream, "FETCH $msgs_str FLAGS", true, $response, $message);
97f7ddf2 265 $result_flags = array();
266
267 for ($i = 0; $i < sizeof($result_list); $i++) {
3411d4ec 268 if (eregi('^\* ([0-9]+).*FETCH.*FLAGS(.*)', $result_list[$i][0], $regs)
97f7ddf2 269 && isset($id2index[$regs[1]]) && count($id2index[$regs[1]])) {
91f68e94 270 $result_flags[$id2index[$regs[1]]] = explode(" ", trim(ereg_replace('[\\(\\)\\\\]', '', $regs[2])));
97f7ddf2 271 } else {
91f68e94 272 set_up_language($squirrelmail_language);
49c17806 273 echo "<br><b><font color=$color[2]>\n" .
274 _("ERROR : Could not complete request.") .
275 "</b><br>\n" .
276 _("Unknown response from IMAP server: ") .
277 $result_list[$i][0] . "</font><br>\n";
91f68e94 278 exit;
97f7ddf2 279 }
280 }
281 arsort($result_flags);
282 return $result_flags;
283}
284
3411d4ec 285/*
286 * Returns a message array with all the information about a message.
287 * See the documentation folder for more information about this array.
288 */
97f7ddf2 289function sqimap_get_message ($imap_stream, $id, $mailbox) {
290 $header = sqimap_get_message_header($imap_stream, $id, $mailbox);
291 return sqimap_get_message_body($imap_stream, $header);
292}
293
3411d4ec 294/* Wrapper function that reformats the header information. */
97f7ddf2 295function sqimap_get_message_header ($imap_stream, $id, $mailbox) {
1c72b151 296 $read = sqimap_run_command ($imap_stream, "FETCH $id:$id BODY[HEADER]", true, $response, $message);
97f7ddf2 297 $header = sqimap_get_header($imap_stream, $read);
298 $header->id = $id;
299 $header->mailbox = $mailbox;
97f7ddf2 300 return $header;
301}
302
3411d4ec 303/* Wrapper function that reformats the entity header information. */
43786d5c 304function sqimap_get_ent_header ($imap_stream, $id, $mailbox, $ent) {
305 $read = sqimap_run_command ($imap_stream, "FETCH $id:$id BODY[$ent.HEADER]", true, $response, $message);
306 $header = sqimap_get_header($imap_stream, $read);
307 $header->id = $id;
308 $header->mailbox = $mailbox;
309 return $header;
310}
311
312
3411d4ec 313/* Wrapper function that returns entity headers for use by decodeMime */
97f7ddf2 314/*
315function sqimap_get_entity_header ($imap_stream, &$read, &$type0, &$type1, &$bound, &$encoding, &$charset, &$filename) {
316 $header = sqimap_get_header($imap_stream, $read);
317 $type0 = $header["TYPE0"];
318 $type1 = $header["TYPE1"];
319 $bound = $header["BOUNDARY"];
320 $encoding = $header["ENCODING"];
321 $charset = $header["CHARSET"];
322 $filename = $header["FILENAME"];
323}
324*/
3411d4ec 325/* Queries the IMAP server and gets all header information. */
97f7ddf2 326function sqimap_get_header ($imap_stream, $read) {
327 global $where, $what;
328
329 $hdr = new msg_header();
330 $i = 0;
3411d4ec 331
97f7ddf2 332 /* Set up some defaults */
333 $hdr->type0 = "text";
334 $hdr->type1 = "plain";
335 $hdr->charset = "us-ascii";
336
337 while ($i < count($read)) {
ec91fad4 338 //unfold multi-line headers
339 while ($i + 1 < count($read) && strspn($read[$i + 1], "\t ") > 0) {
11505466 340 $read[$i + 1] = substr($read[$i], 0, -2) . ' ' . ltrim($read[$i + 1]);
ec91fad4 341 array_splice($read, $i, 1);
342 }
343
97f7ddf2 344 if (substr($read[$i], 0, 17) == "MIME-Version: 1.0") {
8beafbbc 345 $hdr->mime = true;
052e0c26 346 $i++;
97f7ddf2 347 }
3411d4ec 348 /* ENCODING TYPE */
97f7ddf2 349 else if (substr(strtolower($read[$i]), 0, 26) == "content-transfer-encoding:") {
8beafbbc 350 $hdr->encoding = strtolower(trim(substr($read[$i], 26)));
052e0c26 351 $i++;
97f7ddf2 352 }
3411d4ec 353 /* CONTENT-TYPE */
354 else if (strtolower(substr($read[$i], 0, 13)) == "content-type:") {
052e0c26 355 $cont = strtolower(trim(substr($read[$i], 13)));
97f7ddf2 356 if (strpos($cont, ";")) {
357 $cont = substr($cont, 0, strpos($cont, ";"));
358 }
052e0c26 359
052e0c26 360 if (strpos($cont, "/")) {
97f7ddf2 361 $hdr->type0 = substr($cont, 0, strpos($cont, "/"));
362 $hdr->type1 = substr($cont, strpos($cont, "/")+1);
052e0c26 363 } else {
97f7ddf2 364 $hdr->type0 = $cont;
052e0c26 365 }
366
052e0c26 367 $line = $read[$i];
368 $i++;
369 while ( (substr(substr($read[$i], 0, strpos($read[$i], " ")), -1) != ":") && (trim($read[$i]) != "") && (trim($read[$i]) != ")")) {
97f7ddf2 370 str_replace("\n", "", $line);
371 str_replace("\n", "", $read[$i]);
372 $line = "$line $read[$i]";
373 $i++;
052e0c26 374 }
375
3411d4ec 376 /* Detect the boundary of a multipart message */
97f7ddf2 377 if (eregi('boundary="([^"]+)"', $line, $regs)) {
378 $hdr->boundary = $regs[1];
052e0c26 379 }
380
3411d4ec 381 /* Detect the charset */
052e0c26 382 if (strpos(strtolower(trim($line)), "charset=")) {
97f7ddf2 383 $pos = strpos($line, "charset=") + 8;
384 $charset = trim($line);
385 if (strpos($line, ";", $pos) > 0) {
386 $charset = substr($charset, $pos, strpos($line, ";", $pos)-$pos);
387 } else {
388 $charset = substr($charset, $pos);
389 }
390 $charset = str_replace("\"", "", $charset);
391 $hdr->charset = $charset;
052e0c26 392 } else {
97f7ddf2 393 $hdr->charset = "us-ascii";
052e0c26 394 }
97f7ddf2 395 }
97f7ddf2 396 else if (strtolower(substr($read[$i], 0, 20)) == "content-disposition:") {
3411d4ec 397 /* Add better content-disposition support */
052e0c26 398 $line = $read[$i];
399 $i++;
400 while ( (substr(substr($read[$i], 0, strpos($read[$i], " ")), -1) != ":") && (trim($read[$i]) != "") && (trim($read[$i]) != ")")) {
97f7ddf2 401 str_replace("\n", "", $line);
402 str_replace("\n", "", $read[$i]);
403 $line = "$line $read[$i]";
404 $i++;
052e0c26 405 }
406
3411d4ec 407 /* Detects filename if any */
052e0c26 408 if (strpos(strtolower(trim($line)), "filename=")) {
97f7ddf2 409 $pos = strpos($line, "filename=") + 9;
410 $name = trim($line);
411 if (strpos($line, " ", $pos) > 0) {
3411d4ec 412 $name = substr($name, $pos, strpos($line, " ", $pos));
97f7ddf2 413 } else {
3411d4ec 414 $name = substr($name, $pos);
97f7ddf2 415 }
416 $name = str_replace("\"", "", $name);
417 $hdr->filename = $name;
052e0c26 418 }
97f7ddf2 419 }
3411d4ec 420 /* REPLY-TO */
97f7ddf2 421 else if (strtolower(substr($read[$i], 0, 9)) == "reply-to:") {
8beafbbc 422 $hdr->replyto = trim(substr($read[$i], 9, strlen($read[$i])));
052e0c26 423 $i++;
97f7ddf2 424 }
3411d4ec 425 /* FROM */
97f7ddf2 426 else if (strtolower(substr($read[$i], 0, 5)) == "from:") {
8beafbbc 427 $hdr->from = trim(substr($read[$i], 5, strlen($read[$i]) - 6));
97f7ddf2 428 if (! isset($hdr->replyto) || $hdr->replyto == "") {
429 $hdr->replyto = $hdr->from;
430 }
052e0c26 431 $i++;
97f7ddf2 432 }
3411d4ec 433 /* DATE */
97f7ddf2 434 else if (strtolower(substr($read[$i], 0, 5)) == "date:") {
052e0c26 435 $d = substr($read[$i], 5);
436 $d = trim($d);
a5227f0e 437 $d = strtr($d, array(' ' => ' '));
146e0c45 438 $d = explode(' ', $d);
8beafbbc 439 $hdr->date = getTimeStamp($d);
052e0c26 440 $i++;
97f7ddf2 441 }
3411d4ec 442 /* SUBJECT */
97f7ddf2 443 else if (strtolower(substr($read[$i], 0, 8)) == "subject:") {
8beafbbc 444 $hdr->subject = trim(substr($read[$i], 8, strlen($read[$i]) - 9));
53828ec5 445 if (strlen(Chop($hdr->subject)) == 0) {
8beafbbc 446 $hdr->subject = _("(no subject)");
508c06bf 447 }
3411d4ec 448 /*
53828ec5 449 if ($where == 'SUBJECT') {
97f7ddf2 450 $hdr->subject = $what;
451 // $hdr->subject = eregi_replace($what, "<b>\\0</b>", $hdr->subject);
53828ec5 452 }
453 */
052e0c26 454 $i++;
97f7ddf2 455 }
3411d4ec 456 /* CC */
97f7ddf2 457 else if (strtolower(substr($read[$i], 0, 3)) == "cc:") {
052e0c26 458 $pos = 0;
8beafbbc 459 $hdr->cc[$pos] = trim(substr($read[$i], 4));
052e0c26 460 $i++;
11728a4d 461 while (((substr($read[$i], 0, 1) == " ") || (substr($read[$i], 0, 1) == "\t")) && (trim($read[$i]) != "")){
97f7ddf2 462 $pos++;
463 $hdr->cc[$pos] = trim($read[$i]);
464 $i++;
052e0c26 465 }
97f7ddf2 466 }
3411d4ec 467 /* BCC */
97f7ddf2 468 else if (strtolower(substr($read[$i], 0, 4)) == "bcc:") {
853b543d 469 $pos = 0;
470 $hdr->bcc[$pos] = trim(substr($read[$i], 5));
471 $i++;
472 while (((substr($read[$i], 0, 1) == " ") || (substr($read[$i], 0, 1) == "\t")) && (trim($read[$i]) != "")){
97f7ddf2 473 $pos++;
474 $hdr->bcc[$pos] = trim($read[$i]);
475 $i++;
853b543d 476 }
97f7ddf2 477 }
3411d4ec 478 /* TO */
97f7ddf2 479 else if (strtolower(substr($read[$i], 0, 3)) == "to:") {
052e0c26 480 $pos = 0;
8beafbbc 481 $hdr->to[$pos] = trim(substr($read[$i], 4));
052e0c26 482 $i++;
11728a4d 483 while (((substr($read[$i], 0, 1) == " ") || (substr($read[$i], 0, 1) == "\t")) && (trim($read[$i]) != "")){
97f7ddf2 484 $pos++;
485 $hdr->to[$pos] = trim($read[$i]);
486 $i++;
052e0c26 487 }
97f7ddf2 488 }
3411d4ec 489 /* MESSAGE ID */
97f7ddf2 490 else if (strtolower(substr($read[$i], 0, 11)) == "message-id:") {
8beafbbc 491 $hdr->message_id = trim(substr($read[$i], 11));
052e0c26 492 $i++;
97f7ddf2 493 }
3411d4ec 494 /* ERROR CORRECTION */
97f7ddf2 495 else if (substr($read[$i], 0, 1) == ")") {
496 if (strlen(trim($hdr->subject)) == 0) {
8beafbbc 497 $hdr->subject = _("(no subject)");
97f7ddf2 498 }
499 if (strlen(trim($hdr->from)) == 0) {
8beafbbc 500 $hdr->from = _("(unknown sender)");
97f7ddf2 501 }
502 if (strlen(trim($hdr->date)) == 0) {
8beafbbc 503 $hdr->date = time();
97f7ddf2 504 }
052e0c26 505 $i++;
97f7ddf2 506 }
3411d4ec 507 /* X-PRIORITY */
97f7ddf2 508 else if (strtolower(substr($read[$i], 0, 11)) == "x-priority:") {
020abcf3 509 $hdr->priority = trim(substr($read[$i], 11));
510 $i++;
97f7ddf2 511 }
512 else {
052e0c26 513 $i++;
97f7ddf2 514 }
515 }
516 return $hdr;
517}
052e0c26 518
3411d4ec 519/* Returns the body of a message. */
97f7ddf2 520function sqimap_get_message_body ($imap_stream, &$header) {
521 $id = $header->id;
522 return decodeMime($imap_stream, $header);
523}
8beafbbc 524
052e0c26 525?>