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: 11.2.0 build 590 for .NET 4.5
Syntax
public bool SetMessageFlags(
	string messageIndexSet,
	bool indexIsUid,
	SystemMessageFlags systemFlags,
	MessageFlagAction action
)

Parameters

messageIndexSet
Type: SystemString
A message sequence string containing ordinal message numbers or UIDs. Can be composed manually or using ToString.
indexIsUid
Type: SystemBoolean
If true, messageIndexSet is treated as a sequence of UIDs; otherwise, as a sequence of ordinal message numbers.
systemFlags
Type: MailBee.ImapMailSystemMessageFlags
A set of flags to be set or reset.
action
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.
Exceptions
ExceptionCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.
Remarks
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.
Examples
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.Connect("imap4.server.com");
        imp.Login("jdoe@server.com", "secret");
        imp.SelectFolder("INBOX");

        // 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.
        imp.Disconnect();
    }
}
See Also