Localized Gmail IMAP Folders
gmail, imap
Solution
UPDATE June 2016
Bear in mind that `XLIST` in Gmail IMAP was deprecated in 2013 and will eventually be removed.
You will need to use the SPECIAL-USE mailboxes instead.
Unfortunately, Gmail doesn't advertise this capability as per the spec, but it is implemented and works correctly (tested on 09/09/2016) - note the \Trash flag:
C: 55535a988a074191 LIST "" * RETURN (SPECIAL-USE)
S: ...
S: * LIST (\HasNoChildren \Trash) "/" "[Gmail]/Bin"
Regular LIST returns the same response as well (I'd say this is Gmail's bug).
Original Answer
There is a better way: XLIST command.
Google and Apple developed a special IMAP command XLIST to address this issue.
IMAP XLIST command returns a list of folders and their well-know flags (\Inbox, \Drafts, \Trash, \Sent, \Spam):
* XLIST (\HasNoChildren \Inbox) "/" "Inbox"
Mail.dll IMAP client (Commercial product I've created) supports XLIST command. It is used automatically when server advertises support for this feature. You can read more here: https://www.limilabs.com/blog/localized-gmail-imap-folders/
Problem
I'm building a tool that analyzes Gmail specific folders (e.g. '[Gmail]/All Mail', '[Gmail]/Spam'). It seems that the names are localized with respect to the user localization settings, so '[Gmail]/All Mail' show as '[Gmail]/Todos' to Spanish users for example. Is there a non-localized canonical name for gmail folders? A way to detect it? Or in worst case scenario, a list of the possible localized names.