[evolution-data-server] Parse namespaces. fix warnings.
- From: Chenthill Palanisamy <pchen src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Parse namespaces. fix warnings.
- Date: Tue, 3 Nov 2009 20:04:28 +0000 (UTC)
commit 23401961e129b1f991c613b331888ed3d2e54c61
Author: Chenthill Palanisamy <pchenthill novell com>
Date: Wed Nov 4 01:28:59 2009 +0530
Parse namespaces. fix warnings.
camel/providers/imapx/camel-imapx-server.c | 51 +++++--
camel/providers/imapx/camel-imapx-server.h | 2 +
camel/providers/imapx/camel-imapx-store-summary.c | 169 ++++++++++++++-------
camel/providers/imapx/camel-imapx-store-summary.h | 11 ++-
camel/providers/imapx/camel-imapx-store.c | 8 +-
camel/providers/imapx/camel-imapx-stream.c | 32 ++--
camel/providers/imapx/camel-imapx-tokenise.h | 94 ++++++------
camel/providers/imapx/camel-imapx-tokens.txt | 1 +
camel/providers/imapx/camel-imapx-utils.c | 167 ++++++++++++++++++++-
camel/providers/imapx/camel-imapx-utils.h | 6 +
camel/providers/imapx/test-imapx.c | 3 +-
11 files changed, 408 insertions(+), 136 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 533b75a..aef1c63 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -164,7 +164,7 @@ struct _imapx_flag_change {
typedef struct _CamelIMAPXJob CamelIMAPXJob;
struct _CamelIMAPXJob {
- EMsg msg;
+ CamelMsg msg;
CamelException *ex;
@@ -866,10 +866,12 @@ static CamelIMAPXJob *
imapx_find_job(CamelIMAPXServer *imap, gint type, const gchar *uid)
{
CamelIMAPXJob *job;
+ CamelDListNode *node;
QUEUE_LOCK(imap);
- for (job = (CamelIMAPXJob *)imap->jobs.head;job->msg.ln.next;job = (CamelIMAPXJob *)job->msg.ln.next) {
+ for (node = imap->jobs.head;node->next;node = node->next) {
+ job = (CamelIMAPXJob *) node;
if (job->type != type)
continue;
@@ -972,6 +974,19 @@ imapx_untagged(CamelIMAPXServer *imap, CamelException *ex)
g_array_append_val(imap->expunged, expunge);
break;
}
+ case IMAP_NAMESPACE: {
+ CamelIMAPXNamespaceList *nsl = NULL;
+
+ nsl = imap_parse_namespace_list (imap->stream, ex);
+ if (nsl != NULL) {
+ CamelIMAPXStore *imapx_store = (CamelIMAPXStore *) imap->store;
+
+ imapx_store->summary->namespaces = nsl;
+ camel_store_summary_touch ((CamelStoreSummary *) imapx_store->summary);
+ }
+
+ break;
+ }
case IMAP_EXISTS:
printf("exists: %d\n", id);
imap->exists = id;
@@ -1339,10 +1354,13 @@ imapx_select_done(CamelIMAPXServer *is, CamelIMAPXCommand *ic)
{
if (ic->status->result != IMAP_OK) {
- CamelDList failed = E_DLIST_INITIALISER(failed);
+ CamelDList failed;
CamelIMAPXCommand *cw, *cn;
printf("Select failed\n");
+ failed.head = NULL;
+ failed.tail = NULL;
+ failed.tailpred = NULL;
QUEUE_LOCK(is);
cw = (CamelIMAPXCommand *)is->queue.head;
@@ -1585,6 +1603,13 @@ retry:
camel_exception_clear (ex);
goto retry;
}
+
+ /* Fetch namespaces */
+ if (is->cinfo->capa & IMAP_CAPABILITY_NAMESPACE) {
+ ic = camel_imapx_command_new ("NAMESPACE", NULL, "NAMESPACE");
+ imapx_command_run (is, ic, ex);
+ camel_imapx_command_free (ic);
+ }
}
/* ********************************************************************** */
@@ -1599,7 +1624,7 @@ imapx_job_done(CamelIMAPXServer *is, CamelIMAPXCommand *ic)
camel_exception_clear(job->ex);
g_free(job);
} else
- camel_msgport_reply((EMsg *)job);
+ camel_msgport_reply((CamelMsg *)job);
}
/* ********************************************************************** */
@@ -1837,7 +1862,7 @@ imapx_job_refresh_info_step_done(CamelIMAPXServer *is, CamelIMAPXCommand *ic)
}
g_array_free(job->u.refresh_info.infos, TRUE);
camel_dlist_remove((CamelDListNode *)job);
- camel_msgport_reply((EMsg *)job);
+ camel_msgport_reply((CamelMsg *)job);
}
static gint
@@ -1946,7 +1971,7 @@ imapx_job_refresh_info_done(CamelIMAPXServer *is, CamelIMAPXCommand *ic)
}
g_array_free(job->u.refresh_info.infos, TRUE);
camel_dlist_remove((CamelDListNode *)job);
- camel_msgport_reply((EMsg *)job);
+ camel_msgport_reply((CamelMsg *)job);
}
static void
@@ -2051,7 +2076,7 @@ imapx_job_sync_changes_done(CamelIMAPXServer *is, CamelIMAPXCommand *ic)
}*/
}
camel_dlist_remove((CamelDListNode *)job);
- camel_msgport_reply((EMsg *)job);
+ camel_msgport_reply((CamelMsg *)job);
}
}
@@ -2135,7 +2160,7 @@ imapx_job_sync_changes_start(CamelIMAPXServer *is, CamelIMAPXJob *job)
printf("Hmm, we didn't have any work to do afterall? hmm, this isn't right\n");
camel_dlist_remove((CamelDListNode *)job);
- camel_msgport_reply((EMsg *)job);
+ camel_msgport_reply((CamelMsg *)job);
}
}
@@ -2171,7 +2196,7 @@ imapx_server_loop(gpointer d)
if (!is->stream)
imapx_reconnect(is, &ex);
- job = (CamelIMAPXJob *)camel_msgport_get(is->port);
+ job = (CamelIMAPXJob *)camel_msgport_try_pop (is->port);
if (job) {
camel_dlist_addtail(&is->jobs, (CamelDListNode *)job);
job->start(is, job);
@@ -2181,7 +2206,7 @@ imapx_server_loop(gpointer d)
|| camel_imapx_stream_buffered(is->stream))
imapx_step(is, &ex);
else
- camel_msgport_wait(is->port);
+ camel_msgport_pop (is->port);
#if 0
/* TODO:
This poll stuff wont work - we might block
@@ -2366,12 +2391,12 @@ imapx_run_job(CamelIMAPXServer *is, CamelIMAPXJob *job)
QUEUE_UNLOCK(is);
job->start(is, job);
} else {
- camel_msgport_put(is->port, (EMsg *)job);
+ camel_msgport_push (is->port, (CamelMsg *)job);
}
if (!job->noreply) {
- CamelMsg *completed = camel_msgport_wait(reply);
- g_assert(completed == (EMsg *)job);
+ CamelMsg *completed = camel_msgport_pop (reply);
+ g_assert(completed == (CamelMsg *)job);
camel_msgport_destroy(reply);
}
}
diff --git a/camel/providers/imapx/camel-imapx-server.h b/camel/providers/imapx/camel-imapx-server.h
index 70ff0b0..a8e5f24 100644
--- a/camel/providers/imapx/camel-imapx-server.h
+++ b/camel/providers/imapx/camel-imapx-server.h
@@ -51,6 +51,8 @@ struct _CamelIMAPXServer {
struct _CamelIMAPXStream *stream;
struct _capability_info *cinfo;
+ CamelIMAPXNamespaceList *nsl;
+
/* incoming jobs */
CamelMsgPort *port;
CamelDList jobs;
diff --git a/camel/providers/imapx/camel-imapx-store-summary.c b/camel/providers/imapx/camel-imapx-store-summary.c
index 04f49c2..81d6998 100644
--- a/camel/providers/imapx/camel-imapx-store-summary.c
+++ b/camel/providers/imapx/camel-imapx-store-summary.c
@@ -33,7 +33,7 @@
#include "camel-private.h"
#include "camel-store.h"
#include "camel-utf8.h"
-
+#include "camel-imapx-utils.h"
#include "camel-imapx-store-summary.h"
#define d(x)
@@ -45,8 +45,6 @@
#define _PRIVATE(o) (((CamelIMAPXStoreSummary *)(o))->priv)
-static void namespace_clear(CamelStoreSummary *s);
-
static gint summary_header_load(CamelStoreSummary *, FILE *);
static gint summary_header_save(CamelStoreSummary *, FILE *);
@@ -393,8 +391,8 @@ CamelIMAPXStoreNamespace *camel_imapx_store_summary_namespace_new(CamelIMAPXStor
void camel_imapx_store_summary_namespace_set(CamelIMAPXStoreSummary *s, CamelIMAPXStoreNamespace *ns)
{
d(printf("Setting namesapce to '%s' '%c' -> '%s'\n", ns->full_name, ns->sep, ns->path));
- namespace_clear((CamelStoreSummary *)s);
- s->namespace = ns;
+
+ /* CHEN not needed */
camel_store_summary_touch((CamelStoreSummary *)s);
}
@@ -405,7 +403,8 @@ camel_imapx_store_summary_namespace_find_path(CamelIMAPXStoreSummary *s, const g
CamelIMAPXStoreNamespace *ns;
/* NB: this currently only compares against 1 namespace, in future compare against others */
- ns = s->namespace;
+ /* CHEN TODO */
+ ns = s->namespaces->personal;
while (ns) {
len = strlen(ns->path);
if (len == 0
@@ -426,7 +425,8 @@ camel_imapx_store_summary_namespace_find_full(CamelIMAPXStoreSummary *s, const g
CamelIMAPXStoreNamespace *ns;
/* NB: this currently only compares against 1 namespace, in future compare against others */
- ns = s->namespace;
+ /* CHEN TODO */
+ ns = s->namespaces->personal;
while (ns) {
len = strlen(ns->full_name);
d(printf("find_full: comparing namespace '%s' to name '%s'\n", ns->full_name, full));
@@ -441,50 +441,108 @@ camel_imapx_store_summary_namespace_find_full(CamelIMAPXStoreSummary *s, const g
return ns;
}
-static void
-namespace_free(CamelStoreSummary *s, CamelIMAPXStoreNamespace *ns)
+static CamelIMAPXNamespaceList *
+namespace_load(CamelStoreSummary *s, FILE *in)
{
- g_free(ns->path);
- g_free(ns->full_name);
- g_free(ns);
-}
+ CamelIMAPXStoreNamespace *ns, *tail;
+ CamelIMAPXNamespaceList *nsl;
+ guint32 i, j, n;
-static void
-namespace_clear(CamelStoreSummary *s)
-{
- CamelIMAPXStoreSummary *is = (CamelIMAPXStoreSummary *)s;
+ nsl = g_malloc0(sizeof(CamelIMAPXNamespaceList));
+ nsl->personal = NULL;
+ nsl->shared = NULL;
+ nsl->other = NULL;
- if (is->namespace)
- namespace_free(s, is->namespace);
- is->namespace = NULL;
-}
+ for (j = 0; j < 3; j++) {
+ switch (j) {
+ case 0:
+ tail = (CamelIMAPXStoreNamespace *) &nsl->personal;
+ break;
+ case 1:
+ tail = (CamelIMAPXStoreNamespace *) &nsl->shared;
+ break;
+ case 2:
+ tail = (CamelIMAPXStoreNamespace *) &nsl->other;
+ break;
+ }
-static CamelIMAPXStoreNamespace *
-namespace_load(CamelStoreSummary *s, FILE *in)
-{
- CamelIMAPXStoreNamespace *ns;
- guint32 sep = '/';
+ if (camel_file_util_decode_fixed_int32 (in, &n) == -1)
+ goto exception;
- ns = g_malloc0(sizeof(*ns));
- if (camel_file_util_decode_string(in, &ns->path) == -1
- || camel_file_util_decode_string(in, &ns->full_name) == -1
- || camel_file_util_decode_uint32(in, &sep) == -1) {
- namespace_free(s, ns);
- ns = NULL;
- } else {
- ns->sep = sep;
+ for (i = 0; i < n; i++) {
+ guint32 sep;
+ gchar *path;
+ gchar *full_name;
+
+ if (camel_file_util_decode_string (in, &path) == -1)
+ goto exception;
+
+ if (camel_file_util_decode_string (in, &full_name) == -1) {
+ g_free (path);
+ goto exception;
+ }
+
+ if (camel_file_util_decode_uint32 (in, &sep) == -1) {
+ g_free (path);
+ g_free (full_name);
+ goto exception;
+ }
+
+ tail->next = ns = g_malloc (sizeof (CamelIMAPXStoreNamespace));
+ ns->sep = sep;
+ ns->path = path;
+ ns->path = full_name;
+ ns->next = NULL;
+ tail = ns;
+ }
}
- return ns;
+ return nsl;
+exception:
+ camel_imapx_namespace_list_clear (nsl);
+
+ return NULL;
}
static gint
-namespace_save(CamelStoreSummary *s, FILE *in, CamelIMAPXStoreNamespace *ns)
+namespace_save(CamelStoreSummary *s, FILE *out, CamelIMAPXNamespaceList *nsl)
{
- if (camel_file_util_encode_string(in, ns->path) == -1
- || camel_file_util_encode_string(in, ns->full_name) == -1
- || camel_file_util_encode_uint32(in, (guint32)ns->sep) == -1)
- return -1;
+ CamelIMAPXStoreNamespace *ns, *cur = NULL;
+ guint32 i, n;
+
+ for (i = 0; i < 3; i++) {
+ switch (i) {
+ case 0:
+ cur = nsl->personal;
+ break;
+ case 1:
+ cur = nsl->shared;
+ break;
+ case 2:
+ cur = nsl->other;
+ break;
+ }
+
+ for (ns = cur, n = 0; ns; n++)
+ ns = ns->next;
+
+ if (camel_file_util_encode_fixed_int32 (out, n) == -1)
+ return -1;
+
+ ns = cur;
+ while (ns != NULL) {
+ if (camel_file_util_encode_string (out, ns->path) == -1)
+ return -1;
+
+ if (camel_file_util_encode_string (out, ns->full_name) == -1)
+ return -1;
+
+ if (camel_file_util_encode_uint32 (out, ns->sep) == -1)
+ return -1;
+
+ ns = ns->next;
+ }
+ }
return 0;
}
@@ -493,9 +551,9 @@ static gint
summary_header_load(CamelStoreSummary *s, FILE *in)
{
CamelIMAPXStoreSummary *is = (CamelIMAPXStoreSummary *)s;
- gint32 version, capabilities, count;
+ gint32 version, capabilities;
- namespace_clear(s);
+ camel_imapx_namespace_list_clear (is->namespaces);
if (camel_imapx_store_summary_parent->summary_header_load((CamelStoreSummary *)s, in) == -1
|| camel_file_util_decode_fixed_int32(in, &version) == -1)
@@ -509,16 +567,14 @@ summary_header_load(CamelStoreSummary *s, FILE *in)
}
/* note file format can be expanded to contain more namespaces, but only 1 at the moment */
- if (camel_file_util_decode_fixed_int32(in, &capabilities) == -1
- || camel_file_util_decode_fixed_int32(in, &count) == -1
- || count > 1)
+ if (camel_file_util_decode_fixed_int32(in, &capabilities) == -1)
return -1;
is->capabilities = capabilities;
- if (count == 1) {
- if ((is->namespace = namespace_load(s, in)) == NULL)
- return -1;
- }
+
+ /* namespaces */
+ if ((is->namespaces = namespace_load(s, in)) == NULL)
+ return -1;
return 0;
}
@@ -527,18 +583,15 @@ static gint
summary_header_save(CamelStoreSummary *s, FILE *out)
{
CamelIMAPXStoreSummary *is = (CamelIMAPXStoreSummary *)s;
- guint32 count;
- count = is->namespace?1:0;
/* always write as latest version */
if (camel_imapx_store_summary_parent->summary_header_save((CamelStoreSummary *)s, out) == -1
|| camel_file_util_encode_fixed_int32(out, CAMEL_IMAPX_STORE_SUMMARY_VERSION) == -1
- || camel_file_util_encode_fixed_int32(out, is->capabilities) == -1
- || camel_file_util_encode_fixed_int32(out, count) == -1)
+ || camel_file_util_encode_fixed_int32(out, is->capabilities) == -1)
return -1;
- if (is->namespace && namespace_save(s, out, is->namespace) == -1)
+ if (is->namespaces && namespace_save(s, out, is->namespaces) == -1)
return -1;
return 0;
@@ -622,3 +675,11 @@ store_info_set_string(CamelStoreSummary *s, CamelStoreInfo *mi, gint type, const
break;
}
}
+
+void
+camel_imapx_store_summary_set_namespaces (CamelIMAPXStoreSummary *summary, const CamelIMAPXNamespaceList *nsl)
+{
+ if (summary->namespaces)
+ camel_imapx_namespace_list_clear (summary->namespaces);
+ summary->namespaces = camel_imapx_namespace_list_copy (summary->namespaces);
+}
diff --git a/camel/providers/imapx/camel-imapx-store-summary.h b/camel/providers/imapx/camel-imapx-store-summary.h
index aa6015f..5448c54 100644
--- a/camel/providers/imapx/camel-imapx-store-summary.h
+++ b/camel/providers/imapx/camel-imapx-store-summary.h
@@ -49,11 +49,18 @@ struct _CamelIMAPXStoreInfo {
typedef struct _CamelIMAPXStoreNamespace CamelIMAPXStoreNamespace;
struct _CamelIMAPXStoreNamespace {
+ struct _CamelIMAPXStoreNamespace *next;
gchar *path; /* display path */
gchar *full_name; /* real name */
gchar sep; /* directory separator */
};
+typedef struct _CamelIMAPXNamespaceList {
+ CamelIMAPXStoreNamespace *personal;
+ CamelIMAPXStoreNamespace *other;
+ CamelIMAPXStoreNamespace *shared;
+} CamelIMAPXNamespaceList;
+
struct _CamelIMAPXStoreSummary {
CamelStoreSummary summary;
@@ -62,7 +69,7 @@ struct _CamelIMAPXStoreSummary {
/* header info */
guint32 version; /* version of base part of file */
guint32 capabilities;
- CamelIMAPXStoreNamespace *namespace; /* eventually to be a list */
+ CamelIMAPXNamespaceList *namespaces; /* eventually to be a list */
};
struct _CamelIMAPXStoreSummaryClass {
@@ -88,6 +95,8 @@ CamelIMAPXStoreInfo *camel_imapx_store_summary_add_from_full(CamelIMAPXStoreSumm
/* a convenience lookup function. always use this if path known */
gchar *camel_imapx_store_summary_full_from_path(CamelIMAPXStoreSummary *s, const gchar *path);
+void camel_imapx_store_summary_set_namespaces (CamelIMAPXStoreSummary *summary, const CamelIMAPXNamespaceList *nsl);
+
/* helpe macro's */
#define camel_imapx_store_info_full_name(s, i) (camel_store_info_string((CamelStoreSummary *)s, (const CamelStoreInfo *)i, CAMEL_IMAP_STORE_INFO_FULL_NAME))
diff --git a/camel/providers/imapx/camel-imapx-store.c b/camel/providers/imapx/camel-imapx-store.c
index 095db33..c2a3304 100644
--- a/camel/providers/imapx/camel-imapx-store.c
+++ b/camel/providers/imapx/camel-imapx-store.c
@@ -517,8 +517,8 @@ get_folder_info_offline (CamelStore *store, const gchar *top,
gchar *pattern, *name;
gint i;
- if (camel_debug("imap:folder_info"))
- printf("get folder info offline\n");
+// if (camel_debug("imap:folder_info"))
+ printf("get folder info offline\n");
/* FIXME: obey other flags */
@@ -532,8 +532,8 @@ get_folder_info_offline (CamelStore *store, const gchar *top,
/* get starting point */
if (top[0] == 0) {
if (imapx_store->namespace && imapx_store->namespace[0]) {
- name = g_strdup(imapx_store->summary->namespace->full_name);
- top = imapx_store->summary->namespace->path;
+ name = g_strdup(imapx_store->summary->namespaces->personal->full_name);
+ top = imapx_store->summary->namespaces->personal->path;
} else
name = g_strdup("");
} else {
diff --git a/camel/providers/imapx/camel-imapx-stream.c b/camel/providers/imapx/camel-imapx-stream.c
index 223e9b1..b76e9ab 100644
--- a/camel/providers/imapx/camel-imapx-stream.c
+++ b/camel/providers/imapx/camel-imapx-stream.c
@@ -58,7 +58,7 @@ stream_fill(CamelIMAPXStream *is)
memcpy(is->buf, is->ptr, left);
is->end = is->buf + left;
is->ptr = is->buf;
- left = camel_stream_read(is->source, is->end, CAMEL_IMAPX_STREAM_SIZE - (is->end - is->buf));
+ left = camel_stream_read(is->source, (gchar *) is->end, CAMEL_IMAPX_STREAM_SIZE - (is->end - is->buf));
if (left > 0) {
is->end += left;
io(printf("camel_imapx_read: buffer is '%.*s'\n", (gint)(is->end - is->ptr), is->ptr));
@@ -280,6 +280,7 @@ camel_imapx_stream_astring(CamelIMAPXStream *is, guchar **data, CamelException *
{
guchar *p, *start;
guint len, inlen;
+ gint ret;
switch (camel_imapx_stream_token(is, data, &len, ex)) {
case IMAP_TOK_TOKEN:
@@ -296,12 +297,12 @@ camel_imapx_stream_astring(CamelIMAPXStream *is, guchar **data, CamelException *
p = is->tokenptr;
camel_imapx_stream_set_literal(is, len);
do {
- len = camel_imapx_stream_getl(is, &start, &inlen);
- if (len < 0)
- return len;
+ ret = camel_imapx_stream_getl(is, &start, &inlen);
+ if (ret < 0)
+ return ret;
memcpy(p, start, inlen);
p += inlen;
- } while (len > 0);
+ } while (ret > 0);
*data = is->tokenptr;
return 0;
case IMAP_TOK_ERROR:
@@ -320,6 +321,7 @@ camel_imapx_stream_nstring(CamelIMAPXStream *is, guchar **data, CamelException *
{
guchar *p, *start;
guint len, inlen;
+ gint ret;
switch (camel_imapx_stream_token(is, data, &len, ex)) {
case IMAP_TOK_STRING:
@@ -333,12 +335,12 @@ camel_imapx_stream_nstring(CamelIMAPXStream *is, guchar **data, CamelException *
p = is->tokenptr;
camel_imapx_stream_set_literal(is, len);
do {
- len = camel_imapx_stream_getl(is, &start, &inlen);
- if (len < 0)
- return len;
+ ret = camel_imapx_stream_getl(is, &start, &inlen);
+ if (ret < 0)
+ return ret;
memcpy(p, start, inlen);
p += inlen;
- } while (len > 0);
+ } while (ret > 0);
*data = is->tokenptr;
return 0;
case IMAP_TOK_TOKEN:
@@ -365,13 +367,13 @@ camel_imapx_stream_nstring_stream(CamelIMAPXStream *is, CamelStream **stream, Ca
guchar *token;
guint len;
gint ret = 0;
- CamelStream * volatile mem = NULL;
+ CamelStream * mem = NULL;
*stream = NULL;
switch (camel_imapx_stream_token(is, &token, &len, ex)) {
case IMAP_TOK_STRING:
- mem = camel_stream_mem_new_with_buffer(token, len);
+ mem = camel_stream_mem_new_with_buffer((gchar *)token, len);
*stream = mem;
break;
case IMAP_TOK_LITERAL:
@@ -411,7 +413,7 @@ camel_imapx_stream_number(CamelIMAPXStream *is, CamelException *ex)
return 0;
}
- return strtoul(token, 0, 10);
+ return strtoul((gchar *)token, 0, 10);
}
gint
@@ -427,8 +429,8 @@ camel_imapx_stream_text(CamelIMAPXStream *is, guchar **text, CamelException *ex)
case IMAP_TOK_TOKEN:
case IMAP_TOK_STRING:
case IMAP_TOK_INT:
- g_byte_array_append(build, is->unget_token, is->unget_len);
- g_byte_array_append(build, " ", 1);
+ g_byte_array_append(build, (guint8 *) is->unget_token, is->unget_len);
+ g_byte_array_append(build, (guint8 *) " ", 1);
default: /* invalid, but we'll ignore */
break;
}
@@ -447,7 +449,7 @@ camel_imapx_stream_text(CamelIMAPXStream *is, guchar **text, CamelException *ex)
g_byte_array_append(build, token, len);
} while (tok > 0);
- g_byte_array_append(build, "", 1);
+ g_byte_array_append(build, (guint8 *) "", 1);
*text = build->data;
g_byte_array_free(build, FALSE);
diff --git a/camel/providers/imapx/camel-imapx-tokenise.h b/camel/providers/imapx/camel-imapx-tokenise.h
index e174f54..03a82a1 100644
--- a/camel/providers/imapx/camel-imapx-tokenise.h
+++ b/camel/providers/imapx/camel-imapx-tokenise.h
@@ -1,4 +1,4 @@
-/* ANSI-C code produced by gperf version 3.0.1 */
+/* ANSI-C code produced by gperf version 3.0.2 */
/* Command-line: gperf -H imap_hash -N imap_tokenise_struct -L ANSI-C -o -t -k'1,$' camel-imapx-tokens.txt */
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
@@ -29,9 +29,9 @@
#endif
#line 3 "camel-imapx-tokens.txt"
-struct _imap_keyword { gchar *name; camel_imapx_id_t id; };
+struct _imap_keyword { char *name; camel_imapx_id_t id; };
-#define TOTAL_KEYWORDS 31
+#define TOTAL_KEYWORDS 32
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 14
#define MIN_HASH_VALUE 2
@@ -45,10 +45,10 @@ __inline
inline
#endif
#endif
-static guint
-imap_hash (register const gchar *str, register guint len)
+static unsigned int
+imap_hash (register const char *str, register unsigned int len)
{
- static guchar asso_values[] =
+ static unsigned char asso_values[] =
{
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
@@ -56,9 +56,9 @@ imap_hash (register const gchar *str, register guint len)
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
- 50, 50, 50, 50, 50, 20, 15, 0, 20, 0,
- 20, 50, 5, 0, 50, 0, 20, 50, 15, 0,
- 15, 50, 0, 0, 10, 10, 50, 50, 50, 5,
+ 50, 50, 50, 50, 50, 20, 15, 15, 20, 0,
+ 10, 50, 5, 0, 50, 0, 25, 50, 20, 0,
+ 20, 50, 0, 0, 10, 10, 50, 50, 50, 5,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
@@ -77,19 +77,19 @@ imap_hash (register const gchar *str, register guint len)
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50
};
- return len + asso_values[(guchar)str[len - 1]] + asso_values[(guchar)str[0]];
+ return len + asso_values[(unsigned char)str[len - 1]] + asso_values[(unsigned char)str[0]];
}
#ifdef __GNUC__
__inline
#endif
struct _imap_keyword *
-imap_tokenise_struct (register const gchar *str, register guint len)
+imap_tokenise_struct (register const char *str, register unsigned int len)
{
static struct _imap_keyword wordlist[] =
{
{""}, {""},
-#line 22 "camel-imapx-tokens.txt"
+#line 23 "camel-imapx-tokens.txt"
{"OK", IMAP_OK},
{""}, {""}, {""},
#line 13 "camel-imapx-tokens.txt"
@@ -99,73 +99,77 @@ imap_tokenise_struct (register const gchar *str, register guint len)
#line 12 "camel-imapx-tokens.txt"
{"ENVELOPE", IMAP_ENVELOPE},
{""},
-#line 27 "camel-imapx-tokens.txt"
+#line 28 "camel-imapx-tokens.txt"
{"READ-WRITE", IMAP_READ_WRITE},
-#line 30 "camel-imapx-tokens.txt"
+#line 31 "camel-imapx-tokens.txt"
{"RFC822.SIZE", IMAP_RFC822_SIZE},
#line 17 "camel-imapx-tokens.txt"
{"INTERNALDATE", IMAP_INTERNALDATE},
-#line 29 "camel-imapx-tokens.txt"
+#line 30 "camel-imapx-tokens.txt"
{"RFC822.HEADER", IMAP_RFC822_HEADER},
-#line 26 "camel-imapx-tokens.txt"
+#line 27 "camel-imapx-tokens.txt"
{"READ-ONLY", IMAP_READ_ONLY},
-#line 11 "camel-imapx-tokens.txt"
- {"CAPABILITY", IMAP_CAPABILITY},
-#line 28 "camel-imapx-tokens.txt"
+#line 16 "camel-imapx-tokens.txt"
+ {"FLAGS", IMAP_FLAGS},
+#line 29 "camel-imapx-tokens.txt"
{"RECENT", IMAP_RECENT},
-#line 21 "camel-imapx-tokens.txt"
- {"NO", IMAP_NO},
+ {""},
#line 10 "camel-imapx-tokens.txt"
{"BYE", IMAP_BYE},
-#line 32 "camel-imapx-tokens.txt"
+#line 33 "camel-imapx-tokens.txt"
{"TRYCREATE", IMAP_TRYCREATE},
-#line 23 "camel-imapx-tokens.txt"
- {"PARSE", IMAP_PARSE},
-#line 31 "camel-imapx-tokens.txt"
+#line 15 "camel-imapx-tokens.txt"
+ {"FETCH", IMAP_FETCH},
+#line 32 "camel-imapx-tokens.txt"
{"RFC822.TEXT", IMAP_RFC822_TEXT},
-#line 20 "camel-imapx-tokens.txt"
- {"NEWNAME", IMAP_NEWNAME},
+#line 22 "camel-imapx-tokens.txt"
+ {"NO", IMAP_NO},
{""},
#line 8 "camel-imapx-tokens.txt"
{"BODY", IMAP_BODY},
-#line 16 "camel-imapx-tokens.txt"
- {"FLAGS", IMAP_FLAGS},
-#line 34 "camel-imapx-tokens.txt"
+#line 24 "camel-imapx-tokens.txt"
+ {"PARSE", IMAP_PARSE},
+#line 35 "camel-imapx-tokens.txt"
{"UIDVALIDITY", IMAP_UIDVALIDITY},
-#line 25 "camel-imapx-tokens.txt"
- {"PREAUTH", IMAP_PREAUTH},
+#line 21 "camel-imapx-tokens.txt"
+ {"NEWNAME", IMAP_NEWNAME},
#line 9 "camel-imapx-tokens.txt"
{"BODYSTRUCTURE", IMAP_BODYSTRUCTURE},
-#line 24 "camel-imapx-tokens.txt"
- {"PERMANENTFLAGS", IMAP_PERMANENTFLAGS},
-#line 15 "camel-imapx-tokens.txt"
- {"FETCH", IMAP_FETCH},
-#line 35 "camel-imapx-tokens.txt"
- {"UNSEEN", IMAP_UNSEEN},
+#line 20 "camel-imapx-tokens.txt"
+ {"NAMESPACE", IMAP_NAMESPACE},
+#line 11 "camel-imapx-tokens.txt"
+ {"CAPABILITY", IMAP_CAPABILITY},
{""},
-#line 33 "camel-imapx-tokens.txt"
+#line 26 "camel-imapx-tokens.txt"
+ {"PREAUTH", IMAP_PREAUTH},
+#line 34 "camel-imapx-tokens.txt"
{"UID", IMAP_UID},
-#line 18 "camel-imapx-tokens.txt"
- {"LIST", IMAP_LIST},
+#line 25 "camel-imapx-tokens.txt"
+ {"PERMANENTFLAGS", IMAP_PERMANENTFLAGS},
#line 5 "camel-imapx-tokens.txt"
{"ALERT", IMAP_ALERT},
- {""}, {""},
+#line 36 "camel-imapx-tokens.txt"
+ {"UNSEEN", IMAP_UNSEEN},
+ {""},
#line 7 "camel-imapx-tokens.txt"
{"BAD", IMAP_BAD},
+#line 18 "camel-imapx-tokens.txt"
+ {"LIST", IMAP_LIST},
+ {""}, {""}, {""}, {""},
#line 19 "camel-imapx-tokens.txt"
{"LSUB", IMAP_LSUB},
- {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
+ {""}, {""}, {""}, {""},
#line 6 "camel-imapx-tokens.txt"
{"APPENDUID", IMAP_APPENDUID}
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
- register gint key = imap_hash (str, len);
+ register int key = imap_hash (str, len);
if (key <= MAX_HASH_VALUE && key >= 0)
{
- register const gchar *s = wordlist[key].name;
+ register const char *s = wordlist[key].name;
if (*str == *s && !strcmp (str + 1, s + 1))
return &wordlist[key];
diff --git a/camel/providers/imapx/camel-imapx-tokens.txt b/camel/providers/imapx/camel-imapx-tokens.txt
index bd91561..0b10bd4 100644
--- a/camel/providers/imapx/camel-imapx-tokens.txt
+++ b/camel/providers/imapx/camel-imapx-tokens.txt
@@ -17,6 +17,7 @@ FLAGS, IMAP_FLAGS
INTERNALDATE, IMAP_INTERNALDATE
LIST, IMAP_LIST
LSUB, IMAP_LSUB
+NAMESPACE, IMAP_NAMESPACE
NEWNAME, IMAP_NEWNAME
NO, IMAP_NO
OK, IMAP_OK
diff --git a/camel/providers/imapx/camel-imapx-utils.c b/camel/providers/imapx/camel-imapx-utils.c
index 16c3b15..63d1824 100644
--- a/camel/providers/imapx/camel-imapx-utils.c
+++ b/camel/providers/imapx/camel-imapx-utils.c
@@ -10,6 +10,7 @@
#include "camel-imapx-folder.h"
#include "camel-imapx-stream.h"
+#include "camel-imapx-store-summary.h"
#include "camel-imapx-utils.h"
#include "camel-imapx-exception.h"
#include "libedataserver/e-memory.h"
@@ -35,6 +36,8 @@ imap_tokenise (register const gchar *str, register guint len)
return 0;
}
+static void imapx_namespace_clear (CamelIMAPXStoreNamespace **ns);
+
/* flag table */
static struct {
gchar *name;
@@ -56,7 +59,8 @@ void
imap_parse_flags(CamelIMAPXStream *stream, guint32 *flagsp, CamelFlag **user_flagsp, CamelException *ex)
/* throws IO,PARSE exception */
{
- gint tok, len, i;
+ gint tok, i;
+ guint len;
guchar *token, *p, c;
guint32 flags = 0;
@@ -72,12 +76,12 @@ imap_parse_flags(CamelIMAPXStream *stream, guint32 *flagsp, CamelFlag **user_fla
while ((c=*p))
*p++ = toupper(c);
for (i = 0; i < G_N_ELEMENTS (flag_table); i++)
- if (!strcmp(token, flag_table[i].name)) {
+ if (!strcmp((gchar *)token, flag_table[i].name)) {
flags |= flag_table[i].flag;
goto found;
}
if (user_flagsp)
- camel_flag_set(user_flagsp, token, TRUE);
+ camel_flag_set(user_flagsp, (gchar *)token, TRUE);
found:
tok = tok; /* fixes stupid warning */
} else if (tok != ')') {
@@ -184,11 +188,107 @@ imap_parse_capability(CamelIMAPXStream *stream, CamelException *ex)
return cinfo;
}
+
void imap_free_capability(struct _capability_info *cinfo)
{
g_free(cinfo);
}
+struct _CamelIMAPXNamespaceList *
+imap_parse_namespace_list (CamelIMAPXStream *stream, CamelException *ex)
+{
+ CamelIMAPXStoreNamespace *namespaces[3], *node, *tail;
+ CamelIMAPXNamespaceList *nsl = NULL;
+ gint tok, len, i;
+ guchar *token, *p, c;
+ gint n = 0;
+
+ nsl = g_malloc0(sizeof(CamelIMAPXNamespaceList));
+ nsl->personal = NULL;
+ nsl->shared = NULL;
+ nsl->other = NULL;
+
+ tok = camel_imapx_stream_token (stream, &token, &len, ex);
+ do {
+ namespaces[n] = NULL;
+ tail = (CamelIMAPXStoreNamespace *) &namespaces[n];
+
+ if (tok == '(') {
+ tok = camel_imapx_stream_token (stream, &token, &len, ex);
+
+ if (tok != IMAP_TOK_STRING) {
+ camel_exception_set (ex, 1, "namespace: expected a string path name");
+ goto exception;
+ }
+
+ node = g_new0 (CamelIMAPXStoreNamespace, 1);
+ node->next = NULL;
+ node->path = g_strdup (token);
+ g_message ("namespace: Node path is %s \n", node->path);
+
+ tok = camel_imapx_stream_token (stream, &token, &len, ex);
+
+ if (tok == IMAP_TOK_STRING) {
+ if (strlen (token) == 1) {
+ node->sep = *token;
+ } else {
+ if (*token)
+ node->sep = node->path [strlen (node->path) - 1];
+ else
+ node->sep = '\0';
+ }
+ break;
+ } else if (tok == IMAP_TOK_TOKEN) {
+ /* will a NIL be possible here? */
+ node->sep = '\0';
+ } else {
+ camel_exception_set (ex, 1, "namespace: expected a string separator");
+ g_free (node->path);
+ g_free (node);
+ goto exception;
+ }
+
+ tail->next = node;
+ tail = node;
+
+ if (node->path [strlen (node->path) -1] == node->sep)
+ node->path [strlen (node->path) - 1] = '\0';
+
+ if (!g_ascii_strncasecmp (node->path, "INBOX", 5) &&
+ (node->path [6] == '\0' || node->path [6] == node->sep ))
+ memcpy (node->path, "INBOX", 5);
+ tok = camel_imapx_stream_token (stream, &token, &len, ex);
+ if (tok != ')') {
+ camel_exception_set (ex, 1, "namespace: expected a ')'");
+ goto exception;
+ }
+
+ tok = camel_imapx_stream_token (stream, &token, &len, ex);
+
+ } else if (tok == IMAP_TOK_TOKEN && !strcmp (token, "NIL")) {
+ namespaces [n] = NULL;
+ } else {
+ camel_exception_set (ex, 1, "namespace: expected either a '(' or NIL");
+ goto exception;
+ }
+
+ tok = camel_imapx_stream_token (stream, &token, &len, ex);
+ n++;
+ } while (n < 3);
+
+ nsl->personal = namespaces [0];
+ nsl->shared = namespaces [1];
+ nsl->other = namespaces [2];
+
+ return nsl;
+exception:
+ g_free (nsl);
+ for (i=0; i < 3; i++)
+ imapx_namespace_clear (&namespaces [i]);
+
+ return NULL;
+}
+
/*
body ::= "(" body_type_1part / body_type_mpart ")"
@@ -1447,3 +1547,64 @@ imapx_concat (CamelIMAPXStore *imap_store, const gchar *prefix, const gchar *suf
else
return g_strdup_printf ("%s%c%s", prefix, imap_store->dir_sep, suffix);
}
+
+static void
+imapx_namespace_clear (CamelIMAPXStoreNamespace **ns)
+{
+ CamelIMAPXStoreNamespace *node, *next;
+
+ node = *ns;
+ while (node != NULL) {
+ next = node->next;
+ g_free (node->path);
+ g_free (node);
+ node = next;
+ }
+
+ *ns = NULL;
+}
+
+void
+camel_imapx_namespace_list_clear (struct _CamelIMAPXNamespaceList *nsl)
+{
+ imapx_namespace_clear (&nsl->personal);
+ imapx_namespace_clear (&nsl->shared);
+ imapx_namespace_clear (&nsl->other);
+
+ g_free (nsl);
+ nsl = NULL;
+}
+
+static CamelIMAPXStoreNamespace *
+imapx_namespace_copy (const CamelIMAPXStoreNamespace *ns)
+{
+ CamelIMAPXStoreNamespace *list, *node, *tail;
+
+ list = NULL;
+ tail = (CamelIMAPXStoreNamespace *) &list;
+
+ while (ns != NULL) {
+ tail->next = node = g_malloc (sizeof (CamelIMAPXStoreNamespace));
+ node->path = g_strdup (ns->path);
+ node->sep = ns->sep;
+ ns = ns->next;
+ tail = node;
+ }
+
+ tail->next = NULL;
+
+ return list;
+}
+
+struct _CamelIMAPXNamespaceList *
+camel_imapx_namespace_list_copy (const struct _CamelIMAPXNamespaceList *nsl)
+{
+ CamelIMAPXNamespaceList *new;
+
+ new = g_malloc (sizeof (CamelIMAPXNamespaceList));
+ new->personal = imapx_namespace_copy (nsl->personal);
+ new->other = imapx_namespace_copy (nsl->other);
+ new->shared = imapx_namespace_copy (nsl->shared);
+
+ return new;
+}
diff --git a/camel/providers/imapx/camel-imapx-utils.h b/camel/providers/imapx/camel-imapx-utils.h
index a9c2eed..fc7c633 100644
--- a/camel/providers/imapx/camel-imapx-utils.h
+++ b/camel/providers/imapx/camel-imapx-utils.h
@@ -8,6 +8,7 @@
struct _CamelIMAPXStream;
struct _CamelFlag;
+struct _CamelIMAPXNamespaceList;
/* list of strings we know about that can be *quickly* tokenised */
typedef enum _camel_imapx_id_t {
@@ -27,6 +28,7 @@ typedef enum _camel_imapx_id_t {
IMAP_INTERNALDATE,
IMAP_LIST,
IMAP_LSUB,
+ IMAP_NAMESPACE,
IMAP_NEWNAME,
IMAP_NO,
IMAP_OK,
@@ -191,4 +193,8 @@ void imapx_utils_init(void);
gchar *imapx_path_to_physical (const gchar *prefix, const gchar *vpath);
gchar *imapx_concat (CamelIMAPXStore *imap_store, const gchar *prefix, const gchar *suffix);
+void camel_imapx_namespace_list_clear (struct _CamelIMAPXNamespaceList *nsl);
+struct _CamelIMAPXNamespaceList * imap_parse_namespace_list (struct _CamelIMAPXStream *stream, CamelException *ex);
+struct _CamelIMAPXNamespaceList *camel_imapx_namespace_list_copy (const struct _CamelIMAPXNamespaceList *nsl);
+
#endif
diff --git a/camel/providers/imapx/test-imapx.c b/camel/providers/imapx/test-imapx.c
index 5c810c4..80b8ea7 100644
--- a/camel/providers/imapx/test-imapx.c
+++ b/camel/providers/imapx/test-imapx.c
@@ -1,6 +1,7 @@
#include <glib.h>
#include "camel-imapx-store.h"
#include "camel-imapx-folder.h"
+#include <camel/camel.h>
#include <camel/camel-session.h>
gint
@@ -19,7 +20,7 @@ main (gint argc, gchar *argv [])
uri = argv [1];
g_thread_init (NULL);
system ("rm -rf /tmp/test-camel-imapx");
- camel_init ("/tmp/test-camel-imapx");
+ camel_init ("/tmp/test-camel-imapx", 0);
camel_provider_init ();
ex = camel_exception_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]