Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-14-2007, 09:16 AM
Junior Member
 
Join Date: Aug 2007
Posts: 3
Default $mail->removeMessage($messageNum) problem

Hi,

When i want to remove the current message i get this error:

Code:
Fatal error:  Uncaught exception 'Zend_Mail_Protocol_Exception' with message 'the single id was not found in response' in /usr/share/php5/Zend/Mail/Protocol/Imap.php:591
Stack trace:
#0 /usr/share/php5/Zend/Mail/Storage/Imap.php(137): Zend_Mail_Protocol_Imap->fetch(Array, 2)
#1 /usr/share/php5/Zend/Mail/Storage/Abstract.php(298): Zend_Mail_Storage_Imap->getMessage(2)
#2 /opt/dis.pcextreme.nl/htdocs/v2/library/functions.inc.php(18): Zend_Mail_Storage_Abstract->current()
#3 /opt/dis.pcextreme.nl/htdocs/v2/index.php(11): taskqueue_step_one(Array)
#4 {main}
  thrown in /usr/share/php5/Zend/Mail/Protocol/Imap.php on line 591
My script looks like this:

PHP Code:
<?php

require_once('Zend/Loader.php');
Zend_Loader::loadClass('Zend_Mail_Storage_Imap');

$imap_cfg = array();
$imap_cfg['host'] = "SERVER";
$imap_cfg['user'] = "USER";
$imap_cfg['pass'] = "PASS";

function 
taskqueue_step_one($imap_cfg)
{
    
$mail = new Zend_Mail_Storage_Imap(array(
        
'host'     => $imap_cfg['host'],
        
'user'     => $imap_cfg['user'],
        
'password' => $imap_cfg['pass']));

    
//$step_one[0]['totaal'] = $mail->countMessages();

    
foreach ($mail as $messageNum => $message)
    {
        
$step_one[$messageNum]['subject']   = $message->subject;
        
$step_one[$messageNum]['from']      = $message->from;
        
$step_one[$messageNum]['date']      = $message->getHeader('date');
        
$step_one[$messageNum]['content']   = $message->getContent();
        
$mail->removeMessage($messageNum);
    }

    return 
$step_one;
}


$step_one taskqueue_step_one($imap_cfg);
echo 
"<pre>"print_r($step_one); echo "</pre>";

?>
When i run this script it shows the error and deletes all the mails, not just the current one.
When i run this script with removeMessage commented it does what i want (but doesn't delete mail).

What am i doing wrong?

Thank you!

Last edited by mediakings : 08-14-2007 at 09:21 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-31-2007, 12:15 PM
Junior Member
 
Join Date: Aug 2007
Posts: 4
Default

I don't know if you have resolved your problem.

If not: put the following statement before "foreach ($mail as $messageNum => $message)":
$mail->noop();

It works for me.

Bye
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-31-2007, 12:24 PM
Junior Member
 
Join Date: Aug 2007
Posts: 4
Default

Sorry I'm a stupid

The previous solution doesn't work always. I've placed the mail number in an array and, after foreach, I've issued removeMessage on every entry of the array

Bye
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-10-2007, 12:13 PM
Junior Member
 
Join Date: Aug 2007
Posts: 3
Default

Hi,

I still have the same problem. I've tried to fix it the same way as you did, but then some mails get deleted and some not. Really strange.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-11-2007, 01:37 PM
Junior Member
 
Join Date: Aug 2007
Posts: 3
Default

I've found a solution.

Foreach mail i do something. If it's done i push to message number into an array.
After the foreach i remove the messages by reversing the values in the array en then delete them.

PHP Code:
foreach ($mail as $messageNum => $message) {
    
// do something
    
array_push($rm$messageNum);
}

if (
sizeof($rm) > 0) {
    
ZMailRemoveMessage($mail$rm);
}


function 
ZMailRemoveMessage(Zend_Mail_Storage_Abstract $storage$ids)
{
    
$ids = (array) $ids;

    if (
false === rsort($ids)) {
        throw new 
Exception('huh?');
    }

    while (
null !== $idx array_shift($ids)) {
        
$storage->removeMessage($idx);
    }

    return 
$storage;


Last edited by mediakings : 12-11-2007 at 01:40 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:34 AM.