[Chicago] imaplib and gmail... the inbox count is wrong! Wrong, I tell ya!

Jason Huggins jason at jrandolph.com
Sat Feb 21 01:43:30 CET 2009

Hiya, folks!

I tried googling this, but nothing came up in my quest... so I'm
switching to "Let's ask some humans" mode.

I'm trying to get an accurate count of the total number of messages
(read and unread) in my Inbox.

Here's my code:
>>> import imaplib
>>> mail = imaplib.IMAP4_SSL('imap.gmail.com', 993)
>>> mail.login('larry at gmail.com','sergey_is_my_homeboy')
('OK', ['larry at gmail.com authenticated (Success)'])
>>> status, count = mail.select ('Inbox')
>>> status, count
('OK', ['9332'])

If I log into Gmail through the web, the inbox count is different (and
thousands less than 9332). The 9332 number appears to be the number if
I open "All Mail" through the web. Is there a way to *just* get the
number of messages in the inbox? It feels like the above code should
give me the accurate number, but it's not.


- jason

More information about the Chicago mailing list