aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--camel/ChangeLog26
-rw-r--r--camel/providers/imap/Makefile.am6
-rw-r--r--camel/providers/imap/camel-imap-folder.c64
-rw-r--r--camel/providers/imap/camel-imap-store.c70
-rw-r--r--camel/providers/imap/camel-imap-utils.c97
-rw-r--r--camel/providers/imap/camel-imap-utils.h41
6 files changed, 196 insertions, 108 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 0497b7690c..df277663da 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,7 +1,29 @@
2000-07-27 Jeffrey Stedfast <fejj@helixcode.com>
- * providers/imap/camel-imap-folder.c (imap_get_message_info): Now uses
- a hash table for looking up message info rather than a linear search :)
+ * providers/imap/Makefile.am: Added camel-imap-utils.[c,h]
+
+ * providers/imap/camel-imap-utils.[c,h]: Utilities for parsing
+ server responses for use in both camel-imap-store.c and
+ camel-imap-folder.c
+
+ * providers/imap/camel-imap-folder.c (imap_get_summary_internal):
+ Free all the pointers in the headers array.
+ (imap_get_subfolder_names_internal): Updated to use
+ imap_parse_list_response
+ (imap_parse_subfolder_list): Removed in favor of
+ imap_parse_list_response
+
+ * providers/imap/camel-imap-store.c (camel_imap_command_extended):
+ Free all the pointers in the data array.
+ (imap_connect): Updated to use imap_parse_list_response and fixed
+ a leak
+ (folder_is_selectable): Updated.
+
+2000-07-27 Jeffrey Stedfast <fejj@helixcode.com>
+
+ * providers/imap/camel-imap-folder.c (imap_get_message_info): Now
+ uses a hash table for looking up message info rather than a linear
+ search :)
2000-07-27 Peter Williams <peterw@helixcode.com>
diff --git a/camel/providers/imap/Makefile.am b/camel/providers/imap/Makefile.am
index bb876f7afb..5ff249739f 100644
--- a/camel/providers/imap/Makefile.am
+++ b/camel/providers/imap/Makefile.am
@@ -23,12 +23,14 @@ libcamelimap_la_SOURCES = \
camel-imap-folder.c \
camel-imap-provider.c \
camel-imap-store.c \
- camel-imap-stream.c
+ camel-imap-stream.c \
+ camel-imap-utils.c
libcamelimapinclude_HEADERS = \
camel-imap-folder.h \
camel-imap-store.h \
- camel-imap-stream.h
+ camel-imap-stream.h \
+ camel-imap-utils.h
libcamelimap_la_LDFLAGS = -version-info 0:0:0
diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c
index 5f15ee58b4..343d7e9f24 100644
--- a/camel/providers/imap/camel-imap-folder.c
+++ b/camel/providers/imap/camel-imap-folder.c
@@ -39,6 +39,7 @@
#include "camel-imap-folder.h"
#include "camel-imap-store.h"
#include "camel-imap-stream.h"
+#include "camel-imap-utils.h"
#include "string-utils.h"
#include "camel-stream.h"
#include "camel-stream-fs.h"
@@ -77,7 +78,6 @@ static void imap_append_message (CamelFolder *folder, CamelMimeMessage *message,
static void imap_copy_message_to (CamelFolder *source, const char *uid, CamelFolder *destination, CamelException *ex);
static void imap_move_message_to (CamelFolder *source, const char *uid, CamelFolder *destination, CamelException *ex);
-static gboolean imap_parse_subfolder_line (gchar *buf, gchar *namespace, gchar **flags, gchar **sep, gchar **folder);
static GPtrArray *imap_get_subfolder_names_internal (CamelFolder *folder, CamelException *ex);
static GPtrArray *imap_get_subfolder_names (CamelFolder *folder);
@@ -642,55 +642,6 @@ imap_get_uids (CamelFolder *folder)
return array;
}
-static gboolean
-imap_parse_subfolder_line (gchar *buf, gchar *namespace, gchar **flags, gchar **sep, gchar **folder)
-{
- gchar *ptr, *eptr, *f;
-
- *flags = NULL;
- *sep = NULL;
- *folder = NULL;
-
- if (g_strncasecmp (buf, "* LIST", 6))
- return FALSE;
-
- ptr = strstr (buf + 6, "(");
- if (!ptr)
- return FALSE;
-
- ptr++;
- eptr = strstr (ptr, ")");
- if (!eptr)
- return FALSE;
-
- *flags = g_strndup (ptr, (gint)(eptr - ptr));
-
- ptr = strstr (eptr, "\"");
- if (!ptr)
- return FALSE;
-
- ptr++;
- eptr = strstr (ptr, "\"");
- if (!eptr)
- return FALSE;
-
- *sep = g_strndup (ptr, (gint)(eptr - ptr));
-
- ptr = eptr + 1;
- *folder = g_strdup (ptr);
- g_strstrip (*folder);
-
- /* chop out the folder prefix */
- if (*namespace && !strncmp (*folder, namespace, strlen (namespace))) {
- f = *folder + strlen (namespace) + strlen (*sep);
- memmove (*folder, f, strlen (f) + 1);
- }
-
- string_unquote (*folder); /* unquote the mailbox if it's quoted */
-
- return TRUE;
-}
-
static GPtrArray *
imap_get_subfolder_names_internal (CamelFolder *folder, CamelException *ex)
{
@@ -741,16 +692,13 @@ imap_get_subfolder_names_internal (CamelFolder *folder, CamelException *ex)
while (ptr && *ptr == '*') {
gchar *flags, *sep, *folder, *buf, *end;
- gboolean ret;
for (end = ptr; *end && *end != '\n'; end++);
buf = g_strndup (ptr, (gint)(end - ptr));
ptr = end;
- ret = imap_parse_subfolder_line (buf, namespace, &flags, &sep, &folder);
- g_free (buf);
-
- if (!ret /*|| (flags && strstr (flags, "NoSelect"))*/) {
+ if (!imap_parse_list_response (buf, namespace, &flags, &sep, &folder)) {
+ g_free (buf);
g_free (flags);
g_free (sep);
g_free (folder);
@@ -760,6 +708,8 @@ imap_get_subfolder_names_internal (CamelFolder *folder, CamelException *ex)
continue;
}
+
+ g_free (buf);
g_free (flags);
d(fprintf (stderr, "adding folder: %s\n", folder));
@@ -1181,6 +1131,8 @@ imap_get_summary_internal (CamelFolder *folder, CamelException *ex)
g_hash_table_insert (hash, info->uid, info);
}
+ for (i = 0; i < headers->len; i++)
+ g_free (headers->pdata[i]);
g_ptr_array_free (headers, TRUE);
/* clean up any previous summary data */
@@ -1346,6 +1298,8 @@ imap_get_message_info (CamelFolder *folder, const char *uid)
static GPtrArray *
imap_search_by_expression (CamelFolder *folder, const char *expression, CamelException *ex)
{
+ d(fprintf (stderr, "search expression: %s\n", expression));
+
return g_ptr_array_new ();
#if 0
/* NOTE: This is experimental code... */
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index a729d1923a..29baae5b48 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -39,6 +39,7 @@
#include "camel-imap-store.h"
#include "camel-imap-folder.h"
+#include "camel-imap-utils.h"
#include "camel-folder.h"
#include "camel-exception.h"
#include "camel-session.h"
@@ -230,41 +231,6 @@ get_name (CamelService *service, gboolean brief)
}
static gboolean
-parse_list_response (gchar *buf, gchar **flags, gchar **sep)
-{
- gchar *ptr, *eptr;
-
- *flags = NULL;
- *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;
- *flags = g_strndup (ptr, (gint)(eptr - ptr));
-
- 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);
@@ -408,20 +374,22 @@ imap_connect (CamelService *service, CamelException *ex)
status != CAMEL_IMAP_FAIL && result ? result :
"Unknown error");
} else {
- if (!strncasecmp (result, "* LIST", 6)) {
- char *flags, *sep;
-
- if (parse_list_response (result, &flags, &sep)) {
- if (*sep) {
- g_free (store->dir_sep);
- store->dir_sep = g_strdup (sep);
- }
-
- g_free (sep);
+ char *flags, *sep, *folder;
+
+ if (imap_parse_list_response (result, "", &flags, &sep, &folder)) {
+ if (*sep) {
+ g_free (store->dir_sep);
+ store->dir_sep = g_strdup (sep);
}
}
+
+ g_free (flags);
+ g_free (sep);
+ g_free (folder);
}
+ g_free (result);
+
/* Lets add a timeout so that we can hopefully prevent getting disconnected */
store->timeout_id = gtk_timeout_add (600000, imap_noop, store);
@@ -563,7 +531,7 @@ imap_create (CamelFolder *folder, CamelException *ex)
static gboolean
folder_is_selectable (CamelStore *store, const char *folder_path)
{
- char *result, *flags, *sep;
+ char *result, *flags, *sep, *folder;
int status;
if (!strcmp (folder_path, "INBOX"))
@@ -576,17 +544,19 @@ folder_is_selectable (CamelStore *store, const char *folder_path)
return FALSE;
}
- if (parse_list_response (result, &flags, &sep)) {
+ 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;
}
@@ -824,6 +794,7 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **
gchar *cmdid, *cmdbuf, *respbuf;
GPtrArray *data;
va_list app;
+ int i;
#if 0
/* First make sure we're connected... */
@@ -948,7 +919,6 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **
if (status == CAMEL_IMAP_OK) {
char *p;
- int i;
*ret = g_malloc0 (len + 1);
@@ -970,11 +940,13 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **
*ret = NULL;
}
+ for (i = 0; i < data->len; i++)
+ g_free (data->pdata[i]);
g_ptr_array_free (data, TRUE);
if (folder && recent > 0) {
CamelException *ex;
-
+
ex = camel_exception_new ();
camel_imap_folder_changed (folder, recent, ex);
camel_exception_free (ex);
diff --git a/camel/providers/imap/camel-imap-utils.c b/camel/providers/imap/camel-imap-utils.c
new file mode 100644
index 0000000000..6560481505
--- /dev/null
+++ b/camel/providers/imap/camel-imap-utils.c
@@ -0,0 +1,97 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Authors: Jeffrey Stedfast <fejj@helixcode.com>
+ *
+ * Copyright 2000 Helix Code, Inc. (www.helixcode.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "camel-imap-utils.h"
+#include "string-utils.h"
+
+#define d(x) x
+
+char *
+imap_next_word (char *buf)
+{
+ char *word;
+
+ /* skip over current word */
+ for (word = buf; *word && *word != ' '; word++);
+
+ /* skip over white space */
+ for ( ; *word && *word == ' '; word++);
+
+ return word;
+}
+
+gboolean
+imap_parse_list_response (char *buf, char *namespace, char **flags, char **sep, char **folder)
+{
+ char *word, *ep, *f;
+
+ *flags = NULL;
+ *sep = NULL;
+ *folder = NULL;
+
+ if (*buf != '*')
+ return FALSE;
+
+ word = imap_next_word (buf);
+ if (g_strncasecmp (word, "LIST", 4) && g_strncasecmp (word, "LSUB", 4))
+ return FALSE;
+
+ /* get the flags */
+ word = imap_next_word (word);
+ if (*word != '(')
+ return FALSE;
+
+ word++;
+ for (ep = word; *ep && *ep != ')'; ep++);
+ if (*ep != ')')
+ return FALSE;
+
+ *flags = g_strndup (word, (gint)(ep - word));
+
+ /* get the directory separator */
+ word = imap_next_word (ep);
+ if (*word) {
+ for (ep = word; *ep && *ep != ' '; ep++);
+ *sep = g_strndup (word, (gint)(ep - word));
+ string_unquote (*sep);
+ } else {
+ return FALSE;
+ }
+
+ /* get the folder name */
+ word = imap_next_word (word);
+ *folder = g_strdup (word);
+ g_strstrip (*folder);
+
+ /* chop out the folder prefix */
+ if (*namespace && !strncmp (*folder, namespace, strlen (namespace))) {
+ f = *folder + strlen (namespace) + strlen (*sep);
+ memmove (*folder, f, strlen (f) + 1);
+ }
+
+ string_unquote (*folder); /* unquote the mailbox if it's quoted */
+
+ return TRUE;
+}
diff --git a/camel/providers/imap/camel-imap-utils.h b/camel/providers/imap/camel-imap-utils.h
new file mode 100644
index 0000000000..8ea5a40dbc
--- /dev/null
+++ b/camel/providers/imap/camel-imap-utils.h
@@ -0,0 +1,41 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Authors: Jeffrey Stedfast <fejj@helixcode.com>
+ *
+ * Copyright 2000 Helix Code, Inc. (www.helixcode.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef CAMEL_IMAP_UTILS_H
+#define CAMEL_IMAP_UTILS_H 1
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus }*/
+
+#include <glib.h>
+
+char *imap_next_word (char *buf);
+
+gboolean imap_parse_list_response (char *buf, char *namespace, char **flags, char **sep, char **folder);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* CAMEL_IMAP_UTILS_H */