- /**
- ** imap_messages.php
- **
- ** This implements functions that manipulate messages
- **
- ** $Id$
- **/
-
- 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);
- }
-
-
- /******************************************************************************
- ** Remove specified flag from specified messages
- ******************************************************************************/
- function sqimap_messages_remove_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 = 0, $message_id = 0, $cc = '';
- }
-
- 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 = "<>";
- $cc = "";
- $to = "";
- $date = "";
- $type[0] = "";
- $type[1] = "";
-
- $g = 0;
- for ($i = 0; $i < count($read); $i++) {
- if (eregi ("^to:(.*)$", $read[$i], $regs)) {
- //$to = sqimap_find_displayable_name(substr($read[$i], 3));
- $to = $regs[1];
- } else if (eregi ("^from:(.*)$", $read[$i], $regs)) {
- //$from = sqimap_find_displayable_name(substr($read[$i], 5));
- $from = $regs[1];
- } else if (eregi ("^x-priority:(.*)$", $read[$i], $regs)) {
- $priority = trim($regs[1]);
- } else if (eregi ("^message-id:(.*)$", $read[$i], $regs)) {
- $messageid = trim($regs[1]);
- } else if (eregi ("^cc:(.*)$", $read[$i], $regs)) {
- $cc = $regs[1];
- } else if (eregi ("^date:(.*)$", $read[$i], $regs)) {
- $date = $regs[1];
- } else if (eregi ("^subject:(.*)$", $read[$i], $regs)) {
- $subject = htmlspecialchars(trim($regs[1]));
- if ($subject == "")
- $subject = _("(no subject)");
- } else if (eregi ("^content-type:(.*)$", $read[$i], $regs)) {
- $type = strtolower(trim($regs[1]));
- 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);
- eregi("([0-9]+)[^0-9]*$", $read[0], $regs);
- $size = $regs[1];
-
- $header = new small_header;
- if ($sent == true)
- $header->from = (trim($to) != '')? $to : _("(only Cc/Bcc)");
- 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 (ereg("FLAGS(.*)", $read[0], $regs))
- return explode(" ", trim(ereg_replace('[\\(\\)\\\\]', '', $regs[1])));
- return Array('None');
- }
-
- /******************************************************************************
- ** 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) {
- 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"];
- }
- */