]> code.citadel.org Git - citadel.git/blobdiff - citadel/imap_tools.c
* IMAP stuff
[citadel.git] / citadel / imap_tools.c
index a52c8b50e308f20dfd1de14e52141304b123cfdd..8c93605455b2591b4b0eaa868ba8563c25cbaeba 100644 (file)
@@ -7,12 +7,46 @@
 
 #include <stdlib.h>
 #include <unistd.h>
+#include <stdio.h>
 #include <ctype.h>
 #include <string.h>
 #include "citadel.h"
+#include "sysdep_decls.h"
 #include "tools.h"
+#include "internet_addressing.h"
 #include "imap_tools.h"
 
+
+/*
+ * Output a string to the IMAP client, either as a literal or quoted.
+ * (We do a literal if it has any double-quotes or backslashes.)
+ */
+void imap_strout(char *buf) {
+       int i;
+       int is_literal = 0;
+
+       if (buf == NULL) {              /* yeah, we handle this */
+               cprintf("NIL");
+               return;
+       }
+
+       for (i=0; i<strlen(buf); ++i) {
+               if ( (buf[i]=='\"') || (buf[i]=='\\') ) is_literal = 1;
+       }
+
+       if (is_literal) {
+               cprintf("{%d}\r\n%s", strlen(buf), buf);
+       }
+
+       else {
+               cprintf("\"%s\"", buf);
+       }
+}
+
+       
+
+
+
 /*
  * Break a command down into tokens, taking into consideration the
  * possibility of escaping spaces using quoted tokens
@@ -68,18 +102,27 @@ void imap_mailboxname(char *buf, int bufsize, struct quickroom *qrbuf) {
 
 
 /*
- * Parse a parenthesized list of items (as with the FETCH command)
+ * Output a struct internet_address_list in the form an IMAP client wants
  */
-int imap_extract_data_items(char *items) {
-       int num_items = 0;
-       int i;
+void imap_ial_out(struct internet_address_list *ialist) {
+       struct internet_address_list *iptr;
 
-       /* First, convert all whitespace to ordinary space characters */
-       for (i=0; i<strlen(items); ++i) {
-               if (isspace(items[i])) items[i] = ' ';
+       if (ialist == NULL) {
+               cprintf("NIL");
+               return;
        }
 
-       return num_items;
-}
+       cprintf("(");   
 
+       for (iptr = ialist; iptr != NULL; iptr = iptr->next) {
+               cprintf("(");   
+               imap_strout(iptr->ial_name);
+               cprintf(" NIL ");
+               imap_strout(iptr->ial_user);
+               cprintf(" ");
+               imap_strout(iptr->ial_node);
+               cprintf(")");   
+       }
 
+       cprintf(")");
+}