Zig Requires Chilkat v11.0.0+
Zig
Download POP3 Email using UIDLs
Demonstrates how to download POP3 email by first getting the complete set of UIDLs and then downloading email by calling FetchByUIDL for each UIDL.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");
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;
};
const email = try chilkat.Email.init();
defer email.deinit();
const count = st_uidls.getCount();
var i: i32 = 0;
while (i < count) {
// Download the full email.
mailman.fetchByUidl(try st_uidls.stringAt(alloc, i), false, 0, email) catch {
std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
return;
};
std.debug.print("{d}\n", .{i});
std.debug.print("From: {s}\n", .{try email.getFrom(alloc)});
std.debug.print("Subject: {s}\n", .{try email.getSubject(alloc)});
i = i + 1;
}
mailman.pop3EndSession() catch {};
}