aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog9
-rw-r--r--camel/providers/imap/camel-imap-folder.c90
-rw-r--r--camel/string-utils.c30
-rw-r--r--camel/string-utils.h1
4 files changed, 114 insertions, 16 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index ebc9d195e8..6d523c893e 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,12 @@
+2000-06-15 Jeffrey Stedfast <fejj@helixcode.com>
+
+ * providers/imap/camel-imap-folder.c (imap_get_summary): Started to implement
+ (imap_summary_get_by_uid): Started to code, I've got to find a way to get the
+ date in time_t format and also get the flags
+
+ * string-utils.c (strstrcase): Added this convenience function - I know about
+ strcasestr() but it's not portable.
+
2000-06-15 Dan Winship <danw@helixcode.com>
* camel-service.c: Remove camel_service_connect_with_url. (URLs
diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c
index 860a8aed99..33e4980d24 100644
--- a/camel/providers/imap/camel-imap-folder.c
+++ b/camel/providers/imap/camel-imap-folder.c
@@ -728,13 +728,70 @@ imap_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *
}
#endif
+/* This probably shouldn't go here...but it will for now */
+static gchar *
+get_header_field (gchar *header, gchar *field)
+{
+ gchar *part, *index, *p, *q;
+
+ index = strstrcase(header, field);
+ if (index == NULL)
+ return NULL;
+
+ p = index + strlen (field) + 1;
+ for (q = p; *q; q++)
+ if (*q == '\n' && (*(q + 1) != ' ' || *(q + 1) != '\t'))
+ break;
+
+ part = g_strndup (p, (gint)(q - p));
+
+ /* it may be wrapped on multiple lines, so lets strip out \n's */
+ for (p = part; *p; ) {
+ if (*p == '\r' || *p == '\n')
+ memmove(p, p + 1, strlen (p) - 1);
+ else
+ p++;
+ }
+
+ return part;
+}
+
GPtrArray *
imap_get_summary (CamelFolder *folder, CamelException *ex)
{
- /* TODO: what should we do here?? */
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
+ /* TODO: code this - loop: "FETCH <i> BODY.PEEK[HEADER]" and parse */
+ /* TODO: Maybe use FETCH ENVELOPE instead */
+ GPtrArray *array = NULL;
+ CamelMessageInfo *info;
+ int i, num, status;
+ char *result;
- return CAMEL_FOLDER_SUMMARY (imap_folder->summary)->messages;
+ num = imap_get_message_count (folder, ex);
+
+ array = g_ptr_array_new ();
+
+ for (i = 0; i < num; i++) {
+ status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder,
+ &result, "FETCH %d BODY.PEEK[HEADER]", i);
+
+ if (status != CAMEL_IMAP_OK) {
+ g_free (result);
+ break;
+ }
+
+ info = g_malloc0 (sizeof (CamelMessageInfo));
+ info->subject = get_header_field (result, "\nSubject:");
+ info->to = get_header_field (result, "\nTo:");
+ info->from = get_header_field (result, "\nFrom:");
+ info->uid = NULL; /* FIXME: how can we get the UID? */
+ g_free (result);
+
+ /* still need to get flags and date_sent */
+
+ g_ptr_array_add (array, info);
+ }
+
+ return array;
}
void
@@ -746,12 +803,31 @@ imap_free_summary (CamelFolder *folder, GPtrArray *array)
/* get a single message info, by uid */
static const CamelMessageInfo *
-imap_summary_get_by_uid (CamelFolder *f, const char *uid)
+imap_summary_get_by_uid (CamelFolder *folder, const char *uid)
{
- /* TODO: what do we do here? */
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (f);
+ /* TODO: code this - do a "UID FETCH <uid> BODY.PEEK[HEADER]" and parse */
+ CamelMessageInfo *info = NULL;
+ char *result;
+ int status;
+
+ status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder,
+ &result, "UID FETCH %s BODY.PEEK[HEADER]", uid);
+
+ if (status != CAMEL_IMAP_OK) {
+ g_free (result);
+ return NULL;
+ }
+
+ info = g_malloc0 (sizeof (CamelMessageInfo));
+ info->subject = get_header_field (result, "\nSubject:");
+ info->to = get_header_field (result, "\nTo:");
+ info->from = get_header_field (result, "\nFrom:");
+ info->uid = g_strdup (uid);
+ g_free (result);
+
+ /* still need to get flags and date_sent */
- return camel_folder_summary_uid(CAMEL_FOLDER_SUMMARY (imap_folder->summary), uid);
+ return info;
}
static GList *
diff --git a/camel/string-utils.c b/camel/string-utils.c
index 42fb93538a..28a4a81a0e 100644
--- a/camel/string-utils.c
+++ b/camel/string-utils.c
@@ -51,11 +51,6 @@ string_list_free (GList *string_list)
g_list_free (string_list);
}
-
-
-
-
-
GList *
string_split (const gchar *string, char sep, const gchar *trim_chars, StringTrimOption trim_options)
{
@@ -91,7 +86,6 @@ string_split (const gchar *string, char sep, const gchar *trim_chars, StringTrim
return result;
}
-
void
string_trim (gchar *string, const gchar *trim_chars, StringTrimOption options)
{
@@ -122,9 +116,6 @@ string_trim (gchar *string, const gchar *trim_chars, StringTrimOption options)
}
-
-
-
/**
* remove_suffix: remove a suffix from a string
* @s: the string to remove the suffix from.
@@ -183,3 +174,24 @@ string_prefix (const gchar *s, const gchar *suffix, gboolean *suffix_found)
return result_string;
}
+
+gchar *
+strstrcase (const gchar *haystack, const gchar *needle)
+{
+ /* find the needle in the haystack neglecting case */
+ gchar *ptr;
+ guint len;
+
+ g_return_val_if_fail (haystack != NULL, NULL);
+ g_return_val_if_fail (needle != NULL, NULL);
+
+ len = strlen(needle);
+ if (len > strlen(haystack))
+ return NULL;
+
+ for (ptr = haystack; *(ptr + len - 1) != '\0'; ptr++)
+ if (!g_strncasecmp(ptr, needle, len))
+ return ptr;
+
+ return NULL;
+}
diff --git a/camel/string-utils.h b/camel/string-utils.h
index 665aafc01e..fa6297a5e1 100644
--- a/camel/string-utils.h
+++ b/camel/string-utils.h
@@ -56,6 +56,7 @@ void string_trim (gchar *string, const gchar *chars,
gchar *string_prefix (const gchar *s, const gchar *suffix, gboolean *suffix_found);
+gchar *strstrcase (const gchar *haystack, const gchar *needle);
#ifdef __cplusplus
}