Zig
Zig
Embed a Message as message/rfc822
See more MIME Examples
Demonstrates the Chilkat Mime.NewMessageRfc822 method, which clears the object and initializes it as a message/rfc822 entity whose body is a serialized copy of another Mime. The only argument is the message to embed.
Background:
message/rfc822 wraps a whole email as the body of another — the mechanism behind forwarding a message "as attachment" or bundling one message inside another. The inner message is copied at the time of the call, so later edits to the source do not change the embedded copy. The result is a self-contained part a mail client will present as a nested message.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.NewMessageRfc822 method, which clears the current object and initializes
// it as a message/rfc822 entity whose body is a serialized copy of another Mime. The only
// argument is the Mime to embed.
// Build the inner message to embed.
const inner_msg = try chilkat.Mime.init();
defer inner_msg.deinit();
inner_msg.setHeaderField("Subject", "Forwarded message") catch {
std.debug.print("{s}\n", .{try inner_msg.getLastErrorText(alloc)});
return;
};
inner_msg.setBodyFromPlainText("This is the original message being forwarded.") catch {
std.debug.print("{s}\n", .{try inner_msg.getLastErrorText(alloc)});
return;
};
// Wrap it as message/rfc822 (an embedded/forwarded email).
const mime = try chilkat.Mime.init();
defer mime.deinit();
mime.newMessageRfc822(inner_msg) catch {
std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
return;
};
std.debug.print("Content-Type: {s}\n", .{try mime.getContentType(alloc)});
}