Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loMime
LOCAL n
LOCAL i
LOCAL lcFieldName
LOCAL lcFieldValue

lnSuccess = 0

loMime = CreateObject('Chilkat.Mime')
lnSuccess = loMime.LoadMimeFile("qa_data/message.eml")
IF (lnSuccess = 0) THEN
    ? loMime.LastErrorText
    RELEASE loMime
    CANCEL
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 = loMime.NumHeaderFields

FOR i = 0 TO n - 1
    lcFieldName = loMime.GetHeaderFieldName(i)
    IF (loMime.LastMethodSuccess = 0) THEN
        ? loMime.LastErrorText
        RELEASE loMime
        CANCEL
    ENDIF

    lcFieldValue = loMime.GetHeaderFieldValue(i)
    IF (loMime.LastMethodSuccess = 0) THEN
        ? loMime.LastErrorText
        RELEASE loMime
        CANCEL
    ENDIF

    ? lcFieldName + ": " + lcFieldValue
NEXT

RELEASE loMime