Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loImap
LOCAL loMsgSet
lnSuccess = 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.
loImap = CreateObject('Chilkat.Imap')
loImap.Ssl = 1
loImap.Port = 993
lnSuccess = loImap.Connect("imap.example.com")
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
CANCEL
ENDIF
lnSuccess = loImap.Login("user@example.com","myPassword")
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
CANCEL
ENDIF
lnSuccess = loImap.SelectMailbox("Inbox")
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
CANCEL
ENDIF
* Find the messages to move (here, messages from a particular sender, by UID).
loMsgSet = CreateObject('Chilkat.MessageSet')
lnSuccess = loImap.QueryMbx('FROM "newsletter@example.com"',1,loMsgSet)
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loMsgSet
CANCEL
ENDIF
* Move them to the "Archive" mailbox.
lnSuccess = loImap.MoveMessages(loMsgSet,"Archive")
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loMsgSet
CANCEL
ENDIF
? "Moved " + STR(loMsgSet.Count) + " messages to Archive."
lnSuccess = loImap.Disconnect()
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loMsgSet
CANCEL
ENDIF
RELEASE loImap
RELEASE loMsgSet