Zig
Zig
Expunge Deleted Messages from a Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.Expunge method, which permanently removes all messages marked with the \Deleted flag from the currently selected mailbox. The mailbox remains selected. This example marks a message deleted with SetFlag and then expunges.
Background: IMAP deletion is two-phase, much like POP3. First a message is marked with the
\Deleted flag (it still exists, just tagged); then EXPUNGE permanently removes every flagged message and renumbers the rest. Splitting the two steps lets a client mark several messages and remove them together, or unmark (undelete) before committing. Expunge keeps the mailbox selected; ExpungeAndClose does the same and then closes it.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.Expunge method, which permanently removes all messages marked with
// the \Deleted flag from the currently selected mailbox. The mailbox remains selected.
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 mailbox to operate on.
imap.selectMailbox("Inbox") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// Mark message (sequence number 1) with the \Deleted flag. The 4th argument (1) sets the
// flag; the 2nd argument (false) means the id is a sequence number, not a UID.
imap.setFlag(1, false, "\\Deleted", 1) catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// Permanently remove all \Deleted messages from the selected mailbox.
imap.expunge() catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
std.debug.print("Expunged the deleted messages.\n", .{});
imap.disconnect() catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
}