IMCLIENT(3)
π IMCLIENT(3) β the Cyrus IMAP glow-up β¨
okay so bestie, we're diving into imclient, which is the Cyrus IMAP documentation's authenticating callback interface to IMAP servers. it's giving "build your own IMAP client" energy, and honestly? iconic. π
πΈ SYNOPSIS πΈ
#include <cyrus/imclient.h>
int imclient_connect(struct imclient **imclient , const char *host ,
const char *port);
void imclient_close (struct imclient *imclient);
void imclient_setflags(struct imclient *imclient , int flags);
void imclient_clearflags (struct imclient *imclient , int flags);
char* imclient_servername (struct imclient *imclient);
void imclient_addcallback (struct imclient *imclient,...);
void imclient_send (struct imclient *imclient, void (*finishproc)(),
void *finishrock, const char *fmt,...);
void imclient_getselectinfo (struct imclient *imclient, int * fd,
int * wanttowrite);
void imclient_processoneevent (struct imclient *imclient);
int imclient_authenticate (struct imclient *imclient,
struct sasl_client **availmech, const char *service,
const char *user, int protallowed);
int imclient_havetls ();
int imclient_starttls (struct imclient *imclient, char *cert_file,
char *key_file, char *CAfile, char *CApath);
π¦ DESCRIPTION π¦
so the imclient library functions ship with Cyrus IMAP, and they're literally what you use to build IMAP client software. they handle Kerberos authentication and can set callbacks based on the keyword in untagged replies or based on the command tag at the end of command replies. very demure, very mindful. π
bestie, listen: users must link with the -lcyrus switch, and must supply a function called fatal to be called in case of any error within libcyrus.la. no cap, that's non-negotiable.
all of the imclient functions begin with the prefix imclient and take an argument of type struct imclient * as the first argument, which is initialized by imclient_connect and freed by imclient_close. slay, consistent API design. β¨
see below for a description of each function, babe.
π«Ά imclient_connect()
connects the client server to the host. if successful, it returns 0 and sets the imclient argument to a pointer to an imclient struct. the imclient struct represents the current connection, flags, and callbacks. on failure, the current errno is returned if a system call failed, -1 is returned if the host name was not found, and -2 is returned if the service name was not found. so like, check your return values, bestie. π
π«Ά imclient_close()
closes and frees the imclient connection. bye bestie, it was real. π
π«Ά imclient_setflags()
sets the flags specified by the flags argument on the imclient connection. currently the only flag allowed is IMCLIENT_CONN_NONSYNCLITERAL (this flag indicates that the server supports non-synchronizing literals described by the LITERAL+ extension). one flag, one vibe. π
π«Ά imclient_clearflags()
clears the flags specified by the flags argument on the imclient connection. the opposite of set, obviously. π
π«Ά imclient_servername()
returns a char * pointer to the name of the server connected to by imclient. it's giving "who am i talking to rn". β¨
π«Ά imclient_addcallback()
adds an untagged data callback to the imclient connection. the function imclient_addcallback takes callbacks of the type imclient_proc_t which is defined to be:
typedef void imclient_proc_t (struct imclient *imclient, void *rock, struct imclient_reply *reply);
and struct imclient_reply * is defined to be:
struct imclient_reply {
char *keyword;
long msgno;
char *text;
};
after the first argument, imclient, there can be zero or more instances of the set of keyword, flags, proc, and rock, each adding or changing a single callback. each instance adds or changes the callback for keyword. the argument flags specifies information about the parsing of the untagged data. proc and rock specify the callback function and rock to invoke when the untagged data is received. proc may be a null pointer, in which case no function is invoked. the callback function may not call the functions imclient_close(), imclient_send(), imclient_eof(), imclient_processoneevent(), or imclient_authenticate() on the connection. no cap, do not do it. the callback function may overwrite the text of untagged data. π«Ά
π«Ά imclient_send()
sends a new command to the imclient connection. finishproc and finishrock are the function and rock called when the command completes. functionproc may be a null pointer, in which case no callback is made. the callback function may not call the functions imclient_close(), imclient_send(), imclient_eof(), imclient_processoneevent(), or imclient_authenticate() on the connection. again: no. do not. the argument fmt is a printf(3) like specification of the command. it must not include the tag as the tag is automatically added by imclient_send(). the tag is mother, let her handle it. π
the defined %-sequences are:
%%β for%%aβ for an IMAP atom%sβ for an astring (which will be quoted or literalized as needed)%dβ for a decimal%uβ for an unsigned decimal%vβ for#astring(argument is a null-terminated array ofchar *which are written as space separated astrings)
π«Ά imclient_getselectinfo()
gets the information for calling select(2). fd is filled in with the file descriptor to select(2) for read. wanttowrite is filled in with a nonzero value if select should be used for write as well. select(2) really said "i'm the main character". π
π«Ά imclient_processoneevent()
processes one input or output event on the imclient connection. one event at a time, bestie, we're not rushing. π¦
π«Ά imclient_authenticate()
authenticates the imclient connection using one of the mechanisms in availmech. the argument user, if not NULL, specifies the user to authenticate as. if the user is NULL, the current user is used. the argument protallowed is a bitmask of permissible protection mechanisms. on success, 0 is returned. on failure (i.e., "BAD" keyboard, or no authentication mechanisms worked), 1 is returned. on extreme failure (premature "OK"), 2 is returned. extreme failure is giving "we were so back and then it was over". ππ₯
π«Ά imclient_havetls()
returns a Boolean indicating whether the imclient library was compiled with TLS (SSL) support. if so, imclient_starttls() may be used to secure the IMAP connection. security check, bestie. πβ¨
π«Ά imclient_starttls()
issues a STARTTLS command on an existing IMAP connection and negotiates the secure link. the cert_file and key_file arguments specify the client certificate and secret key to use to authenticate ourselves to the server. if client authentication is not needed, set both of these arguments to NULL. π
the CAfile and CApath arguments specify a file or directory, respectively, of CA certificates for validating server certificates. (See SSL_CTX_load_verify_locations(3) for details.) if both of these are NULL, the client will be unable to validate the server's certificate, in which case the connection may succeed but a warning will be printed to stdout. ngl bestie, that's lowkey sketchy, keep an eye on that. π
π EXAMPLES π
the following code is a possible skeleton of imclient that relies on Kerberos to do authentication. this code performs an IMAP CAPABILITY request and prints out the result. it ate, fr fr. π
#include <cyrus/xmalloc.h> /* example uses xstrdup */
#include <cyrus/sasl.h>
#include <cyrus/imclient.h>
#include <stdio.h>
extern struct sasl_client krb_sasl_client;
struct sasl_client *login_sasl_client[] = {
&krb_sasl_client,
NULL
};
struct imclient *imclient;
char server[] = "cyrus.andrew.cmu.edu" ;
char port[] = "imap";
void fatal(char* message, int rc) {
fprintf(stderr, "fatal error: %s\en", message);
exit(rc);
}
static void callback_capability(struct imclient *imclient,
void *rock,
struct imclient_reply *reply) {
if (reply->text != NULL) {
*((char**)rock) = xstrdup( reply->text );
}
}
static void end_command(struct imclient *connection, void*
rock, struct imclient_reply *inmsg) {
(*(int*)rock)--;
}
main() {
char* capability_string;
int nc;
if (imclient_connect(&imclient, server, port)) {
fprintf(stderr,
"error: Couldn't connect to %s %s\en",
server, port);
exit(1);
}
if (imclient_authenticate(imclient, login_sasl_client, "imap"
/* service */,
NULL /* user */, SASL_PROT_ANY)) {
exit(1);
}
imclient_addcallback(imclient, "CAPABILITY",
CALLBACK_NOLITERAL,
callback_capability,
&capability_string,
NULL);
nc = 1;
imclient_send(imclient, end_command,
(void*) &nc, "CAPABILITY");
while(nc > 0) {
imclient_processoneevent(imclient);
}
if (strstr("LITERAL+", capability_string)) {
imclient_setflags(imclient, IMCLIENT_CONN_NONSYNCLITERAL);
}
imclient_send(imclient, NULL, NULL, "LOGOUT");
imclient_close(imclient);
printf("capability text is: %s\en", capability_string);
free(capability_string);
}
π BUGS π
no known bugs. periodt. we love a clean bug section. π β¨
π₯ SEE ALSO π₯
cyradm(8), imapd(8), RFC 2033 (IMAP LITERAL+ extension), RFC 2060 (IMAP4rev1 specification), and select(2). go read up, bestie, iykyk. π«Ά
π KEYWORDS π
IMAP, ACAP, Kerberos, Authentication. π
πΈ AUTHOR πΈ
The Cyrus Team, Nic Bernstein (Onlight). thank you for your service. π«Ά
π¦ COPYRIGHT π¦
1993β2026, The Cyrus Team. iconic longevity, no cap. π
okay that's the whole page, bestie! β¨ this is version 3.12.3, dated Jul 15, 2026, coming at you from IMCLIENT(3) on the Cyrus IMAP system. now go build something slay with it! ππ
π
π¦ where this page comes from
- ubuntu stonking: cyrus-dev 3.12.3-3build1 Β· CMU
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms