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.
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:
I had to comment out the connect code there in order to make it work again.