Renames an existing folder (mailbox in IMAP4 terms) of the IMAP4 account.
Namespace: MailBee.ImapMailAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax public bool RenameFolder(
string oldName,
string newName
)
Public Function RenameFolder (
oldName As String,
newName As String
) As Boolean
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:
Booleantrue if the folder was renamed successfully; otherwise,
false.
Exceptions Remarks 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.
using MailBee;
using MailBee.ImapMail;
Imap imp = new Imap();
imp.Connect("imap4.company.com");
imp.Login("jdoe@company.com", "secret");
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();
Imports MailBee
Imports MailBee.ImapMail
Dim imp As New Imap
imp.Connect("imap4.company.com")
imp.Login("jdoe@company.com", "secret")
Dim sentFolderName As String = Nothing
Dim isSentItems As Boolean = False
Dim folders As FolderCollection = _
imp.DownloadFolders(False, String.Empty, "%")
For Each imapFolder As Folder In folders
Dim folderName As String = imapFolder.Name.ToLower()
If folderName = "sent" Then
sentFolderName = imapFolder.Name
ElseIf folderName = "sent items" Then
isSentItems = True
End If
Next
If sentFolderName Is Nothing Then
Console.WriteLine("Sent folder does not exist.")
ElseIf isSentItems Then
Console.WriteLine()
Else
imp.RenameFolder(sentFolderName, "Sent Items")
Console.WriteLine(sentFolderName & )
End If
imp.Disconnect()
See Also