Sample code for 30+ languages & platforms
Zig

Send an IMAP NOOP Command

See more IMAP Examples

Demonstrates the Chilkat Imap.Noop method, which sends the IMAP NOOP command and waits for the server response. It is useful for verifying that an existing authenticated connection is still responsive, and for keeping the connection alive. This example connects, logs in, and sends a NOOP.

Background: Because NOOP makes an actual round trip to the server, a successful reply proves the connection is genuinely alive — something the cached IsConnected cannot. It doubles as a keep-alive to prevent an idle session from timing out. In IMAP, NOOP also gives the server a chance to report changes in the selected mailbox, such as newly-arrived messages.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // Demonstrates the Imap.Noop method, which sends the IMAP NOOP command and waits for the
    // server response.  It is useful for verifying that an existing authenticated connection is
    // still responsive and for keeping the connection alive.

    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;
    };

    // Send a NOOP round trip to confirm the connection is alive.
    imap.noop() catch {
        std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("IMAP NOOP succeeded.\n", .{});

    imap.disconnect() catch {
        std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
        return;
    };
}