diff options
author | Paul J Stevens <paul@nfg.nl> | 2010-06-12 14:44:46 +0200 |
---|---|---|
committer | Paul J Stevens <paul@nfg.nl> | 2010-06-12 14:44:46 +0200 |
commit | 69a3be943eb7e09513e19c6c46ffaac40f483252 (patch) | |
tree | 5843ba171343efe369a941ccaa88c9490c76ef6c /src | |
parent | 8343cd7ba23ac74072a0322db6f20e0018647c0a (diff) | |
parent | cf724b7e8189d58a07d01ca824d9717a44df806a (diff) |
Merge branch 'master' of ssh://nfg3.nfgs.net/home/paul/git/dbmail
Diffstat (limited to 'src')
-rw-r--r-- | src/dbmail-imapsession.c | 9 | ||||
-rw-r--r-- | src/dbmail-mailbox.c | 54 | ||||
-rw-r--r-- | src/dm_mailboxstate.c | 5 | ||||
-rw-r--r-- | src/sortmodule.h | 2 |
4 files changed, 36 insertions, 34 deletions
diff --git a/src/dbmail-imapsession.c b/src/dbmail-imapsession.c index 711c2f62..d15480ba 100644 --- a/src/dbmail-imapsession.c +++ b/src/dbmail-imapsession.c @@ -1315,7 +1315,7 @@ static void notify_fetch(ImapSession *self, MailboxState_T N, u64_t *uid) static gboolean notify_expunge(ImapSession *self, u64_t *uid) { - u64_t * msn; + u64_t *msn = NULL, m = 0; if (! (msn = g_tree_lookup(MailboxState_getIds(self->mailbox->mbstate), uid))) { TRACE(TRACE_DEBUG,"[%p] can't find uid [%llu]", self, *uid); @@ -1328,8 +1328,11 @@ static gboolean notify_expunge(ImapSession *self, u64_t *uid) case IMAP_COMM_SEARCH: break; default: - dbmail_imap_session_buff_printf(self, "* %llu EXPUNGE\r\n", *msn); - MailboxState_removeUid(self->mailbox->mbstate, *uid); + m = *msn; + if (MailboxState_removeUid(self->mailbox->mbstate, *uid) == DM_SUCCESS) + dbmail_imap_session_buff_printf(self, "* %llu EXPUNGE\r\n", m); + else + return TRUE; break; } diff --git a/src/dbmail-mailbox.c b/src/dbmail-mailbox.c index db9c74e4..0d70d3ac 100644 --- a/src/dbmail-mailbox.c +++ b/src/dbmail-mailbox.c @@ -789,19 +789,21 @@ static int _handle_search_args(DbmailMailbox *self, char **search_keys, u64_t *i value->type = IST_IDATE; (*idx)++; s = date_imap2sql(search_keys[*idx]); - g_snprintf(value->search, MAX_SEARCH_LEN, "internal_date < '%s'", s); + g_snprintf(value->search, MAX_SEARCH_LEN, "p.internal_date < '%s'", s); g_free(s); (*idx)++; } else if ( MATCH(key, "on") ) { - char *s; + char *s, *d; g_return_val_if_fail(search_keys[*idx + 1], -1); g_return_val_if_fail(check_date(search_keys[*idx + 1]),-1); value->type = IST_IDATE; (*idx)++; s = date_imap2sql(search_keys[*idx]); - g_snprintf(value->search, MAX_SEARCH_LEN, "internal_date %s '%s%%'", db_get_sql(SQL_SENSITIVE_LIKE), s); + d = g_strdup_printf(db_get_sql(SQL_TO_DATE), "p.internal_date"); + g_snprintf(value->search, MAX_SEARCH_LEN, "%s = '%s'", d, s); g_free(s); + g_free(d); (*idx)++; } else if ( MATCH(key, "since") ) { @@ -811,7 +813,7 @@ static int _handle_search_args(DbmailMailbox *self, char **search_keys, u64_t *i value->type = IST_IDATE; (*idx)++; s = date_imap2sql(search_keys[*idx]); - g_snprintf(value->search, MAX_SEARCH_LEN, "internal_date > '%s'", s); + g_snprintf(value->search, MAX_SEARCH_LEN, "p.internal_date > '%s'", s); g_free(s); (*idx)++; } @@ -1193,7 +1195,8 @@ static GTree * mailbox_search(DbmailMailbox *self, search_key_t *s) "HAVING v.headervalue %s ? OR k.data %s ? " "ORDER BY m.message_idnr", DBPFX, DBPFX, DBPFX, DBPFX, DBPFX, DBPFX, - db_get_sql(SQL_INSENSITIVE_LIKE), db_get_sql(SQL_INSENSITIVE_LIKE)); + db_get_sql(SQL_INSENSITIVE_LIKE), + db_get_sql(SQL_SENSITIVE_LIKE)); // pgsql will trip over ilike against bytea st = db_stmt_prepare(c,q->str); db_stmt_set_u64(st, 1, dbmail_mailbox_get_id(self)); @@ -1209,7 +1212,7 @@ static GTree * mailbox_search(DbmailMailbox *self, search_key_t *s) case IST_IDATE: g_string_printf(q, "SELECT message_idnr FROM %smessages m " "LEFT JOIN %sphysmessage p ON m.physmessage_id=p.id " - "WHERE mailbox_idnr = ? AND status IN (?,?) AND p.%s " + "WHERE mailbox_idnr = ? AND status IN (?,?) AND %s " "ORDER BY message_idnr", DBPFX, DBPFX, s->search); @@ -1312,7 +1315,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; @@ -1322,22 +1325,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); @@ -1348,11 +1343,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)); @@ -1427,10 +1418,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)) { diff --git a/src/dm_mailboxstate.c b/src/dm_mailboxstate.c index b49500cc..a0705983 100644 --- a/src/dm_mailboxstate.c +++ b/src/dm_mailboxstate.c @@ -259,10 +259,11 @@ int MailboxState_removeUid(T M, u64_t uid) { if (! g_tree_remove(M->msginfo, &uid)) { TRACE(TRACE_WARNING,"trying to remove unknown UID [%llu]", uid); - } else { - M->exists--; + return DM_EGENERAL; } + M->exists--; + MailboxState_remap(M); return DM_SUCCESS; diff --git a/src/sortmodule.h b/src/sortmodule.h index 3c849bc4..85c222d3 100644 --- a/src/sortmodule.h +++ b/src/sortmodule.h @@ -12,7 +12,7 @@ /* Prototypes must match with those in sort.h * and in the sorting drivers. */ typedef struct { - sort_result_t *(* process)(u64_t user_idnr, DbmailMessage *message); + sort_result_t *(* process)(u64_t user_idnr, DbmailMessage *message, const char *mailbox); sort_result_t *(* validate)(u64_t user_idnr, char *scriptname); void (* free_result)(sort_result_t *result); const char *(* listextensions)(void); |