Zig
Zig
Check for IMAP IDLE Mailbox Updates
See more IMAP Examples
Demonstrates the Chilkat Imap.IdleCheck method, which waits for mailbox updates after IdleStart has entered IDLE mode. The only argument is a timeout in milliseconds; 0 performs a non-blocking poll of notifications already received. This example waits up to 30 seconds.
Background:
IdleCheck consumes the notifications already waiting on the connection rather than sending a new polling command. A typical monitoring loop repeatedly calls IdleCheck with a timeout and reacts when updates arrive. Because servers usually drop an idle connection after about 29 minutes, long-lived monitors periodically call IdleDone and then IdleStart again to refresh 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.IdleCheck method, which waits for IMAP IDLE mailbox updates and returns
// them. The only argument is a timeout in milliseconds. Use 0 for a non-blocking poll.
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;
};
imap.idleStart() catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// Wait up to 30 seconds for mailbox updates. IdleCheck returns a string, so assign it to a
// string variable and check for success.
const timeout_ms = 30000;
const updates = imap.idleCheck(alloc, timeout_ms) catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
std.debug.print("{s}\n", .{updates});
imap.idleDone() catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
imap.disconnect() catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
}