I'm trying to build an email client using Python and imaplib.
Currently my problem is: I want to do searches on the folder that contains all the email. Usually called "[GMail]/All email".
My problem is, my GMail is natively Portuguese. Therefore, in my case, doing a select on "[Gmail]/Todo o correio", which is the portuguese equivalent, works, but selecting "[Gmail/All email" does not work.
This is a problem, because naturally I want a universal way to access my "All mail" folder in any Gmail account regardless of country.
And of course I could follow a naive solution such as doing the search on all folders and returning the aggregate results, but I definitely do not want to go down that path.
Is the a universal fix for this? Thank you
Found a solution shortly after. Will mention for convenience.
When you run mail_instance.list() you obtain a list of folders, such as:
(\Noselect \HasChildren) "/" "[Gmail]"
(\HasChildren \HasNoChildren \Trash) "/" "[Gmail]/Caixote do Lixo"
(\HasNoChildren \Flagged) "/" "[Gmail]/Com estrela"
(\HasChildren \HasNoChildren \Sent) "/" "[Gmail]/Correio enviado"
(\HasChildren \HasNoChildren \Important) "/" "[Gmail]/Importante"
(\HasChildren \HasNoChildren \Drafts) "/" "[Gmail]/Rascunhos"
(\HasNoChildren \Junk) "/" "[Gmail]/Spam"
(\HasChildren \HasNoChildren \All) "/" "[Gmail]/Todo o correio"
(these are in Portuguese)
The name of the "all mail" folder always contains the tag "\\All" in the string, so just do a search for "\\All" in all folder names that are returned by .list().
Then just extract the substring from the index of "[Gmail]" to the index of the first double quote after that, and you obtain the "all mail" folder name.
See this answer: https://stackoverflow.com/a/3846248/2131094
"Google and Apple developed a special IMAP command XLIST to address this issue."
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.