I am bulding a mail client using Django and for extracting emails i'm using imaplib. So far, i can select inbox folder cause in every imap server it's name is "INBOX". But when it comes to selecting other folders like Spam, Sent and others i have troubles because their name come based on account language. For exemple my account is set to russian language and listing mails like this:
mail = imaplib.IMAP4_SSL(IMAP)
mail.login(USERNAME, PASSWORD)
for i in mail.list()[1]:
print(i)
gives me the following output (utf-7):
b'(\\Inbox) "/" "INBOX"'
b'(\\Spam) "/" "&BCEEPwQwBDw-"'
b'(\\Sent) "/" "&BB4EQgQ,BEAEMAQyBDsENQQ9BD0ESwQ1-"'
b'(\\Drafts) "/" "&BCcENQRABD0EPgQyBDgEOgQ4-"'
b'(\\Trash) "/" "&BBoEPgRABDcEOAQ9BDA-"'
How can i select folders despite the account's selected language? If i use:
mail.select("&BBoEPgRABDcEOAQ9BDA-")
it works but my mail client is useless like this.
I decided to split the output and use folder names as they are, in the language they came:
for i in mail.list()[1]:
l = i.decode().split(' "/" ')
print(l[0] + " = " + l[1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With