Sample code for 30+ languages & platforms
Zig

Clear the S/MIME Recipient Certificate List

See more MIME Examples

Demonstrates ClearEncryptCerts, which empties the recipient-certificate list previously populated by AddEncryptCert. This is useful to start over with a different set of recipients before calling EncryptN.

Background. The recipient list is internal state that accumulates across AddEncryptCert calls. ClearEncryptCerts resets it so a subsequent EncryptN encrypts only for the certificates added afterward.

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();

    const mime = try chilkat.Mime.init();
    defer mime.deinit();
    mime.setBodyFromPlainText("This message will be encrypted.") catch {
        std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
        return;
    };

    // Add a recipient certificate.
    const cert = try chilkat.Cert.init();
    defer cert.deinit();
    cert.loadFromFile("qa_data/recipient.cer") catch {
        std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
        return;
    };

    mime.addEncryptCert(cert) catch {
        std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
        return;
    };

    // ClearEncryptCerts empties the recipient-certificate list, for example to start over with a
    // different set of recipients before calling EncryptN.  It is a void method.
    mime.clearEncryptCerts();

    std.debug.print("Recipient certificate list cleared.\n", .{});
}