Skip to content

Commit

Permalink
wip mailbox sync
Browse files Browse the repository at this point in the history
  • Loading branch information
pjstevns committed Jun 7, 2010
1 parent 385e20b commit 757b8b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
39 changes: 17 additions & 22 deletions src/dbmail-mailbox.c
Expand Up @@ -1312,7 +1312,7 @@ GTree * dbmail_mailbox_get_set(DbmailMailbox *self, const char *set, gboolean ui
GString *t;
GTree *uids;
char *rest;
u64_t i, l, r, lo = 0, hi = 0;
u64_t i, l, r, lo = 0, hi = 0, maxmsn = 0;
u64_t *k, *v, *w = NULL;
GTree *a, *b, *c;
gboolean error = FALSE;
Expand All @@ -1322,22 +1322,14 @@ GTree * dbmail_mailbox_get_set(DbmailMailbox *self, const char *set, gboolean ui
if (! self->mbstate)
return b;

uids = MailboxState_getIds(self->mbstate);

assert (self && uids && set);
assert (self && self->mbstate && set);

if (g_tree_nnodes(uids) == 0) {
/*
TRACE(TRACE_DEBUG, "empty mailbox, return fake set");
k = g_new0(u64_t,1);
v = g_new0(u64_t,1);
*k = 1;
*v = 1;
g_tree_insert(b,k,v);
*/
if (MailboxState_getExists(self->mbstate) == 0) // empty mailbox
return b;
}

maxmsn = MailboxState_getExists(self->mbstate);
uids = MailboxState_getIds(self->mbstate);
ids = g_tree_keys(uids);
assert(ids);
ids = g_list_last(ids);
Expand All @@ -1348,11 +1340,7 @@ GTree * dbmail_mailbox_get_set(DbmailMailbox *self, const char *set, gboolean ui

if (! uid) {
lo = 1;
if (self->mbstate)
hi = MailboxState_getExists(self->mbstate);
else
hi = (u64_t)g_tree_nnodes(uids);

hi = maxmsn;
if (hi != (u64_t)g_tree_nnodes(uids))
TRACE(TRACE_WARNING, "[%p] mailbox info out of sync: exists [%llu] ids [%u]",
self->mbstate, hi, g_tree_nnodes(uids));
Expand Down Expand Up @@ -1427,10 +1415,17 @@ GTree * dbmail_mailbox_get_set(DbmailMailbox *self, const char *set, gboolean ui

// we always want to return a tree with
// uids as keys and msns as values
if (uid)
g_tree_insert(a,k,v);
else
g_tree_insert(a,v,k);
if (uid) {
if (*k >= lo && *k <= hi)
g_tree_insert(a,k,v);
else
TRACE(TRACE_DEBUG,"lo: %llu, uid: %llu, msn: %llu, hi: %llu", lo, *k, *v, hi);
} else {
if (*k >= 1 && *k <= maxmsn)
g_tree_insert(a,v,k);
else
TRACE(TRACE_DEBUG,"lo: %llu, uid: %llu, msn: %llu, hi: %llu", lo, *v, *k, hi);
}
}

if (g_tree_merge(b,a,IST_SUBSEARCH_OR)) {
Expand Down
5 changes: 5 additions & 0 deletions test/check_dbmail_mailbox.c
Expand Up @@ -432,6 +432,7 @@ START_TEST(test_dbmail_mailbox_get_set)
GTree *set;
DbmailMailbox *mb = dbmail_mailbox_new(get_mailbox_id("INBOX"));
dbmail_mailbox_set_uid(mb,TRUE);
dbmail_mailbox_open(mb);

// basic tests;
set = dbmail_mailbox_get_set(mb, "1:*", 0);
Expand Down Expand Up @@ -491,6 +492,8 @@ START_TEST(test_dbmail_mailbox_get_set)

// empty box
mb = dbmail_mailbox_new(get_mailbox_id("empty"));
dbmail_mailbox_open(mb);

set = dbmail_mailbox_get_set(mb, "1:*", 0);
fail_unless(set != NULL,"dbmail_mailbox_get_set failed");
g_tree_destroy(set);
Expand All @@ -514,6 +517,7 @@ Suite *dbmail_mailbox_suite(void)
suite_add_tcase(s, tc_mailbox);
tcase_add_checked_fixture(tc_mailbox, setup, teardown);
tcase_add_test(tc_mailbox, test_dbmail_mailbox_get_set);
/*
tcase_add_test(tc_mailbox, test_dbmail_mailbox_new);
tcase_add_test(tc_mailbox, test_dbmail_mailbox_free);
tcase_add_test(tc_mailbox, test_dbmail_mailbox_dump);
Expand All @@ -523,6 +527,7 @@ Suite *dbmail_mailbox_suite(void)
tcase_add_test(tc_mailbox, test_dbmail_mailbox_search_parsed_1);
tcase_add_test(tc_mailbox, test_dbmail_mailbox_search_parsed_2);
tcase_add_test(tc_mailbox, test_dbmail_mailbox_orderedsubject);
*/
return s;
}

Expand Down

0 comments on commit 757b8b7

Please sign in to comment.