** This implements functions that manipulate messages
**/
- if (!$mime_php) include "../functions/mime.php";
+ if (!isset($mime_php)) include "../functions/mime.php";
/******************************************************************************
** Copies specified messages to specified folder
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))) {
+ 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 {
/******************************************************************************
** Returns some general header information -- FROM, DATE, and SUBJECT
******************************************************************************/
- class small_header {
- var $from, $subject, $date;
- }
+ 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 Subject)]\r\n");
+
+ fputs ($imap_stream, "a001 FETCH $id BODY.PEEK[HEADER.FIELDS (Date To From Cc Subject Message-Id X-Priority)]\r\n");
$read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
$subject = _("(no subject)");
$from = _("Unknown Sender");
- $g = 0;
+ $priority = "0";
+ $messageid = "<>";
+
+ $g = 0;
for ($i = 0; $i < count($read); $i++) {
- if ($sent == true) {
- if (eregi ("^to:", $read[$i])) {
- $from = sqimap_find_displayable_name(substr($read[$i], 3));
- }
- } else {
- if (eregi ("^from:", $read[$i])) {
- $from = sqimap_find_displayable_name(substr($read[$i], 5));
- }
- }
-
- if (eregi ("^date:", $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 (strlen(Chop($subject)) == 0)
+ if (trim($subject) == "")
$subject = _("(no subject)");
}
- }
+ }
- $header = new small_header;
- $header->from = $from;
- $header->date = $date;
- $header->subject = $subject;
+ // 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] / 1024;
+ settype($size, "integer");
+
+ $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;
- return $header;
+ return $header;
}
/******************************************************************************
** 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;
** 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->type1 = "plain";
$hdr->charset = "us-ascii";
+ preg_match("/\{([0-9]+)\}/", $read[$i], $regs);
+ preg_match("/[0-9]+/", $regs[0], $regs);
+
while ($i < count($read)) {
if (substr($read[$i], 0, 17) == "MIME-Version: 1.0") {
$hdr->mime = true;
$hdr->subject = trim(substr($read[$i], 8, strlen($read[$i]) - 9));
if (strlen(Chop($hdr->subject)) == 0)
$hdr->subject = _("(no subject)");
+
+ if ($where == "SUBJECT") {
+ $hdr->subject = eregi_replace($what, "<b>\\0</b>", $hdr->subject);
+ }
$i++;
}
/** CC **/
******************************************************************************/
function sqimap_get_message_body ($imap_stream, &$header) {
$id = $header->id;
- //fputs ($imap_stream, "a001 FETCH $id:$id BODY[TEXT]\r\n");
- //$read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
-
- $i = 0;
- $j = 0;
- while ($i < count($read)-1) {
- if ( ($i != 0) ) {
- $body[$j] = $read[$i];
- $j++;
- }
- $i++;
- }
- return decodeMime($body, &$header);
+ return decodeMime($imap_stream, $body, &$header);
}