{"id":1583,"date":"2012-09-21T18:37:35","date_gmt":"2012-09-21T14:37:35","guid":{"rendered":"https:\/\/blog.alwawee.ru\/?p=1583"},"modified":"2012-09-22T16:57:05","modified_gmt":"2012-09-22T12:57:05","slug":"how-to-work-with-flags-in-mailcore","status":"publish","type":"post","link":"https:\/\/blog.alwawee.ru\/?p=1583","title":{"rendered":"How to Work With Flags in MailCore"},"content":{"rendered":"<p>Recently I was guessing, how to work with flags in MailCore, where a flag is NSUInteger. I got answer from <a href=\"http:\/\/librelist.com\/browser\/mailcore\/\" title=\"http:\/\/librelist.com\/browser\/mailcore\/\" target=\"_blank\">MailCore Librelist<\/a>. <\/p>\n<p>The flags are stored as bitwise operations. If you want to check to see if a message is deleted, for example, you can do the following bitwise operation:<\/p>\n<pre lang=\"ObjC\">\r\nif (coreMessage.flags & CTFlagDeleted) {\r\n            NSLog(@\"Message has been deleted.\");\r\n}\r\n<\/pre>\n<p>More explanation from me. <\/p>\n<p>This is a list of Flags: <\/p>\n<pre lang=\"ObjC\">\r\n\/** List of Message Flags **\/\r\n\r\n#define CTFlagNew\t\tMAIL_FLAG_NEW \r\n#define CTFlagSeen\t\tMAIL_FLAG_SEEN\r\n#define CTFlagFlagged\t\tMAIL_FLAG_FLAGGED\r\n#define CTFlagDeleted\t\tMAIL_FLAG_DELETED\r\n#define CTFlagAnswered\t\tMAIL_FLAG_ANSWERED\r\n#define CTFlagForwarded\t\tMAIL_FLAG_FORWARDED\r\n#define CTFlagCancelled \tMAIL_FLAG_CANCELLED\r\n<\/pre>\n<p>Meaning of the right column here is:<\/p>\n<pre>\r\nenum {\r\n  MAIL_FLAG_NEW       = 1 << 0,\r\n  MAIL_FLAG_SEEN      = 1 << 1,\r\n  MAIL_FLAG_FLAGGED   = 1 << 2,\r\n  MAIL_FLAG_DELETED   = 1 << 3,\r\n  MAIL_FLAG_ANSWERED  = 1 << 4,\r\n  MAIL_FLAG_FORWARDED = 1 << 5,\r\n  MAIL_FLAG_CANCELLED = 1 << 6\r\n};\r\n<\/pre>\n<p>Let's use a <a href=\"http:\/\/www.mathsisfun.com\/binary-decimal-hexadecimal-converter.html\" title=\"http:\/\/www.mathsisfun.com\/binary-decimal-hexadecimal-converter.html\" target=\"_blank\">Decimal to Binary converter<\/a>. <\/p>\n<p>For instance, 34 is 100010. We see, that 2nd and 6th bits are not null. So Flags are CTFlagSeen and CTFlagForwarded. Since CTFlagSeen = MAIL_FLAG_SEEN = 1 << 1 in binary. It means, that we should shift by 1 symbol and compare 2nd symbol in 100010. It is 1, or YES. The same is for CTFlagForwarded which is a shift by 6.\n\nIf flags = 50, then binary is 110010. Flags are CTFlagSeen, CTFlagAnswered, CTFlagForwarded. Let's now assume, that we want to remove CTFlagSeen flag. What should we do? If we do this: flags = flags^CTFlagSeen we will get this in bit level: (110010)^(1<<1)=(110000), so the flag will be removed. If there was no flag, it will be installed, when we use XOR operator, represented by ^ symbol. \n\nIf 18, then 10010. Flags are CTFlagSeen (10) and CTFlagAnswered(101). \n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I was guessing, how to work with flags in MailCore, where a flag is NSUInteger. I got answer from MailCore Librelist. The flags are stored as bitwise operations. If you want to check to see if a message is deleted, for example, you can do the following bitwise operation: if (coreMessage.flags &#038; CTFlagDeleted) { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1583","post","type-post","status-publish","format-standard","hentry","category-ios"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Work With Flags in MailCore - Denis Kutlubaev<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.alwawee.ru\/?p=1583\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Work With Flags in MailCore - Denis Kutlubaev\" \/>\n<meta property=\"og:description\" content=\"Recently I was guessing, how to work with flags in MailCore, where a flag is NSUInteger. I got answer from MailCore Librelist. The flags are stored as bitwise operations. If you want to check to see if a message is deleted, for example, you can do the following bitwise operation: if (coreMessage.flags &amp; CTFlagDeleted) { [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.alwawee.ru\/?p=1583\" \/>\n<meta property=\"og:site_name\" content=\"Denis Kutlubaev\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/alwaweemobile\" \/>\n<meta property=\"article:published_time\" content=\"2012-09-21T14:37:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-09-22T12:57:05+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/blog.alwawee.com\/?attachment_id=1982\" \/>\n<meta name=\"author\" content=\"Denis Kutlubaev\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Denis Kutlubaev\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1583#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1583\"},\"author\":{\"name\":\"Denis Kutlubaev\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"headline\":\"How to Work With Flags in MailCore\",\"datePublished\":\"2012-09-21T14:37:35+00:00\",\"dateModified\":\"2012-09-22T12:57:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1583\"},\"wordCount\":106,\"commentCount\":0,\"articleSection\":[\"iOS\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1583#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1583\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1583\",\"name\":\"How to Work With Flags in MailCore - Denis Kutlubaev\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\"},\"datePublished\":\"2012-09-21T14:37:35+00:00\",\"dateModified\":\"2012-09-22T12:57:05+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1583#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1583\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1583#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blog.alwawee.ru\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Work With Flags in MailCore\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/\",\"name\":\"Denis Kutlubaev\",\"description\":\"iOS Development\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blog.alwawee.ru\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\",\"name\":\"Denis Kutlubaev\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"caption\":\"Denis Kutlubaev\"},\"description\":\"iOS Developer, creator of Tornado Browser and many other popular apps\",\"sameAs\":[\"http:\\\/\\\/dennis.alwawee.com\"],\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Work With Flags in MailCore - Denis Kutlubaev","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.alwawee.ru\/?p=1583","og_locale":"en_US","og_type":"article","og_title":"How to Work With Flags in MailCore - Denis Kutlubaev","og_description":"Recently I was guessing, how to work with flags in MailCore, where a flag is NSUInteger. I got answer from MailCore Librelist. The flags are stored as bitwise operations. If you want to check to see if a message is deleted, for example, you can do the following bitwise operation: if (coreMessage.flags & CTFlagDeleted) { [&hellip;]","og_url":"https:\/\/blog.alwawee.ru\/?p=1583","og_site_name":"Denis Kutlubaev","article_publisher":"https:\/\/www.facebook.com\/alwaweemobile","article_published_time":"2012-09-21T14:37:35+00:00","article_modified_time":"2012-09-22T12:57:05+00:00","og_image":[{"url":"http:\/\/blog.alwawee.com\/?attachment_id=1982","type":"","width":"","height":""}],"author":"Denis Kutlubaev","twitter_misc":{"Written by":"Denis Kutlubaev","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.alwawee.ru\/?p=1583#article","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/?p=1583"},"author":{"name":"Denis Kutlubaev","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"headline":"How to Work With Flags in MailCore","datePublished":"2012-09-21T14:37:35+00:00","dateModified":"2012-09-22T12:57:05+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.alwawee.ru\/?p=1583"},"wordCount":106,"commentCount":0,"articleSection":["iOS"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.alwawee.ru\/?p=1583#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.alwawee.ru\/?p=1583","url":"https:\/\/blog.alwawee.ru\/?p=1583","name":"How to Work With Flags in MailCore - Denis Kutlubaev","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/#website"},"datePublished":"2012-09-21T14:37:35+00:00","dateModified":"2012-09-22T12:57:05+00:00","author":{"@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"breadcrumb":{"@id":"https:\/\/blog.alwawee.ru\/?p=1583#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.alwawee.ru\/?p=1583"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.alwawee.ru\/?p=1583#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.alwawee.ru\/"},{"@type":"ListItem","position":2,"name":"How to Work With Flags in MailCore"}]},{"@type":"WebSite","@id":"https:\/\/blog.alwawee.ru\/#website","url":"https:\/\/blog.alwawee.ru\/","name":"Denis Kutlubaev","description":"iOS Development","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.alwawee.ru\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7","name":"Denis Kutlubaev","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","caption":"Denis Kutlubaev"},"description":"iOS Developer, creator of Tornado Browser and many other popular apps","sameAs":["http:\/\/dennis.alwawee.com"],"url":"https:\/\/blog.alwawee.ru\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/1583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1583"}],"version-history":[{"count":0,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/1583\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}