如何在不打开新连接的情况下遍历所有PHP Imap文件夹

I'm trying to search through my entire inbox with the PHP Imap Library, using imap_search()

I am using imap_open() to open the stream for each folder, but the issue is that servers like hotmail block you after 6 or 7 tries, so I need to be able to switch through folders without opening a new connection stream.

This is the current code I use to connect to each folder.
$server is something like

$server = '{imap.gmail.com:993/ssl}INBOX';
if($connection = imap_open($server,$login,$password))  

See imap_reopen()

Update: You may also be interested in imap_list()