Gmail folders have attributes and you can rely on them to get the folder that you want (if it's one of the standard ones).
So, if you do
store.getDefaultFolder().list("*");
You would get all the folders, not just the first level. And response from the server should looks like this:
A3 LIST "" "*"
* LIST (\HasNoChildren) "/" "INBOX"
* LIST (\Noselect \HasChildren) "/" "[Gmail]"
* LIST (\HasNoChildren \All) "/" "[Gmail]/All Mail"
* LIST (\HasNoChildren \Drafts) "/" "[Gmail]/Drafts"
* LIST (\HasNoChildren \Important) "/" "[Gmail]/Important"
* LIST (\HasNoChildren \Sent) "/" "[Gmail]/Sent Mail"
* LIST (\HasNoChildren \Junk) "/" "[Gmail]/Spam"
* LIST (\HasNoChildren \Flagged) "/" "[Gmail]/Starred"
* LIST (\HasNoChildren \Trash) "/" "[Gmail]/Trash"
* LIST (\HasNoChildren) "/" "[Gmail]Trash"
Once you get the the list of folders you can iterate them looking for the attribute that you want. So if you are looking for the sent folder you could do this:
public Folder getSentFolder(Folder[] folders) throws MessagingException {
for (Folder folder : folders) {
IMAPFolder imapFolder = (IMAPFolder) folder;
for(String attribute : imapFolder.getAttributes()) {
if ("\\Sent".equals(attribute)) {
return folder;
}
}
}
return null;
}
And then you have a folder selector that is language agnostic.
NOTE That this works because is Gmail. Other email servers may not have the attributes