4 * Utility functions for the IMAP module.
14 #include "imap_tools.h"
17 * Break a command down into tokens, taking into consideration the
18 * possibility of escaping spaces using quoted tokens
20 int imap_parameterize(char **args, char *buf) {
29 original_len = strlen(buf);
31 for (i=0; i<original_len; ++i) {
33 if ( (isspace(buf[i])) && (!in_quote) ) {
35 args[num] = &buf[start];
37 if (args[num][0] == '\"') {
39 args[num][strlen(args[num])-1] = 0;
44 else if ( (buf[i] == '\"') && (!in_quote) ) {
48 else if ( (buf[i] == '\"') && (in_quote) ) {
58 * Convert a struct quickroom to an IMAP-compatible mailbox name.
60 void imap_mailboxname(char *buf, int bufsize, struct quickroom *qrbuf) {
62 safestrncpy(buf, qrbuf->QRname, bufsize);
63 if (qrbuf->QRflags & QR_MAILBOX) {
64 strcpy(buf, &buf[11]);
65 if (!strcasecmp(buf, MAILROOM)) strcpy(buf, "INBOX");
71 * Parse a parenthesized list of items (as with the FETCH command)
73 int imap_extract_data_items(char *items) {
77 /* First, convert all whitespace to ordinary space characters */
78 for (i=0; i<strlen(items); ++i) {
79 if (isspace(items[i])) items[i] = ' ';