Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Subscribe to Mailboxes and List Subscribed MailboxesDemonstrates how to list subscribed mailboxes, and unsubscribe/subscribe to a mailbox.
IncludeFile "CkMailboxes.pb" IncludeFile "CkImap.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. imap.i = CkImap::ckCreate() If imap.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Connect to an IMAP server. ; Use TLS CkImap::setCkSsl(imap, 1) CkImap::setCkPort(imap, 993) success.i = CkImap::ckConnect(imap,"imap.someMailServer.com") If success <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf ; Login success = CkImap::ckLogin(imap,"myLogin","myPassword") If success <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf ; First examine the already subscribed mailboxes. refName.s = "" wildcardedMailbox.s = "*" ; Alternatively, the ListMailboxes method can be called to list all mailboxes (both subscribed and unsubscribed). mboxes.i = CkImap::ckListSubscribed(imap,refName,wildcardedMailbox) If CkImap::ckLastMethodSuccess(imap) <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf i.i For i = 0 To CkMailboxes::ckCount(mboxes) - 1 Debug CkMailboxes::ckGetName(mboxes,i) Next Debug "----" CkMailboxes::ckDispose(mboxes) ; Sample output. ; INBOX ; INBOX/recent ; INBOX/misc ; INBOX/misc/solutions ; ... ; Outbox ; Deleted Items ; Sent Items ; Drafts ; Junk E-mail ; Trash ; Sent ; Templates ; Let's unsubscribe to "INBOX/misc/solutions". success = CkImap::ckUnsubscribe(imap,"INBOX/misc/solutions") If success <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf ; Get the list of subscribed mailboxes again to verify that "INBOX/misc/solutions" is missing. mboxes = CkImap::ckListSubscribed(imap,"","INBOX/misc*") If CkImap::ckLastMethodSuccess(imap) <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf For i = 0 To CkMailboxes::ckCount(mboxes) - 1 Debug CkMailboxes::ckGetName(mboxes,i) Next CkMailboxes::ckDispose(mboxes) Debug "----" ; Re-subscribe to "INBOX/misc/solutions". success = CkImap::ckSubscribe(imap,"INBOX/misc/solutions") If success <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf ; Get the list of subscribed mailboxes again to verify that "INBOX/misc/solutions" is back in the list. mboxes = CkImap::ckListSubscribed(imap,"","INBOX/misc*") If CkImap::ckLastMethodSuccess(imap) <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf For i = 0 To CkMailboxes::ckCount(mboxes) - 1 Debug CkMailboxes::ckGetName(mboxes,i) Next CkMailboxes::ckDispose(mboxes) Debug "----" ; Disconnect from the IMAP server. success = CkImap::ckDisconnect(imap) CkImap::ckDispose(imap) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.