I have had trouble on this as well... but the answer is:
you would do something like:
$imapstream = imap_open("{localhost:143}INBOX", "user", "password");
// You would sort however you want to sort em...
$array = IMAP_SORT($imapstream,1,1);
$num = IMAP_NUM_MSG($imapstream);
for($i = 0; $i < $num; $i++) {
$msg = IMAP_HEADER($imapstream,$array[$i]);
// Now that we have the msg object we can get the
// From and the Subject
$from = $msg->from[0];
$subject = $msg->Subject;
// Now we can do whatever we want with them...
do something .....
}// end for
You dont nessecarily have to do some of these steps, this is just copied and pasted code 🙂.
I hope this helps and is what you wanted... Good Luck!