.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "IMCLIENT" "3" "Mar 18, 2024" "3.10.0" "Cyrus IMAP" .SH NAME imclient \- Cyrus IMAP documentation .sp Authenticating callback interface to IMAP servers .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C #include \fBint imclient_connect(struct imclient **\fP\fIimclient\fP \fB, const char *\fP\fIhost\fP \fB, const char *\fP\fIport\fP\fB);\fP \fBvoid imclient_close (struct imclient *\fP\fIimclient\fP\fB);\fP \fBvoid imclient_setflags(struct imclient *\fP\fIimclient\fP \fB, int\fP \fIflags\fP\fB);\fP \fBvoid imclient_clearflags (struct imclient *\fP\fIimclient\fP \fB, int\fP \fIflags\fP\fB);\fP \fBchar* imclient_servername (struct imclient *\fP\fIimclient\fP\fB);\fP \fBvoid imclient_addcallback (struct imclient *\fP\fIimclient\fP,...\fB);\fP \fBvoid imclient_send (struct imclient *\fP\fIimclient\fP\fB, void (*\fP\fIfinishproc\fP\fB)(), void *\fP\fIfinishrock\fP\fB, const char *\fP\fIfmt\fP,...\fB);\fP \fBvoid imclient_getselectinfo (struct imclient *\fP\fIimclient\fP\fB, int *\fP \fIfd\fP\fB, int *\fP \fIwanttowrite\fP\fB);\fP \fBvoid imclient_processoneevent (struct imclient *\fP\fIimclient\fP\fB);\fP \fBint imclient_authenticate (struct imclient *\fP\fIimclient\fP\fB, struct sasl_client **\fP\fIavailmech\fP\fB, const char *\fP\fIservice\fP\fB, const char *\fP\fIuser\fP\fB, int\fP \fIprotallowed\fP\fB);\fP \fBint imclient_havetls ();\fP \fBint imclient_starttls (struct imclient *\fP\fIimclient\fP\fB, char *\fP\fIcert_file\fP\fB, char *\fP\fIkey_file\fP\fB, char *\fP\fICAfile\fP\fB, char *\fP\fICApath\fP\fB);\fP .ft P .fi .UNINDENT .UNINDENT .SH DESCRIPTION .sp The imclient library functions are distributed with Cyrus IMAP. These functions are used for building IMAP client software. These functions 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. .sp Users must link with the \-lcyrus switch, and must supply a function called \fIfatal\fP to be called in case of any error within \fIlibcyrus.la\fP\&. .sp All of the \fBimclient\fP functions begin with the prefix \fIimclient\fP and take an argument of type \fBstruct imclient *\fP as the first argument which is initialized by \fBimclient_connect\fP and freed by \fBimclient_close\fP\&. .sp See below for a description of each function. .INDENT 0.0 .TP \fBimclient_connect()\fP Connects the client server to the host. If successful, it returns 0 and sets the imclient argument to a pointer to an \fBimclient\fP struct. The \fBimclient\fP struct represents the current connection, flags, and callbacks. On failure, the current \fBerrno\fP 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. .TP \fBimclient_close()\fP Closes and frees the \fBimclient\fP connection. .TP \fBimclient_setflags()\fP Sets the flags specified by the \fIflags\fP argument on the \fBimclient\fP connection. Currently the only flag allowed is \fBIMCLIENT_CONN_NONSYNCLITERAL\fP (this flag indicates that the server supports non\-synchronizing literals described by the LITERAL+ extension). .TP \fBimclient_clearflags()\fP Clears the flags specified by the \fIflags\fP argument on the \fBimclient\fP connection. .TP \fBimclient_servername()\fP Returns a char * pointer to the name of the server connected to by \fBimclient\fP\&. .TP \fBimclient_addcallback()\fP Adds an untagged data callback to the \fBimclient\fP connection. The function \fBimclient_addcallback\fP takes callbacks of the type \fBimclient_proc_t\fP which is defined to be: .INDENT 7.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C typedef void imclient_proc_t (struct imclient *imclient, void *rock, struct imclient_reply *reply); .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp and \fBstruct imclient_reply *\fP is defined to be: .INDENT 7.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C struct imclient_reply { char *keyword; long msgno; char *text; }; .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp After the first argument, \fIimclient\fP, there can be zero or more instances of the set of \fIkeyword\fP, \fIflags\fP, \fIproc\fP, and \fIrock\fP, each adding or changing a single callback. Each instance adds or changes the callback for \fIkeyword\fP\&. The argument \fIflags\fP specifies information about the parsing of the untagged data. \fIproc\fP and \fIrock\fP specify the callback function and rock to invoke when the untagged data is received. \fIproc\fP may be a null pointer, in which case no function is invoked. The callback function may not call the functions \fBimclient_close(), imclient_send(), imclient_eof(), imclient_processoneevent()\fP, or \fBimclient_authenticate()\fP on the connection. The callback function may overwrite the text of untagged data. .TP \fBimclient_send()\fP Sends a new command to the \fBimclient\fP connection. \fIfinishproc\fP and \fIfinishrock\fP are the function and rock called when the command completes. \fIfunctionproc\fP may be a null pointer, in which case no callback is made. The callback function may not call the functions \fBimclient_close(), imclient_send(), imclient_eof(), imclient_processoneevent()\fP, or \fBimclient_authenticate()\fP on the connection. The argument \fIfmt\fP is a \fBprintf(3)\fP like specification of the command. It must not include the tag as the tag is automatically added by \fBimclient_send()\fP\&. .sp The defined %\-sequences are: .INDENT 7.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C %% 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 of char * which are written as space separated astrings) .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .TP \fBimclient_getselectinfo()\fP Gets the information for calling \fBselect(2)\fP\&. \fIfd\fP is filled in with the file descriptor to \fBselect(2)\fP for read. \fIwanttowrite\fP is filled in with a nonzero value if \fBselect\fP should be used for write as well. .TP \fBimclient_processoneevent()\fP Processes one input or output event on the \fBimclient\fP connection. .TP \fBimclient_authenticate()\fP Authenticates the \fBimclient\fP connection using one of the mechanisms in \fIavailmech\fP\&. The argument \fIuser\fP, if not NULL, specifies the user to authenticate as. If the user is NULL, the current user is used. The argument \fIprotallowed\fP is a bitmask of permissible protection mechanisms. On success, 0 is returned. On failure (i.e., \(dqBAD\(dq keyboard, or no authentication mechanisms worked), 1 is returned. On extreme failure (premature \(dqOK\(dq), 2 is returned. .TP \fBimclient_havetls()\fP Returns a Boolean indicating whether the \fBimclient\fP library was compiled with TLS (SSL) support. If so, \fBimclient_starttls()\fP may be used to secure the IMAP connection. .TP \fBimclient_starttls()\fP Issues a STARTTLS command on an existing IMAP connection and negotiates the secure link. The \fIcert_file\fP and \fIkey_file\fP 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. .sp The \fICAfile\fP and \fICApath\fP arguments specify a file or directory, respectively, of CA certificates for validating server certificates. (See \fBSSL_CTX_load_verify_locations(3)\fP for details.) If both of these are NULL, the client will be unable to validate the server\(aqs certificate, in which case the connection may succeed but a warning will be printed to stdout. .UNINDENT .SH EXAMPLES .sp The following code is a possible skeleton of \fBimclient\fP that relies on Kerberos to do authentication. This code performs an IMAP CAPABILITY request and prints out the result. .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C #include /* example uses xstrdup */ #include #include #include extern struct sasl_client krb_sasl_client; struct sasl_client *login_sasl_client[] = { &krb_sasl_client, NULL }; struct imclient *imclient; char server[] = \(dqcyrus.andrew.cmu.edu\(dq ; char port[] = \(dqimap\(dq; void fatal(char* message, int rc) { fprintf(stderr, \(dqfatal error: %s\een\(dq, 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, \(dqerror: Couldn\(aqt connect to %s %s\een\(dq, server, port); exit(1); } if (imclient_authenticate(imclient, login_sasl_client, \(dqimap\(dq /* service */, NULL /* user */, SASL_PROT_ANY)) { exit(1); } imclient_addcallback(imclient, \(dqCAPABILITY\(dq, CALLBACK_NOLITERAL, callback_capability, &capability_string, NULL); nc = 1; imclient_send(imclient, end_command, (void*) &nc, \(dqCAPABILITY\(dq); while(nc > 0) { imclient_processoneevent(imclient); } if (strstr(\(dqLITERAL+\(dq, capability_string)) { imclient_setflags(imclient, IMCLIENT_CONN_NONSYNCLITERAL); } imclient_send(imclient, NULL, NULL, \(dqLOGOUT\(dq); imclient_close(imclient); printf(\(dqcapability text is: %s\een\(dq, capability_string); free(capability_string); } .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .SH BUGS .sp No known bugs. .SH SEE ALSO .sp \fI\%cyradm(8)\fP, \fI\%imapd(8)\fP, \fI\%RFC 2033\fP (IMAP LITERAL+ extension), \fI\%RFC 2060\fP (IMAP4rev1 specification), and \fBselect(2)\fP .SH KEYWORDS .sp IMAP, ACAP, Kerberos, Authentication .SH AUTHOR The Cyrus Team, Nic Bernstein (Onlight) .SH COPYRIGHT 1993–2024, The Cyrus Team .\" Generated by docutils manpage writer. .