Zig Requires Chilkat v11.0.0+
Zig
Download POP3 Email to MIME
Download the email from a POP3 mailbox directly into MIME, without parsing into email objects.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The mailman object is used for receiving (POP3)
// and sending (SMTP) email.
const mailman = try chilkat.MailMan.init();
defer mailman.deinit();
// Set the POP3 server's hostname
mailman.setMailHost("pop.example.com");
// Set the POP3 login/password.
mailman.setPopUsername("myLogin");
mailman.setPopPassword("myPassword");
// First, get the complete set of UIDLs for the email in the POP3 mailbox:
const st_uidls = try chilkat.StringTable.init();
defer st_uidls.deinit();
mailman.fetchUidls(st_uidls) catch {
std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
return;
};
// Download each email as MIME.
// If desired, the MIME can be loaded into an email object.
const bd_mime = try chilkat.BinData.init();
defer bd_mime.deinit();
const email = try chilkat.Email.init();
defer email.deinit();
const count = st_uidls.getCount();
var i: i32 = 0;
while (i < count) {
mailman.fetchMimeBd(try st_uidls.stringAt(alloc, i), bd_mime) catch {
std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
return;
};
email.setFromMimeBd(bd_mime) catch {};
std.debug.print("From: {s}\n", .{try email.getFrom(alloc)});
std.debug.print("Subject: {s}\n", .{try email.getSubject(alloc)});
i = i + 1;
}
}