4 * Utility functions for the IMAP module.
14 #include "sysdep_decls.h"
16 #include "internet_addressing.h"
17 #include "imap_tools.h"
21 * Output a string to the IMAP client, either as a literal or quoted.
22 * (We do a literal if it has any double-quotes or backslashes.)
24 void imap_strout(char *buf) {
28 if (buf == NULL) { /* yeah, we handle this */
33 for (i=0; i<strlen(buf); ++i) {
34 if ( (buf[i]=='\"') || (buf[i]=='\\') ) is_literal = 1;
38 cprintf("{%d}\r\n%s", strlen(buf), buf);
42 cprintf("\"%s\"", buf);
51 * Break a command down into tokens, taking into consideration the
52 * possibility of escaping spaces using quoted tokens
54 int imap_parameterize(char **args, char *buf) {
63 original_len = strlen(buf);
65 for (i=0; i<original_len; ++i) {
67 if ( (isspace(buf[i])) && (!in_quote) ) {
69 args[num] = &buf[start];
71 if (args[num][0] == '\"') {
73 args[num][strlen(args[num])-1] = 0;
78 else if ( (buf[i] == '\"') && (!in_quote) ) {
82 else if ( (buf[i] == '\"') && (in_quote) ) {
92 * Convert a struct quickroom to an IMAP-compatible mailbox name.
94 void imap_mailboxname(char *buf, int bufsize, struct quickroom *qrbuf) {
96 safestrncpy(buf, qrbuf->QRname, bufsize);
97 if (qrbuf->QRflags & QR_MAILBOX) {
98 strcpy(buf, &buf[11]);
99 if (!strcasecmp(buf, MAILROOM)) strcpy(buf, "INBOX");
105 * Output a struct internet_address_list in the form an IMAP client wants
107 void imap_ial_out(struct internet_address_list *ialist) {
108 struct internet_address_list *iptr;
110 if (ialist == NULL) {
117 for (iptr = ialist; iptr != NULL; iptr = iptr->next) {
119 imap_strout(iptr->ial_name);
121 imap_strout(iptr->ial_user);
123 imap_strout(iptr->ial_node);