-<?
+<?php
/**
** imap_messages.php
**
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
******************************************************************************/
- function sqimap_get_small_header ($imap_stream, $id, &$from, &$subject, &$date) {
- fputs ($imap_stream, "a001 FETCH $id:$id BODY[HEADER.FIELDS (From Subject Date)]\r\n");
+ function sqimap_get_small_header ($imap_stream, $id, &$from, &$subject, &$date, $sent) {
+ //fputs ($imap_stream, "a001 FETCH $id BODY[HEADER.FIELDS (DATE FROM SUBJECT)]\r\n");
+ fputs ($imap_stream, "a001 FETCH $id RFC822.HEADER\r\n");
$read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+ $subject = _("(no subject)");
+ $from = _("Unknown Sender");
for ($i = 0; $i < count($read); $i++) {
- if (strtolower(substr($read[$i], 0, 5)) == "from:") {
- $from = sqimap_find_displayable_name(substr($read[$i], 5));
- } else if (strtolower(substr($read[$i], 0, 5)) == "date:") {
+ if ($sent == true) {
+ if (strtolower(substr($read[$i], 0, 3)) == "to:")
+ $from = sqimap_find_displayable_name(substr($read[$i], 3));
+ } else {
+ if (strtolower(substr($read[$i], 0, 5)) == "from:")
+ $from = sqimap_find_displayable_name(substr($read[$i], 5));
+ }
+
+ if (strtolower(substr($read[$i], 0, 5)) == "date:") {
$date = substr($read[$i], 5);
} else if (strtolower(substr($read[$i], 0, 8)) == "subject:") {
$subject = htmlspecialchars(substr($read[$i], 8));
/******************************************************************************
** Returns the flags for the specified messages
******************************************************************************/
- function sqimap_get_flags ($imap_stream, $start, $end) {
- fputs ($imap_stream, "a001 FETCH $start:$end FLAGS\r\n");
+ 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);
- $i = 0;
- while ($i < count($read)) {
- if (strpos($read[$i], "FLAGS")) {
- $tmp = ereg_replace("\(", "", $read[$i]);
- $tmp = ereg_replace("\)", "", $tmp);
- $tmp = str_replace("\\", "", $tmp);
- $tmp = substr($tmp, strpos($tmp, "FLAGS")+6, strlen($tmp));
- $tmp = trim($tmp);
- $flags[$i] = explode(" ", $tmp);
- } else {
- $flags[$i][0] = "None";
- }
- $i++;
+ 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;
}
}
/** Detect the boundary of a multipart message **/
- if (strpos(strtolower(trim($line)), "boundary=")) {
- $pos = strpos(strtolower($line), "boundary=") + 9;
- $bound = trim($line);
- if (strpos($line, " ", $pos) > 0) {
- $bound = substr($bound, $pos, strpos($line, " ", $pos));
- } else {
- $bound = substr($bound, $pos);
- }
- $bound = str_replace("\"", "", $bound);
- $header["BOUNDARY"] = $bound;
+ if (eregi("boundary=\"([^\"]+)\"", $line, $regs)) {
+ $header["BOUNDARY"] = $regs[1];
}
/** Detect the charset **/