title: Perl: Mail::IMAPClient with Gmail doesn't read new messages
body: <p>After hours of searching, reading, and clawing for an answer, I come here to beg for help: <br><br> I am trying to write a client to read my Gmail with the Perl module <a href="http://search.cpan.org/~djkernen/Mail-IMAPClient/IMAPClient.pod" rel="nofollow">Mail::IMAPClient</a>. Everything so far is functional, and it works great, but when I try to get the number of emails in my "INBOX" folder, it doesn't give the correct number:</p>
  
  <pre><code># initialize the IMAP object
  $imap = Mail::IMAPClient-&gt;new ( Server =&gt; 'imap.gmail.com',
                                  User =&gt; $username,
                                  Password =&gt; $password,
                                  Port =&gt; 993,
                                  Ssl =&gt; 1,
                                  Uid =&gt; 1 )
  or die "Could not connect to server, terminating...\n";
  
  # find which folder to read from
  print "Mailboxes: ".  join(", ", $imap-&gt;folders) . "\n";
  print "Folder to use: ";
  chomp (my $folder = &lt;STDIN&gt;);
  $imap-&gt;select($folder) or die "select() failed, terminating...\n";
  
  # get message IDs and number of messages
  my @msgIDs = $imap-&gt;search("ALL");
  print scalar(@msgIDs) . " message(s) found in mailbox.\n";
  </code></pre>
  
  <p>When reading from my "INBOX" folder, assigning <code>@msgIDs</code> to the commands:</p>
  
  <pre><code>$imap-&gt;search("ALL");
  $imap-&gt;messages;
  $imap-&gt;message_count;
  </code></pre>
  
  <p>All result in the same number being said to be the number of messages (<code>1194</code>, to be exact) in the inbox, when there are actually <code>1149</code>.
  After the number of messages is printed, the program continues with asking the user how many "headers" of recent messages they want to see (this means that if I put in "5", I would see the "Subject" and "From" header fields from the five newest messages). This code comes right after the previously shown code:</p>
  
  <pre><code># get number of messages to read (so the entire inbox isn't looked at)
  print "Read how many? ";
  chomp (my $read_num = &lt;STDIN&gt;);
  
  # read the original number of headers requested
  &amp;read_more (scalar(@msgIDs), $read_num);
  </code></pre>
  
  <p>The &amp;read_more() subroutine works with one or two arguments, but here's the two argument version:</p>
  
  <pre><code>if (@_ == 2) {
          # if an empty string was passed
          if ( $_[1] eq "" ) {
                  $_[1] = 0;
          }
  
          # print $_[1] headers behind $_[0]
          foreach ( ($_[0]-$_[1])..($_[0]-1) ) {
  
                  my $from = $imap-&gt;get_header ($_, "from");
                  my $subject = $imap-&gt;get_header ($_, "subject");
  
                  (printf "%d: %s\n", $_, $from);
                  (printf "%d: %s\n\n", $_, $subject);
           }
  }
  </code></pre>
  
  <p>So, if I called <code>&amp;read_more(1000, 5)</code>, I would see "Subject" and "From" header fields for message IDs 990-999. So when I call <code>&amp;read_more(scalar(@msgIDs), $read_num)</code>, I intend to see the header fields for the <code>$read_num</code> latest messages. Instead, I DO NOT see any header fields for my 9 latest messages, even though I am able to read them perfectly fine in the program (I'm not showing the code for that; it would complicate things). The number of messages found doesn't change. If I received one new message, then I wouldn't be able to see the 10 latest messages. The client is stuck at message ID 1193. I already configured my Gmail settings to allow IMAP. <br><br> Is this an error in my code, or is it a problem with my Gmail configuration, or something else?</p>