Eddie Shipman
asked on
Problems using imap functions
I'm trying to build an email message parser for our site. What I'm eventually going to do is iterate through the messages that have attachments and save the attachment if the message comes from a particular email address.
This is just the initial test, however, I am running into problems, see comments below.
This is just the initial test, however, I am running into problems, see comments below.
<?php
echo "Loading..."."<br />\n";
$mailuser="help@mysite.com";
echo "User=$mailuser"."<br />\n";;
$mailpass="mypassword";
echo "Pass=$mailpass"."<br />\n";
// had to use this because we have SSL on site and regular port 110 didn't work
$mailhost="{localhost:995/pop3/ssl/novalidate-cert}";
echo "Host=$mailhost"."<br />\n";
$mailbox=imap_open($mailhost,$mailuser,$mailpass) or die("<br />\nFAILLED! ".imap_last_error());
$check = imap_check($mailbox);
// last message parsed will be stored in the file msgcounter.dat
$firstmsg = file_get_contents('msgcounter.dat') + 1;
$lastmsg = $firstmsg+$check->Recent; // should be == last msg index + count of latest messages
echo 'First:'.$firstmsg.' - Last:'.$lastmsg."<br>";
$result = imap_fetch_overview($mailbox,"$firstmsg:$lastmsg");
print_r($result); // returns empty array
foreach ($result as $overview) {
// never enters this loop.
echo "#{$overview->msgno} ({$overview->date}) - From: {$overview->from}
{$overview->subject}\n";
}
// the following approach didn't work either, Kept getting warnings about
// Bad message number
//
// Some messages in the sequence HAVE been deleted.
/*
for ($index = $firstmsg-1; $index <= ($lastmsg); $index++ ) {
if (strlen(trim(imap_fetchheader($mailbox, $index))) > 0) {
echo 'in message index loop:'.$index;
}
}
*/
imap_close($mailbox);
echo "completed.". "<br />\n";;
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.