{"id":2566,"date":"2012-03-30T12:32:39","date_gmt":"2012-03-30T10:32:39","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=2566"},"modified":"2013-06-25T23:00:44","modified_gmt":"2013-06-25T21:00:44","slug":"list-all-gmail-labels","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/list-all-gmail-labels","title":{"rendered":"List all Gmail labels"},"content":{"rendered":"<p>Gmail treats labels as folders for the purposes of IMAP.<\/p>\n<p>As such, labels can be modified using the standard IMAP commands, <a href=\"\/blog\/folder-management-using-imap-create-delete-rename\">CreateFolder, RenameFolder, and DeleteFolder<\/a>, that act on folders.<\/p>\n<p>System labels, which are labels created by Gmail, are reserved and prefixed by &#8220;[Gmail]&#8221; or &#8220;[GoogleMail]&#8221; in the list of labels.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nusing (Imap imap = new Imap())\r\n{\r\n    imap.ConnectSSL(&quot;imap.gmail.com&quot;);\r\n    imap.Login(&quot;pat@gmail.com&quot;, &quot;password&quot;);\r\n\r\n    List&lt;FolderInfo&gt; folders = imap.GetFolders();\r\n    List&lt;FolderInfo&gt; system = folders.FindAll(x =&gt; x.Name.StartsWith(&quot;&#x5B;Gmail]&quot;));\r\n    List&lt;FolderInfo&gt; user = folders.FindAll(x =&gt; !x.Name.StartsWith(&quot;&#x5B;Gmail]&quot;));\r\n\r\n    Console.WriteLine(&quot;System labels:&quot;);\r\n    system.ForEach(x =&gt; Console.WriteLine(x.Name));\r\n    Console.WriteLine();\r\n    Console.WriteLine(&quot;User labels:&quot;);\r\n    user.ForEach(x =&gt; Console.WriteLine(x.Name));\r\n\r\n    imap.Close();\r\n}\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nUsing imap As New Imap()\r\n    imap.ConnectSSL(&quot;imap.gmail.com&quot;)\r\n    imap.Login(&quot;pat@gmail.com&quot;, &quot;password&quot;)\r\n\r\n    Dim folders As List(Of FolderInfo) = imap.GetFolders()\r\n    Dim system As List(Of FolderInfo) = \r\n        folders.FindAll(Function(x) x.Name.StartsWith(&quot;&#x5B;Gmail]&quot;))\r\n    Dim user As List(Of FolderInfo) = \r\n        folders.FindAll(Function(x) Not x.Name.StartsWith(&quot;&#x5B;Gmail]&quot;))\r\n\r\n    Console.WriteLine(&quot;System labels:&quot;)\r\n    system.ForEach(Function(x) Console.WriteLine(x.Name))\r\n    Console.WriteLine()\r\n    Console.WriteLine(&quot;User labels:&quot;)\r\n    user.ForEach(Function(x) Console.WriteLine(x.Name))\r\n\r\n    imap.Close()\r\nEnd Using\r\n<\/pre>\n<p>Here is the output:<\/p>\n<p><code><br \/>\nSystem labels:<br \/>\n[Gmail]<br \/>\n[Gmail]\/All Mail<br \/>\n[Gmail]\/Drafts<br \/>\n[Gmail]\/Sent Mail<br \/>\n[Gmail]\/Spam<br \/>\n[Gmail]\/Starred<br \/>\n[Gmail]\/Trash<br \/>\n<\/code><\/p>\n<p><code><br \/>\nUser labels:<br \/>\nInbox<br \/>\nPersonal<br \/>\nReceipts<br \/>\nTravel<br \/>\nUpload<br \/>\nWork<br \/>\nmy label<br \/>\nmy label\/nested<br \/>\nmy second label<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gmail treats labels as folders for the purposes of IMAP. As such, labels can be modified using the standard IMAP commands, CreateFolder, RenameFolder, and DeleteFolder, that act on folders. System labels, which are labels created by Gmail, are reserved and prefixed by &#8220;[Gmail]&#8221; or &#8220;[GoogleMail]&#8221; in the list of labels. \/\/ C# using (Imap imap [&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,25,28,77,57,63],"class_list":["post-2566","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-gmail","tag-imap","tag-imap-component","tag-vb-net","tag-x-gm-labels"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2566"}],"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=2566"}],"version-history":[{"count":12,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2566\/revisions"}],"predecessor-version":[{"id":4071,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2566\/revisions\/4071"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=2566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=2566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=2566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}