Sample code for 30+ languages & platforms
Zig Requires Chilkat v11.0.0+

Retrieve UIDL's from POP3 Server

Retrieve a list of UIDLs from a POP3 server. UIDLs are unique identifiers, 1 to 70 characters long, composed of characters ranging from 0x21 to 0x7E. These identifiers uniquely distinguish messages within a mailbox and remain consistent across sessions.

Chilkat Zig Downloads

Zig
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.

    const mailman = try chilkat.MailMan.init();
    defer mailman.deinit();

    mailman.setMailHost("pop.example.com");

    mailman.setPopUsername("myLogin");
    mailman.setPopPassword("myPassword");

    mailman.setMailPort(995);
    mailman.setPopSsl(true);

    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 by UIDL.
    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.
        const uidl = try st_uidls.stringAt(alloc, i);
        mailman.fetchByUidl(uidl, false, 0, email) catch {
            std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
            return;
        };

        std.debug.print("{d}\n", .{i});
        std.debug.print("UIDL: {s}\n", .{uidl});
        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 {};
}