[balsa] * libbalsa/imap/imap-handle.c: namespace queries need to encode



commit 8fa8bc0564ff95ec0d560530b0f796e072fe0183
Author: Pawel Salek <pawsa damage localdomain>
Date:   Thu Aug 27 10:40:27 2009 +0200

    * libbalsa/imap/imap-handle.c: namespace queries need to encode
      the prefix.
    * libbalsa/imap/imap_tst.c: test mailbox name encoding.
    * libbalsa/imap/util.c: encode backslash and quote marks.

 ChangeLog                   |    7 +++++++
 libbalsa/imap/imap-handle.c |    8 +++++---
 libbalsa/imap/imap_tst.c    |   37 +++++++++++++++++++++++++++++++++++++
 libbalsa/imap/util.c        |    6 ++++++
 4 files changed, 55 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 421d10e..766f75f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-08-27  Pawel Salek
+
+	* libbalsa/imap/imap-handle.c: namespace queries need to encode
+	the prefix.
+	* libbalsa/imap/imap_tst.c: test mailbox name encoding.
+	* libbalsa/imap/util.c: encode backslash and quote marks.
+	
 2009-08-26  Peter Bloomfield 
 
 	set-statusbar is a BalsaWindow method.
diff --git a/libbalsa/imap/imap-handle.c b/libbalsa/imap/imap-handle.c
index 9daeb84..7f47277 100644
--- a/libbalsa/imap/imap-handle.c
+++ b/libbalsa/imap/imap-handle.c
@@ -939,7 +939,7 @@ imap_mbox_handle_get_delim(ImapMboxHandle* handle,
 {
   int delim;
   guint handler_id;
-  gchar * cmd;
+  gchar * cmd, *mbx7;
 
   HANDLE_LOCK(handle);
   /* FIXME: block other list response signals here? */
@@ -947,8 +947,10 @@ imap_mbox_handle_get_delim(ImapMboxHandle* handle,
 				G_CALLBACK(get_delim),
 				&delim);
 
-  cmd = g_strdup_printf("LIST \"%s\" \"\"", namespace);
-  imap_cmd_exec(handle, cmd);
+  mbx7 = imap_utf8_to_mailbox(namespace);
+  cmd = g_strdup_printf("LIST \"%s\" \"\"", mbx7);
+  g_free(mbx7);
+  imap_cmd_exec(handle, cmd); /* ignore return code.. */
   g_free(cmd);
   g_signal_handler_disconnect(G_OBJECT(handle), handler_id);
   HANDLE_UNLOCK(handle);
diff --git a/libbalsa/imap/imap_tst.c b/libbalsa/imap/imap_tst.c
index 1a96dd7..e59193b 100644
--- a/libbalsa/imap/imap_tst.c
+++ b/libbalsa/imap/imap_tst.c
@@ -6,6 +6,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
@@ -16,6 +17,7 @@
 #include "libimap.h"
 #include "imap-handle.h"
 #include "imap-commands.h"
+#include "util.h"
 
 struct {
   char *user;
@@ -556,6 +558,40 @@ test_mbox_delete(int argc, char *argv[])
   return rc == IMR_OK ? 0 : 1;
 }
 
+/** test mailbox name quoting. */
+static int
+test_mailbox_name_quoting()
+{
+  static const struct {
+    const char *test, *reference;
+  } test_mailbox_names[] = {
+    { "INBOX", "INBOX" },
+    { "ehlo", "ehlo" },
+    { "ångström", "&AOU-ngstr&APY-m" },
+    { "quot\"ed\"", "quot\\\"ed\\\"" },
+    { "dirty & ugly", "dirty &- ugly" },
+    { "dir\\mbox", "dir\\\\mbox" }
+  };
+  int failure_count = 0;
+  unsigned i;
+  for(i=0;
+      i<sizeof(test_mailbox_names)/sizeof(test_mailbox_names[0]);
+      ++i) {
+    char *mbx7 = imap_utf8_to_mailbox(test_mailbox_names[i].test);
+    if (!mbx7)
+      continue;
+    if (strcmp(mbx7, test_mailbox_names[i].reference) != 0) {
+      printf("Encoded name for '%s' expected '%s' found '%s'\n",
+             test_mailbox_names[i].test,
+             test_mailbox_names[i].reference,
+             mbx7);
+      ++failure_count;
+    }
+    free(mbx7);
+  }
+  return failure_count;
+}
+
 static unsigned
 process_options(int argc, char *argv[])
 {
@@ -591,6 +627,7 @@ main(int argc, char *argv[]) {
   if(argc<=1) {
     test_envelope_strings();
     test_body_strings();
+    test_mailbox_name_quoting();
   } else {
     static const struct {
       int (*func)(int argc, char *argv[]);
diff --git a/libbalsa/imap/util.c b/libbalsa/imap/util.c
index 4486271..fa05811 100644
--- a/libbalsa/imap/util.c
+++ b/libbalsa/imap/util.c
@@ -385,6 +385,10 @@ imap_utf8_to_mailbox(const char *src)
         bitstogo = 0;
         utf8total= 0;
       }
+      /* encode '\' as '\\', and '"' as '\"' */
+      if (c == '\\' || c == '"') {
+        *dst++ = '\\';
+      }
       *dst++ = c;
       /* encode '&' as '&-' */
       if (c == '&') {
@@ -464,6 +468,8 @@ int main(int argc, char *argv[])
   for(i=1; i<argc; i++) {
     char *mbx = imap_utf8_to_mailbox(argv[i]);
     char *utf8 = imap_mailbox_to_utf8(mbx);
+    if (!mbx || !utf8)
+      continue;
     printf("orig='%s' mbx='%s' back='%s'\n", argv[i], mbx, utf8);
     free(mbx); free(utf8);
   }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]