Zig
Zig
Serialize MIME to a StringBuilder
See more MIME Examples
Demonstrates the Chilkat Mime.GetMimeSb method, which serializes the complete MIME entity and appends it to a StringBuilder. The only argument is the StringBuilder; existing content is preserved.
Background: Serializing into a
StringBuilder avoids creating a new string and is convenient when you are accumulating output or building a larger document. Because it appends, you can assemble several pieces in one buffer. As with GetMime, use the BinData form for content with arbitrary binary bytes.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// Demonstrates the Mime.GetMimeSb method, which serializes the complete MIME entity and appends
// it to a StringBuilder. The only argument is the StringBuilder.
const mime = try chilkat.Mime.init();
defer mime.deinit();
mime.setBodyFromPlainText("Hello, this is the message body.") catch {
std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
return;
};
// Append the serialized MIME to a StringBuilder. Existing content is preserved.
const sb = try chilkat.StringBuilder.init();
defer sb.deinit();
mime.getMimeSb(sb) catch {
std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
return;
};
std.debug.print("{s}\n", .{try sb.getAsString(alloc)});
}