Sample code for 30+ languages & platforms
PowerBuilder

Copy an IMAP Message to Another Mailbox

See more IMAP Examples

Demonstrates the Chilkat Imap.Copy method, which copies one message from the currently selected mailbox to a destination mailbox. The first argument identifies the source message; the second (bUid) indicates whether the id is a UID (true) or a sequence number (false). This example copies a message from the Inbox to another mailbox.

Background: Messages can be identified two ways in IMAP: a sequence number (the message's current 1-based position, which shifts as messages are added or expunged) or a UID (a stable identifier that doesn't change). The bUid flag tells Copy which you're passing. Copying leaves the original in place and places a duplicate in the destination — use MoveMessages to relocate instead of duplicate.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Imap

li_Success = 0

//  Demonstrates the Imap.Copy method, which copies one message from the currently selected
//  mailbox to a destination mailbox.  The 1st argument identifies the source message; the 2nd
//  (bUid) indicates whether the id is a UID (1) or a sequence number (0).

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

//  Select the source mailbox.
li_Success = loo_Imap.SelectMailbox("Inbox")
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

//  Copy message sequence number 1 to the "Archive2026" mailbox.  bUid = 0 means the id
//  is a sequence number, not a UID.
li_Success = loo_Imap.Copy(1,0,"Archive2026")
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

Write-Debug "Message copied."

li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if



destroy loo_Imap