How to Work With Flags in MailCore

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:

More explanation from me.

This is a list of Flags:

Meaning of the right column here is:

Let’s use a Decimal to Binary converter.

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. If 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. If 18, then 10010. Flags are CTFlagSeen (10) and CTFlagAnswered(101).

Leave a Reply

Your email address will not be published. Required fields are marked *