Zig
Zig
Store One or More Flags on a Single Message
See more IMAP Examples
Demonstrates the Chilkat Imap.StoreFlags method, which sets or clears one or more flags on a single message identified by ID. The first argument is the message ID, the second (bUid) selects UID vs sequence number, the third is a space-separated list of flag names, and the fourth is the value (1 to set, 0 to clear). This example applies the Seen and Flagged flags to one message by UID.
Background:
StoreFlags is the single-message counterpart to SetFlags and lets you change several flags at once by listing them space-separated (without leading backslashes). Because the ID can be either a UID or a sequence number, the bUid argument must match how you obtained it — a UID from a UID search, or a sequence number from a sequence-based operation. UIDs are the safer choice since they remain valid as the mailbox changes.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.StoreFlags method, which sets or clears one or more flags on a single
// message identified by ID. The 1st argument is the message ID, the 2nd (bUid) selects UID
// vs sequence number, the 3rd is a space-separated list of flag names, and the 4th is the
// value (1 to set, 0 to clear).
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;
};
imap.selectMailbox("Inbox") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// Get the UIDs of all messages.
const msg_set = try chilkat.MessageSet.init();
defer msg_set.deinit();
imap.queryMbx("ALL", true, msg_set) catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
if (msg_set.getCount() > 0) {
// Apply the Seen and Flagged flags to the first message. bUid is true because the ID
// came from a UID search.
const uid = msg_set.getId(0);
imap.storeFlags(uid, true, "Seen Flagged", 1) catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
std.debug.print("Updated flags on UID {d}\n", .{uid});
}
imap.disconnect() catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
}