ImapBeginSetMessageFlags Method

Note: This API is now obsolete.

Begins an asynchronous request to set or reset the specified message flags for the specified messages in the currently selected folder.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
[ObsoleteAttribute("This method is obsolete in .NET 4.5+. Use SetMessageFlagsAsync instead.")]
public IAsyncResult BeginSetMessageFlags(
	string messageIndexSet,
	bool indexIsUid,
	string flags,
	MessageFlagAction action,
	bool silentMode,
	AsyncCallback callback,
	Object state
)

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.
flags
Type: SystemString
The string containing IMAP4 flags to be set or reset.
action
Type: MailBee.ImapMailMessageFlagAction
The action to perform with the specified flags (set, reset, etc).
silentMode
Type: SystemBoolean
If true, the server will NOT respond with the new values of flags of the affected messages; otherwise, the server will produce a series of untagged FETCH responses containing the updated flag lists of affected messages.
callback
Type: SystemAsyncCallback
The AsyncCallback delegate. You can leave it a null reference (Nothing in Visual Basic) if you do not use callbacks.
state
Type: SystemObject
An object that contains state information for this request. You can leave it a null reference (Nothing in Visual Basic).

Return Value

Type: IAsyncResult
An IAsyncResult that references the asynchronous setting message flags.
Exceptions
ExceptionCondition
MailBeeInvalidStateExceptionThere is already an operation in progress.
Remarks
Examples

This WinForms samples deletes the first message in the inbox folder of the mail account asynchronously (in a worker thread). The sample then expunges the deleted messages (the expunge is also performed in worker thread).

The sample also demonstrates how to wait for asynchronous operation completion without blocking user interface of the application (the user can click buttons, move windows, etc) during the asynchronous processing. However, the sample does not allow the user to click a button which starts the asynchronous operation if this operation is already in progress.

// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.ImapMail;

// Put the code below inside your class.

bool finished;
bool started = false;

// A callback function. Since it's called on Imap worker thread,
// it cannot display any messages or otherwise access UI.
// Any updates of UI must take place on message loop thread.
// See the sample in BeginSearch() topic on how to update UI in
// such scenario.
private void SetMessageFlagsCallback(IAsyncResult result)
{
    Imap imp = (Imap)result.AsyncState;

    // It's important to handle exceptions in worker threads. Otherwise,
    // the worker thread could silently die and the application would
    // have never known this had happened.
    try
    {
        imp.EndSetMessageFlags();
        imp.Expunge();
    }
    catch (MailBeeException e)
    {
        MessageBox.Show(e.Message);
    }
    finally
    {
        finished = true;
    }
}

// Add button1 on the form to make this sample working.
private void button1_Click(object sender, System.EventArgs e)
{
    if (started)
    {
        MessageBox.Show("The operation is already in progress");
    }
    else
    {
        started = true;
    }

    finished = false;

    Imap imp = new Imap();

    // Connect to the server, login and select inbox.
    imp.Connect("mail.company.com");
    imp.Login("jdoe", "secret");
    imp.SelectFolder("Inbox");

    // Asynchronously mark the first message as deleted. Instead of
    // MessageFlagSet.SystemFlagsToString(SystemMessageFlags.Deleted),
    // we could simply use "\Deleted" (@"\Deleted" in C#).
    imp.BeginSetMessageFlags("1", false,
        MessageFlagSet.SystemFlagsToString(SystemMessageFlags.Deleted),
        MessageFlagAction.Add, true,
        new AsyncCallback(SetMessageFlagsCallback), imp);

    // Wait until completion via periodic polling
    // of the completion status.
    while (!finished)
    {
        System.Threading.Thread.Sleep(1);

        // It's not necessary to call DoEvents here since we do not
        // handle any MailBee events in this sample. However, if we did,
        // we would have needed this call to let the events be processed.
        // Alternatively, we could have set imp.RaiseEventsViaMessageLoop
        // to false and use imp.Wait() instead of Thread.Sleep() and
        // Application.DoEvents(). If using imp.Wait(), we would not need
        // to prevent this routine from being called again while it's
        // already being executed since imp.Wait() blocks UI and it would
        // be impossible to click a button until imp.Wait() completes.
        Application.DoEvents();
    }

    // Disconnect from the server.
    imp.Disconnect();

    started = false;
}
See Also