Sample code for 30+ languages & platforms
Lua

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 Lua Downloads

Lua
local chilkat = require("chilkat")

local mime = chilkat.Mime.new()
local success = mime:load_mime_file("qa_data/message.eml")
if not success then
    print(mime.last_error_text)
    return
end

-- Iterate the header fields by index and print each name and unfolded value.  Continuation lines
-- (folded headers) are combined into a single value.
local n = mime.num_header_fields
for i = 0, n - 1 do
    local fieldName = mime:get_header_field_name(i)
    if not mime.last_method_success then
        print(mime.last_error_text)
        return
    end

    local fieldValue = mime:get_header_field_value(i)
    if not mime.last_method_success then
        print(mime.last_error_text)
        return
    end

    print(fieldName .. ": " .. fieldValue)
end