PowerBuilder
PowerBuilder
Copy a Range of IMAP Messages
See more IMAP Examples
Demonstrates the Chilkat Imap.CopySequence method, which copies a contiguous range of messages, identified by sequence number, from the selected mailbox to a destination mailbox. The first argument is the starting sequence number and the second is the number of messages to copy. This example copies the first ten messages to another mailbox.
Background: Copying a whole range in a single command is far more efficient than copying messages one at a time — it's one server round trip instead of many. This method works by sequence number (position), so it is well suited to "copy the first N" or "copy messages 50–100" style operations. To copy an arbitrary, non-contiguous set of messages, build a
MessageSet and use CopyMultiple.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
li_Success = 0
// Demonstrates the Imap.CopySequence method, which copies a contiguous range of messages,
// identified by sequence number, from the selected mailbox to a destination mailbox. The
// 1st argument is the first sequence number and the 2nd is the number of messages to copy.
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
// Copy the first 10 messages (sequence numbers 1 through 10) to "Archive2026".
li_Success = loo_Imap.CopySequence(1,10,"Archive2026")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
Write-Debug "Copied the message range."
li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
destroy loo_Imap