Zig Requires Chilkat v11.0.0+
Zig
Parsing a Multipart/Digest Email
See more Email Object Examples
This example demonstrates how to parse a multipart/digest email. An email parsed by this sample could have a MIME structure as follows:
multipart/mixed
text/plain
text/plain
multipart/digest
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
message/rfc822
text/plain
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 eml_path = "qa_data/eml/multipart_digest.eml";
const email = try chilkat.Email.init();
defer email.deinit();
// For this example, we'll load the email from a .eml.
// The email could alternatively be loaded as a result of downloading from an IMAP or POP3 server..
email.loadEml(eml_path) catch {
std.debug.print("{s}\n", .{try email.getLastErrorText(alloc)});
return;
};
const num_digests = email.getNumDigests();
std.debug.print("num digests = {d}\n", .{num_digests});
const e_digest = try chilkat.Email.init();
defer e_digest.deinit();
var i: i32 = 0;
while (i < num_digests) {
email.getDigestEmail(i, e_digest) catch {};
std.debug.print("{d}:{s}, {s}\n", .{ i, try e_digest.getFromAddress(alloc), try e_digest.getSubject(alloc) });
if (e_digest.getHeaderField(alloc, "Message")) |m| {
std.debug.print(" Message = {s}\n", .{m});
} else |_| {}
i = i + 1;
}
}