From da95cb001269e87eb4830227db6fa362909e712f Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Fri, 14 Jul 2000 23:32:04 +0000 Subject: New convenience function to unquote a string if it's encapsulated by "'s 2000-07-14 Jeffrey Stedfast * string-utils.c (string_unquote): New convenience function to unquote a string if it's encapsulated by "'s * providers/imap/camel-imap-folder.c: * providers/imap/camel-imap-store.c: Made the necessary changes to stop using hard coded directory separators. svn path=/trunk/; revision=4170 --- camel/providers/imap/camel-imap-folder.c | 43 +++++++++------ camel/providers/imap/camel-imap-store.c | 93 ++++++++++++++++++++++++++++---- camel/providers/imap/camel-imap-store.h | 4 +- 3 files changed, 113 insertions(+), 27 deletions(-) (limited to 'camel/providers') diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c index f1e2365dcb..f52134585b 100644 --- a/camel/providers/imap/camel-imap-folder.c +++ b/camel/providers/imap/camel-imap-folder.c @@ -224,7 +224,7 @@ imap_init (CamelFolder *folder, CamelStore *parent_store, CamelFolder *parent_fo CamelStore *store = CAMEL_STORE (parent_store); CamelURL *url = CAMEL_SERVICE (store)->url; int status; - char *result, *folder_path; + char *result, *folder_path, *dir_sep; /* call parent method */ parent_class->init (folder, parent_store, parent_folder, name, separator, path_begins_with_sep, ex); @@ -253,8 +253,10 @@ imap_init (CamelFolder *folder, CamelStore *parent_store, CamelFolder *parent_fo imap_folder->summary = NULL; /* SELECT the IMAP mail spool */ + dir_sep = CAMEL_IMAP_STORE (folder->parent_store)->dir_sep; + if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); + folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name); else folder_path = g_strdup (folder->full_name); @@ -409,7 +411,7 @@ imap_get_message_count (CamelFolder *folder, CamelException *ex) CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder); CamelStore *store = CAMEL_STORE (folder->parent_store); CamelURL *url = CAMEL_SERVICE (store)->url; - gchar *result, *msg_count, *folder_path; + gchar *result, *msg_count, *folder_path, *dir_sep; gint status; g_return_val_if_fail (folder != NULL, -1); @@ -418,8 +420,10 @@ imap_get_message_count (CamelFolder *folder, CamelException *ex) if (imap_folder->count != -1) return imap_folder->count; + dir_sep = CAMEL_IMAP_STORE (folder->parent_store)->dir_sep; + if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); + folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name); else folder_path = g_strdup (folder->full_name); @@ -486,7 +490,7 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message, guint32 fla CamelStore *store = CAMEL_STORE (folder->parent_store); CamelURL *url = CAMEL_SERVICE (store)->url; CamelStreamMem *mem; - gchar *result, *folder_path, *flagstr = NULL; + gchar *result, *folder_path, *dir_sep, *flagstr = NULL; gint status; g_return_if_fail (folder != NULL); @@ -505,9 +509,11 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message, guint32 fla } mem->buffer = g_byte_array_append (mem->buffer, g_strdup ("\r\n"), 3); + + dir_sep = CAMEL_IMAP_STORE (folder->parent_store)->dir_sep; if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); + folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name); else folder_path = g_strdup (folder->full_name); @@ -552,11 +558,13 @@ imap_copy_message_to (CamelFolder *source, const char *uid, CamelFolder *destina { CamelStore *store = CAMEL_STORE (source->parent_store); CamelURL *url = CAMEL_SERVICE (store)->url; - char *result, *folder_path; + char *result, *folder_path, *dir_sep; int status; + + dir_sep = CAMEL_IMAP_STORE (source->parent_folder)->dir_sep; if (url && url->path && *(url->path + 1) && strcmp (destination->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, destination->full_name); + folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, destination->full_name); else folder_path = g_strdup (destination->full_name); @@ -588,11 +596,13 @@ imap_move_message_to (CamelFolder *source, const char *uid, CamelFolder *destina CamelStore *store = CAMEL_STORE (source->parent_store); CamelURL *url = CAMEL_SERVICE (store)->url; CamelMessageInfo *info; - char *result, *folder_path; + char *result, *folder_path, *dir_sep; int status; + + dir_sep = CAMEL_IMAP_STORE (source->parent_store)->dir_sep; if (url && url->path && *(url->path + 1) && strcmp (destination->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, destination->full_name); + folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, destination->full_name); else folder_path = g_strdup (destination->full_name); @@ -685,6 +695,7 @@ imap_parse_subfolder_line (gchar *buf, gchar **flags, gchar **sep, gchar **folde ptr = eptr + 1; *folder = g_strdup (ptr); g_strstrip (*folder); + string_unquote (*folder); /* unquote the mailbox if it's quoted */ return TRUE; } @@ -697,25 +708,27 @@ imap_get_subfolder_names (CamelFolder *folder, CamelException *ex) CamelURL *url = CAMEL_SERVICE (store)->url; GPtrArray *listing; gint status; - gchar *result, *folder_path; + gchar *result, *folder_path, *dir_sep; - g_return_val_if_fail (folder != NULL, g_ptr_array_new()); + g_return_val_if_fail (folder != NULL, g_ptr_array_new ()); if (imap_folder->count != -1) return g_ptr_array_new (); + dir_sep = CAMEL_IMAP_STORE (folder->parent_store)->dir_sep; + if (url && url->path) { if (!strcmp (folder->full_name, "INBOX")) folder_path = g_strdup (url->path + 1); else - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); + folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name); } else { folder_path = g_strdup (folder->full_name); } status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, - &result, "LIST \"\" \"%s%s\"", folder_path, - *folder_path ? "/*" : "*"); + &result, "LIST \"\" \"%s%s*\"", folder_path, + *folder_path ? dir_sep : ""); if (status != CAMEL_IMAP_OK) { CamelService *service = CAMEL_SERVICE (folder->parent_store); diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c index cd22095287..4705cb8e53 100644 --- a/camel/providers/imap/camel-imap-store.c +++ b/camel/providers/imap/camel-imap-store.c @@ -104,6 +104,7 @@ camel_imap_store_init (gpointer object, gpointer klass) CAMEL_SERVICE_URL_ALLOW_PATH); store->folders = g_hash_table_new (g_str_hash, g_str_equal); + CAMEL_IMAP_STORE (store)->dir_sep = NULL; } GtkType @@ -224,6 +225,39 @@ get_name (CamelService *service, gboolean brief) } } +static gboolean +parse_list_response (gchar *buf, gchar **sep) +{ + gchar *ptr, *eptr; + + *sep = NULL; + + if (strncasecmp (buf, "* LIST", 6)) + return FALSE; + + ptr = strstr (buf + 6, "("); + if (!ptr) + return FALSE; + + ptr++; + eptr = strstr (ptr, ")"); + if (!eptr) + return FALSE; + + ptr = strstr (eptr, "\""); + if (!ptr) + return FALSE; + + ptr++; + eptr = strstr (ptr, "\""); + if (!eptr) + return FALSE; + + *sep = g_strndup (ptr, (gint)(eptr - ptr)); + + return TRUE; +} + static gboolean imap_connect (CamelService *service, CamelException *ex) { @@ -262,9 +296,10 @@ imap_connect (CamelService *service, CamelException *ex) } store->ostream = camel_stream_fs_new_with_fd (fd); - store->istream = camel_stream_buffer_new (store->ostream, - CAMEL_STREAM_BUFFER_READ); + store->istream = camel_stream_buffer_new (store->ostream, CAMEL_STREAM_BUFFER_READ); store->command = 0; + g_free (store->dir_sep); + store->dir_sep = g_strdup ("/"); /* default dir sep */ /* Read the greeting, if any. */ buf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream)); @@ -327,6 +362,7 @@ imap_connect (CamelService *service, CamelException *ex) status = camel_imap_command_extended (store, NULL, &result, "CAPABILITY"); if (status != CAMEL_IMAP_OK) { + /* Non-fatal error, but we should still warn the user... */ CamelService *service = CAMEL_SERVICE (store); camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, @@ -345,6 +381,34 @@ imap_connect (CamelService *service, CamelException *ex) d(fprintf (stderr, "IMAP provider does%shave SEARCH support\n", store->has_search_capability ? " " : "n't ")); + /* FIXME: We now need to find out which directory separator this daemon uses */ + status = camel_imap_command_extended (store, NULL, &result, "LIST \"\" \"\""); + + if (status != CAMEL_IMAP_OK) { + /* Again, this is non-fatal */ + CamelService *service = CAMEL_SERVICE (store); + + camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, + "Could not get directory separator on IMAP server %s: %s.", + service->url->host, + status != CAMEL_IMAP_FAIL && result ? result : + "Unknown error"); + } else { + if (!strncasecmp (result, "* LIST", 6)) { + char *sep; + + if (parse_list_response (result, &sep)) { + if (*sep) { + g_free (store->dir_sep); + store->dir_sep = g_strdup (sep); + } + + g_free (sep); + } + } + } + + /* parent class conect initialization */ service_class->connect (service, ex); return TRUE; @@ -365,6 +429,8 @@ imap_disconnect (CamelService *service, CamelException *ex) gtk_object_unref (GTK_OBJECT (store->istream)); store->ostream = NULL; store->istream = NULL; + g_free (store->dir_sep); + store->dir_sep = NULL; return TRUE; } @@ -383,11 +449,13 @@ imap_folder_exists (CamelFolder *folder) { CamelStore *store = CAMEL_STORE (folder->parent_store); CamelURL *url = CAMEL_SERVICE (store)->url; - gchar *result, *folder_path; + gchar *result, *folder_path, *dir_sep; gint status; + dir_sep = CAMEL_IMAP_STORE (folder->parent_store)->dir_sep; + if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); + folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name); else folder_path = g_strdup (folder->full_name); @@ -411,7 +479,7 @@ imap_create (CamelFolder *folder, CamelException *ex) { CamelStore *store = CAMEL_STORE (folder->parent_store); CamelURL *url = CAMEL_SERVICE (store)->url; - gchar *result, *folder_path; + gchar *result, *folder_path, *dir_sep; gint status; g_return_val_if_fail (folder != NULL, FALSE); @@ -429,8 +497,10 @@ imap_create (CamelFolder *folder, CamelException *ex) return TRUE; /* create the directory for the subfolder */ + dir_sep = CAMEL_IMAP_STORE (folder->parent_store)->dir_sep; + if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); + folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name); else folder_path = g_strdup (folder->full_name); @@ -536,11 +606,12 @@ camel_imap_command (CamelImapStore *store, CamelFolder *folder, char **ret, char if (folder && store->current_folder != folder && strncmp (fmt, "CREATE", 5)) { /* We need to select the correct mailbox first */ - char *r, *folder_path; + char *r, *folder_path, *dir_sep; int s; + dir_sep = store->dir_sep; if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); + folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name); else folder_path = g_strdup (folder->full_name); @@ -640,11 +711,13 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char ** if (folder && store->current_folder != folder && strncmp (fmt, "SELECT", 6) && strncmp (fmt, "CREATE", 6)) { /* We need to select the correct mailbox first */ - char *r, *folder_path; + char *r, *folder_path, *dir_sep; int s; + dir_sep = store->dir_sep; + if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); + folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name); else folder_path = g_strdup (folder->full_name); diff --git a/camel/providers/imap/camel-imap-store.h b/camel/providers/imap/camel-imap-store.h index 09dd2be148..b38ed769c9 100644 --- a/camel/providers/imap/camel-imap-store.h +++ b/camel/providers/imap/camel-imap-store.h @@ -50,6 +50,8 @@ typedef struct { guint32 command; gboolean has_search_capability; + + gchar *dir_sep; } CamelImapStore; @@ -81,5 +83,3 @@ const gchar *camel_imap_store_get_toplevel_dir (CamelImapStore *store); #endif /* __cplusplus */ #endif /* CAMEL_IMAP_STORE_H */ - - -- cgit v1.2.3