4 * Utility functions for the IMAP module.
14 #include "sysdep_decls.h"
16 #include "imap_tools.h"
20 * Output a string to the IMAP client, either as a literal or quoted.
21 * (We do a literal if it has any double-quotes or backslashes.)
23 void imap_strout(char *buf) {
27 if (buf == NULL) { /* yeah, we handle this */
32 for (i=0; i<strlen(buf); ++i) {
33 if ( (buf[i]=='\"') || (buf[i]=='\\') ) is_literal = 1;
37 cprintf("{%d}\r\n%s", strlen(buf), buf);
41 cprintf("\"%s\"", buf);
50 * Break a command down into tokens, taking into consideration the
51 * possibility of escaping spaces using quoted tokens
53 int imap_parameterize(char **args, char *buf) {
62 original_len = strlen(buf);
64 for (i=0; i<original_len; ++i) {
66 if ( (isspace(buf[i])) && (!in_quote) ) {
68 args[num] = &buf[start];
70 if (args[num][0] == '\"') {
72 args[num][strlen(args[num])-1] = 0;
77 else if ( (buf[i] == '\"') && (!in_quote) ) {
81 else if ( (buf[i] == '\"') && (in_quote) ) {
91 * Convert a struct quickroom to an IMAP-compatible mailbox name.
93 void imap_mailboxname(char *buf, int bufsize, struct quickroom *qrbuf) {
95 safestrncpy(buf, qrbuf->QRname, bufsize);
96 if (qrbuf->QRflags & QR_MAILBOX) {
97 strcpy(buf, &buf[11]);
98 if (!strcasecmp(buf, MAILROOM)) strcpy(buf, "INBOX");