MailBee.NET Objects 4.0

Imap.MoveMessages Method (String, Boolean, String)

Moves the specified messages from the currently selected folder to the specified folder.

public bool MoveMessages(
   string messageIndexSet,
   bool indexIsUid,
   string targetFolderName
);

Parameters

messageIndexSet
A message sequence string containing ordinal message numbers or UIDs. Can be composed manually or using ToString.
indexIsUid
If true, messageIndexSet is treated as a sequence of UIDs; otherwise, as a sequence of ordinal message numbers.
targetFolderName
The full name of the destination folder.

Return Value

true if the messages were moved successfully; otherwise, false.

Remarks

To learn how to specify a valid message sequence (messageIndexSet value), see DownloadEnvelopes topic.

Note   The IMAP4 protocol actually does not directly support moving messages between folders. MailBee emulates moving messages as a sequence of copying, marking copied messages as deleted in the source folder, and then expunging deleted messages. You can find more detailed description of this process in MoveMessages overload topic.

Exceptions

Exception TypeCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.

Example

This sample moves all seen (already read) messages from the Inbox folder into the Archive folder.

The sample assumes "Archive" folder had already been created in the past. To learn how to make sure the folder exists, see UploadMessage or UploadMessage samples.

[C#]
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("imap.server.com");
        imp.Login("jdoe@server.com", "secret");
        imp.SelectFolder("INBOX");

        // Find all messages which are already read.
        UidCollection uids = (UidCollection)imp.Search(true, "SEEN", null);

        if (uids.Count > 0)
        {
            // Move all SEEN messages into Archive.
            imp.MoveMessages(uids.ToString(), true, "Archive");
        }

        // Disconnect from the server.
        imp.Disconnect();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail

Module Sample
    Sub Main(ByVal args As String())
        Dim imp As New Imap

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

        ' Find all messages which are already read.
        Dim uids As UidCollection = CType(imp.Search(True, "SEEN", Nothing), UidCollection)

        If uids.Count > 0 Then
            ' Move all SEEN messages into Archive.
            imp.MoveMessages(uids.ToString(), True, "Archive")
        End If

        ' Disconnect from the server.
        imp.Disconnect()
    End Sub
End Module

See Also

Imap Class | MailBee.ImapMail Namespace | Imap.MoveMessages Overload List | CopyMessages