{"id":1638,"date":"2011-01-05T23:40:03","date_gmt":"2011-01-05T21:40:03","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1638"},"modified":"2012-07-27T11:21:25","modified_gmt":"2012-07-27T09:21:25","slug":"unique-id-in-imap-protocol","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/unique-id-in-imap-protocol","title":{"rendered":"Unique ID in IMAP protocol"},"content":{"rendered":"<p><a href=\"\/mail\/rfc\/3501\">RFC 3501<\/a> specification says:<\/p>\n<p><em>&#8220;2.3.1.1. Unique Identifier (UID) Message Attribute<\/em><\/p>\n<p><em>A 32-bit value assigned to each message, which when used with the unique identifier validity value (see below) forms a 64-bit value that <strong>MUST NOT<\/strong> refer to any other message in the <strong>mailbox (folder) or any subsequent mailbox (folder)<\/strong> with the same name forever. Unique identifiers are assigned in a <strong>strictly ascending<\/strong> fashion&#8221;<\/em><\/p>\n<p><em>&#8220;The unique identifier of a message <strong>MUST NOT<\/strong> change during the session, and <strong>SHOULD NOT<\/strong> change between sessions.&#8221;<\/em><\/p>\n<p><em>&#8220;Any change of unique identifiers between sessions <strong>MUST<\/strong> be detectable using the <strong>UIDVALIDITY <\/strong> mechanism&#8221;<\/em><\/p>\n<p><em>&#8220;The unique identifier validity value is sent in a UIDVALIDITY response code in an OK untagged response at mailbox (folder) selection time.&#8221;<\/em><\/p>\n<p>Any change of unique identifiers between session causes the change of <strong>FolderStatus.UIDValidity<\/strong>:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing(Imap client = new Imap())\r\n{\r\n    client.Connect(&quot;imap.example.org&quot;);\r\n    FolderStatus folderStatus = client.Select(&quot;Inbox&quot;);\r\n    Console.WriteLine(\r\n        &quot;Folder UIDValidity: &quot; + folderStatus.UIDValidity);\r\n    client.Close();\r\n}\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nUsing client As New Imap()\r\n    client.Connect(&quot;imap.example.org&quot;)\r\n    Dim folderStatus As FolderStatus = client.Select(&quot;Inbox&quot;)\r\n    Console.WriteLine( _\r\n        &quot;Folder UIDValidity: &quot; + folderStatus.UIDValidity)\r\n    client.Close()\r\nEnd Using\r\n<\/pre>\n<h3>Uniqueness<\/h3>\n<p>Unfortunately: &#8220;There is no assurance that the UIDVALIDITY values of two mailboxes (folders) be different, so the <strong>UIDVALIDITY in no way identifies a mailbox (folder)<\/strong>.&#8221;<\/p>\n<p>This means that:<\/p>\n<ul>\n<li> UID of the email may be not unique on the server (2 messages in different folders may have same UID)<\/li>\n<li> FolderStatus.UIDValidity + UID may be not unique on the server (2 folders may have same UIDValidity)<\/li>\n<li> To identify a message across all folders you need 3 variables: UID, folder name and FolderStatus.UIDValidity. <\/li>\n<\/ul>\n<h3>UIDs across sessions<\/h3>\n<ul>\n<li>UIDs are &#8216;supposed&#8217; to be stable across sessions, and never change, and always increase in value.<\/li>\n<li>You need to check the FolderStatus.UIDValidity when you select the folder. If the FolderStatus.UIDValidity number hasn&#8217;t changed, then the UIDs are still valid across sessions.<\/li>\n<\/ul>\n<h3>Other<\/h3>\n<ul>\n<li>UIDs are assigned in ascending fashion &#8211; higher the value newer the message.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>RFC 3501 specification says: &#8220;2.3.1.1. Unique Identifier (UID) Message Attribute A 32-bit value assigned to each message, which when used with the unique identifier validity value (see below) forms a 64-bit value that MUST NOT refer to any other message in the mailbox (folder) or any subsequent mailbox (folder) with the same name forever. Unique [&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,57],"class_list":["post-1638","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-imap","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1638"}],"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=1638"}],"version-history":[{"count":9,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1638\/revisions"}],"predecessor-version":[{"id":3290,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1638\/revisions\/3290"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}