]> code.citadel.org Git - citadel.git/blobdiff - citadel/imap_tools.c
* More IMAP tweaks
[citadel.git] / citadel / imap_tools.c
index 05bfe3230021973e1ce9a81bf32c681c2cb00605..a633cbde46c698b221a8d36c26e56c80f6fa0f15 100644 (file)
@@ -7,10 +7,45 @@
 
 #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 "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
@@ -52,5 +87,15 @@ int imap_parameterize(char **args, char *buf) {
        return(num);
 }
                        
+/*
+ * Convert a struct quickroom to an IMAP-compatible mailbox name.
+ */
+void imap_mailboxname(char *buf, int bufsize, struct quickroom *qrbuf) {
 
+       safestrncpy(buf, qrbuf->QRname, bufsize);
+       if (qrbuf->QRflags & QR_MAILBOX) {
+               strcpy(buf, &buf[11]);
+               if (!strcasecmp(buf, MAILROOM)) strcpy(buf, "INBOX");
+       }
+}