Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoImap
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the Imap.RenameMailbox method, which renames a mailbox.  Changing hierarchy
    //  components can also move a mailbox within the server's folder tree.

    Get Create (RefClass(cComChilkatImap)) To hoImap
    If (Not(IsComObjectCreated(hoImap))) Begin
        Send CreateComObject of hoImap
    End

    Set ComSsl Of hoImap To True
    Set ComPort Of hoImap To 993

    Get ComConnect Of hoImap "imap.example.com" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComLogin Of hoImap "user@example.com" "myPassword" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Rename a mailbox from "OldName" to "NewName".
    Get ComRenameMailbox Of hoImap "OldName" "NewName" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Mailbox renamed."

    Get ComDisconnect Of hoImap To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End



End_Procedure