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

DataFlex 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
Cloud Signature CSC
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
Secrets
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

 

 

 

(DataFlex) 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

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    Boolean iSuccess
    Handle hoSbContentType
    Boolean iCaseSensitive
    Boolean iInlineOnly
    Boolean iExcludeAttachments
    String sSearchSpec
    Integer iNumParts
    Integer i
    String sTextBody
    Handle hoAttachedEmail
    Variant vBdMime
    Handle hoBdMime
    Variant vBd
    Handle hoBd
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    // 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

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    Get ComLoadEml Of hoEmail "qa_data/eml/sample.eml" To iSuccess
    If (iSuccess = False) Begin
        Showln "Failed to load .eml"
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbContentType
    If (Not(IsComObjectCreated(hoSbContentType))) Begin
        Send CreateComObject of hoSbContentType
    End
    Move False To iCaseSensitive

    // 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)
    Move False To iInlineOnly
    Move False To iExcludeAttachments
    Move "*/*" To sSearchSpec

    Get ComGetNumPartsOfType Of hoEmail sSearchSpec iInlineOnly iExcludeAttachments To iNumParts
    Move 0 To i
    While (i < iNumParts)
        // What is the Content-Type of this MIME part?
        Get ComGetNthContentType Of hoEmail i sSearchSpec iInlineOnly iExcludeAttachments To sTemp1
        Get ComAppend Of hoSbContentType sTemp1 To iSuccess
        Get ComStartsWith Of hoSbContentType "text/" iCaseSensitive To bTemp1
        If (bTemp1 = True) Begin
            // Get the text body of this MIME part.
            Get ComGetNthTextPartOfType Of hoEmail i sSearchSpec iInlineOnly iExcludeAttachments To sTextBody
            Get ComGetAsString Of hoSbContentType To sTemp1
            Showln "Got text body for " sTemp1
        End
        Else Begin
            Get ComContentsEqual Of hoSbContentType "message/rfc822" iCaseSensitive To bTemp1
            If (bTemp1 = True) Begin
                // 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...
                Get Create (RefClass(cComChilkatEmail)) To hoAttachedEmail
                If (Not(IsComObjectCreated(hoAttachedEmail))) Begin
                    Send CreateComObject of hoAttachedEmail
                End
                Get Create (RefClass(cComChilkatBinData)) To hoBdMime
                If (Not(IsComObjectCreated(hoBdMime))) Begin
                    Send CreateComObject of hoBdMime
                End
                Get pvComObject of hoBdMime to vBdMime
                Get ComGetNthBinaryPartOfTypeBd Of hoEmail i sSearchSpec iInlineOnly iExcludeAttachments vBdMime To iSuccess
                Get pvComObject of hoBdMime to vBdMime
                Get ComSetFromMimeBd Of hoAttachedEmail vBdMime To iSuccess
                // Now your app can recursively process the attachedEmail...
            End
            Else Begin
                // Get the bytes of this MIME body part.
                Get Create (RefClass(cComChilkatBinData)) To hoBd
                If (Not(IsComObjectCreated(hoBd))) Begin
                    Send CreateComObject of hoBd
                End
                Get pvComObject of hoBd to vBd
                Get ComGetNthBinaryPartOfTypeBd Of hoEmail i sSearchSpec iInlineOnly iExcludeAttachments vBd To iSuccess
                Get ComGetAsString Of hoSbContentType To sTemp1
                Get ComNumBytes Of hoBd To iTemp1
                Showln "Got binary body for " sTemp1 " numBytes = " iTemp1
            End

        End

        Send ComClear To hoSbContentType
        Move (i + 1) To i
    Loop



End_Procedure

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.