2009-04-24 Milan Crha <mcrha@redhat.com>
+ ** Part of fix for bug #563954
+
+ * camel-folder.h: (camel_folder_cmp_uids), (struct CamelFolder):
+ * camel-folder.c: (cmp_uids), (camel_folder_class_init),
+ (camel_folder_cmp_uids), (cmp_array_uids), (sort_uids):
+ Define camel_folder_cmp_uids to compare UIDs properly.
+ * camel-folder-summary.h: (camel_folder_summary_ensure_infos_loaded):
+ * camel-folder-summary.c: (camel_folder_summary_ensure_infos_loaded):
+ Define new function.
+
+ * camel-db.h: (camel_db_get_folder_uids),
+ (camel_db_get_folder_uids_flags):
+ * camel-db.c: (camel_db_get_folder_uids),
+ (camel_db_get_folder_uids_flags):
+ * camel-folder-summary.c: (camel_folder_summary_load_from_db):
+ Functions prototype cleanup.
+
+2009-04-24 Milan Crha <mcrha@redhat.com>
+
** Part of fix for bug #571206
* camel-vee-folder.c: (camel_vee_folder_add_folder), (vee_sync):
}
int
-camel_db_get_folder_uids_flags (CamelDB *db, char *folder_name, char *sort_by, char *collate, GPtrArray *summary, GHashTable *table, CamelException *ex)
+camel_db_get_folder_uids_flags (CamelDB *db, const char *folder_name, const char *sort_by, const char *collate, GPtrArray *summary, GHashTable *table, CamelException *ex)
{
GPtrArray *uids = summary;
GPtrArray *flags = g_ptr_array_new ();
}
int
-camel_db_get_folder_uids (CamelDB *db, char *folder_name, char *sort_by, char *collate, GPtrArray *array, CamelException *ex)
+camel_db_get_folder_uids (CamelDB *db, const char *folder_name, const char *sort_by, const char *collate, GPtrArray *array, CamelException *ex)
{
char *sel_query;
int ret;
int camel_db_add_to_vfolder (CamelDB *db, char *folder_name, char *vuid, CamelException *ex);
int camel_db_add_to_vfolder_transaction (CamelDB *db, char *folder_name, char *vuid, CamelException *ex);
-int camel_db_get_folder_uids (CamelDB *db, char *folder_name, char *sort_by, char *collate, GPtrArray *array, CamelException *ex);
-int camel_db_get_folder_uids_flags (CamelDB *db, char *folder_name, char *sort_by, char *collate, GPtrArray *summary, GHashTable *table, CamelException *ex);
+int camel_db_get_folder_uids (CamelDB *db, const char *folder_name, const char *sort_by, const char *collate, GPtrArray *array, CamelException *ex);
+int camel_db_get_folder_uids_flags (CamelDB *db, const char *folder_name, const char *sort_by, const char *collate, GPtrArray *summary, GHashTable *table, CamelException *ex);
GPtrArray * camel_db_get_folder_junk_uids (CamelDB *db, char *folder_name, CamelException *ex);
GPtrArray * camel_db_get_folder_deleted_uids (CamelDB *db, char *folder_name, CamelException *ex);
return ret == 0 ? 0 : -1;
}
+/**
+ * camel_folder_summary_ensure_infos_loaded:
+ * @s: #CamelFolderSummary object
+ * @at_least: How many infos already loaded are considered fine to not reload all of them.
+ * Use -1 to force reload of all of them if not in memory yet.
+ * @ex: #CamelException object.
+ *
+ * Loads all infos into memory, if they are not yet.
+ **/
+void
+camel_folder_summary_ensure_infos_loaded (CamelFolderSummary *s, int at_least, CamelException *ex)
+{
+ guint loaded, known;
+
+ g_return_if_fail (s != NULL);
+
+ loaded = camel_folder_summary_cache_size (s);
+ known = camel_folder_summary_count (s);
+
+ if ((at_least == -1 && known != loaded) || at_least > loaded) {
+ camel_folder_summary_reload_from_db (s, ex);
+ }
+}
+
static void
camel_folder_summary_dump (CamelFolderSummary *s)
{
folder_name = s->folder->full_name;
cdb = s->folder->parent_store->cdb_r;
- ret = camel_db_get_folder_uids_flags (cdb, folder_name, (char *)s->sort_by, (char *)s->collate, s->uids, p->flag_cache, ex);
+ ret = camel_db_get_folder_uids_flags (cdb, folder_name, s->sort_by, s->collate, s->uids, p->flag_cache, ex);
/* camel_folder_summary_dump (s); */
#if 0
int camel_folder_summary_cache_size (CamelFolderSummary *s);
/* reload the summary at any required point if required */
int camel_folder_summary_reload_from_db (CamelFolderSummary *s, CamelException *ex);
+/* ensures all CamelMessagesInfos loaded in memory */
+void camel_folder_summary_ensure_infos_loaded (CamelFolderSummary *s, int at_least, CamelException *ex);
/* insert mi to summary */
void camel_folder_summary_insert (CamelFolderSummary *s, CamelMessageInfo *info, gboolean load);
static GPtrArray *get_uncached_uids (CamelFolder *, GPtrArray * uids, CamelException *);
static void free_uids (CamelFolder *folder,
GPtrArray *array);
+static gint cmp_uids (CamelFolder *folder, const char *uid1, const char *uid2);
static void sort_uids (CamelFolder *folder,
GPtrArray *uids);
static GPtrArray *get_summary (CamelFolder *folder);
camel_folder_class->get_uids = get_uids;
camel_folder_class->get_uncached_uids = get_uncached_uids;
camel_folder_class->free_uids = free_uids;
+ camel_folder_class->cmp_uids = cmp_uids;
camel_folder_class->sort_uids = sort_uids;
camel_folder_class->get_summary = get_summary;
camel_folder_class->free_summary = free_summary;
return CF_CLASS (folder)->get_uncached_uids(folder, uids, ex);
}
+static gint
+cmp_uids (CamelFolder *folder, const char *uid1, const char *uid2)
+{
+ g_return_val_if_fail (uid1 != NULL, 0);
+ g_return_val_if_fail (uid2 != NULL, 0);
-static int
-uidcmp (const void *v0, const void *v1)
+ return strtoul (uid1, NULL, 10) - strtoul (uid2, NULL, 10);
+}
+
+/**
+ * camel_folder_cmp_uids:
+ * @folder: a #CamelFolder object
+ * @uid1: The first uid.
+ * @uid2: the second uid.
+ *
+ * Compares two uids. The return value meaning is the same as in any other compare function.
+ *
+ * Note that the default compare function expects a decimal number at the beginning of a uid,
+ * thus if provider uses different uid values, then it should subclass this function.
+ **/
+gint
+camel_folder_cmp_uids (CamelFolder *folder, const char *uid1, const char *uid2)
{
- const char *str0 = *(const char **) v0;
- const char *str1 = *(const char **) v1;
- guint32 uid0 = strtoul (str0, NULL, 10);
- guint32 uid1 = strtoul (str1, NULL, 10);
-
- if (uid0 < uid1)
- return -1;
- else if (uid0 == uid1)
- return 0;
- else
- return 1;
+ g_return_val_if_fail (CAMEL_IS_FOLDER (folder), 0);
+ g_return_val_if_fail (uid1 != NULL, 0);
+ g_return_val_if_fail (uid2 != NULL, 0);
+
+ return CF_CLASS (folder)->cmp_uids (folder, uid1, uid2);
+}
+
+static gint
+cmp_array_uids (gconstpointer a, gconstpointer b, gpointer user_data)
+{
+ const char *uid1 = *(const char **) a;
+ const char *uid2 = *(const char **) b;
+ CamelFolder *folder = user_data;
+
+ g_return_val_if_fail (CAMEL_IS_FOLDER (folder), 0);
+
+ return camel_folder_cmp_uids (folder, uid1, uid2);
}
static void
sort_uids (CamelFolder *folder, GPtrArray *uids)
{
- qsort (uids->pdata, uids->len, sizeof (void *), uidcmp);
+ g_qsort_with_data (uids->pdata, uids->len, sizeof (void *), cmp_array_uids, folder);
}
void (*free_uids) (CamelFolder *folder,
GPtrArray *array);
+ gint (* cmp_uids) (CamelFolder *folder, const char *uid1, const char *uid2);
void (* sort_uids) (CamelFolder *folder, GPtrArray *uids);
GPtrArray * (*get_summary) (CamelFolder *folder);
GPtrArray * camel_folder_get_uncached_uids (CamelFolder *,
GPtrArray * uids,
CamelException *);
+gint camel_folder_cmp_uids (CamelFolder *folder, const char *uid1, const char *uid2);
void camel_folder_sort_uids (CamelFolder *folder,
GPtrArray *uids);
+2009-04-24 Milan Crha <mcrha@redhat.com>
+
+ ** Part of fix for bug #563954
+
+ * camel-groupwise-folder.c: (groupwise_cmp_uids),
+ (camel_groupwise_folder_class_init):
+ Define its own compare function for UIDs.
+
2009-04-13 Chenthill Palanisamy <pchenthill@novell.com>
static char* groupwise_get_filename (CamelFolder *folder, const char *uid, CamelException *ex);
static const char *get_from_from_org (EGwItemOrganizer *org);
-
#define d(x)
const char * GET_ITEM_VIEW_WITH_CACHE = "peek default recipient threading attachments subject status priority startDate created delivered size recurrenceKey message notification";
camel_folder_change_info_free (changes);
}
+static gint
+groupwise_cmp_uids (CamelFolder *folder, const char *uid1, const char *uid2)
+{
+ g_return_val_if_fail (uid1 != NULL, 0);
+ g_return_val_if_fail (uid2 != NULL, 0);
+
+ return strcmp (uid1, uid2);
+}
+
static void
camel_groupwise_folder_class_init (CamelGroupwiseFolderClass *camel_groupwise_folder_class)
{
camel_folder_class->rename = groupwise_folder_rename;
camel_folder_class->search_by_expression = groupwise_folder_search_by_expression;
camel_folder_class->count_by_expression = groupwise_folder_count_by_expression;
+ camel_folder_class->cmp_uids = groupwise_cmp_uids;
camel_folder_class->search_by_uids = groupwise_folder_search_by_uids;
camel_folder_class->search_free = groupwise_folder_search_free;
camel_folder_class->append_message = groupwise_append_message;
2009-04-24 Milan Crha <mcrha@redhat.com>
+ ** Part of fix for bug #563954
+
+ * camel-mh-summary.c: (sort_uid_cmp), (camel_mh_summary_new):
+ Little cleanup.
+ * camel-mbox-folder.c: (mbox_cmp_uids), (mbox_sort_uids),
+ (camel_mbox_folder_class_init):
+ * camel-maildir-folder.c: (maildir_cmp_uids),
+ (maildir_sort_uids), (camel_maildir_folder_class_init):
+ Subslass sort and compare uids functions to compare based on the
+ position in the mbox file or a received date for maildir, instead
+ of uid values.
+
+2009-04-24 Milan Crha <mcrha@redhat.com>
+
** Fix for bug #571206
* camel-maildir-summary.c: (message_info_new_from_header):
static void maildir_append_message(CamelFolder * folder, CamelMimeMessage * message, const CamelMessageInfo *info, char **appended_uid, CamelException * ex);
static CamelMimeMessage *maildir_get_message(CamelFolder * folder, const gchar * uid, CamelException * ex);
static char* maildir_get_filename (CamelFolder *folder, const char *uid, CamelException *ex);
+static gint maildir_cmp_uids (CamelFolder *folder, const char *uid1, const char *uid2);
+static void maildir_sort_uids (CamelFolder *folder, GPtrArray *uids);
static void maildir_finalize(CamelObject * object);
camel_folder_class->append_message = maildir_append_message;
camel_folder_class->get_message = maildir_get_message;
camel_folder_class->get_filename = maildir_get_filename;
+ camel_folder_class->cmp_uids = maildir_cmp_uids;
+ camel_folder_class->sort_uids = maildir_sort_uids;
lclass->create_summary = maildir_create_summary;
}
return message;
}
+
+static gint
+maildir_cmp_uids (CamelFolder *folder, const char *uid1, const char *uid2)
+{
+ CamelMessageInfo *a, *b;
+ time_t tma, tmb;
+
+ g_return_val_if_fail (folder != NULL, 0);
+ g_return_val_if_fail (folder->summary != NULL, 0);
+
+ a = camel_folder_summary_uid (folder->summary, uid1);
+ b = camel_folder_summary_uid (folder->summary, uid2);
+
+ g_return_val_if_fail (a != NULL, 0);
+ g_return_val_if_fail (b != NULL, 0);
+
+ tma = camel_message_info_date_received (a);
+ tmb = camel_message_info_date_received (b);
+
+ return tma < tmb ? -1 : tma == tmb ? 0 : 1;
+}
+
+static void
+maildir_sort_uids (CamelFolder *folder, GPtrArray *uids)
+{
+ g_return_if_fail (parent_class != NULL);
+ g_return_if_fail (folder != NULL);
+
+ if (uids && uids->len > 1) {
+ CamelException ex;
+
+ camel_exception_init (&ex);
+
+ camel_folder_summary_ensure_infos_loaded (folder->summary, uids->len, &ex);
+
+ if (camel_exception_is_set (&ex))
+ g_warning ("%s: %s", G_STRFUNC, camel_exception_get_description (&ex));
+
+ camel_exception_clear (&ex);
+ }
+
+ CAMEL_FOLDER_CLASS (parent_class)->sort_uids (folder, uids);
+}
static CamelMimeMessage *mbox_get_message(CamelFolder *folder, const gchar * uid, CamelException *ex);
static CamelLocalSummary *mbox_create_summary(CamelLocalFolder *lf, const char *path, const char *folder, CamelIndex *index);
static char* mbox_get_filename (CamelFolder *folder, const char *uid, CamelException *ex);
+static gint mbox_cmp_uids (CamelFolder *folder, const char *uid1, const char *uid2);
+static void mbox_sort_uids (CamelFolder *folder, GPtrArray *uids);
static void mbox_finalise(CamelObject * object);
camel_folder_class->append_message = mbox_append_message;
camel_folder_class->get_message = mbox_get_message;
camel_folder_class->get_filename = mbox_get_filename;
+ camel_folder_class->cmp_uids = mbox_cmp_uids;
+ camel_folder_class->sort_uids = mbox_sort_uids;
lclass->create_summary = mbox_create_summary;
lclass->lock = mbox_lock;
return message;
}
+
+static gint
+mbox_cmp_uids (CamelFolder *folder, const char *uid1, const char *uid2)
+{
+ CamelMboxMessageInfo *a, *b;
+
+ g_return_val_if_fail (folder != NULL, 0);
+ g_return_val_if_fail (folder->summary != NULL, 0);
+
+ a = (CamelMboxMessageInfo *) camel_folder_summary_uid (folder->summary, uid1);
+ b = (CamelMboxMessageInfo *) camel_folder_summary_uid (folder->summary, uid2);
+
+ g_return_val_if_fail (a != NULL, 0);
+ g_return_val_if_fail (b != NULL, 0);
+
+ return a->frompos < b->frompos ? -1 : a->frompos == b->frompos ? 0 : 1;
+}
+
+static void
+mbox_sort_uids (CamelFolder *folder, GPtrArray *uids)
+{
+ g_return_if_fail (parent_class != NULL);
+ g_return_if_fail (folder != NULL);
+
+ if (uids && uids->len > 1) {
+ CamelException ex;
+
+ camel_exception_init (&ex);
+
+ camel_folder_summary_ensure_infos_loaded (folder->summary, uids->len, &ex);
+
+ if (camel_exception_is_set (&ex))
+ g_warning ("%s: %s", G_STRFUNC, camel_exception_get_description (&ex));
+
+ camel_exception_clear (&ex);
+ }
+
+ CAMEL_FOLDER_CLASS (parent_class)->sort_uids (folder, uids);
+}
#include "camel-private.h"
#include "camel-mh-summary.h"
+#include "camel-local-private.h"
#define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
g_free(o->priv);
}
-static int
-sort_uid_cmp (void *enc, int len1, void * data1, int len2, void *data2)
-{
- static char *sa1=NULL, *sa2=NULL;
- static int l1=0, l2=0;
- int a1, a2;
-
- if (l1 < len1+1) {
- sa1 = g_realloc (sa1, len1+1);
- l1 = len1+1;
- }
- if (l2 < len2+1) {
- sa2 = g_realloc (sa2, len2+1);
- l2 = len2+1;
- }
- strncpy (sa1, data1, len1);sa1[len1] = 0;
- strncpy (sa2, data2, len2);sa2[len2] = 0;
-
- a1 = strtoul (sa1, NULL, 10);
- a2 = strtoul (sa2, NULL, 10);
-
- return (a1 < a1) ? -1 : (a1 > a2) ? 1 : 0;
-}
-
/**
* camel_mh_summary_new:
*
((CamelFolderSummary *)o)->folder = folder;
if (folder) {
- camel_db_set_collate (folder->parent_store->cdb_r, "uid", "mh_uid_sort", (CamelDBCollate)sort_uid_cmp);
+ camel_db_set_collate (folder->parent_store->cdb_r, "uid", "mh_uid_sort", (CamelDBCollate)camel_local_frompos_sort);
((CamelFolderSummary *)o)->sort_by = "uid";
((CamelFolderSummary *)o)->collate = "mh_uid_sort";
}