With the values returned from the imap_list function, you can search a message in the folder, but you have to use the imap_reopen function before . Continuing the previous example (from c6h1206free at gmail dot com )
<?php
$srv = '{imap.example.com}';
$conn = imap_open($srv, 'me', 'mypass');
$boxes = imap_list($conn, $srv, '*');
foreach($boxes as $box)
{
imap_reopen($srv, $box);
var_dump(imap_search($srv, "ALL"));
}
imap_close($conn);
?>