SQL Server
SQL Server
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 SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @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.
DECLARE @imap int
EXEC @hr = sp_OACreate 'Chilkat.Imap', @imap OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @imap, 'Ssl', 1
EXEC sp_OASetProperty @imap, 'Port', 993
EXEC sp_OAMethod @imap, 'Connect', @success OUT, 'imap.example.com'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @imap
RETURN
END
EXEC sp_OAMethod @imap, 'Login', @success OUT, 'user@example.com', 'myPassword'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @imap
RETURN
END
-- Rename a mailbox from "OldName" to "NewName".
EXEC sp_OAMethod @imap, 'RenameMailbox', @success OUT, 'OldName', 'NewName'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @imap
RETURN
END
PRINT 'Mailbox renamed.'
EXEC sp_OAMethod @imap, 'Disconnect', @success OUT
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @imap
RETURN
END
EXEC @hr = sp_OADestroy @imap
END
GO