Java
Chilkat2 Java
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 Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Imap;
public class ChilkatExample {
public static void main(String[] args) {
// Demonstrates the Imap.RenameMailbox method, which renames a mailbox. Changing hierarchy
// components can also move a mailbox within the server's folder tree.
Imap imap = new Imap();
imap.setSsl(true);
imap.setPort(993);
try {
imap.connect("imap.example.com");
imap.login("user@example.com", "myPassword");
// Rename a mailbox from "OldName" to "NewName".
imap.renameMailbox("OldName", "NewName");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Mailbox renamed.");
try {
imap.disconnect();
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
}
}