Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PowerBuilder) Iterate MIME Parts of an Email

Demonstrates 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.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

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
li_rc = loo_Email.ConnectToNewObject("Chilkat_9_5_0.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
li_rc = loo_SbContentType.ConnectToNewObject("Chilkat_9_5_0.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
            li_rc = loo_AttachedEmail.ConnectToNewObject("Chilkat_9_5_0.Email")

            loo_BdMime = create oleobject
            li_rc = loo_BdMime.ConnectToNewObject("Chilkat_9_5_0.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
            li_rc = loo_Bd.ConnectToNewObject("Chilkat_9_5_0.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.