Newbie Help with IMAPLIB Module

Josh Smith josh+news at nextyme.net
Sun Mar 21 14:35:52 EST 2004


In comp.lang.python, you wrote:
> 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
> 

You want to use the search member function to do something like this:

#prints the message numbers of unread email
m=imaplib.IMAP4('localhost')
m.login('username','password')
result, message_count = m.select(readonly=1)
if result != 'OK':
	raise Exception, message
result,messages_found = m.search(None, '(UNSEEN UNDELETED)')
for num in string.split(messages_found[0]):
	print num

I found a long example using imaplib (lots of good stuff) here:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52299

You may also want to search for NEW instead of UNSEEN but I'm a 
little hazy about that. HTH.

-jbs



More information about the Python-list mailing list