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) Iterate MIME Parts of an EmailDemonstrates how to iterate over the MIME sub-parts of an email, and retrieve the content of each MIME sub-part body. Note: This example requires some new features added to Chilkat v9.5.0.95.
integer li_rc oleobject loo_Email integer li_Success oleobject loo_SbContentType integer li_CaseSensitive integer li_InlineOnly integer li_ExcludeAttachments string ls_SearchSpec integer li_NumParts integer i string ls_TextBody oleobject loo_AttachedEmail oleobject loo_BdMime oleobject loo_Bd // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // See the following Chilkat post to Quickly Understand Email MIME loo_Email = create oleobject // Use "Chilkat_9_5_0.Email" for versions of Chilkat < 10.0.0 li_rc = loo_Email.ConnectToNewObject("Chilkat.Email") if li_rc < 0 then destroy loo_Email MessageBox("Error","Connecting to COM object failed") return end if li_Success = loo_Email.LoadEml("qa_data/eml/sample.eml") if li_Success = 0 then Write-Debug "Failed to load .eml" destroy loo_Email return end if loo_SbContentType = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbContentType.ConnectToNewObject("Chilkat.StringBuilder") li_CaseSensitive = 0 // Get the total number of non-multipart MIME sub-parts. // (This is a simple way of iterating over all the MIME leaf parts regardless of the MIME tree structure) li_InlineOnly = 0 li_ExcludeAttachments = 0 ls_SearchSpec = "*/*" li_NumParts = loo_Email.GetNumPartsOfType(ls_SearchSpec,li_InlineOnly,li_ExcludeAttachments) i = 0 do while i < li_NumParts // What is the Content-Type of this MIME part? loo_SbContentType.Append(loo_Email.GetNthContentType(i,ls_SearchSpec,li_InlineOnly,li_ExcludeAttachments)) if loo_SbContentType.StartsWith("text/",li_CaseSensitive) = 1 then // Get the text body of this MIME part. ls_TextBody = loo_Email.GetNthTextPartOfType(i,ls_SearchSpec,li_InlineOnly,li_ExcludeAttachments) Write-Debug "Got text body for " + loo_SbContentType.GetAsString() else if loo_SbContentType.ContentsEqual("message/rfc822",li_CaseSensitive) = 1 then // If the Content-Type is message/rfc822, then the MIME body for this part contains a full embedded MIME messages. // Your application could load it into a Chilkat email object and recursively process... loo_AttachedEmail = create oleobject // Use "Chilkat_9_5_0.Email" for versions of Chilkat < 10.0.0 li_rc = loo_AttachedEmail.ConnectToNewObject("Chilkat.Email") loo_BdMime = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_BdMime.ConnectToNewObject("Chilkat.BinData") loo_Email.GetNthBinaryPartOfTypeBd(i,ls_SearchSpec,li_InlineOnly,li_ExcludeAttachments,loo_BdMime) loo_AttachedEmail.SetFromMimeBd(loo_BdMime) // Now your app can recursively process the attachedEmail... else // Get the bytes of this MIME body part. loo_Bd = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData") loo_Email.GetNthBinaryPartOfTypeBd(i,ls_SearchSpec,li_InlineOnly,li_ExcludeAttachments,loo_Bd) Write-Debug "Got binary body for " + loo_SbContentType.GetAsString() + " numBytes = " + string(loo_Bd.NumBytes) end if end if loo_SbContentType.Clear() i = i + 1 loop destroy loo_Email destroy loo_SbContentType destroy loo_AttachedEmail destroy loo_BdMime destroy loo_Bd |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.