Sample code for 30+ languages & platforms
Xbase++

Iterate Email Headers

Demonstrates how to iterate over the email header fields.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oEmail
LOCAL n
LOCAL i
LOCAL cName
LOCAL cValue

nSuccess := 0

oEmail := CreateObject("Chilkat.Email")

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

nSuccess := oEmail:LoadEml("testReceivedHdrs.eml")
IF (nSuccess != 1)
    ? oEmail:LastErrorText
    oEmail:destroy()
    RETURN
ENDIF

//  How many header fields?

n := oEmail:NumHeaderFields
IF (n > 0)

    //  Display the name and value of each header:

    FOR i := 0 TO n - 1
        cName := oEmail:GetHeaderFieldName(i)
        cValue := oEmail:GetHeaderFieldValue(i)
        ? Str(i)
        ? cName
        ? cValue

    NEXT

ENDIF

oEmail:destroy()