Zig
Zig
Refresh an Email Object's IMAP Flags
See more IMAP Examples
Demonstrates the Chilkat Imap.RefetchMailFlags method, which updates the flags stored on an Email object to the current values on the server. The only argument is the Email object. This example re-reads the flags for a previously fetched message and then checks its Seen state.
Background: Flags are shared mailbox state, so between the time you fetch a message and the time you act on it, another client (a phone, a webmail tab) may have marked it read, flagged, or deleted.
RefetchMailFlags pulls just the flags — not the whole message — so a long-running job can cheaply re-check the live state before deciding what to do, avoiding acting on stale information.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.RefetchMailFlags method, which updates the flags stored on an Email
// object to the current values on the server. The only argument is the Email object.
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;
};
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;
};
const bundle = try chilkat.EmailBundle.init();
defer bundle.deinit();
imap.fetchMsgSet(true, msg_set, bundle) catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
const email = try chilkat.Email.init();
defer email.deinit();
if (bundle.getMessageCount() > 0) {
try bundle.emailAt(0, email);
// Re-read the flags from the server, in case another client changed them since the fetch.
imap.refetchMailFlags(email) catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
const seen = imap.getMailFlag(email, "Seen");
std.debug.print("Current Seen state: {d}\n", .{seen});
}
imap.disconnect() catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
}