Zig Requires Chilkat v11.0.0+
Zig
Find the "Sent" IMAP Mailbox
See more IMAP Examples
Find the "Sent" IMAP mailbox. Also finds the Junk and Trash mailboxes..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 assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const imap = try chilkat.Imap.init();
defer imap.deinit();
imap.setSsl(true);
imap.setPort(993);
imap.connect("imap.yourmailserver.com") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// Login or authenticate in some way..
imap.login("your_login", "your_password") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// Get the list of mailboxes.
const ref_name = "";
const wildcarded_mailbox = "*";
const subscribed = false;
const mboxes = try chilkat.Mailboxes.init();
defer mboxes.deinit();
imap.mbxList(subscribed, ref_name, wildcarded_mailbox, mboxes) catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// The mailbox with the "/Sent" flag is the "Sent" mailbox.
// Likewise for Junk and Trash..
var i: i32 = 0;
while (i < mboxes.getCount()) {
if (mboxes.hasFlag(i, "\\Sent")) {
std.debug.print("Sent mailbox: {s}\n", .{try mboxes.getName(alloc, i)});
}
if (mboxes.hasFlag(i, "\\Junk")) {
std.debug.print("Junk mailbox: {s}\n", .{try mboxes.getName(alloc, i)});
}
if (mboxes.hasFlag(i, "\\Trash")) {
std.debug.print("Trash mailbox: {s}\n", .{try mboxes.getName(alloc, i)});
}
i = i + 1;
}
// Disconnect from the IMAP server.
try imap.disconnect();
}