ImapMoveMessages Method (String, Boolean, String, UidPlusResult) |
Moves the specified messages from the currently selected folder to the specified folder,
and retrieves UIDs assigned to the moved messages in the destination folder.
Namespace: MailBee.ImapMailAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax public bool MoveMessages(
string messageIndexSet,
bool indexIsUid,
string targetFolderName,
UidPlusResult result
)
Public Function MoveMessages (
messageIndexSet As String,
indexIsUid As Boolean,
targetFolderName As String,
result As UidPlusResult
) As Boolean
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 move operation reported by UIDPLUS enabled server (the outcome includes the UIDs
of the source messages being moved, the UIDs assigned to the 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.
Return Value
Type:
Booleantrue if the messages were moved successfully; otherwise,
false.
Exceptions Remarks To learn how to specify a valid message sequence (messageIndexSet value), see DownloadEnvelopes(String, Boolean) topic.
When result is specified and the server supports UIDPLUS extension, CopyMessages(String, Boolean, String, UidPlusResult) method will
set the supplied UidPlusResult object properties as below:
Property | Value |
---|
IsValid | true |
IsSupported | true |
SrcUids | The UidCollection object containing the UIDs of the messages which had been moved from the source folder. |
SrcUidString | The string containing the message sequence of UIDs of the messages which had been moved from the source folder. |
DestUids | The UidCollection object containing the UIDs assigned to the moved messages in targetFolderName folder. |
DestUidString | The string containing the message sequence of UIDs assigned to the moved messages in targetFolderName folder. |
DestUidValidity | The UIDVALIDITY of the targetFolderName folder. |
If UIDPLUS capability is not supported by the server,
IsSupported will be set to
false.
Note |
---|
The IMAP4 protocol might not directly support moving messages between folders (unless the server supports MOVE extension).
If MOVE command is not supported by the server, MailBee emulates moving messages
as a sequence of copying, marking copied messages as deleted in the source folder, and then expunging deleted messages.
This operation performs quicker when the server supports UIDPLUS extension (because UIDPLUS allows the client to expunge specific
"\Deleted" messages rather than all such messages in the folder).
If UIDPLUS is not supported, it takes a bit longer to move messages since MailBee needs to preserve messages which have already had "\Deleted" flag set
to the moment when MoveMessages(String, Boolean, String, UidPlusResult) method started. If MailBee just expunged the deleted messages from the folder,
this would affect not only messages being copied but rather all messages which have already had "\Deleted" flag set.
MailBee avoids this by temporary removing "\Deleted" flag from the messages which have already had this flag, and then restoring
this flag back when the moving completes. However, when all messages in the folder are being moved, it's not required
to care about remaining messages. Thus, when UIDPLUS is not supported, moving all messages is performed in less count of steps than moving
specific messages only. Again, all of the above only makes sense when MOVE command is not supported. With MOVE command, moving messages is
fast and straight-forward process.
|
Examples This sample moves the first message from the inbox folder to the Sent folder (it's assumed the Sent folder already exists and the inbox
contains at least 1 message). The UIDs assigned to the moved messages in the destination folder is displayed if UIDPLUS capability is supported by the server.
using System;
using MailBee;
using MailBee.ImapMail;
class Sample
{
static void Main(string[] args)
{
Imap imp = new Imap();
imp.Connect("mail.somehost.com");
imp.Login("jdoe", "secret");
imp.SelectFolder("INBOX");
UidPlusResult res = new UidPlusResult();
imp.MoveMessages("1", false, "Sent", res);
if (res.IsSupported)
{
Console.WriteLine("UID assigned to the moved message is " +
res.DestUidString);
}
else
{
Console.WriteLine("Sorry, UIDPLUS is not supported by the server");
}
imp.Disconnect();
}
}
Imports System
Imports MailBee
Imports MailBee.ImapMail
Module Sample
Sub Main(ByVal args As String())
Dim imp As New Imap
imp.Connect("mail.somehost.com")
imp.Login("jdoe", "secret")
imp.SelectFolder("INBOX")
Dim res As New UidPlusResult
imp.MoveMessages("1", False, "Sent", res)
If res.IsSupported Then
Console.WriteLine("UID assigned to the moved message is " & res.DestUidString)
Else
Console.WriteLine("Sorry, UIDPLUS is not supported by the server")
End If
imp.Disconnect()
End Sub
End Module
See Also