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) How to Copy IMAP Mail to another IMAP ServerDemonstrates how to copy the entire contents of an IMAP mailbox to another IMAP server.
IncludeFile "CkImap.pb" IncludeFile "CkStringArray.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. imapSrc.i = CkImap::ckCreate() If imapSrc.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Connect to our source IMAP server. success.i = CkImap::ckConnect(imapSrc,"imap.someMailServer.com") If success <> 1 Debug CkImap::ckLastErrorText(imapSrc) CkImap::ckDispose(imapSrc) ProcedureReturn EndIf ; Login to the source IMAP server success = CkImap::ckLogin(imapSrc,"admin@chilkatsoft.com","myPassword") If success <> 1 Debug CkImap::ckLastErrorText(imapSrc) CkImap::ckDispose(imapSrc) ProcedureReturn EndIf imapDest.i = CkImap::ckCreate() If imapDest.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Connect to our destination IMAP server. success = CkImap::ckConnect(imapDest,"mail.example-code.com") If success <> 1 Debug CkImap::ckLastErrorText(imapDest) CkImap::ckDispose(imapSrc) CkImap::ckDispose(imapDest) ProcedureReturn EndIf ; Login to the destination IMAP server success = CkImap::ckLogin(imapDest,"myLogin","myPassword") If success <> 1 Debug CkImap::ckLastErrorText(imapDest) CkImap::ckDispose(imapSrc) CkImap::ckDispose(imapDest) ProcedureReturn EndIf ; Select an IMAP mailbox on the source IMAP server success = CkImap::ckSelectMailbox(imapSrc,"Inbox") If success <> 1 Debug CkImap::ckLastErrorText(imapSrc) CkImap::ckDispose(imapSrc) CkImap::ckDispose(imapDest) ProcedureReturn EndIf ; After selecting a mailbox, the NumMessages property will ; be updated to reflect the total number of emails in the mailbox: Debug Str(CkImap::ckNumMessages(imapSrc)) ; The emails in the mailbox will always have sequence numbers ; ranging from 1 to NumMessages. ; This example will copy the first 10 messages. ; We'll leave it up to you to write code to copy ; the entire sequence range in reasonable size chunks. startSeqNum.i = 1 msgCount.i = 10 sa.i sa = CkImap::ckFetchSequenceAsMime(imapSrc,startSeqNum,msgCount) If CkImap::ckLastMethodSuccess(imapSrc) <> 1 Debug CkImap::ckLastErrorText(imapSrc) CkImap::ckDispose(imapSrc) CkImap::ckDispose(imapDest) ProcedureReturn EndIf i.i For i = 0 To CkStringArray::ckCount(sa) - 1 success = CkImap::ckAppendMime(imapDest,"Inbox",CkStringArray::ckGetString(sa,i)) If success <> 1 Debug CkImap::ckLastErrorText(imapDest) CkImap::ckDispose(imapSrc) CkImap::ckDispose(imapDest) ProcedureReturn EndIf Next CkStringArray::ckDispose(sa) ; Disconnect from the IMAP servers. success = CkImap::ckDisconnect(imapSrc) success = CkImap::ckDisconnect(imapDest) CkImap::ckDispose(imapSrc) CkImap::ckDispose(imapDest) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.