{"id":1102,"date":"2010-09-14T11:24:36","date_gmt":"2010-09-14T09:24:36","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1102"},"modified":"2013-06-25T22:49:34","modified_gmt":"2013-06-25T20:49:34","slug":"get-shared-folders-from-imap","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/get-shared-folders-from-imap","title":{"rendered":"Get shared folders from IMAP"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/2010\/09\/ShredFolder.jpg\" alt=\"\" title=\"Shred folder\" width=\"154\" height=\"134\" class=\"alignleft size-full wp-image-1123\" \/>This article describes how to get shared folder list from your IMAP server using <a href=\"\/mail\">Mail.dll IMAP component for .NET<\/a>.<\/p>\n<p>Shared folder names usually start with &#8216;#&#8217; character. This is not a rule, but it&#8217;s very common.<\/p>\n<p>IMAP server when asked for all folder list should return also shared folders.<\/p>\n<p>Here&#8217;s the unit test code that shows this:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nList&lt;folderInfo&gt; allFolders = client.GetFolders();\r\nCollectionAssert.Contains(allFolders.Select(x =&gt; x.Name), &quot;#Public.PublicFolder1&quot;);\r\nCollectionAssert.Contains(allFolders.Select(x =&gt; x.Name), &quot;#Public&quot;);\r\n<\/pre>\n<p>If you want to <strong>list only shared folders<\/strong> you&#8217;ll need to use IMAP&#8217;s <strong>NAMESPACE <\/strong>command. <em>Imap.GetNamespaces()<\/em> method returns <em>Namespaces<\/em> class which contains information about personal, <strong>shared<\/strong> and other users namespaces:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C# version\r\n\r\nusing (Imap client = new Imap())\r\n{\r\n    client.Connect(&quot;server&quot;);\r\n    client.Login(&quot;user&quot;, &quot;password&quot;);\r\n\r\n    Namespaces namespaces = client.GetNamespaces();\r\n\r\n    \/\/ List shared folders in all shared namespaces\r\n    foreach (NamespaceInfo space in namespaces.Shared)\r\n    {\r\n        List&lt;folderInfo&gt; sharedFolders = client.GetFolders(space.Name);\r\n        sharedFolders.ForEach(x =&gt; Console.WriteLine(x.Name));\r\n    }\r\n\r\n    client.Close();\r\n}\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET version\r\n\r\nUsing client As New Imap()\r\n\tclient.Connect(&quot;server&quot;)\r\n\tclient.Login(&quot;user&quot;, &quot;password&quot;)\r\n\r\n\tDim namespaces As Namespaces = client.GetNamespaces()\r\n\r\n\t' List shared folders in all shared namespaces\r\n\tFor Each space As NamespaceInfo In namespaces.&#x5B;Shared]\r\n\t\tDim sharedFolders As List(Of FolderInfo) = client.GetFolders(space.Name)\r\n\t\tsharedFolders.ForEach(Function(x) Console.WriteLine(x.Name))\r\n\tNext\r\n\r\n\tclient.Close()\r\nEnd Using\r\n<\/pre>\n<p>The above code lists all public folders available for the currently logged-in user:<br \/>\n<code><br \/>\n#Public.PublicFolder1<br \/>\n#Public.PublicFolder2<br \/>\n#Public<br \/>\n<\/code><\/p>\n<p>Please note that server <strong>will not let you select<\/strong> some folders. In the example above the user can not select &#8216;#Public&#8217; folder. You can use <em>FolderInfo.CanSelect<\/em> property to check if the user is allowed to select the folder.<\/p>\n<p>You can <a href=\"\/mail\">download Mail.dll IMAP library for .NET here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article describes how to get shared folder list from your IMAP server using Mail.dll IMAP component for .NET. Shared folder names usually start with &#8216;#&#8217; character. This is not a rule, but it&#8217;s very common. IMAP server when asked for all folder list should return also shared folders. Here&#8217;s the unit test code that [&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,57],"class_list":["post-1102","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-imap","tag-imap-component","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1102"}],"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=1102"}],"version-history":[{"count":2,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1102\/revisions"}],"predecessor-version":[{"id":4062,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1102\/revisions\/4062"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}