Zig
Zig
Copy an IMAP Message to Another Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.Copy method, which copies one message from the currently selected mailbox to a destination mailbox. The first argument identifies the source message; the second (bUid) indicates whether the id is a UID (true) or a sequence number (false). This example copies a message from the Inbox to another mailbox.
Background: Messages can be identified two ways in IMAP: a sequence number (the message's current 1-based position, which shifts as messages are added or expunged) or a UID (a stable identifier that doesn't change). The
bUid flag tells Copy which you're passing. Copying leaves the original in place and places a duplicate in the destination — use MoveMessages to relocate instead of duplicate.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// Demonstrates the Imap.Copy method, which copies one message from the currently selected
// mailbox to a destination mailbox. The 1st argument identifies the source message; the 2nd
// (bUid) indicates whether the id is a UID (true) or a sequence number (false).
const imap = try chilkat.Imap.init();
defer imap.deinit();
imap.setSsl(true);
imap.setPort(993);
imap.connect("imap.example.com") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
imap.login("user@example.com", "myPassword") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// Select the source mailbox.
imap.selectMailbox("Inbox") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// Copy message sequence number 1 to the "Archive2026" mailbox. bUid = false means the id
// is a sequence number, not a UID.
imap.copy(1, false, "Archive2026") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
std.debug.print("Message copied.\n", .{});
imap.disconnect() catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
}