ImapBeginCopyOrMoveMessages Method

Note: This API is now obsolete.

Begins an asynchronous request for copying or moving the specified messages from the currently selected folder to the specified 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 CopyMessagesAsync or MoveMessagesAsync instead.")]
public IAsyncResult BeginCopyOrMoveMessages(
	string messageIndexSet,
	bool indexIsUid,
	string targetFolderName,
	UidPlusResult result,
	bool move,
	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.
targetFolderName
Type: SystemString
The full name of the destination folder.
result
Type: MailBee.ImapMailUidPlusResult
A reference to the UidPlusResult object to be filled with the outcome of the copy/move operation reported by UIDPLUS enabled server (the outcome includes the UIDs of the source messages being copied/moved, the UIDs assigned to the copied/moved messages in the destination folder, and the UIDVALIDITY of the destination folder), or a null reference (Nothing in Visual Basic) if the application does not need this information.
move
Type: SystemBoolean
If true, the messages will be moved; otherwise, copied.
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 copying or moving messages process.
Exceptions
ExceptionCondition
MailBeeInvalidStateExceptionThere is already an operation in progress.
Remarks
This method is an asynchronous version of CopyMessages(String, Boolean, String, UidPlusResult) (if move is false) or MoveMessages(String, Boolean, String, UidPlusResult) (if move is true).
Examples

This console sample demonstrates asynchronous moving the first and the last messages from the Inbox folder into the Trash folder. A callback function is used as well.

The sample assumes "Trash" folder had already been created in the past. To learn how to make sure the folder exists, see UploadMessage(MailMessage, String, String, DateTime) or UploadMessage(MailMessage, String, String, String) samples.

using System;
using MailBee;
using MailBee.ImapMail;

class Sample
{
    // A callback function.
    private static void CopyOrMoveMessagesCallback(IAsyncResult result)
    {
        Imap imp = (Imap)result.AsyncState;
        try
        {
            imp.EndCopyOrMoveMessages();
            Console.WriteLine("The messages moved successfully");
        }
        catch (MailBeeException e)
        {
            // In callback functions (generally speaking, in worker threads),
            // it's better to handle exceptions. If exception is not handled,
            // the worker thread silently dies and the application may never
            // know that something went wrong.
            Console.WriteLine(e.Message);
        }
    }

    // The actual code.
    static void Main(string[] args)
    {
        Imap imp = new Imap();

        // Connect to the server, login and select inbox.
        imp.Connect("imap4.somehost.com");
        imp.Login("jdoe", "secret");
        imp.SelectFolder("INBOX");

        // Initiate an asynchronous messages moving attempt.
        // We move the first and the last messages.
        IAsyncResult ar = imp.BeginCopyOrMoveMessages(
            "1," + imp.MessageCount.ToString(), false,
            "Trash", null, true,
            new AsyncCallback(CopyOrMoveMessagesCallback), imp);

        // Simulate some lengthy work here. At the same time,
        // messages are moved on another thread.
        System.Threading.Thread.Sleep(3000);

        // If the messages moving attempt is still in progress,
        // then wait until it's finished.
        while (imp.IsBusy) ar.AsyncWaitHandle.WaitOne();

        // Disconnect from the server.
        imp.Disconnect();
    }
}
See Also