ImapSetMessageFlags Method (String, Boolean, SystemMessageFlags, MessageFlagAction)
Sets or resets the specified flags for the specified messages in the currently selected folder.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.2.0 build 630 for .NET 4.5
public bool SetMessageFlags(
	string messageIndexSet,
	bool indexIsUid,
	SystemMessageFlags systemFlags,
	MessageFlagAction action


Type: SystemString
A message sequence string containing ordinal message numbers or UIDs. Can be composed manually or using ToString.
Type: SystemBoolean
If true, messageIndexSet is treated as a sequence of UIDs; otherwise, as a sequence of ordinal message numbers.
Type: MailBee.ImapMailSystemMessageFlags
A set of flags to be set or reset.
Type: MailBee.ImapMailMessageFlagAction
The action to perform with the specified flags (set, reset, etc).

Return Value

Type: Boolean
true if the message flags have been updated successfully; otherwise, false.
MailBeeExceptionAn error occurred and ThrowExceptions is true.
To learn how to specify a valid message sequence (messageIndexSet value), see DownloadEnvelopes(String, Boolean) topic.
Note Note
This method can also set Gmail-specific labels for messages (see MessageFlagAction topic for details). If the label contains international characters, you should encode it with UTF-7M unless it's already encoded. You can use ToUtf7QuotedString(String) method for that.
This sample undeletes all messages marked as deleted in the inbox folder.
using System;
using MailBee;
using MailBee.ImapMail;

class Sample
    static void Main(string[] args)
        Imap imp = new Imap();

        // Connect to the server, login and select inbox.
        imp.Login("", "secret");

        // Get UIDs of deleted messages. We could have also skipped this
        // stage and just tell the server to remove \Deleted flag for
        // all messages (even for those message which do not have this
        // flag set - such messages won't be affected). We call Search()
        // method and then consume its results in SetMessageFlags() just
        // for purposes of illustration.
        UidCollection uids = (UidCollection)imp.Search(true, "DELETED", null);

        if (uids.Count > 0)
            // Remove \Deleted flag from the deleted messages.
            imp.SetMessageFlags(uids.ToString(), true,
                SystemMessageFlags.Deleted, MessageFlagAction.Remove);

        // Disconnect from the server.
See Also