aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2000-09-22 03:40:20 +0800
committerDan Winship <danw@src.gnome.org>2000-09-22 03:40:20 +0800
commit8fb132dab0e8291ed8ac2017a329c23148cc5f1a (patch)
tree378a43c24ae1920607f4c473be6ffa73ebbdeccf /camel/providers
parent0b1e68cb22f92bfe82b3fcbca4d57814cc26ad4f (diff)
downloadgsoc2013-evolution-8fb132dab0e8291ed8ac2017a329c23148cc5f1a.tar.gz
gsoc2013-evolution-8fb132dab0e8291ed8ac2017a329c23148cc5f1a.tar.zst
gsoc2013-evolution-8fb132dab0e8291ed8ac2017a329c23148cc5f1a.zip
INBOX is case-insensitive. (get_root_folder_name): Make the root folder ""
* providers/imap/camel-imap-store.c (get_folder_name): INBOX is case-insensitive. (get_root_folder_name): Make the root folder "" rather than "/". (get_folder): Update for root folder name change. (camel_imap_store_get_toplevel_dir): Removed. (Unused, unneeded.) (camel_imap_store_folder_path): New function to turn a Camel folder name into the corresponding namespaced IMAP path. (imap_folder_exists): Make this take a store and a path rather than a folder. (imap_create): Likewise (get_folder): Update for camel_imap_store_folder_path and other changes. (check_current_folder): Likewise. * providers/imap/camel-imap-folder.c: Change a bunch of CamelStore variables to CamelImapStore (and add a few more) to prevent excess gratuitous casting. Use camel_imap_store_folder_path where appropriate. (camel_imap_folder_new): Update for root folder name change. svn path=/trunk/; revision=5541
Diffstat (limited to 'camel/providers')
-rw-r--r--camel/providers/imap/camel-imap-folder.c154
-rw-r--r--camel/providers/imap/camel-imap-store.c217
-rw-r--r--camel/providers/imap/camel-imap-store.h2
3 files changed, 110 insertions, 263 deletions
diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c
index 66cc567278..f0d69333ad 100644
--- a/camel/providers/imap/camel-imap-folder.c
+++ b/camel/providers/imap/camel-imap-folder.c
@@ -189,7 +189,6 @@ CamelFolder *
camel_imap_folder_new (CamelStore *parent, char *folder_name)
{
CamelFolder *folder = CAMEL_FOLDER (camel_object_new (camel_imap_folder_get_type ()));
- CamelURL *url = CAMEL_SERVICE (parent)->url;
char *dir_sep, *short_name;
dir_sep = CAMEL_IMAP_STORE (parent)->dir_sep;
@@ -200,7 +199,7 @@ camel_imap_folder_new (CamelStore *parent, char *folder_name)
short_name = folder_name;
camel_folder_construct (folder, parent, folder_name, short_name);
- if (!strcmp (folder_name, url->path + 1))
+ if (!*folder_name)
folder->can_hold_messages = FALSE;
return folder;
@@ -272,6 +271,7 @@ imap_refresh_info (CamelFolder *folder, CamelException *ex)
static void
imap_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
{
+ CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
gint i, max;
@@ -300,8 +300,7 @@ imap_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
gint s;
*(flags + strlen (flags) - 1) = '\0';
- s = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store),
- folder, &result, ex,
+ s = camel_imap_command_extended (store, folder, &result, ex,
"UID STORE %s FLAGS.SILENT (%s)",
info->uid, flags);
@@ -332,27 +331,20 @@ imap_expunge (CamelFolder *folder, CamelException *ex)
static gint
imap_get_message_count_internal (CamelFolder *folder, CamelException *ex)
{
- CamelStore *store = CAMEL_STORE (folder->parent_store);
- CamelURL *url = CAMEL_SERVICE (store)->url;
- gchar *result, *msg_count, *folder_path, *dir_sep;
+ CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
+ gchar *result, *msg_count, *folder_path;
gint status, count = 0;
- g_return_val_if_fail (folder != NULL, 0);
g_return_val_if_fail (folder->can_hold_messages, 0);
- 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%s", url->path + 1, dir_sep, folder->full_name);
- else
- folder_path = g_strdup (folder->full_name);
+ folder_path = camel_imap_store_folder_path (store, folder->full_name);
- if (CAMEL_IMAP_STORE (store)->has_status_capability)
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (store), folder,
- &result, ex, "STATUS %s (MESSAGES)", folder_path);
+ if (store->has_status_capability)
+ status = camel_imap_command_extended (store, folder, &result, ex,
+ "STATUS %s (MESSAGES)", folder_path);
else
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (store), folder,
- &result, ex, "EXAMINE %s", folder_path);
+ status = camel_imap_command_extended (store, folder, &result, ex,
+ "EXAMINE %s", folder_path);
g_free (folder_path);
@@ -361,7 +353,7 @@ imap_get_message_count_internal (CamelFolder *folder, CamelException *ex)
/* parse out the message count */
if (result && *result == '*') {
- if (CAMEL_IMAP_STORE (store)->has_status_capability) {
+ if (store->has_status_capability) {
/* should come in the form: "* STATUS <folder> (MESSAGES <count>)" */
if ((msg_count = strstr (result, "MESSAGES")) != NULL) {
msg_count = imap_next_word (msg_count);
@@ -425,23 +417,14 @@ imap_get_unread_message_count (CamelFolder *folder)
static void
imap_append_message (CamelFolder *folder, CamelMimeMessage *message, const CamelMessageInfo *info, CamelException *ex)
{
- CamelStore *store = CAMEL_STORE (folder->parent_store);
- CamelURL *url = CAMEL_SERVICE (store)->url;
+ CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
CamelStream *memstream;
GByteArray *ba;
- gchar *result, *cmdid, *dir_sep;
+ gchar *result, *cmdid;
gchar *folder_path, *flagstr = NULL;
gint status;
- g_return_if_fail (folder != NULL);
- g_return_if_fail (message != NULL);
-
- 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%s", url->path + 1, dir_sep, folder->full_name);
- else
- folder_path = g_strdup (folder->full_name);
+ folder_path = camel_imap_store_folder_path (store, folder->full_name);
/* create flag string param */
if (info && info->flags) {
@@ -460,8 +443,7 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message, const Camel
camel_stream_write_string (memstream, "\r\n");
camel_stream_reset (memstream);
- status = camel_imap_command_preliminary (CAMEL_IMAP_STORE (folder->parent_store),
- &cmdid, ex, "APPEND %s%s {%d}",
+ status = camel_imap_command_preliminary (store, &cmdid, ex, "APPEND %s%s {%d}",
folder_path, flagstr ? flagstr : "", ba->len - 2);
g_free (folder_path);
@@ -471,8 +453,7 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message, const Camel
}
/* send the rest of our data - the mime message */
- status = camel_imap_command_continuation_with_stream (CAMEL_IMAP_STORE (folder->parent_store),
- &result, cmdid, memstream, ex);
+ status = camel_imap_command_continuation_with_stream (store, &result, cmdid, memstream, ex);
g_free (cmdid);
if (status != CAMEL_IMAP_OK)
@@ -487,19 +468,12 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message, const Camel
static void
imap_copy_message_to (CamelFolder *source, const char *uid, CamelFolder *destination, CamelException *ex)
{
- CamelStore *store = CAMEL_STORE (source->parent_store);
- CamelURL *url = CAMEL_SERVICE (store)->url;
- char *result, *folder_path, *dir_sep;
+ CamelImapStore *store = CAMEL_IMAP_STORE (source->parent_store);
+ char *result, *folder_path;
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%s", url->path + 1, dir_sep, destination->full_name);
- else
- folder_path = g_strdup (destination->full_name);
-
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (store), source, &result, ex,
+ folder_path = camel_imap_store_folder_path (store, destination->full_name);
+ status = camel_imap_command_extended (store, source, &result, ex,
"UID COPY %s %s", uid, folder_path);
g_free (folder_path);
@@ -515,20 +489,13 @@ imap_copy_message_to (CamelFolder *source, const char *uid, CamelFolder *destina
static void
imap_move_message_to (CamelFolder *source, const char *uid, CamelFolder *destination, CamelException *ex)
{
- CamelStore *store = CAMEL_STORE (source->parent_store);
- CamelURL *url = CAMEL_SERVICE (store)->url;
+ CamelImapStore *store = CAMEL_IMAP_STORE (source->parent_store);
CamelMessageInfo *info;
- char *result, *folder_path, *dir_sep;
+ char *result, *folder_path;
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%s", url->path + 1, dir_sep, destination->full_name);
- else
- folder_path = g_strdup (destination->full_name);
-
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (store), source, &result, ex,
+ folder_path = camel_imap_store_folder_path (store, destination->full_name);
+ status = camel_imap_command_extended (store, source, &result, ex,
"UID COPY %s %s", uid, folder_path);
g_free (folder_path);
@@ -577,41 +544,19 @@ static GPtrArray *
imap_get_subfolder_info_internal (CamelFolder *folder, CamelException *ex)
{
CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
- CamelStore *store = CAMEL_STORE (folder->parent_store);
- CamelURL *url = CAMEL_SERVICE (store)->url;
+ CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
GPtrArray *listing;
gboolean found_inbox = FALSE;
gint status;
- gchar *result, *namespace, *dir_sep;
+ gchar *result, *namespace;
CamelFolderInfo *fi;
g_return_val_if_fail (folder != NULL, g_ptr_array_new ());
- dir_sep = CAMEL_IMAP_STORE (folder->parent_store)->dir_sep;
-
- if (url && url->path) {
- char *path = url->path + 1;
-
- if (*path) {
- if (!strcmp (folder->full_name, path))
- namespace = g_strdup (path);
- else if (!g_strcasecmp (folder->full_name, "INBOX"))
- namespace = g_strdup (path); /* FIXME: erm...not sure */
- else
- namespace = g_strdup_printf ("%s%s%s", path, dir_sep, folder->full_name);
- } else {
- if (!strcmp (folder->full_name, "/"))
- namespace = g_strdup ("");
- else
- namespace = g_strdup (folder->full_name);
- }
- } else {
- namespace = g_strdup (folder->full_name);
- }
-
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), NULL,
- &result, ex, "LIST \"\" \"%s%s*\"", namespace,
- *namespace ? dir_sep : "");
+ namespace = camel_imap_store_folder_path (store, folder->full_name);
+ status = camel_imap_command_extended (store, NULL, &result, ex,
+ "LIST \"\" \"%s%s*\"", namespace,
+ *namespace ? store->dir_sep : "");
if (status != CAMEL_IMAP_OK) {
g_free (namespace);
@@ -698,19 +643,19 @@ imap_get_subfolder_info (CamelFolder *folder)
static CamelMimeMessage *
imap_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
{
+ CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
CamelStream *msgstream = NULL;
CamelMimeMessage *msg = NULL;
gchar *result, *header, *body, *mesg, *p, *q, *data_item;
int status, part_len;
- if (CAMEL_IMAP_STORE (folder->parent_store)->server_level >= IMAP_LEVEL_IMAP4REV1)
+ if (store->server_level >= IMAP_LEVEL_IMAP4REV1)
data_item = "BODY.PEEK[HEADER]";
else
data_item = "RFC822.HEADER";
- status = camel_imap_fetch_command (CAMEL_IMAP_STORE (folder->parent_store), folder,
- &result, ex, "UID FETCH %s %s", uid,
- data_item);
+ status = camel_imap_fetch_command (store, folder, &result, ex,
+ "UID FETCH %s %s", uid, data_item);
if (!result || status != CAMEL_IMAP_OK)
return NULL;
@@ -756,14 +701,13 @@ imap_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
g_free (result);
d(fprintf (stderr, "*** We got the header ***\n"));
- if (CAMEL_IMAP_STORE (folder->parent_store)->server_level >= IMAP_LEVEL_IMAP4REV1)
+ if (store->server_level >= IMAP_LEVEL_IMAP4REV1)
data_item = "BODY[TEXT]";
else
data_item = "RFC822.TEXT";
- status = camel_imap_fetch_command (CAMEL_IMAP_STORE (folder->parent_store), folder,
- &result, ex, "UID FETCH %s %s", uid,
- data_item);
+ status = camel_imap_fetch_command (store, folder, &result, ex,
+ "UID FETCH %s %s", uid, data_item);
if (!result || status != CAMEL_IMAP_OK) {
g_free (header);
@@ -884,12 +828,12 @@ static char *header_fields[] = { "subject", "from", "to", "cc", "date",
* IMAP4: UID FLAGS RFC822.HEADER.LINES (SUBJECT FROM .. IN-REPLY-TO)
**/
static char *
-imap_protocol_get_summary_specifier (CamelFolder *folder)
+imap_protocol_get_summary_specifier (CamelImapStore *store)
{
char *sect_begin, *sect_end;
char *headers_wanted = "SUBJECT FROM TO CC DATE MESSAGE-ID REFERENCES IN-REPLY-TO";
- if (CAMEL_IMAP_STORE (folder->parent_store)->server_level >= IMAP_LEVEL_IMAP4REV1) {
+ if (store->server_level >= IMAP_LEVEL_IMAP4REV1) {
sect_begin = "BODY.PEEK[HEADER.FIELDS";
sect_end = "]";
} else {
@@ -904,6 +848,7 @@ static GPtrArray *
imap_get_summary_internal (CamelFolder *folder, CamelException *ex)
{
/* This ALWAYS updates the summary except on fail */
+ CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
GPtrArray *summary = NULL, *headers = NULL;
GHashTable *hash = NULL;
@@ -928,15 +873,15 @@ imap_get_summary_internal (CamelFolder *folder, CamelException *ex)
return imap_folder->summary;
}
- summary_specifier = imap_protocol_get_summary_specifier (folder);
+ summary_specifier = imap_protocol_get_summary_specifier (store);
/* We use camel_imap_command_extended here because it's safe */
if (num == 1) {
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder,
- &result, ex, "FETCH 1 (%s)", summary_specifier);
+ status = camel_imap_command_extended (store, folder, &result, ex,
+ "FETCH 1 (%s)", summary_specifier);
} else {
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder,
- &result, ex, "FETCH 1:%d (%s)", num, summary_specifier);
+ status = camel_imap_command_extended (store, folder, &result, ex,
+ "FETCH 1:%d (%s)", num, summary_specifier);
}
g_free (summary_specifier);
@@ -1108,6 +1053,7 @@ imap_get_summary (CamelFolder *folder)
static CamelMessageInfo *
imap_get_message_info_internal (CamelFolder *folder, guint id, CamelException *ex)
{
+ CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
CamelMessageInfo *info = NULL;
struct _header_raw *h, *tail = NULL;
const char *received;
@@ -1116,11 +1062,11 @@ imap_get_message_info_internal (CamelFolder *folder, guint id, CamelException *e
int j, status;
/* we don't have a cached copy, so fetch it */
- summary_specifier = imap_protocol_get_summary_specifier (folder);
+ summary_specifier = imap_protocol_get_summary_specifier (store);
/* again, we use camel_imap_command_extended here because it's safe to do so */
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder,
- &result, ex, "FETCH %d (%s)", id, summary_specifier);
+ status = camel_imap_command_extended (store, folder, &result, ex,
+ "FETCH %d (%s)", id, summary_specifier);
g_free (summary_specifier);
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index 8dc82ed7e5..83d46b4ac7 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -51,13 +51,15 @@
static CamelRemoteStoreClass *remote_store_class = NULL;
-static gboolean imap_create (CamelFolder *folder, CamelException *ex);
static gboolean imap_connect (CamelService *service, CamelException *ex);
static gboolean imap_disconnect (CamelService *service, CamelException *ex);
static GList *query_auth_types_generic (CamelService *service, CamelException *ex);
static GList *query_auth_types_connected (CamelService *service, CamelException *ex);
static CamelFolder *get_folder (CamelStore *store, const char *folder_name, gboolean create,
CamelException *ex);
+static char *get_folder_name (CamelStore *store, const char *folder_name,
+ CamelException *ex);
+static char *get_root_folder_name (CamelStore *store, CamelException *ex);
static void imap_keepalive (CamelRemoteStore *store);
/*static gboolean stream_is_alive (CamelStream *istream);*/
static int camel_imap_status (char *cmdid, char *respbuf);
@@ -83,6 +85,8 @@ camel_imap_store_class_init (CamelImapStoreClass *camel_imap_store_class)
camel_service_class->disconnect = imap_disconnect;
camel_store_class->get_folder = get_folder;
+ camel_store_class->get_folder_name = get_folder_name;
+ camel_store_class->get_root_folder_name = get_root_folder_name;
camel_remote_store_class->keepalive = imap_keepalive;
}
@@ -98,7 +102,7 @@ camel_imap_store_init (gpointer object, gpointer klass)
CAMEL_SERVICE_URL_ALLOW_PATH |
CAMEL_SERVICE_URL_ALLOW_AUTH);
- imap_store->dir_sep = g_strdup ("/"); /*default*/
+ imap_store->dir_sep = NULL;
imap_store->current_folder = NULL;
}
@@ -310,35 +314,33 @@ imap_disconnect (CamelService *service, CamelException *ex)
return CAMEL_SERVICE_CLASS (remote_store_class)->disconnect (service, ex);
}
-const gchar *
-camel_imap_store_get_toplevel_dir (CamelImapStore *store)
+char *
+camel_imap_store_folder_path (CamelImapStore *store, const char *name)
{
CamelURL *url = CAMEL_SERVICE (store)->url;
-
- g_assert (url != NULL);
- return url->path;
+ char *namespace;
+
+ if (url->path && *url->path)
+ namespace = url->path + 1;
+ else
+ namespace = "";
+
+ if (!*name)
+ return g_strdup (namespace);
+ else if (!g_strcasecmp (name, "INBOX") || !*namespace)
+ return g_strdup (name);
+ else
+ return g_strdup_printf ("%s%s%s", namespace, store->dir_sep, name);
}
static gboolean
-imap_folder_exists (CamelFolder *folder, gboolean *selectable, CamelException *ex)
+imap_folder_exists (CamelImapStore *store, const char *folder_path, gboolean *selectable, CamelException *ex)
{
- CamelStore *store = CAMEL_STORE (folder->parent_store);
- CamelURL *url = CAMEL_SERVICE (store)->url;
- gchar *result, *folder_path, *dir_sep;
+ gchar *result;
char *flags, *sep, *dirname;
gint status;
- dir_sep = CAMEL_IMAP_STORE (folder->parent_store)->dir_sep;
-
- g_return_val_if_fail (dir_sep, FALSE);
-
- if (url && url->path && *(url->path + 1) && g_strcasecmp (folder->full_name, "INBOX"))
- folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name);
- else
- folder_path = g_strdup (folder->full_name);
-
if (!g_strcasecmp (folder_path, "INBOX")) {
- g_free (folder_path);
if (selectable)
*selectable = TRUE;
return TRUE;
@@ -350,9 +352,6 @@ imap_folder_exists (CamelFolder *folder, gboolean *selectable, CamelException *e
status = camel_imap_command_extended (CAMEL_IMAP_STORE (store), NULL,
&result, ex, "LIST \"\" %s", folder_path);
-
- g_free (folder_path);
-
if (status != CAMEL_IMAP_OK) {
g_free (result);
return FALSE;
@@ -376,164 +375,73 @@ imap_folder_exists (CamelFolder *folder, gboolean *selectable, CamelException *e
return FALSE;
}
-#if 0
static gboolean
-imap_folder_exists (CamelFolder *folder, CamelException *ex)
+imap_create (CamelImapStore *store, const char *folder_path, CamelException *ex)
{
- CamelStore *store = CAMEL_STORE (folder->parent_store);
- CamelURL *url = CAMEL_SERVICE (store)->url;
- gchar *result, *folder_path, *dir_sep;
+ gchar *result;
gint status;
- dir_sep = CAMEL_IMAP_STORE (folder->parent_store)->dir_sep;
-
- g_return_val_if_fail (dir_sep, FALSE);
-
- if (url && url->path && *(url->path + 1) && g_strcasecmp (folder->full_name, "INBOX"))
- 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), NULL,
- &result, ex, "EXAMINE %s", folder_path);
-
- if (status != CAMEL_IMAP_OK) {
- g_free (folder_path);
- return FALSE;
- }
- g_free (folder_path);
+ status = camel_imap_command_extended (store, NULL, &result, ex,
+ "CREATE %s", folder_path);
g_free (result);
- return TRUE;
-}
-#endif
-
-static gboolean
-imap_create (CamelFolder *folder, CamelException *ex)
-{
- CamelStore *store = CAMEL_STORE (folder->parent_store);
- CamelURL *url = CAMEL_SERVICE (store)->url;
- gchar *result, *folder_path, *dir_sep;
- gint status;
-
- g_return_val_if_fail (folder != NULL, FALSE);
-
- if (!(folder->full_name || folder->name)) {
- camel_exception_set (ex, CAMEL_EXCEPTION_FOLDER_INVALID,
- "invalid folder path. Use set_name ?");
- return FALSE;
- }
-
- if (!g_strcasecmp (folder->full_name, "INBOX"))
- return TRUE;
-
- if (imap_folder_exists (folder, NULL, ex))
- return TRUE;
-
- /* create the directory for the subfolder */
- dir_sep = CAMEL_IMAP_STORE (folder->parent_store)->dir_sep;
-
- g_return_val_if_fail (dir_sep, FALSE);
-
- if (url && url->path && *(url->path + 1) && g_strcasecmp (folder->full_name, "INBOX"))
- 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), NULL,
- &result, ex, "CREATE %s", folder_path);
- g_free (folder_path);
-
- if (status != CAMEL_IMAP_OK)
- return FALSE;
-
- return TRUE;
-}
-
-#if 0
-static gboolean
-folder_is_selectable (CamelStore *store, const char *folder_path, CamelException *ex)
-{
- char *result, *flags, *sep, *folder;
- int status;
-
- if (!g_strcasecmp (folder_path, "INBOX"))
- return TRUE;
-
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (store), NULL,
- &result, ex, "LIST \"\" %s", folder_path);
- if (status != CAMEL_IMAP_OK)
- return FALSE;
-
- if (imap_parse_list_response (result, "", &flags, &sep, &folder)) {
- gboolean retval;
-
- retval = !e_strstrcase (flags, "NoSelect");
- g_free (flags);
- g_free (sep);
- g_free (folder);
-
- return retval;
- }
- g_free (flags);
- g_free (sep);
- g_free (folder);
-
- return FALSE;
+ return status == CAMEL_IMAP_OK;
}
-#endif
static CamelFolder *
get_folder (CamelStore *store, const char *folder_name, gboolean create, CamelException *ex)
{
- CamelURL *url = CAMEL_SERVICE (store)->url;
+ CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
CamelFolder *new_folder;
char *folder_path;
gboolean exists = FALSE;
gboolean selectable;
- g_return_val_if_fail (store != NULL, NULL);
- g_return_val_if_fail (folder_name != NULL, NULL);
-
- /* if we're trying to get the top-level dir, we really want the namespace */
- /* Yes, we use a hard-coded "/" here - this just means top-level directory */
- if (!strcmp (folder_name, "/"))
- folder_path = g_strdup (url->path + 1);
- else
- folder_path = g_strdup (folder_name);
-
+ folder_path = camel_imap_store_folder_path (imap_store, folder_name);
new_folder = camel_imap_folder_new (store, folder_path);
-
+
/* this is the top-level dir, we already know it exists - it has to! */
- /* Yes, we use a hard-coded "/" here - this just means top-level directory */
- if (!strcmp (folder_name, "/")) {
+ if (!*folder_name) {
+ g_free (folder_path);
camel_folder_refresh_info (new_folder, ex);
return new_folder;
}
-
- if (imap_folder_exists (new_folder, &selectable, ex)) {
- /* ah huh, so the folder *does* exist... */
+
+ if (imap_folder_exists (imap_store, folder_path, &selectable, ex)) {
exists = TRUE;
-
- /* now lets see if it's selectable... */
- if (!selectable) {
- camel_exception_clear (ex);
+ if (!selectable)
new_folder->can_hold_messages = FALSE;
- }
}
-
- if (!exists && create && !imap_create (new_folder, ex)) {
+
+ if (!exists && create && !imap_create (imap_store, folder_path, ex)) {
g_free (folder_path);
- camel_object_unref (CAMEL_OBJECT (new_folder));
+ camel_object_unref (CAMEL_OBJECT (new_folder));
return NULL;
}
-
+
/* this is where we *should refresh_info, not in imap_folder_new() */
camel_folder_refresh_info (new_folder, ex);
return new_folder;
}
+static char *
+get_folder_name (CamelStore *store, const char *folder_name,
+ CamelException *ex)
+{
+ /* INBOX is case-insensitive */
+ if (g_strcasecmp (folder_name, "INBOX") == 0)
+ return g_strdup ("INBOX");
+ else
+ return g_strdup (folder_name);
+}
+
+static char *
+get_root_folder_name (CamelStore *store, CamelException *ex)
+{
+ return g_strdup ("");
+}
+
static void
imap_keepalive (CamelRemoteStore *store)
{
@@ -592,8 +500,7 @@ camel_imap_status (char *cmdid, char *respbuf)
static gint
check_current_folder (CamelImapStore *store, CamelFolder *folder, char *fmt, CamelException *ex)
{
- CamelURL *url = CAMEL_SERVICE (store)->url;
- char *result, *folder_path, *dir_sep;
+ char *result, *folder_path;
int status;
/* return OK if we meet one of the following criteria:
@@ -603,13 +510,7 @@ check_current_folder (CamelImapStore *store, CamelFolder *folder, char *fmt, Cam
if (!folder || store->current_folder == folder || !strncmp (fmt, "CREATE ", 7))
return CAMEL_IMAP_OK;
- dir_sep = store->dir_sep;
-
- if (url && url->path && *(url->path + 1) && g_strcasecmp (folder->full_name, "INBOX"))
- folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name);
- else
- folder_path = g_strdup (folder->full_name);
-
+ folder_path = camel_imap_store_folder_path (store, folder->full_name);
status = camel_imap_command_extended (store, NULL, &result, ex, "SELECT %s", folder_path);
g_free (folder_path);
diff --git a/camel/providers/imap/camel-imap-store.h b/camel/providers/imap/camel-imap-store.h
index 2b946f065c..fe7b9f2f78 100644
--- a/camel/providers/imap/camel-imap-store.h
+++ b/camel/providers/imap/camel-imap-store.h
@@ -110,7 +110,7 @@ gint camel_imap_command_continuation_with_stream (CamelImapStore *store,
/* Standard Camel function */
CamelType camel_imap_store_get_type (void);
-const gchar *camel_imap_store_get_toplevel_dir (CamelImapStore *store);
+char *camel_imap_store_folder_path (CamelImapStore *store, const char *name);
#ifdef __cplusplus
}