Page 1 of 1

Refreshing the inbox before reading mails thru PHP

Posted: Wed Mar 31, 2010 6:48 am
by siji86
Hi,
Is there any PHP function to refresh a mailbox before reading it. I searched for imap functions, but der isn't any function to refresh the mailbox.
Any Idea?

Thanks in advance
Elizabeth. :)

Re: Refreshing the inbox before reading mails thru PHP

Posted: Wed Mar 31, 2010 6:56 am
by roders
Tricky question, you want to refresh the mailbox before reading an email or before seeing the mailbox, can you elaborate on that please? thanks.

Re: Refreshing the inbox before reading mails thru PHP

Posted: Wed Mar 31, 2010 8:08 am
by siji86
Hi,

I want to refresh the mailbox before seeing the mailbox to get the most recent mails.

Thanks.

Re: Refreshing the inbox before reading mails thru PHP

Posted: Wed Mar 31, 2010 10:50 am
by Weiry
i have no idea what your on about.. or what sort of mailbox you want help with.

Before Post Read: General Posting Guidelines
6. Write your question carefully, think about what you need to achieve and exactly what help you are looking for.
7. Write a clear subject line, it'll help people deciding whether to look at your post or not - 'help, PHP noob' is probably going to be ignored by some.
While you completed #7 barley, you may want to read #6 again.

Re: Refreshing the inbox before reading mails thru PHP

Posted: Thu Apr 01, 2010 12:18 am
by siji86
ok, let me elaborate with some code that i have written.

I am using imap function in php to open a particular mailbox (inbox) and fetch the mails. Particularly i want to fetch all bounced mails. So following is the code:

$hostname="{124.163.948.918:110/pop3/novalidate-cert}INBOX";
$username = 'dfgd';
$password = 'dgdooopoo';


$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Graphserver: ' . imap_last_error());
$emails = imap_search($inbox,'SUBJECT "Undelivered Mail Returned to Sender" ');

rsort($emails);
foreach($emails as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,1);
$message = imap_fetchbody($inbox,$email_number,1);
$find= "To: "; // look for the 'To' part
$foundatloc= strpos($message,$find);
if ($foundatloc > 1){ // test if a mail adres was found
$findend = "\n";
$foundendloc = strpos($message,$findend,$foundatloc); // find the location of EOL
$foundendloc = $foundendloc -($foundatloc + 5);
$adres = substr($message,$foundatloc + 5,$foundendloc);
$adres = str_replace("<","",$adres); // strip <, > and spaces
$adres = str_replace(">","",$adres);
$adres = trim($adres);
$arr=explode(' ',$adres);
print($arr[1]);
//$arr[1] contains the bounced address !!!
}
else{
$listemails = extract_emails_from($message);
print(implode("\n", $listemails));
}


print('<br>');
}

//There is a function that sends the mail

//After that i call the above code to catch bounced mails

Now, the problem is that i do not get the most recent bounced mail, i get it only the next time i run this script. So i am finding some way to refresh the inbox before fetching the mails.

I hope my problem is clear now.
pls help....
:?