{"id":2565,"date":"2012-03-31T09:08:40","date_gmt":"2012-03-31T07:08:40","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=2565"},"modified":"2015-08-16T13:57:05","modified_gmt":"2015-08-16T11:57:05","slug":"label-message-with-gmail-system-label-starred","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/label-message-with-gmail-system-label-starred","title":{"rendered":"Label message with Gmail system label (e.g. Starred)"},"content":{"rendered":"<p>If you want to use user-defined label please read <a href=\"\/blog\/label-message-with-gmail-label\">label message with user defined label<\/a>.<\/p>\n<p>There are two ways of labeling message with Gmail system label (e.g. Starred)<\/p>\n<h2>Imap.GmailLabelMessageByUID method<\/h2>\n<p><em>GmailLabelMessageByUID <\/em>method uses Gmail&#8217;s <strong>X-GM-LABELS<\/strong> extension to the IMAP protocol. You need to provide a folder flag name for it to work correctly e.g. @&#8221;\\Starred&#8221;.<\/p>\n<p>You can use FolderFlag class static properties to get common flags:<br \/>\n<em>FolderFlag.XImportant<\/em>, <em>FolderFlag.XSpam<\/em>, <em>FolderFlag.XStarred<\/em>.<\/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.UseBestLogin(&quot;pat@gmail.com&quot;, &quot;password&quot;);\r\n\r\n    imap.SelectInbox();\r\n    long last = imap.GetAll().Last();\r\n\r\n    imap.GmailLabelMessageByUID(last, FolderFlag.XStarred.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.UseBestLogin(&quot;pat@gmail.com&quot;, &quot;password&quot;)\r\n\r\n    imap.SelectInbox()\r\n    Dim last As Long = imap.GetAll().Last()\r\n\r\n    imap.GmailLabelMessageByUID(last, FolderFlag.XStarred.Name)\r\n\r\n    imap.Close()\r\nEnd Using\r\n<\/pre>\n<h2>Imap.CopyByUID method<\/h2>\n<p>The second method basis on the fact that <strong>Gmail treats labels as regular IMAP folders<\/strong>.<br \/>\nYou just need to know correct folder name and copy the message to this folder.<\/p>\n<p>You can use <em>CommonFolders <\/em>class to get common folders:<\/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.UseBestLogin(&quot;pat@gmail.com&quot;, &quot;password&quot;);\r\n\r\n    List&lt;FolderInfo&gt; folders = imap.GetFolders();\r\n\r\n    imap.SelectInbox();\r\n    long last = imap.GetAll().Last();\r\n\r\n    imap.CopyByUID(last, new CommonFolders(folders).Flagged);\r\n\r\n    imap.Close();\r\n}\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.UseBestLogin(&quot;pat@gmail.com&quot;, &quot;password&quot;)\r\n\r\n    Dim folders As List(Of FolderInfo) = imap.GetFolders()\r\n\r\n    imap.SelectInbox()\r\n    Dim last As Long = imap.GetAll().Last()\r\n\r\n    imap.CopyByUID(last, New CommonFolders(folders).Flagged)\r\n\r\n    imap.Close()\r\nEnd Using\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you want to use user-defined label please read label message with user defined label. There are two ways of labeling message with Gmail system label (e.g. Starred) Imap.GmailLabelMessageByUID method GmailLabelMessageByUID method uses Gmail&#8217;s X-GM-LABELS extension to the IMAP protocol. You need to provide a folder flag name for it to work correctly e.g. @&#8221;\\Starred&#8221;. [&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-2565","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\/2565"}],"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=2565"}],"version-history":[{"count":14,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2565\/revisions"}],"predecessor-version":[{"id":4962,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/2565\/revisions\/4962"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=2565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=2565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=2565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}