a,folders = imap.list()
if a == "OK":
print folders
for folder in folders:
rv, data = imap.select(folder)
if rv == "OK":
d,base =imap.search(None, "ALL")
print(base)
['(\\Inbox) "/" "INBOX"', '(\\Spam) "/" "&BCEEPwQwBDw-"', '(\\Sent) "/" "&BB4EQgQ,BEAEMAQyBDsENQQ9BD0ESwQ1-"', '(\\Drafts) "/" "&BCcENQRABD0EPgQyBDgEOgQ4-"', '(\\Trash) "/" "&BBoEPgRABDcEOAQ9BDA-"']