Zig
Zig
Use an XML Certificate Vault with IMAP
See more IMAP Examples
Demonstrates the Chilkat Imap.UseCertVault method, which associates an XmlCertVault with the Imap object as a source of certificates and private keys for S/MIME operations. The only argument is the vault. Only one vault is associated at a time.
Note: The certificate path is relative to the application's current working directory. Supply the path to your own certificate file.
Background: An
XmlCertVault is a portable container that can hold multiple certificates and keys in a single (optionally password-protected) XML file. It is a convenient way to ship the exact set of credentials an application needs without depending on the operating system's certificate stores. Associating a vault makes all of its contents available for S/MIME decryption and signature verification.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.UseCertVault method, which associates an XmlCertVault with the Imap
// object as a source of certificates and private keys for S/MIME operations. The only
// argument is the XmlCertVault.
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;
};
// The PFX password is not hard-coded in source. Insert code here to obtain it from an
// interactive prompt, environment variable, or a secrets vault.
const pfx_password: [:0]const u8 = "";
// Build a certificate vault and add a PFX to it.
const vault = try chilkat.XmlCertVault.init();
defer vault.deinit();
vault.addPfxFile("qa_data/smime.pfx", pfx_password) catch {
std.debug.print("{s}\n", .{try vault.getLastErrorText(alloc)});
return;
};
// Associate the vault with the Imap object. Only one vault is associated at a time.
imap.useCertVault(vault) catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
imap.disconnect() catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
}