That's why ns_imap caches all connections to IMAP server, so
you do not open new imap connection with every HTTP request like it is done in almost all PHP Webmail products.
Once the IMAP session is created, it lasts as long as needed and
garbage collection thread closes unused sessions periodically. In this case acess to IMAP server is very fast, c-client IMAP caches all messages and so does IMAP server on the other end, so standard
mailbox format is not an issue here, once mailbox file is open and parsed, you do not need to scan directory and close/open new messages.