Sample code for 30+ languages & platforms
DataFlex

Parsing a Multipart/Digest Email

See more Email Object Examples

This example demonstrates how to parse a multipart/digest email. An email parsed by this sample could have a MIME structure as follows:
multipart/mixed
    text/plain
    text/plain
    multipart/digest
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
        message/rfc822
    text/plain

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    String sEmlPath
    Handle hoEmail
    Integer iNumDigests
    Variant vEDigest
    Handle hoEDigest
    Integer i
    String m
    String sTemp1
    String sTemp2
    Boolean bTemp1

    Move False To iSuccess

    Move "qa_data/eml/multipart_digest.eml" To sEmlPath

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

    // For this example, we'll load the email from a .eml.
    // The email could alternatively be loaded as a result of downloading from an IMAP or POP3 server..

    Get ComLoadEml Of hoEmail sEmlPath To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComNumDigests Of hoEmail To iNumDigests
    Showln "num digests = " iNumDigests

    Get Create (RefClass(cComChilkatEmail)) To hoEDigest
    If (Not(IsComObjectCreated(hoEDigest))) Begin
        Send CreateComObject of hoEDigest
    End
    Move 0 To i
    While (i < iNumDigests)
        Get pvComObject of hoEDigest to vEDigest
        Get ComGetDigestEmail Of hoEmail i vEDigest To iSuccess
        Get ComFromAddress Of hoEDigest To sTemp1
        Get ComSubject Of hoEDigest To sTemp2
        Showln i ":" sTemp1 ", " sTemp2
        Get ComGetHeaderField Of hoEDigest "Message" To m
        Get ComLastMethodSuccess Of hoEDigest To bTemp1
        If (bTemp1 = True) Begin
            Showln "    Message = " m
        End

        Move (i + 1) To i
    Loop



End_Procedure