Sample code for 30+ languages & platforms
Xbase++

Enumerate MIME Header Field Values

See more MIME Examples

Demonstrates the Chilkat Mime.GetHeaderFieldValue method, which returns the unfolded value of the header-field occurrence at a zero-based index. The only argument is the index. Continuation (folded) lines are combined into a single value.

Note: The file path is relative to the application's current working directory. Absolute paths may also be used. Supply the path to your own file.

Background: Paired with GetHeaderFieldName, this lets you list every header as name/value pairs, including duplicates. A useful detail is unfolding: long headers are wrapped across multiple physical lines in the raw message, and this recombines them into the single logical value the header actually represents, so you never have to reassemble continuation lines yourself.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oMime
LOCAL n
LOCAL i
LOCAL cFieldName
LOCAL cFieldValue

nSuccess := 0

oMime := CreateObject("Chilkat.Mime")
nSuccess := oMime:LoadMimeFile("qa_data/message.eml")
IF (nSuccess == 0)
    ? oMime:LastErrorText
    oMime:destroy()
    RETURN
ENDIF

//  Iterate the header fields by index and print each name and unfolded value.  Continuation lines
//  (folded headers) are combined into a single value.
n := oMime:NumHeaderFields

FOR i := 0 TO n - 1
    cFieldName := oMime:GetHeaderFieldName(i)
    IF (oMime:LastMethodSuccess == 0)
        ? oMime:LastErrorText
        oMime:destroy()
        RETURN
    ENDIF

    cFieldValue := oMime:GetHeaderFieldValue(i)
    IF (oMime:LastMethodSuccess == 0)
        ? oMime:LastErrorText
        oMime:destroy()
        RETURN
    ENDIF

    ? cFieldName + ": " + cFieldValue
NEXT

oMime:destroy()