Sample code for 30+ languages & platforms
PureBasic

Iterate Email Headers

Demonstrates how to iterate over the email header fields.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkEmail.pb"

Procedure ChilkatExample()

    success.i = 0

    email.i = CkEmail::ckCreate()
    If email.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; First, load an email from a file. 
    ; Note: an email object may be loaded from a file, or
    ; downloaded directly from a POP3 or IMAP server...

    success = CkEmail::ckLoadEml(email,"testReceivedHdrs.eml")
    If success <> 1
        Debug CkEmail::ckLastErrorText(email)
        CkEmail::ckDispose(email)
        ProcedureReturn
    EndIf

    ; How many header fields?
    n.i
    n = CkEmail::ckNumHeaderFields(email)
    If n > 0

        ; Display the name and value of each header:
        i.i
        name.s
        value.s
        For i = 0 To n - 1
            name = CkEmail::ckGetHeaderFieldName(email,i)
            value = CkEmail::ckGetHeaderFieldValue(email,i)
            Debug Str(i)
            Debug name
            Debug value

        Next

    EndIf



    CkEmail::ckDispose(email)


    ProcedureReturn
EndProcedure