Sample code for 30+ languages & platforms
Zig

Unpack HTML Email to Files

Unpacks an HTML email into an HTML file and related files (images and style sheets). The links within the HTML are updated to point to the files unpacked and saved to disk.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const email = try chilkat.Email.init();
    defer email.deinit();

    email.loadEml("qa_data/eml/happyHour.eml") catch {
        std.debug.print("{s}\n", .{try email.getLastErrorText(alloc)});
        return;
    };

    // Is this an HTML email?
    if (email.hasHtmlBody()) {
        // Unpack the HTML to files.  The image and css URLs
        // in the HTML are modified to point to the files extracted to disk.
        const unpack_dir = "qa_output/emails";
        const parts_subdir = "images";
        const html_filename = "happyHour.html";
        email.unpackHtml(unpack_dir, html_filename, parts_subdir) catch {
            std.debug.print("{s}\n", .{try email.getLastErrorText(alloc)});
            return;
        };

        std.debug.print("Success.\n", .{});
    }
}