- /**
- ** imap_messages.php
- **
- ** This implements functions that manipulate messages
- **/
-
- if (!isset($mime_php)) include "../functions/mime.php";
-
- /******************************************************************************
- ** Copies specified messages to specified folder
- ******************************************************************************/
- function sqimap_messages_copy ($imap_stream, $start, $end, $mailbox) {
- fputs ($imap_stream, "a001 COPY $start:$end \"$mailbox\"\r\n");
- $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
- }
-
- /******************************************************************************
- ** Deletes specified messages and moves them to trash if possible
- ******************************************************************************/
- function sqimap_messages_delete ($imap_stream, $start, $end, $mailbox) {
- global $move_to_trash, $trash_folder, $auto_expunge;
-
- if (($move_to_trash == true) && (sqimap_mailbox_exists($imap_stream, $trash_folder) && ($mailbox != $trash_folder))) {
- sqimap_messages_copy ($imap_stream, $start, $end, $trash_folder);
- sqimap_messages_flag ($imap_stream, $start, $end, "Deleted");
- } else {
- sqimap_messages_flag ($imap_stream, $start, $end, "Deleted");
- }
- }
-
- /******************************************************************************
- ** Sets the specified messages with specified flag
- ******************************************************************************/
- function sqimap_messages_flag ($imap_stream, $start, $end, $flag) {
- fputs ($imap_stream, "a001 STORE $start:$end +FLAGS (\\$flag)\r\n");
- $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
- }
-
- /******************************************************************************
- ** Returns some general header information -- FROM, DATE, and SUBJECT
- ******************************************************************************/
- class small_header {
- var $from, $subject, $date, $to, $priority, $message_id;
- }
-
- function sqimap_get_small_header ($imap_stream, $id, $sent) {
-
- fputs ($imap_stream, "a001 FETCH $id BODY.PEEK[HEADER.FIELDS (Date To From Cc Subject Message-Id X-Priority Content-Type)]\r\n");
- $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
-
- $subject = _("(no subject)");
- $from = _("Unknown Sender");
- $priority = "0";
- $messageid = "<>";
-
- $g = 0;
- for ($i = 0; $i < count($read); $i++) {
- if (eregi ("^to:", $read[$i])) {
- //$to = sqimap_find_displayable_name(substr($read[$i], 3));
- $to = substr($read[$i], 3);
- } else if (eregi ("^from:", $read[$i])) {
- //$from = sqimap_find_displayable_name(substr($read[$i], 5));
- $from = substr($read[$i], 5);
- } else if (eregi ("^x-priority:", $read[$i])) {
- $priority = trim(substr($read[$i], 11));
- } else if (eregi ("^message-id:", $read[$i])) {
- $messageid = trim(substr($read[$i], 11));
- } else if (eregi ("^cc:", $read[$i])) {
- $cc = substr($read[$i], 3);
- } else if (eregi ("^date:", $read[$i])) {
- $date = substr($read[$i], 5);
- } else if (eregi ("^subject:", $read[$i])) {
- $subject = htmlspecialchars(eregi_replace ("^subject: ", "", $read[$i]));
- if (trim($subject) == "")
- $subject = _("(no subject)");
- } else if (eregi ("^content-type:", $read[$i])) {
- $type = substr($read[$i], 14);
- $type = strtolower(trim($type));
- if ($pos = strpos($type, ";"))
- $type = substr($type, 0, $pos);
- $type = explode("/", $type);
- }
-
- }
-
- // If there isn't a date, it takes the internal date and uses
- // that as the normal date.
- if (trim($date) == "") {
- fputs ($imap_stream, "a002 FETCH $id INTERNALDATE\r\n");
- $internal_read = sqimap_read_data ($imap_stream, "a002", true, $r, $m);
-
- // * 22 FETCH (INTERNALDATE " 8-Sep-2000 13:17:07 -0500")
- $date = $internal_read[0];
- $date = eregi_replace(".*internaldate \"", "", $date);
- $date = eregi_replace("\".*", "", $date);
- $date_ary = explode(" ", trim($date));
- $date_ary[0] = str_replace("-", " ", $date_ary[0]);
- $date = implode (" ", $date_ary);
- }
-
- fputs ($imap_stream, "a003 FETCH $id RFC822.SIZE\r\n");
- $read = sqimap_read_data($imap_stream, "a003", true, $r, $m);
- preg_match("/([0-9]+)\)\s*$/i", $read[0], $regs);
- $size = $regs[1];
-
- $header = new small_header;
- if ($sent == true)
- $header->from = $to;
- else
- $header->from = $from;
-
- $header->date = $date;
- $header->subject = $subject;
- $header->to = $to;
- $header->priority = $priority;
- $header->message_id = $messageid;
- $header->cc = $cc;
- $header->size = $size;
- $header->type0 = $type[0];
- $header->type1 = $type[1];
-
- return $header;
- }
-
- /******************************************************************************
- ** Returns the flags for the specified messages
- ******************************************************************************/
- function sqimap_get_flags ($imap_stream, $i) {
- fputs ($imap_stream, "a001 FETCH $i:$i FLAGS\r\n");
- $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
- if (strpos($read[0], "FLAGS")) {
- $tmp = ereg_replace("\(", "", $read[0]);
- $tmp = ereg_replace("\)", "", $tmp);
- $tmp = str_replace("\\", "", $tmp);
- $tmp = substr($tmp, strpos($tmp, "FLAGS")+6, strlen($tmp));
- $tmp = trim($tmp);
- $flags = explode(" ", $tmp);
- } else {
- $flags[0] = "None";
- }
- return $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);
- $msg = sqimap_get_message_body($imap_stream, &$header);
- return $msg;
- }
-
- /******************************************************************************
- ** Wrapper function that reformats the header information.
- ******************************************************************************/
- function sqimap_get_message_header ($imap_stream, $id, $mailbox) {
- fputs ($imap_stream, "a001 FETCH $id:$id BODY[HEADER]\r\n");
- $read = sqimap_read_data ($imap_stream, "a001", 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"];
- }
- */