Sample code for 30+ languages & platforms
Zig

Send a Raw IMAP Command

See more IMAP Examples

Demonstrates the Chilkat Imap.SendRawCommand method, which sends raw IMAP command text and returns the raw server response. Pass the command itself (such as NOOP) without an IMAP tag — Chilkat adds the tag automatically. This example sends a raw NOOP.

Background: Every IMAP command a client sends is prefixed with a short unique tag (like a001) so the client can match the tagged completion response to the command it issued. SendRawCommand handles that tagging for you and returns the server's reply verbatim — an escape hatch for issuing a command Chilkat doesn't wrap directly, or a server-specific extension, without leaving the established authenticated session.

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.SendRawCommand method, which sends raw IMAP command text and returns
    // the raw server response.  Pass the command itself (such as NOOP) without an IMAP tag --
    // Chilkat adds the tag automatically.

    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 raw IMAP command and read the raw response.
    const response = imap.sendRawCommand(alloc, "NOOP") catch {
        std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("{s}\n", .{response});

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