Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oImap
nSuccess := 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).
oImap := CreateObject("Chilkat.Imap")
oImap:Ssl := 1
oImap:Port := 993
nSuccess := oImap:Connect("imap.example.com")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
nSuccess := oImap:Login("user@example.com", "myPassword")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
// Select the source mailbox.
nSuccess := oImap:SelectMailbox("Inbox")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
// Copy message sequence number 1 to the "Archive2026" mailbox. bUid = 0 means the id
// is a sequence number, not a UID.
nSuccess := oImap:Copy(1, 0, "Archive2026")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
? "Message copied."
nSuccess := oImap:Disconnect()
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
oImap:destroy()