Sample code for 30+ languages & platforms
Zig

Load Emails from a .mbx Mailbox File

See more POP3 Examples

Demonstrates the Chilkat MailMan.LoadMbxFile method, which loads emails from a .mbx mailbox file and stores them in an EmailBundle. If a filter has been configured, only the matching emails are returned. This example loads a local mailbox file and iterates the resulting bundle.

Background: An .mbx file is a single-file mailbox format that stores many messages concatenated together — historically produced by Outlook Express and similar clients. LoadMbxFile parses that archive into individual Email objects, which is useful for importing, migrating, or analyzing old mail without any server connection. No POP3 or SMTP session is involved — this reads purely from disk.

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.LoadMbxFile method, which loads emails from a .mbx mailbox file
    // and stores them in an EmailBundle.  If a filter has been configured, only the matching
    // emails are returned.

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

    // Load emails from a local .mbx mailbox file (no server connection is made).
    const bundle = try chilkat.EmailBundle.init();
    defer bundle.deinit();

    mailman.loadMbxFile("qa_data/mbx/inbox.mbx", bundle) catch {
        std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
        return;
    };

    const n = bundle.getMessageCount();
    std.debug.print("Loaded {d} emails from the .mbx file.\n", .{n});

    const email = try chilkat.Email.init();
    defer email.deinit();
    var i: i32 = 0;
    i = 0;
    while (i < n) : (i += 1) {
        try bundle.emailAt(i, email);
        std.debug.print("{s}\n", .{try email.getSubject(alloc)});
    }

    // Note: The path "qa_data/mbx/inbox.mbx" is a relative local filesystem path,
    // relative to the current working directory of the running application.
}