+2 votes

I have an email client that sets its own email flags, which appear as "$label1", "$label2" in the flag list when I call GetFlagsByUID() for a given message.

Is there a way to use FlagMessageByUID() to set my own, similar, custom flags?

by

1 Answer

+1 vote
 
Best answer

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.

by (276k points)
selected by
Thank you so much for the prompt response! We're still evaluating whether or not we're going to use this IMAP functionality in our system, but if we do, be assured we will be purchasing your product.
...