Topic Path: Symbol Reference > Classes > TIdIMAP4 Class > TIdIMAP4 Methods > DeleteMailBox Method
TIdIMAP4.DeleteMailBox Method

Removes the specified mailbox on the IMAP4 server.

function DeleteMailBox(
    const AMBName: String
): Boolean;
Mailbox name to be removed for the current account. 

Boolean - True on success, or False when a protocol error has occurred.

DeleteMailBox is a Boolean function used to permanently remove the mailbox specified in AMBName from the IMAP4 server. Attempting to remove the "INBOX" mailbox, or a mailbox name that does not exist, will result in an error response from the server. 

DeleteMailBox requires that the value of ConnectionState contain either csAuthenticated or csSelected, or an EIdConnectionStateError exception will be raised. 

DeleteMailBox calls SendCmd using the IMAP DELETE Command, and sets the return value to True when the server response contains the value IMAP_OK

Please note that IMAP servers are required to have an "Inbox" or "INBOX" folder to allow them to receive email for a given user. This may or may not be case-sensitive. Your implementation may require you to create an Inbox folder if it does not already exist. Because of this requirement, you may not be able to delete a mailbox named Inbox, and if it succeeded, such a deletion may cause unexpected results. 

In additional, use caustion when choosing the characters included in mailbox names. Different IMAP servers may allow, and may interpret differently, various characters, as allowed within the IMAP specification. Characters such as ~/ and . may have special meaning in the IMAP servers context, and may produce unexpected results. In practice, some IMAP servers may be case-sensitive and others not. It is recommended that you only use the characters A-Z and 0-9 and that you program to allow for case sensitivity or insensitivity, as applicable. Please note that, in general, IdIMAP4 adds double-quotes around mailbox names, which allows the use of spaces in mailbox names. Some IMAP servers may not allow spaces (this functionality is necessary to allow IdIMAP4 to deal with pre-existing mailboxes that include spaces). 

Use CreateMailBox to create a new mailbox.

Copyright 1993-2006, Chad Z. Hower (aka Kudzu) and the Indy Pit Crew. All rights reserved.
Post feedback to the Indy Docs Newsgroup.