Newbie Help with IMAPLIB Module

Velomanhere velomanhere at
Sun Mar 21 17:22:11 CET 2004

I am just learning Python and need some assistance with the IMAPLIB

I am trying to check whether there are any unread messages in the
mailbox of the IMAP server.  I have found the following object
imap.recent() which returns a tuple with the number of mesages that
haven't been checked.

However, this isn't exactly what I want.  The definition of the
"RECENT" flag in IMAP only returns a number if no other program has
checked the mailbox.  From the RFC: "This session is the first session
to have been notified about this message; subsequent sessions will not
see \Recent set for this message."

Does anyone know how I can check if \Seen flag is *not* true on any
messages in the mailbox and then return how many message are not
tagged as /Seen

Here is what I have so far:

import imaplib

def imapcheck():
    """Check IMAP server for messages"""
    newmessages = ()

    imap.login("username", "password")

    newmessages = imap.recent()

    if [None] not in newmessages:
        print "You have new messages"

def main():


More information about the Python-list mailing list