Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Delete All IMAP EmailDemonstrates two ways to delete all email in a mailbox on an IMAP server. CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) DECLARE @sTmp1 nvarchar(4000) DECLARE @success int DECLARE @imap int EXEC @hr = sp_OACreate 'Chilkat.Imap', @imap OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Anything unlocks the component and begins a fully-functional 30-day trial. EXEC sp_OAMethod @imap, 'UnlockComponent', @success OUT, 'Anything for 30-day trial' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Turn on session logging: EXEC sp_OASetProperty @imap, 'KeepSessionLog', 1 -- Connect to an IMAP server. EXEC sp_OAMethod @imap, 'Connect', @success OUT, 'mail.chilkatsoft.com' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Login EXEC sp_OAMethod @imap, 'Login', @success OUT, 'myLogin', 'myPassword' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Select an IMAP mailbox EXEC sp_OAMethod @imap, 'SelectMailbox', @success OUT, 'Inbox.RubyMail' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END DECLARE @messageSet int -- Get the complete set of Uids for email in the selected mailbox. EXEC sp_OAMethod @imap, 'GetAllUids', @messageSet OUT IF @messageSet Is NULL BEGIN EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Set the Deleted flag for each message. -- (ExpungeAndClose must be called to finalize the delete.) EXEC sp_OAMethod @imap, 'SetFlags', @success OUT, @messageSet, 'Deleted', 1 IF @success <> 1 BEGIN EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Alternatively, the Deleted flag may be set for each UID -- individiually, but this is less efficient: DECLARE @i int DECLARE @n int EXEC sp_OAGetProperty @messageSet, 'Count', @n OUT SELECT @i = 0 WHILE @i <= @n - 1 BEGIN EXEC sp_OAMethod @messageSet, 'GetId', @sTmp0 OUT, @i EXEC sp_OAGetProperty @messageSet, 'HasUids', @sTmp1 OUT EXEC sp_OAMethod @imap, 'SetFlag', @success OUT, @sTmp0, @sTmp1, 'Deleted', 1 IF @success <> 1 BEGIN EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END SELECT @i = @i + 1 END -- Expunge and close the mailbox. EXEC sp_OAMethod @imap, 'ExpungeAndClose', @success OUT IF @success <> 1 BEGIN EXEC sp_OAGetProperty @imap, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Display the session log. EXEC sp_OAGetProperty @imap, 'SessionLog', @sTmp0 OUT PRINT @sTmp0 -- Disconnect from the IMAP server. EXEC sp_OAMethod @imap, 'Disconnect', NULL END GO |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.