PowerBuilder
PowerBuilder
Move IMAP Messages to Another Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.MoveMessages method, which moves the messages in a MessageSet to another mailbox on the server. The first argument is the MessageSet and the second is the destination folder name. This example searches for newsletter messages and moves them to the Archive mailbox.
Background: A true server-side move (the IMAP
MOVE extension) is atomic and efficient: the message never leaves the server, so no download/re-upload is involved. If the server lacks the MOVE capability, the equivalent is copy-then-delete-then-expunge — Chilkat handles that fallback for you, but the destination mailbox must already exist.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
oleobject loo_MsgSet
li_Success = 0
// Demonstrates the Imap.MoveMessages method, which moves the messages in a MessageSet to
// another mailbox on the server. The 1st argument is the MessageSet and the 2nd is the
// destination folder 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 move (here, messages from a particular sender, by UID).
loo_MsgSet = create oleobject
li_rc = loo_MsgSet.ConnectToNewObject("Chilkat.MessageSet")
li_Success = loo_Imap.QueryMbx("FROM ~"newsletter@example.com~"",1,loo_MsgSet)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_MsgSet
return
end if
// Move them to the "Archive" mailbox.
li_Success = loo_Imap.MoveMessages(loo_MsgSet,"Archive")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_MsgSet
return
end if
Write-Debug "Moved " + string(loo_MsgSet.Count) + " messages to Archive."
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