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
(PowerBuilder) Copy Email from one IMAP Account to AnotherDemonstrates how to copy the email in a mailbox from one account to another.
integer li_rc oleobject loo_ImapSrc integer li_Success oleobject loo_ImapDest integer li_FetchUids oleobject loo_Mset oleobject loo_Fac oleobject loo_MsetAlreadyCopied string ls_StrMsgSet integer li_NumUids oleobject loo_SbFlags integer i integer li_Uid string ls_Flags string ls_MimeStr integer li_Seen integer li_Flagged integer li_Answered integer li_Draft loo_ImapSrc = create oleobject // Use "Chilkat_9_5_0.Imap" for versions of Chilkat < 10.0.0 li_rc = loo_ImapSrc.ConnectToNewObject("Chilkat.Imap") if li_rc < 0 then destroy loo_ImapSrc MessageBox("Error","Connecting to COM object failed") return end if // This example assumes Chilkat Imap to have been previously unlocked. // See Unlock Imap for sample code. // Connect to our source IMAP server. loo_ImapSrc.Ssl = 1 loo_ImapSrc.Port = 993 li_Success = loo_ImapSrc.Connect("MY-IMAP-DOMAIN") if li_Success <> 1 then Write-Debug loo_ImapSrc.LastErrorText destroy loo_ImapSrc return end if // Login to the source IMAP server li_Success = loo_ImapSrc.Login("MY-IMAP-LOGIN","MY-IMAP-PASSWORD") if li_Success <> 1 then Write-Debug loo_ImapSrc.LastErrorText destroy loo_ImapSrc return end if loo_ImapDest = create oleobject // Use "Chilkat_9_5_0.Imap" for versions of Chilkat < 10.0.0 li_rc = loo_ImapDest.ConnectToNewObject("Chilkat.Imap") // Connect to our destination IMAP server. loo_ImapDest.Ssl = 1 loo_ImapDest.Port = 993 li_Success = loo_ImapDest.Connect("MY-IMAP-DOMAIN2") if li_Success <> 1 then Write-Debug loo_ImapDest.LastErrorText destroy loo_ImapSrc destroy loo_ImapDest return end if // Login to the destination IMAP server li_Success = loo_ImapDest.Login("MY-IMAP-LOGIN2","MY-IMAP-PASSWORD2") if li_Success <> 1 then Write-Debug loo_ImapDest.LastErrorText destroy loo_ImapSrc destroy loo_ImapDest return end if // Select a source IMAP mailbox on the source IMAP server li_Success = loo_ImapSrc.SelectMailbox("Inbox") if li_Success <> 1 then Write-Debug loo_ImapSrc.LastErrorText destroy loo_ImapSrc destroy loo_ImapDest return end if li_FetchUids = 1 // Get the set of UIDs for all emails on the source server. loo_Mset = loo_ImapSrc.Search("ALL",li_FetchUids) if loo_ImapSrc.LastMethodSuccess <> 1 then Write-Debug loo_ImapSrc.LastErrorText destroy loo_ImapSrc destroy loo_ImapDest return end if // Load the complete set of UIDs that were previously copied. // We dont' want to copy any of these to the destination. loo_Fac = create oleobject // Use "Chilkat_9_5_0.FileAccess" for versions of Chilkat < 10.0.0 li_rc = loo_Fac.ConnectToNewObject("Chilkat.FileAccess") loo_MsetAlreadyCopied = create oleobject // Use "Chilkat_9_5_0.MessageSet" for versions of Chilkat < 10.0.0 li_rc = loo_MsetAlreadyCopied.ConnectToNewObject("Chilkat.MessageSet") ls_StrMsgSet = loo_Fac.ReadEntireTextFile("qa_cache/saAlreadyLoaded.txt","utf-8") if loo_Fac.LastMethodSuccess = 1 then loo_MsetAlreadyCopied.FromCompactString(ls_StrMsgSet) end if li_NumUids = loo_Mset.Count loo_SbFlags = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbFlags.ConnectToNewObject("Chilkat.StringBuilder") i = 0 do while i < li_NumUids // If this UID was not already copied... li_Uid = loo_Mset.GetId(i) if not loo_MsetAlreadyCopied.ContainsId(li_Uid) then Write-Debug "copying " + string(li_Uid) + "..." // Get the flags. ls_Flags = loo_ImapSrc.FetchFlags(li_Uid,1) if loo_ImapSrc.LastMethodSuccess = 0 then Write-Debug loo_ImapSrc.LastErrorText destroy loo_ImapSrc destroy loo_ImapDest destroy loo_Fac destroy loo_MsetAlreadyCopied destroy loo_SbFlags return end if loo_SbFlags.SetString(ls_Flags) // Get the MIME of this email from the source. ls_MimeStr = loo_ImapSrc.FetchSingleAsMime(li_Uid,1) if loo_ImapSrc.LastMethodSuccess = 0 then Write-Debug loo_ImapSrc.LastErrorText destroy loo_ImapSrc destroy loo_ImapDest destroy loo_Fac destroy loo_MsetAlreadyCopied destroy loo_SbFlags return end if li_Seen = loo_SbFlags.Contains("\Seen",0) li_Flagged = loo_SbFlags.Contains("\Flagged",0) li_Answered = loo_SbFlags.Contains("\Answered",0) li_Draft = loo_SbFlags.Contains("\Draft",0) li_Success = loo_ImapDest.AppendMimeWithFlags("Inbox",ls_MimeStr,li_Seen,li_Flagged,li_Answered,li_Draft) if li_Success <> 1 then Write-Debug loo_ImapDest.LastErrorText destroy loo_ImapSrc destroy loo_ImapDest destroy loo_Fac destroy loo_MsetAlreadyCopied destroy loo_SbFlags return end if // Update msetAlreadyCopied with the uid just copied. loo_MsetAlreadyCopied.InsertId(li_Uid) // Save at every iteration just in case there's a failure.. ls_StrMsgSet = loo_MsetAlreadyCopied.ToCompactString() loo_Fac.WriteEntireTextFile("qa_cache/saAlreadyLoaded.txt",ls_StrMsgSet,"utf-8",0) end if i = i + 1 loop destroy loo_Mset // Disconnect from the IMAP servers. li_Success = loo_ImapSrc.Disconnect() li_Success = loo_ImapDest.Disconnect() destroy loo_ImapSrc destroy loo_ImapDest destroy loo_Fac destroy loo_MsetAlreadyCopied destroy loo_SbFlags |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.