aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/imap4/camel-imap4-utils.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@novell.com>2004-06-11 03:47:46 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2004-06-11 03:47:46 +0800
commitd46d24e504b30b8b9f7b1045c5a2d252b9daf1d4 (patch)
treeb8ec8d986d2edf5af609cdbe3a74c98be1d8e248 /camel/providers/imap4/camel-imap4-utils.c
parentb1c7fda1bcdb890774764aa8dbf7be1581eadc76 (diff)
downloadgsoc2013-evolution-d46d24e504b30b8b9f7b1045c5a2d252b9daf1d4.tar.gz
gsoc2013-evolution-d46d24e504b30b8b9f7b1045c5a2d252b9daf1d4.tar.zst
gsoc2013-evolution-d46d24e504b30b8b9f7b1045c5a2d252b9daf1d4.zip
If flags does not include FOLDER_INFO_FAST, get the total/unread counts
2004-06-10 Jeffrey Stedfast <fejj@novell.com> * providers/imap4/camel-imap4-store.c (imap4_build_folder_info): If flags does not include FOLDER_INFO_FAST, get the total/unread counts for the folder-info. * providers/imap4/camel-imap4-engine.c (engine_parse_status): Removed. (camel_imap4_engine_handle_untagged_1): Don't handle untagged STATUS responses anymore. Let the STATUS requestor handle them instead. * providers/imap4/camel-imap4-utils.c (camel_imap4_untagged_status): New function to parse untagged status events. svn path=/trunk/; revision=26291
Diffstat (limited to 'camel/providers/imap4/camel-imap4-utils.c')
-rw-r--r--camel/providers/imap4/camel-imap4-utils.c149
1 files changed, 149 insertions, 0 deletions
diff --git a/camel/providers/imap4/camel-imap4-utils.c b/camel/providers/imap4/camel-imap4-utils.c
index 67dd828134..2efac2ff42 100644
--- a/camel/providers/imap4/camel-imap4-utils.c
+++ b/camel/providers/imap4/camel-imap4-utils.c
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include <errno.h>
#include <camel/camel-store.h>
@@ -313,3 +314,151 @@ camel_imap4_untagged_list (CamelIMAP4Engine *engine, CamelIMAP4Command *ic, guin
return -1;
}
+
+
+static struct {
+ const char *name;
+ int type;
+} imap4_status[] = {
+ { "MESSAGES", CAMEL_IMAP4_STATUS_MESSAGES },
+ { "RECENT", CAMEL_IMAP4_STATUS_RECENT },
+ { "UIDNEXT", CAMEL_IMAP4_STATUS_UIDNEXT },
+ { "UIDVALIDITY", CAMEL_IMAP4_STATUS_UIDVALIDITY },
+ { "UNSEEN", CAMEL_IMAP4_STATUS_UNSEEN },
+ { NULL, CAMEL_IMAP4_STATUS_UNKNOWN },
+};
+
+
+void
+camel_imap4_status_free (camel_imap4_status_t *status)
+{
+ camel_imap4_status_attr_t *attr, *next;
+
+ attr = status->attr_list;
+ while (attr != NULL) {
+ next = attr->next;
+ g_free (attr);
+ attr = next;
+ }
+
+ g_free (status->mailbox);
+ g_free (status);
+}
+
+
+int
+camel_imap4_untagged_status (CamelIMAP4Engine *engine, CamelIMAP4Command *ic, guint32 index, camel_imap4_token_t *token, CamelException *ex)
+{
+ camel_imap4_status_attr_t *attr, *tail, *list = NULL;
+ GPtrArray *array = ic->user_data;
+ camel_imap4_status_t *status;
+ char *mailbox;
+ size_t len;
+ int type;
+
+ if (camel_imap4_engine_next_token (engine, token, ex) == -1)
+ return -1;
+
+ switch (token->token) {
+ case CAMEL_IMAP4_TOKEN_ATOM:
+ mailbox = g_strdup (token->v.atom);
+ break;
+ case CAMEL_IMAP4_TOKEN_QSTRING:
+ mailbox = g_strdup (token->v.qstring);
+ break;
+ case CAMEL_IMAP4_TOKEN_LITERAL:
+ if (camel_imap4_engine_literal (engine, (unsigned char **) &mailbox, &len, ex) == -1)
+ return -1;
+ break;
+ default:
+ fprintf (stderr, "Unexpected token in IMAP4 untagged STATUS response: %s%c\n",
+ token->token == CAMEL_IMAP4_TOKEN_NIL ? "NIL" : "",
+ (unsigned char) (token->token & 0xff));
+ camel_imap4_utils_set_unexpected_token_error (ex, engine, token);
+ return -1;
+ }
+
+ if (camel_imap4_engine_next_token (engine, token, ex) == -1) {
+ g_free (mailbox);
+ return -1;
+ }
+
+ if (token->token != '(') {
+ d(fprintf (stderr, "Expected to find a '(' token after the mailbox token in the STATUS response\n"));
+ camel_imap4_utils_set_unexpected_token_error (ex, engine, token);
+ g_free (mailbox);
+ return -1;
+ }
+
+ if (camel_imap4_engine_next_token (engine, token, ex) == -1) {
+ g_free (mailbox);
+ return -1;
+ }
+
+ tail = (camel_imap4_status_attr_t *) &list;
+
+ while (token->token == CAMEL_IMAP4_TOKEN_ATOM) {
+ /* parse the status messages list */
+ for (type = 0; type < G_N_ELEMENTS (imap4_status); type++) {
+ if (!g_ascii_strcasecmp (imap4_status[type].name, token->v.atom))
+ break;
+ }
+
+ if (type == CAMEL_IMAP4_STATUS_UNKNOWN)
+ fprintf (stderr, "unrecognized token in STATUS list: %s\n", token->v.atom);
+
+ if (camel_imap4_engine_next_token (engine, token, ex) == -1)
+ goto exception;
+
+ if (token->token != CAMEL_IMAP4_TOKEN_NUMBER)
+ break;
+
+ attr = g_new (camel_imap4_status_attr_t, 1);
+ attr->next = NULL;
+ attr->type = type;
+ attr->value = token->v.number;
+
+ tail->next = attr;
+ tail = attr;
+
+ if (camel_imap4_engine_next_token (engine, token, ex) == -1)
+ goto exception;
+ }
+
+ status = g_new (camel_imap4_status_t, 1);
+ status->mailbox = mailbox;
+ status->attr_list = list;
+ list = NULL;
+
+ g_ptr_array_add (array, status);
+
+ if (token->token != ')') {
+ d(fprintf (stderr, "Expected to find a ')' token terminating the untagged STATUS response\n"));
+ camel_imap4_utils_set_unexpected_token_error (ex, engine, token);
+ return -1;
+ }
+
+ if (camel_imap4_engine_next_token (engine, token, ex) == -1)
+ return -1;
+
+ if (token->token != '\n') {
+ d(fprintf (stderr, "Expected to find a '\\n' token after the STATUS response\n"));
+ camel_imap4_utils_set_unexpected_token_error (ex, engine, token);
+ return -1;
+ }
+
+ return 0;
+
+ exception:
+
+ g_free (mailbox);
+
+ attr = list;
+ while (attr != NULL) {
+ list = attr->next;
+ g_free (attr);
+ attr = list;
+ }
+
+ return -1;
+}