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:
(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.