Sample code for 30+ languages & platforms
Tcl

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

Tcl

load ./chilkat.dll

set success 0

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

set imap [new_CkImap]

CkImap_put_Ssl $imap 1
CkImap_put_Port $imap 993

set success [CkImap_Connect $imap "imap.example.com"]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

set success [CkImap_Login $imap "user@example.com" "myPassword"]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

#  Rename a mailbox from "OldName" to "NewName".
set success [CkImap_RenameMailbox $imap "OldName" "NewName"]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

puts "Mailbox renamed."

set success [CkImap_Disconnect $imap]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}


delete_CkImap $imap