PowerBuilder
PowerBuilder
Copy Multiple IMAP Messages to Another Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.CopyMultiple method, which copies the messages in a MessageSet to another mailbox, leaving the originals in place. The first argument is the MessageSet and the second is the destination mailbox name. This example searches for recent messages and copies them to a Backup mailbox.
Background: This maps to the IMAP
COPY command, which duplicates messages entirely on the server — nothing is downloaded. The copy in the destination mailbox is an independent message with its own UID; changing flags on one copy does not affect the other. Combine CopyMultiple with a search from QueryMbx to snapshot or archive matching messages without removing them from their current folder.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
oleobject loo_MsgSet
li_Success = 0
// Demonstrates the Imap.CopyMultiple method, which copies the messages in a MessageSet to
// another mailbox, leaving the originals in place. The 1st argument is the MessageSet and
// the 2nd is the destination mailbox name.
loo_Imap = create oleobject
li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap")
if li_rc < 0 then
destroy loo_Imap
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Imap.Ssl = 1
loo_Imap.Port = 993
li_Success = loo_Imap.Connect("imap.example.com")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_Success = loo_Imap.Login("user@example.com","myPassword")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_Success = loo_Imap.SelectMailbox("Inbox")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
// Find the messages to copy (here, messages seen today, by UID).
loo_MsgSet = create oleobject
li_rc = loo_MsgSet.ConnectToNewObject("Chilkat.MessageSet")
li_Success = loo_Imap.QueryMbx("SINCE 15-Jul-2026",1,loo_MsgSet)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_MsgSet
return
end if
// Copy them to the "Backup" mailbox. The originals remain in the Inbox.
li_Success = loo_Imap.CopyMultiple(loo_MsgSet,"Backup")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_MsgSet
return
end if
Write-Debug "Copied " + string(loo_MsgSet.Count) + " messages to Backup."
li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_MsgSet
return
end if
destroy loo_Imap
destroy loo_MsgSet