javanile / php-imap2

PHP IMAP with OAUTH2
https://php-imap2.javanile.org/
GNU General Public License v3.0
52 stars 31 forks source link

imap2_reopen broken (tries to open a new connection while it should simply select the new inbox) #14

Open bago opened 2 years ago

bago commented 2 years ago

In my code I use imap_open with the "OP_HALFOPEN" to open an imap connection without opening a folder, then I list the folders and I cycle through the folders and open each of them through imap_reopen: https://www.php.net/manual/en/function.imap-reopen.php

When I switched to imap2_open + imap2_reopen it didn't work because imap2_reopen tries to reconnect, while the imap connection is already there:

    public static function reopen($imap, $mailbox, $flags = 0, $retries = 0)
    {
        if (!is_a($imap, Connection::class)) {
            return Errors::invalidImapConnection(debug_backtrace(), 1, null);
        }

        $imap->openMailbox($mailbox);

/* Should not be done
        $success = $imap->connect();

        if (empty($success)) {
            trigger_error('imap2_reopen(): Couldn\'t re-open stream', E_USER_WARNING);

            return false;
        }
*/

        $imap->selectMailbox();

        return true;
    }

I had to comment out the connect code there in order to make it work again.