- }
- arsort($result_flags);
- return $result_flags;
-}
-
-/*
- * Returns a message array with all the information about a message.
- * See the documentation folder for more information about this array.
- */
-function sqimap_get_message ($imap_stream, $id, $mailbox) {
- $header = sqimap_get_message_header($imap_stream, $id, $mailbox);
- return sqimap_get_message_body($imap_stream, $header);
-}
-
-/* Wrapper function that reformats the header information. */
-function sqimap_get_message_header ($imap_stream, $id, $mailbox) {
- $read = sqimap_run_command ($imap_stream, "FETCH $id:$id BODY[HEADER]", true, $response, $message);
- $header = sqimap_get_header($imap_stream, $read);
- $header->id = $id;
- $header->mailbox = $mailbox;
- return $header;
-}
-
-/* Wrapper function that reformats the entity header information. */
-function sqimap_get_ent_header ($imap_stream, $id, $mailbox, $ent) {
- $read = sqimap_run_command ($imap_stream, "FETCH $id:$id BODY[$ent.HEADER]", true, $response, $message);
- $header = sqimap_get_header($imap_stream, $read);
- $header->id = $id;
- $header->mailbox = $mailbox;
- return $header;
-}
-
-
-/* Wrapper function that returns entity headers for use by decodeMime */
-/*
-function sqimap_get_entity_header ($imap_stream, &$read, &$type0, &$type1, &$bound, &$encoding, &$charset, &$filename) {
- $header = sqimap_get_header($imap_stream, $read);
- $type0 = $header["TYPE0"];
- $type1 = $header["TYPE1"];
- $bound = $header["BOUNDARY"];
- $encoding = $header["ENCODING"];
- $charset = $header["CHARSET"];
- $filename = $header["FILENAME"];
-}
-
-/* function to get the mime headers */
-function sqimap_get_mime_ent_header ($imap_stream, $id, $mailbox, $ent) {
- $read = sqimap_run_command ($imap_stream, "FETCH $id:$id BODY[$ent.MIME]", true, $response, $message);
- $header = sqimap_get_header($imap_stream, $read);
- $header->id = $id;
- $header->mailbox = $mailbox;
- return $header;
-}
-
-*/
-/* Queries the IMAP server and gets all header information. */
-function sqimap_get_header ($imap_stream, $read) {
- global $where, $what;
-
- $hdr = new msg_header();
- $i = 0;
-
- /* Set up some defaults */
- $hdr->type0 = "text";
- $hdr->type1 = "plain";
- $hdr->charset = "us-ascii";
-
- $read_fold = array();
-
- while ($i < count($read)) {
- /* unfold multi-line headers */
- /* remember line for to, cc and bcc */
- $read_fold[] = $read[$i];
- $folded = false;
- while (($i + 1 < count($read)) && (strspn($read[$i + 1], "\t ") > 0) ) {
- if ($read[$i+1] != '') $read_fold[] = $read[$i+1];
- $read[$i + 1] = substr($read[$i], 0, -2) . ' ' . ltrim($read[$i+1]);
- array_splice($read, $i, 1);
- $folded = true;
- }
- if (!$folded) {
- $read_fold = array();
- }
-
- if (substr($read[$i], 0, 17) == "MIME-Version: 1.0") {
- $hdr->mime = true;
- $i++;
- }
- /* ENCODING TYPE */
- else if (substr(strtolower($read[$i]), 0, 26) == "content-transfer-encoding:") {
- $hdr->encoding = strtolower(trim(substr($read[$i], 26)));
- $i++;
- }
- /* CONTENT-TYPE */
- else if (strtolower(substr($read[$i], 0, 13)) == "content-type:") {
- $cont = strtolower(trim(substr($read[$i], 13)));
- if (strpos($cont, ";")) {
- $cont = substr($cont, 0, strpos($cont, ";"));
- }
-
- if (strpos($cont, "/")) {
- $hdr->type0 = substr($cont, 0, strpos($cont, "/"));
- $hdr->type1 = substr($cont, strpos($cont, "/")+1);
- } else {
- $hdr->type0 = $cont;
- }
-
- $line = $read[$i];
- $i++;
- while ( (substr(substr($read[$i], 0, strpos($read[$i], " ")), -1) != ":") && (trim($read[$i]) != "") && (trim($read[$i]) != ")")) {
- str_replace("\n", "", $line);
- str_replace("\n", "", $read[$i]);
- $line = "$line $read[$i]";
- $i++;
- }
-
- /* Detect the boundary of a multipart message */
- if (eregi('boundary="([^"]+)"', $line, $regs)) {
- $hdr->boundary = $regs[1];
- }
-
- /* Detect the charset */
- if (strpos(strtolower(trim($line)), "charset=")) {
- $pos = strpos($line, "charset=") + 8;
- $charset = trim($line);
- if (strpos($line, ";", $pos) > 0) {
- $charset = substr($charset, $pos, strpos($line, ";", $pos)-$pos);
- } else {
- $charset = substr($charset, $pos);