Not all IMAP servers supports custom flags (sometimes called keywords) feature.
You can easily check if your server supports it for specific IMAP mailbox folder by examining FolderStatus.SupportsCustomFlags
property:
FolderStatus folderStatus= imap.SelectInbox();
bool customFlags = folderStatus.SupportsCustomFlags;
You can the flag message and search by it:
List<Flag> flags = imap.FlagMessageByUID(
uid,
new Flag("MY_KEYWORD"));
List<long> uids = imap.Search(
Expression.HasKeyword("MY_KEYWORD"));
When applied to a message your flag will also appear on a FolderStatus.PermanentFlags
collection.