PHP Gmail fetching wrong emails in label/box
===

I've got the code with a label applied and emails showing up in Gmail under the label 'Rejected'

    $hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Rejected';
    $username = 'myusername';
    $password = '10sneONE';

    $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' .   imap_last_error());


    $emails = imap_search($inbox,'ALL');

This is connecting, fetching the emails and then I

    $overview = imap_fetch_overview($inbox,$email_number,0);
    //needs to be '1' for gmail label emails, '2' returns nothing
    $message = imap_fetchbody($inbox,$email_number,1); 

As I 'foreach($emails as $email_number)' and fetch the details of each email, I'm getting some emails that are not in the label box in Gmail.  I'm checking back and forth.  I'm also getting email numbers that when I fetchbody or overview, I get emails that are just in the inbox.  There appears to be a disconnect between the email numbers returned by the imap_search and the fetching that I then do with the $email_number from the same $inbox.   Any ideas?
