Zig
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const mime = try chilkat.Mime.init();
defer mime.deinit();
mime.loadMimeFile("qa_data/message.eml") catch {
std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
return;
};
// Iterate the header fields by index and print each name and unfolded value. Continuation lines
// (folded headers) are combined into a single value.
const n = mime.getNumHeaderFields();
var i: i32 = 0;
i = 0;
while (i < n) : (i += 1) {
const field_name = mime.getHeaderFieldName(alloc, i) catch {
std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
return;
};
const field_value = mime.getHeaderFieldValue(alloc, i) catch {
std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
return;
};
std.debug.print("{s}: {s}\n", .{ field_name, field_value });
}
}