How do I verify that Zend\Mail has an open IMAP Stream?

265 views Asked by At

My host company will not enable the IMAP extension on our web server so I cannot utilize IMAP functions. I am trying to use Zend\Mail as a replacement, but I have been unable to map out a one to one ratio of native IMAP functions with Zend\Mail functions.

Part of my scripts checks to see if an open IMAP stream exists and if it does, to close it and then reopen it. Here's how my php script does it using IMAP functions:

function open($box='INBOX') {

    if ($this->mbox)
       $this->close();

    $args = array($this->srvstr.$this->mailbox_encode($box),
        $this->getUsername(), $this->getPassword());

    // Disable Kerberos and NTLM authentication if it happens to be
    // supported locally or remotely
    if (version_compare(PHP_VERSION, '5.3.2', '>='))
        $args += array(NULL, 0, array(
            'DISABLE_AUTHENTICATOR' => array('GSSAPI', 'NTLM')));

    $this->mbox = call_user_func_array('imap_open', $args);

    return $this->mbox;
}

function close($flag=CL_EXPUNGE) {
    imap_close($this->mbox, $flag);
}

How do I do the same thing with Zend\Mail v2.2?

I have tried using this code, but it errors out with Status 500 and just returns a blank screen:

function open($box='INBOX') {

    if ($mail)
       $this->close();

    $args = array($this->srvstr.$this->mailbox_encode($box),
        $this->getUsername(), $this->getPassword());

    // Disable Kerberos and NTLM authentication if it happens to be
    // supported locally or remotely
    if (version_compare(PHP_VERSION, '5.3.2', '>='))
        $args += array(NULL, 0, array(
            'DISABLE_AUTHENTICATOR' => array('GSSAPI', 'NTLM')));

    $this->getProtocol();
    $protocol = $this->ht['protocol'];
    if ($protocol=="Imap")
        $mail = new Zend\Mail\Storage\Imap($args);
    else
        $mail = new Zend\Mail\Storage\Pop3($args);

    return $mail;
}

function close() {
    $mail->close();
    $mail='';
}
1

There are 1 answers

0
nedt On

Your $args are wrong. That's how the params are written:

$mail = new Zend_Mail_Storage_Pop3(array('host'     => 'localhost',
                                         'user'     => 'test',
                                         'password' => 'test'));