NYCPHP Meetup

NYPHP.org

[nycphp-talk] manipulating an IMAP account

David Mintz vtbludgeon at gmail.com
Fri Oct 2 12:32:47 EDT 2009


On Fri, Oct 2, 2009 at 12:04 PM, John Campbell <jcampbell1 at gmail.com> wrote:

> On Fri, Oct 2, 2009 at 11:21 AM, David Mintz <david at davidmintz.org> wrote:
> > If you were working on a Zend Framework application, and if you were
> writing
> > a simple script to log into an IMAP email account, fetch messages,
> iterate
> > through them finding ones matching particular criteria, do something with
> > the information in each of those messages, delete the message, and call
> it a
> > day... And if you found that Zend_Mail_Storage_Imap has a flawed
> > implementation of removeMessage(), because it sends an EXPUNGE command on
> > every invocation and thereby screws up the class'  ArrayAccess
> > implementation by disrupting the mapping between message numbers and
> > messages... then what would you do?
>
> So, let me make sure I understand this correctly.  Expunge, iirc,
> deletes everything marked for deletion, and ZEND calls expunge
> immediately after you mark something for deletion, which is not quite
> right (but, makes imap behave more like pop).  It is unlikely the
> class maintainers are going to change that.
>
> How is the ArrayAccess broken?  The key=>message mapping should change
> every time you call delete.
>

I think that's exactly the problem.
http://framework.zend.com/issues/browse/ZF-5655 explains it better than I
can.

And, since my initial post, I went ahead and wrote my own extension stealing
all the suggestions provided in the above link.  It works.

Whoever wrote removeMessage() apparently did have some misgivings about
EXPUNGE. Note the TODO comment:

    public function removeMessage($id)
    {
        if (!$this->_protocol->store(array(Zend_Mail_Storage::FLAG_DELETED),
$id, null, '+')) {
            /**
             * @see Zend_Mail_Storage_Exception
             */
            require_once 'Zend/Mail/Storage/Exception.php';
            throw new Zend_Mail_Storage_Exception('cannot set deleted
flag');
        }
        // TODO: expunge here or at close? we can handle an error here
better and are more fail safe
        if (!$this->_protocol->expunge()) {
            /**
             * @see Zend_Mail_Storage_Exception
             */
            require_once 'Zend/Mail/Storage/Exception.php';
            throw new Zend_Mail_Storage_Exception('message marked as
deleted, but could not expunge');
        }
    }

I overwrote this method, simply moving the expunge part to  __destruct()


-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20091002/71b1ccf7/attachment.html>


More information about the talk mailing list