PureBasic
PureBasic
Rename an IMAP Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.RenameMailbox method, which renames a mailbox from the first name to the second. Changing the hierarchy components in the new name can also move a mailbox within the server's folder tree. This example renames OldName to NewName.
Background: Because a mailbox's full name encodes its place in the folder hierarchy, renaming is also how you move a folder: renaming
Inbox/Draft to Archive/Draft relocates it under a different parent. The messages inside move along with the folder. This makes RenameMailbox the tool for both relabeling and reorganizing an account's folder structure.Chilkat PureBasic Downloads
IncludeFile "CkImap.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the Imap.RenameMailbox method, which renames a mailbox. Changing hierarchy
; components can also move a mailbox within the server's folder tree.
imap.i = CkImap::ckCreate()
If imap.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkImap::setCkSsl(imap, 1)
CkImap::setCkPort(imap, 993)
success = CkImap::ckConnect(imap,"imap.example.com")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
success = CkImap::ckLogin(imap,"user@example.com","myPassword")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
; Rename a mailbox from "OldName" to "NewName".
success = CkImap::ckRenameMailbox(imap,"OldName","NewName")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
Debug "Mailbox renamed."
success = CkImap::ckDisconnect(imap)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
CkImap::ckDispose(imap)
ProcedureReturn
EndProcedure