{"id":2647,"date":"2012-04-19T16:56:18","date_gmt":"2012-04-19T14:56:18","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=2647"},"modified":"2014-06-17T15:17:07","modified_gmt":"2014-06-17T13:17:07","slug":"common-imap-folders","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/common-imap-folders","title":{"rendered":"Common IMAP folders"},"content":{"rendered":"<p>There are <strong>no well-know names for common folders<\/strong> such as Drafts, Trash, Spam, &#8230; defined in IMAP protocol standards.<\/p>\n<p>This makes quite difficult for an <a href=\"\/mail\">IMAP client<\/a> to know the real purpose of the folders on the server.<\/p>\n<p>Fortunately there are two IMAP protocol extensions:<\/p>\n<ul>\n<li> <a href=\"\/blog\/localized-gmail-imap-folders\"><strong>XLIST <\/strong> &#8211; supported by Gmail<\/a><\/li>\n<li> <strong>SPECIAL-USE<\/strong> &#8211; <a href=\"\/mail\/rfc\/6154\">RFC 6154<\/a> standardized extension<\/li>\n<\/ul>\n<p>You can check if your servers support it by <a href=\"\/blog\/get-supported-server-extensions-imap-pop3-smtp\">checking if <em>SupportedExtensions<\/em> returns <em>ImapExtension.XList<\/em> or <em>ImapExtension.SpecialUse<\/em><\/a><\/p>\n<p>Both extensions are supported by Mail.dll and, if your server supports any of them, you can take advantage of <em>CommonFolders <\/em>class. <em>CommonFolders<\/em> allows you to get the name of the folder and <em>Select <\/em>it, by knowing its purpose (for example Spam folder may be called &#8220;Junk email&#8221; on the server).<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C# version:\r\n\r\nusing (Imap imap = new Imap())\r\n{\r\n    imap.ConnectSSL(&quot;imap.gmail.com&quot;);\r\n    imap.UseBestLogin(&quot;pat@gmail.com&quot;, &quot;password&quot;);\r\n\r\n    CommonFolders folders = new CommonFolders(imap.GetFolders());\r\n\r\n    Console.WriteLine(&quot;Inbox folder: &quot; + folders.Inbox.Name);\r\n    Console.WriteLine(&quot;Sent folder: &quot; + folders.Sent.Name);\r\n    Console.WriteLine(&quot;Spam folder: &quot; + folders.Spam.Name);\r\n\r\n    \/\/ You can select folders easy:\r\n    imap.Select(folders.Inbox);\r\n    imap.Select(folders.Sent);\r\n    imap.Select(folders.Spam);\r\n\r\n    imap.Close();\r\n}\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET version:\r\n\r\nUsing imap As New Imap()\r\n    imap.ConnectSSL(&quot;imap.gmail.com&quot;)\r\n    imap.UseBestLogin(&quot;pat@gmail&quot;, &quot;password&quot;)\r\n\r\n    Dim folders As New CommonFolders(imap.GetFolders())\r\n\r\n    Console.WriteLine(&quot;Inbox folder: &quot; + folders.Inbox.Name)\r\n    Console.WriteLine(&quot;Sent folder: &quot; + folders.Sent.Name)\r\n\r\n    ' You can select folders easy:\r\n    imap.Select(folders.Inbox)\r\n    imap.Select(folders.Sent)\r\n\r\n\r\n    imap.Close()\r\nEnd Using\r\n<\/pre>\n<p>You can check if you can use <em>CommonFolders <\/em>with following code:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nList&lt;ImapExtension&gt; extensions = client.SupportedExtensions();\r\nbool canUseCommonFolders = extensions.Contains(ImapExtension.XList) \r\n    || extensions.Contains(ImapExtension.SpecialUse);\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nDim extensions As List(Of ImapExtension) = client.SupportedExtensions()\r\nDim canUseCommonFolders As Boolean = extensions.Contains(ImapExtension.XList) OrElse extensions.Contains(ImapExtension.SpecialUse)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>There are no well-know names for common folders such as Drafts, Trash, Spam, &#8230; defined in IMAP protocol standards. This makes quite difficult for an IMAP client to know the real purpose of the folders on the server. Fortunately there are two IMAP protocol extensions: XLIST &#8211; supported by Gmail SPECIAL-USE &#8211; RFC 6154 standardized [&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":[15,28,77,73,57,67],"class_list":["post-2647","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-imap","tag-imap-component","tag-special-use","tag-vb-net","tag-xlist"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2647"}],"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=2647"}],"version-history":[{"count":11,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2647\/revisions"}],"predecessor-version":[{"id":4693,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2647\/revisions\/4693"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=2647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=2647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=2647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}