ImapRenameFolder Method
Renames an existing folder (mailbox in IMAP4 terms) of the IMAP4 account.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax
public bool RenameFolder(
	string oldName,
	string newName
)

Parameters

oldName
Type: SystemString
The full name of the folder to be renamed.
newName
Type: SystemString
The new full name of the folder.

Return Value

Type: Boolean
true if the folder was renamed successfully; otherwise, false.
Exceptions
ExceptionCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.
Remarks
The developer should specify the full names of the folder (including all parent folders' names if the folder is or should become a subfolder of another existing folder). See CreateFolder(String) topic for details regarding folder names.
Note Note
Inbox folder cannot be renamed.

To rename a folder asynchronously, see the sample code in BeginExecuteCustomCommand(String, String, AsyncCallback, Object) topic.

Examples
This sample connects to the IMAP4 server, logs in the mail account, and renames "Sent" to "Sent Items". Before renaming, the sample code checks if "Sent" exists and "Sent Items" does not already exist, and displays the corresponding warning is these conditions are not met.
// To use the code below, import MailBee namespaces at the top of your code
using MailBee;
using MailBee.ImapMail;

// The actual code (put it into a method of your class)
Imap imp = new Imap();

// Connect to the server and log in the account.
imp.Connect("imap4.company.com");
imp.Login("jdoe@company.com", "secret");

// First, check if "Sent" exists and "Sent Items" does not exist. To
// determine this, we'll will get the list of root level folders only
// (we could have received all the folders, but it's more effecient
// to download only root ones since we're going to rename a root level
// folder into another root level name).

string sentFolderName = null;
bool isSentItems = false;
FolderCollection folders = imp.DownloadFolders(false, string.Empty, "%");

foreach (Folder imapFolder in folders)
{
    string folderName = imapFolder.Name.ToLower();
    if (folderName == "sent")
    {
        sentFolderName = imapFolder.Name;
    } 
    else if (folderName == "sent items")
    {
        isSentItems = true;
    }
}

if (sentFolderName == null)
{
    Console.WriteLine("Sent folder does not exist.");
}
else if (isSentItems)
{
    Console.WriteLine("'Sent Items' folder already exists.");
}
else
{
    imp.RenameFolder(sentFolderName, "Sent Items");
    Console.WriteLine(sentFolderName + " renamed to 'Sent Items'.");
}

imp.Disconnect();
See Also