You do not have enough error checking on your calls to choose. As a rule, this is how I will structure the first parts of the connection to the mailbox:
# self.conn is an instance of IMAP4 connected to my server.
status, msgs = self.conn.select('INBOX')
if status != 'OK':
return # could be break, or continue, depending on surrounding code.
msgs = int(msgs[0])
, , , , , , , , "", , , , . , . ( , "UNSEEN" ). , :
('NO', ['The requested item could not be found.'])
for email id in items
. , , . , , :
('OK', ['337'])
, .
, , :
status, msgs = self.conn.select('INBOX')
status, ids = self.conn.search(None, 'UNSEEN')
if status == 'OK':
ids = map(int, ids[0].split())
select, .