Zig
Zig
Get an Alternative Body into a BinData
See more Email Object Examples
Demonstrates the Chilkat Email.GetAlternativeBodyBd method, which copies the contents of the Nth alternative body into a BinData object. The first alternative body is at index 0, and it should only be called when NumAlternatives is greater than 0. This example builds a message with plain-text and HTML alternatives and copies the first into a BinData.
Background: This is the binary counterpart to
GetAlternativeBody (which returns text). Reading an alternative into a BinData preserves the exact bytes — important when a body part uses a binary or unusual transfer encoding, or when you intend to hash it or write it out verbatim rather than decode it to a string.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 GetAlternativeBodyBd method, which copies the contents of the Nth
// alternative body into a BinData object. The first alternative body is at index 0; call
// only when NumAlternatives is greater than 0.
const email = try chilkat.Email.init();
defer email.deinit();
email.setSubject("GetAlternativeBodyBd example");
email.setTextBody("This is the plain-text alternative.", "text/plain");
email.addHtmlAlternativeBody("<html><body>This is the HTML alternative.</body></html>") catch {};
// Copy the first alternative body (index 0) into a BinData object.
const bd = try chilkat.BinData.init();
defer bd.deinit();
email.getAlternativeBodyBd(0, bd) catch {
std.debug.print("{s}\n", .{try email.getLastErrorText(alloc)});
return;
};
std.debug.print("Alternative 0 size (bytes) = {d}\n", .{bd.getNumBytes()});
}