PHP Classes

How do I loop through all email messages?

Recommend this page to a friend!

      POP3 e-mail client  >  All threads  >  How do I loop through all email...  >  (Un) Subscribe thread alerts  
Subject:How do I loop through all email...
Summary:How do I loop through all email messages?
Messages:2
Author:Alex V
Date:2011-09-26 15:12:13
Update:2011-09-26 15:29:14
 

  1. How do I loop through all email...   Reply   Report abuse  
Picture of Alex V Alex V - 2011-09-26 15:12:13
I want to loop through all emails in my inbox, save them to my database and then delete them one by one.

I manage to read and save the first one but when I try to delete it, I always get "connection is not in TRANSACTION state".

My code looks like this:

$messages = $mailReader->ListMessages('', 0);
if (is_array($messages)) {
if (count($messages) > 0) {
$parser = new Core_MimeParser();
for(reset($messages), $message = 0; $message < count($messages); next($messages), $message++) {
$error = $mailReader->OpenMessage(key($messages));
if ($error != '') {
return false;
}
$error = $mailReader->GetMessage($messages[key($messages)], $msgContent, $eofReached);

//Decode & save here

$mailReader->DeleteMessage(key($messages));
}
}
}

I guess I miss something in my loop... Anyone can help me point what it is?

  2. Re: How do I loop through all email...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2011-09-26 15:29:15 - In reply to message 1 from Alex V
You need to keep calling GetMessage until $eofReached is true so you have retrieved whole messages.