}
#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
/* 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 *
g_list_free (string_list);
}
-
-
-
-
-
GList *
string_split (const gchar *string, char sep, const gchar *trim_chars, StringTrimOption trim_options)
{
return result;
}
-
void
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.
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;
+}