Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IMAP mail reading

Status
Not open for further replies.

crazybeans128

Programmer
Aug 5, 2003
79
US
I have a project where my PHP script has to open emails and sort through them trying to find some general information. I'm experimenting with the IMAP protocols to do this, as I cannot edit the configuration on ther server. I quickly figured out how to work the protocols, however if I want to look at the same message again using the message number, it shows me a completeley different message and the message I want to see is nowhere to be found, at least, not that I can find. My current code looks like this:

<?php
$mbox = imap_open (information I don't care for you to know);

$message = imap_body($mbox,350,);
echo $message;
imap_clearflag_full($mbox,350,"\\Seen");

imap_close($mbox);
?>

I placed the flag in there in hopes that it would leave the message intact, but it does not. Any ideas?

 
use imap_uid to identify the message. the sequencenumber will change every time a new message is delivered but the uid stays the same. you can get the uid by calling imap_uid().

to open a message using a uid append the FT_UID constant to the parameter list of imap_body.

Code:
$messageid = imap_uid$mbox, 350);
$message = imap_body($mbox,$messageid, FT_UID); 
echo $message;
 
I tried something similiar before by attempting to find the UID of a message. I find that the problem occurs when I use "imap_body" the message simply dissapears and my PHP script no longer can find it.

 
Yes, I did. Nothing change, the same things were happening. I tried building on it though and used this:

$messageid = imap_uid($mbox, 350);
echo "$messageid<br>";
echo imap_body($mbox,$messageid, FT_UID);
echo "<br><br>";
echo imap_body($mbox,350, FT_UID);

When the page displays, it claims that the UID for that message was 350, however if i refresh the page, it shows a totally new message, and the UID of 350 has apparantly changed.

 
but that behaviour is expected!! as the 350th mail has changed.

a better test is

Code:
session_start();
$messageid = (isset($_SESSION['messageid'])) ? $_SESSION['messageid'] : imap_uid($mbox, 350);
$_SESSION['messageid'] = $messageid;
echo imap_body($mbox,$messageid, FT_UID);

refresh the page a number of times and you should always get the same body. the uid is static but the message sequence number will change.
 
That still shows a different message each time. I've also realized I have the problem of retrieving the messages. As I've been doing this I've also been monitoring my inbox using Thunderbird, and as I do this, the number of messages it thinks are on the server is dropping.

 
i don't know what to tell you. the code works on my boxes.
 
maybe it is a problem on the mail server's side. thank you anyway!

 
Yes is turned out to be a problem with the server. I discovered gmail did not support IMAP protocols, and even with the /pop3 in the connection it still didn't work. Another mail service that does support IMAP works though, thank you for all you help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top