aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2001-02-15 05:51:33 +0800
committerDan Winship <danw@src.gnome.org>2001-02-15 05:51:33 +0800
commit7d76ff550168871217e6d483f965ce430427c536 (patch)
tree86afc5a45c2b45f79587093267d680704d5d836c /camel
parent3245f9dacf18e68ed5e1bc18226d0ffe65c7bf6c (diff)
downloadgsoc2013-evolution-7d76ff550168871217e6d483f965ce430427c536.tar
gsoc2013-evolution-7d76ff550168871217e6d483f965ce430427c536.tar.gz
gsoc2013-evolution-7d76ff550168871217e6d483f965ce430427c536.tar.bz2
gsoc2013-evolution-7d76ff550168871217e6d483f965ce430427c536.tar.lz
gsoc2013-evolution-7d76ff550168871217e6d483f965ce430427c536.tar.xz
gsoc2013-evolution-7d76ff550168871217e6d483f965ce430427c536.tar.zst
gsoc2013-evolution-7d76ff550168871217e6d483f965ce430427c536.zip
New method to create a folder when you don't know its full name.
* camel-store.c (camel_store_create_folder): New method to create a folder when you don't know its full name. * providers/imap/camel-imap-store.c (create_folder): Implement. svn path=/trunk/; revision=8231
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog7
-rw-r--r--camel/camel-store.c42
-rw-r--r--camel/camel-store.h8
-rw-r--r--camel/providers/imap/camel-imap-store.c47
4 files changed, 95 insertions, 9 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 5a0d7bfdaf..123aaef782 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,10 @@
+2001-02-14 Dan Winship <danw@ximian.com>
+
+ * camel-store.c (camel_store_create_folder): New method to create
+ a folder when you don't know its full name.
+
+ * providers/imap/camel-imap-store.c (create_folder): Implement.
+
2001-02-12 Not Zed <NotZed@Ximian.com>
* camel-mime-part.c (init_header_name_table): Add address headers
diff --git a/camel/camel-store.c b/camel/camel-store.c
index e7bd25a4be..bc86a72232 100644
--- a/camel/camel-store.c
+++ b/camel/camel-store.c
@@ -42,6 +42,10 @@ static CamelFolder *get_folder (CamelStore *store, const char *folder_name,
guint32 flags, CamelException *ex);
static CamelFolder *get_inbox (CamelStore *store, CamelException *ex);
+static CamelFolderInfo *create_folder (CamelStore *store,
+ const char *parent_name,
+ const char *folder_name,
+ CamelException *ex);
static void delete_folder (CamelStore *store, const char *folder_name,
CamelException *ex);
static void rename_folder (CamelStore *store, const char *old_name,
@@ -68,6 +72,7 @@ camel_store_class_init (CamelStoreClass *camel_store_class)
camel_store_class->compare_folder_name = g_str_equal;
camel_store_class->get_folder = get_folder;
camel_store_class->get_inbox = get_inbox;
+ camel_store_class->create_folder = create_folder;
camel_store_class->delete_folder = delete_folder;
camel_store_class->rename_folder = rename_folder;
camel_store_class->sync = store_sync;
@@ -211,6 +216,42 @@ camel_store_get_folder (CamelStore *store, const char *folder_name, guint32 flag
}
+static CamelFolderInfo *
+create_folder (CamelStore *store, const char *parent_name,
+ const char *folder_name, CamelException *ex)
+{
+ g_warning ("CamelStore::create_folder not implemented for `%s'",
+ camel_type_to_name (CAMEL_OBJECT_GET_TYPE (store)));
+ return NULL;
+}
+
+/**
+ * camel_store_create_folder:
+ * @store: a CamelStore
+ * @parent_name: name of the new folder's parent, or %NULL
+ * @folder_name: name of the folder to create
+ * @ex: a CamelException
+ *
+ * Creates a new folder as a child of an existing folder.
+ * @parent_name can be %NULL to create a new top-level folder.
+ *
+ * Return value: info about the created folder, which the caller must
+ * free with camel_store_free_folder_info().
+ **/
+CamelFolderInfo *
+camel_store_create_folder (CamelStore *store, const char *parent_name,
+ const char *folder_name, CamelException *ex)
+{
+ CamelFolderInfo *fi;
+
+ CAMEL_STORE_LOCK(store, folder_lock);
+ fi = CS_CLASS (store)->create_folder (store, parent_name, folder_name, ex);
+ CAMEL_STORE_UNLOCK(store, folder_lock);
+
+ return fi;
+}
+
+
static void
delete_folder (CamelStore *store, const char *folder_name, CamelException *ex)
{
@@ -232,7 +273,6 @@ camel_store_delete_folder (CamelStore *store, const char *folder_name, CamelExce
CAMEL_STORE_LOCK(store, folder_lock);
CS_CLASS (store)->delete_folder (store, folder_name, ex);
CAMEL_STORE_UNLOCK(store, folder_lock);
-
}
diff --git a/camel/camel-store.h b/camel/camel-store.h
index da81a435f0..cd53b7813d 100644
--- a/camel/camel-store.h
+++ b/camel/camel-store.h
@@ -83,6 +83,10 @@ typedef struct {
CamelFolder * (*get_inbox) (CamelStore *store,
CamelException *ex);
+ CamelFolderInfo *(*create_folder) (CamelStore *store,
+ const char *parent_name,
+ const char *folder_name,
+ CamelException *ex);
void (*delete_folder) (CamelStore *store,
const char *folder_name,
CamelException *ex);
@@ -126,6 +130,10 @@ CamelFolder * camel_store_get_folder (CamelStore *store,
CamelFolder * camel_store_get_inbox (CamelStore *store,
CamelException *ex);
+CamelFolderInfo *camel_store_create_folder (CamelStore *store,
+ const char *parent_name,
+ const char *folder_name,
+ CamelException *ex);
void camel_store_delete_folder (CamelStore *store,
const char *folder_name,
CamelException *ex);
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index f19d8feb31..d02a2f991e 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -63,6 +63,7 @@ static GList *query_auth_types (CamelService *service, gboolean connect, CamelEx
static guint hash_folder_name (gconstpointer key);
static gint compare_folder_name (gconstpointer a, gconstpointer b);
static CamelFolder *get_folder (CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex);
+static CamelFolderInfo *create_folder (CamelStore *store, const char *parent_name, const char *folder_name, CamelException *ex);
static CamelFolderInfo *get_folder_info (CamelStore *store, const char *top,
gboolean fast, gboolean recursive,
gboolean subscribed_only,
@@ -96,6 +97,7 @@ camel_imap_store_class_init (CamelImapStoreClass *camel_imap_store_class)
camel_store_class->hash_folder_name = hash_folder_name;
camel_store_class->compare_folder_name = compare_folder_name;
camel_store_class->get_folder = get_folder;
+ camel_store_class->create_folder = create_folder;
camel_store_class->get_folder_info = get_folder_info;
camel_store_class->free_folder_info = camel_store_free_folder_info_full;
@@ -681,6 +683,42 @@ get_folder (CamelStore *store, const char *folder_name, guint32 flags,
return new_folder;
}
+static char *
+imap_concat (CamelImapStore *imap_store, const char *prefix, const char *suffix)
+{
+ int len;
+
+ len = strlen (prefix);
+ if (len > 0 && prefix[len - 1] == imap_store->dir_sep)
+ return g_strdup_printf ("%s%s", prefix, suffix);
+ else
+ return g_strdup_printf ("%s%c%s", prefix, imap_store->dir_sep, suffix);
+}
+
+static CamelFolderInfo *
+create_folder (CamelStore *store, const char *parent_name,
+ const char *folder_name, CamelException *ex)
+{
+ CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
+ CamelFolderInfo *fi;
+ char *full_name;
+
+ if (parent_name)
+ full_name = imap_concat (imap_store, parent_name, folder_name);
+ else
+ full_name = g_strdup (folder_name);
+
+ imap_create (imap_store, full_name, ex);
+ if (camel_exception_is_set (ex)) {
+ g_free (full_name);
+ return NULL;
+ }
+
+ fi = get_folder_info (store, full_name, FALSE, FALSE, FALSE, ex);
+ g_free (full_name);
+ return fi;
+}
+
static CamelFolderInfo *
parse_list_response_as_folder_info (CamelImapStore *imap_store,
const char *response)
@@ -839,14 +877,7 @@ get_folder_info (CamelStore *store, const char *top, gboolean fast,
if (subscribed_only && !imap_store->useful_lsub)
get_subscribed_folders_by_hand (imap_store, name, folders, ex);
else {
- if (*name && name[strlen (name) - 1] != imap_store->dir_sep) {
- pattern = g_strdup_printf ("%s%c%c", name,
- imap_store->dir_sep,
- recursive ? '*' : '%');
- } else {
- pattern = g_strdup_printf ("%s%c", name,
- recursive ? '*' : '%');
- }
+ pattern = imap_concat (imap_store, name, recursive ? "*" : "%");
get_folders (imap_store, pattern, folders, subscribed_only, ex);
g_free (pattern);
}