CopyMessages Method


Copies one or more messages from the currently selected mailbox to another mailbox.

To copy a single message, set First and Last parameters to the same message number or UID.

To copy an arbitrary set of messages, specify MessageSet property and pass -1 as First value (Last value is not important when First is -1). AsUID parameter is still honored when IDs are taken from MessageSet property (depending on AsUID value, they will be treated as UIDs or ordinal message numbers).

To copy all messages starting from a particular one, set First to its UID or ordinal message number and Last to -1. This issues a special IMAP request COPY X:* where X is your First value. Alternatively, you can set Last to MessageCount (like in the sample below) but it only works for ordinal message numbers and not UIDs (because you may not know the UID of the last message in the mailbox and requesting it from the server causes the overhead of an extra IMAP query).

To get the UID values assigned to the messages in the destination folder, you can use UIDPlusResult property.


blnResult = ObjectName.CopyMessages(MailboxName, First, Last, AsUID)  
Parameters:  
MailboxName As String Destination mailbox name. Messages will be copied to this mailbox  
First As Long Message number or UID of the first message in the copied range, or -1 to use MessageSet as input.  
Last As Long Message number or UID of the last message in the copied range. -1 means "last message in the mailbox".  
AsUID As Boolean If True, First and Last parameters must be specified as UIDs (unique-IDs). Otherwise, First and Last must be message numbers.  
Return value As Boolean True if successful, False if error has occurred. You can check ErrDesc property or log file to get more detailed error information.  

Usage example:

' This sample copies all messages with message numbers starting at 20 from "Inbox" folder
' into "Archive" folder. Both folders must exist.

Dim Mailer
'Using visual basic to create object
Set Mailer = CreateObject("MailBee.IMAP4")
'Using ASP to create object
'Set Mailer = Server.CreateObject("MailBee.IMAP4")
'In ASP use Response.Write instead of MsgBox

Mailer.EnableLogging = True ' Logging helps discover any problems
Mailer.LogFilePath = "C:\Temp\imap4_log.txt"

Mailer.LicenseKey = "put your license key here"
If Mailer.Connect("mailserver.com", 143, "MyName", "MyPassword") Then
  If Mailer.SelectMailbox("Inbox") Then
    If Mailer.CopyMessages("Archive", 20, Mailer.MessageCount, False) Then
        MsgBox "Messages copied successfully"
    End If
  End If
  Mailer.Disconnect
Else
  MsgBox Mailer.ErrDesc
End If

See Also:

MessageCount Property

SelectMailbox Method


Copyright © 2002-2024, AfterLogic Corporation. All rights reserved.