diff options
author | Jeffrey Stedfast <fejj@helixcode.com> | 2000-07-15 07:32:04 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2000-07-15 07:32:04 +0800 |
commit | da95cb001269e87eb4830227db6fa362909e712f (patch) | |
tree | 97d947612e21c8b03fed8b79b6568d0bb048a046 | |
parent | 6746c025d5cdb4cd8f49b7bc3e339aa956b3d7c9 (diff) | |
download | gsoc2013-evolution-da95cb001269e87eb4830227db6fa362909e712f.tar gsoc2013-evolution-da95cb001269e87eb4830227db6fa362909e712f.tar.gz gsoc2013-evolution-da95cb001269e87eb4830227db6fa362909e712f.tar.bz2 gsoc2013-evolution-da95cb001269e87eb4830227db6fa362909e712f.tar.lz gsoc2013-evolution-da95cb001269e87eb4830227db6fa362909e712f.tar.xz gsoc2013-evolution-da95cb001269e87eb4830227db6fa362909e712f.tar.zst gsoc2013-evolution-da95cb001269e87eb4830227db6fa362909e712f.zip |
New convenience function to unquote a string if it's encapsulated by "'s
2000-07-14 Jeffrey Stedfast <fejj@helixcode.com>
* 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
-rw-r--r-- | camel/ChangeLog | 9 | ||||
-rw-r--r-- | camel/providers/imap/camel-imap-folder.c | 43 | ||||
-rw-r--r-- | camel/providers/imap/camel-imap-store.c | 93 | ||||
-rw-r--r-- | camel/providers/imap/camel-imap-store.h | 4 | ||||
-rw-r--r-- | camel/string-utils.c | 14 | ||||
-rw-r--r-- | camel/string-utils.h | 2 |
6 files changed, 138 insertions, 27 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 0a0893bdcf..9bf96f3c48 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,12 @@ +2000-07-14 Jeffrey Stedfast <fejj@helixcode.com> + + * 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. + 2000-07-13 Dan Winship <danw@helixcode.com> * providers/mbox/camel-mbox-summary.c (camel_mbox_summary_load): 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 @@ -225,6 +226,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) { CamelImapStore *store = CAMEL_IMAP_STORE (service); @@ -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 */ - - diff --git a/camel/string-utils.c b/camel/string-utils.c index cdeebe8322..63e9eafabf 100644 --- a/camel/string-utils.c +++ b/camel/string-utils.c @@ -174,3 +174,17 @@ string_prefix (const gchar *s, const gchar *suffix, gboolean *suffix_found) return result_string; } + +void +string_unquote (gchar *string) +{ + /* if the string is quoted, unquote it */ + + g_return_if_fail (string != NULL); + + if (*string == '"' && *(string + strlen (string) - 1) == '"') { + *(string + strlen (string) - 1) = '\0'; + if (*string) + memmove (string, string+1, strlen (string)); + } +} diff --git a/camel/string-utils.h b/camel/string-utils.h index 5595ad3247..4cfef5b746 100644 --- a/camel/string-utils.h +++ b/camel/string-utils.h @@ -56,6 +56,8 @@ void string_trim (gchar *string, const gchar *chars, gchar *string_prefix (const gchar *s, const gchar *suffix, gboolean *suffix_found); +void string_unquote (gchar *string); + #ifdef __cplusplus } #endif /* __cplusplus */ |