AutoIt
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; 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.
$oImap = ObjCreate("Chilkat.Imap")
$oImap.Ssl = True
$oImap.Port = 993
$bSuccess = $oImap.Connect("imap.example.com")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oImap.Login("user@example.com","myPassword")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oImap.SelectMailbox("Inbox")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Find the messages to move (here, messages from a particular sender, by UID).
$oMsgSet = ObjCreate("Chilkat.MessageSet")
$bSuccess = $oImap.QueryMbx("FROM ""newsletter@example.com""",True,$oMsgSet)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Move them to the "Archive" mailbox.
$bSuccess = $oImap.MoveMessages($oMsgSet,"Archive")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Moved " & $oMsgSet.Count & " messages to Archive." & @CRLF)
$bSuccess = $oImap.Disconnect()
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf