{"id":700,"date":"2010-03-22T20:57:55","date_gmt":"2010-03-22T18:57:55","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=700"},"modified":"2023-03-24T13:54:13","modified_gmt":"2023-03-24T11:54:13","slug":"localized-gmail-imap-folders","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/localized-gmail-imap-folders","title":{"rendered":"Localized Gmail IMAP folders"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"alignleft\"><img loading=\"lazy\" decoding=\"async\" width=\"131\" height=\"61\" src=\"\/blog\/wp-content\/uploads\/2009\/11\/gmail.png\" alt=\"\" class=\"wp-image-271\" title=\"gmail\"\/><\/figure><\/div>\n\n\n\n<p><br>There are<strong> no well-know names for common folders<\/strong> such as Drafts, Trash, Spam, &#8230; on IMAP servers.<\/p>\n\n\n\n<p>The problem is even worse when you use localized version of IMAP client. <strong>Gmail folder names are localized<\/strong> with respect to the user localization settings, so &#8216;[Gmail]\/All Mail&#8217; show as &#8216;[Gmail]\/Todos&#8217; to Spanish users for example.<\/p>\n\n\n\n<p>Google and Apple developed a special IMAP XLIST command to address this issue.<\/p>\n\n\n\n<p>IMAP <strong>XLIST<\/strong> command returns a list of folders and their well-know flags.<\/p>\n\n\n\n<p>Here&#8217;s the sample XLIST response:<\/p>\n\n\n\n<p><code><br>\nC: A001 CAPABILITY<br>\nS: * CAPABILITY IMAP4rev1 ID XLIST ...<br>\nS:  A001 OK Thats all she wrote! 17if1168678ebj.35<br>\nC: A002 XLIST \"\" \"*\"<br>\nS: * XLIST (\\HasNoChildren \\Inbox) \"\/\" \"Inbox\"<br>\nS: * XLIST (\\HasNoChildren \\AllMail) \"\/\" \"[Gmail]\/All Mail\"<br>\nS: * XLIST (\\HasNoChildren \\Drafts) \"\/\" \"[Gmail]\/Drafts\"<br>\nS: * XLIST (\\HasNoChildren \\Spam) \"\/\" \"[Gmail]\/Spam\"<br>\n...<br>\n<\/code><\/p>\n\n\n\n<p>As you can see XLIST is advertised in CAPABILITY response.<br>You can probably spot additional flags in the XLIST response: \\AllMail, \\Spam, \\Drafts&#8230;<\/p>\n\n\n\n<p><a href=\"\/mail\">Mail.dll IMAP library<\/a><strong> supports XLIST<\/strong> command (and SPECIAL-USE extension). It is used automatically when server advertises support for this feature.<\/p>\n\n\n\n<p>You can use <em>CommonFolders <\/em>class to match folder names with they real purpose.<\/p>\n\n\n\n<p>Take a look at the examples:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ C# version:\n\nusing (Imap imap = new Imap())\n{\n    imap.ConnectSSL(\"imap.gmail.com\");\n    imap.UseBestLogin(\"pat@gmail.com\", \"app-password\");\n\n    CommonFolders folders = new CommonFolders(imap.GetFolders());\n\n    Console.WriteLine(\"Inbox folder: \" + folders.Inbox.Name);\n    Console.WriteLine(\"Sent folder: \" + folders.Sent.Name);\n\n    \/\/ You can select folders easy:\n\n    imap.Select(folders.Inbox);\n    imap.Select(folders.Sent);\n\n    imap.Close();\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: vb; title: ; notranslate\" title=\"\">\n' VB.NET version:\n\nUsing imap As New Imap()\n    imap.ConnectSSL(\"imap.gmail.com\")\n    imap.UseBestLogin(\"pat@gmail\", \"app-password\")\n\n    Dim folders As New CommonFolders(imap.GetFolders())\n\n    Console.WriteLine(\"Inbox folder: \" + folders.Inbox.Name)\n    Console.WriteLine(\"Sent folder: \" + folders.Sent.Name)\n\n    ' You can select folders easy:\n\n    imap.Select(folders.Inbox)\n    imap.Select(folders.Sent)\n\n    imap.Close()\nEnd Using\n<\/pre><\/div>\n\n\n<p>Remember to <a href=\"\/blog\/enable-imap-in-gmail\">enable IMAP in Gmail<\/a> (your authentication options are app-passwords and OAuth 2.0).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are no well-know names for common folders such as Drafts, Trash, Spam, &#8230; on IMAP servers. The problem is even worse when you use localized version of IMAP client. Gmail folder names are localized with respect to the user localization settings, so &#8216;[Gmail]\/All Mail&#8217; show as &#8216;[Gmail]\/Todos&#8217; to Spanish users for example. Google and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[25,28,77,67],"class_list":["post-700","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-gmail","tag-imap","tag-imap-component","tag-xlist"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/700"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=700"}],"version-history":[{"count":8,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/700\/revisions"}],"predecessor-version":[{"id":6450,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/700\/revisions\/6450"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}