Sample code for 30+ languages & platforms
Zig

Download the Full Version of a Partial Email

See more POP3 Examples

Demonstrates the Chilkat MailMan.FetchFull method, which downloads the complete version of a header-only or partial Email and stores it in a second Email. The full result includes the complete body and any attachments, and the partial email must retain its UIDL. This example previews message 1 (headers only) and then downloads it in full.

Background: A common pattern is to download headers first — cheap and fast — show the user a message list, and only pull the full content when a message is actually opened. FetchFull completes that "download on demand" flow: given a partial email (which carries its UIDL), it fetches the rest from the server. This keeps bandwidth and latency low when browsing a large mailbox.

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();

    // Demonstrates the MailMan.FetchFull method, which downloads the complete version of a
    // header-only or partial Email and stores it in a second Email.  The full result includes
    // the complete body and any attachments.  The partial email must retain its UIDL.

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

    // Configure the POP3 server connection.
    mailman.setMailHost("pop.example.com");
    mailman.setMailPort(995);
    mailman.setPopSsl(true);
    mailman.setPopUsername("user@example.com");
    mailman.setPopPassword("myPassword");

    // First fetch message 1 as headers only (a fast preview).  headerOnly=true.
    const partial_email = try chilkat.Email.init();
    defer partial_email.deinit();

    mailman.fetchOne(true, 0, 1, partial_email) catch {
        std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Preview subject: {s}\n", .{try partial_email.getSubject(alloc)});

    // Now download the complete message (body and attachments).
    const full_email = try chilkat.Email.init();
    defer full_email.deinit();
    mailman.fetchFull(partial_email, full_email) catch {
        std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Full email NumAttachments: {d}\n", .{full_email.getNumAttachments()});

    // Note: Explicitly connecting/authenticating is optional.  Chilkat MailMan automatically
    // connects and authenticates -- using the property settings above -- whenever a server
    // operation requires it.  Calling the explicit connect/authenticate methods can still be
    // helpful to determine whether a failure occurs while connecting or while authenticating.
}