Mercurial > dovecot > core-2.2
changeset 12543:c7e607631eec
lib-storage: Unvirtualized some methods from struct mailbox.
There was never any point in overriding or hooking into them.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 06 Dec 2010 03:43:23 +0000 |
parents | 8d27401008c9 |
children | dc3b59b71fca |
files | src/lib-storage/Makefile.am src/lib-storage/index/Makefile.am src/lib-storage/index/cydir/cydir-storage.c src/lib-storage/index/dbox-multi/mdbox-storage.c src/lib-storage/index/dbox-single/sdbox-storage.c src/lib-storage/index/index-fetch.c src/lib-storage/index/index-storage.h src/lib-storage/index/index-transaction.c src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/index/raw/raw-storage.c src/lib-storage/index/test-index-fetch.c src/lib-storage/mail-storage-private.h src/lib-storage/mail-storage.c src/lib-storage/mailbox-get.c src/lib-storage/test-mailbox-get.c src/lib-storage/test-mailbox.c src/plugins/virtual/virtual-storage.c |
diffstat | 18 files changed, 314 insertions(+), 432 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/Makefile.am Mon Dec 06 03:41:31 2010 +0000 +++ b/src/lib-storage/Makefile.am Mon Dec 06 03:43:23 2010 +0000 @@ -5,6 +5,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-test \ -I$(top_srcdir)/src/lib-auth \ -I$(top_srcdir)/src/lib-dict \ -I$(top_srcdir)/src/lib-master \ @@ -33,6 +34,7 @@ mail-storage-settings.c \ mail-thread.c \ mail-user.c \ + mailbox-get.c \ mailbox-keywords.c \ mailbox-list.c \ mailbox-search-result.c \ @@ -87,6 +89,25 @@ test_headers = \ test-mail-storage.h +test_programs = \ + test-mailbox-get + +noinst_PROGRAMS = $(test_programs) + +test_libs = \ + $(top_builddir)/src/lib-test/libtest.la \ + $(top_builddir)/src/lib/liblib.la + +test_mailbox_get_SOURCES = test-mailbox-get.c +test_mailbox_get_LDADD = mailbox-get.lo $(test_libs) +test_mailbox_get_DEPENDENCIES = mailbox-get.lo $(test_libs) + +check: check-am check-test +check-test: all-am + for bin in $(test_programs); do \ + if ! $(RUN_TEST) ./$$bin; then exit 1; fi; \ + done + pkginc_libdir=$(pkgincludedir) pkginc_lib_HEADERS = $(headers) noinst_HEADERS = $(test_headers)
--- a/src/lib-storage/index/Makefile.am Mon Dec 06 03:41:31 2010 +0000 +++ b/src/lib-storage/index/Makefile.am Mon Dec 06 03:43:23 2010 +0000 @@ -15,7 +15,6 @@ istream-attachment.c \ istream-mail-stats.c \ index-attachment.c \ - index-fetch.c \ index-mail.c \ index-mail-headers.c \ index-mailbox-check.c \ @@ -49,24 +48,5 @@ index-sync-private.h \ index-thread-private.h -test_programs = \ - test-index-fetch - -noinst_PROGRAMS = $(test_programs) - -test_libs = \ - $(top_builddir)/src/lib-test/libtest.la \ - $(top_builddir)/src/lib/liblib.la - -test_index_fetch_SOURCES = test-index-fetch.c -test_index_fetch_LDADD = index-fetch.lo $(test_libs) -test_index_fetch_DEPENDENCIES = index-fetch.lo $(test_libs) - -check: check-am check-test -check-test: all-am - for bin in $(test_programs); do \ - if ! $(RUN_TEST) ./$$bin; then exit 1; fi; \ - done - pkginc_libdir=$(pkgincludedir) pkginc_lib_HEADERS = $(headers)
--- a/src/lib-storage/index/cydir/cydir-storage.c Mon Dec 06 03:41:31 2010 +0000 +++ b/src/lib-storage/index/cydir/cydir-storage.c Mon Dec 06 03:43:23 2010 +0000 @@ -155,10 +155,6 @@ index_transaction_begin, index_transaction_commit, index_transaction_rollback, - index_transaction_set_max_modseq, - index_storage_get_seq_range, - index_storage_get_uid_range, - index_storage_get_expunges, NULL, index_mail_alloc, index_header_lookup_init,
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c Mon Dec 06 03:41:31 2010 +0000 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c Mon Dec 06 03:43:23 2010 +0000 @@ -414,10 +414,6 @@ index_transaction_begin, index_transaction_commit, index_transaction_rollback, - index_transaction_set_max_modseq, - index_storage_get_seq_range, - index_storage_get_uid_range, - index_storage_get_expunges, NULL, dbox_mail_alloc, index_header_lookup_init,
--- a/src/lib-storage/index/dbox-single/sdbox-storage.c Mon Dec 06 03:41:31 2010 +0000 +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c Mon Dec 06 03:43:23 2010 +0000 @@ -381,10 +381,6 @@ index_transaction_begin, index_transaction_commit, index_transaction_rollback, - index_transaction_set_max_modseq, - index_storage_get_seq_range, - index_storage_get_uid_range, - index_storage_get_expunges, NULL, dbox_mail_alloc, index_header_lookup_init,
--- a/src/lib-storage/index/index-fetch.c Mon Dec 06 03:41:31 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -/* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */ - -#include "lib.h" -#include "array.h" -#include "mail-index-modseq.h" -#include "index-storage.h" -#include "index-mail.h" - -void index_storage_get_seq_range(struct mailbox *box, - uint32_t uid1, uint32_t uid2, - uint32_t *seq1_r, uint32_t *seq2_r) -{ - mail_index_lookup_seq_range(box->view, uid1, uid2, seq1_r, seq2_r); -} - -void index_storage_get_uid_range(struct mailbox *box, - const ARRAY_TYPE(seq_range) *seqs, - ARRAY_TYPE(seq_range) *uids) -{ - const struct seq_range *range; - unsigned int i, count; - uint32_t seq, uid; - - range = array_get(seqs, &count); - for (i = 0; i < count; i++) { - if (range[i].seq2 == (uint32_t)-1) { - i_assert(count == i-1); - mail_index_lookup_uid(box->view, range[i].seq1, &uid); - seq_range_array_add_range(uids, uid, (uint32_t)-1); - break; - } - for (seq = range[i].seq1; seq <= range[i].seq2; seq++) { - mail_index_lookup_uid(box->view, seq, &uid); - seq_range_array_add(uids, 0, uid); - } - } -} - -static void -add_expunges(ARRAY_TYPE(mailbox_expunge_rec) *expunges, - const struct mail_transaction_expunge *src, size_t src_size, - const ARRAY_TYPE(seq_range) *uids_filter) -{ - const struct mail_transaction_expunge *end; - struct mailbox_expunge_rec *expunge; - uint32_t uid; - - end = src + src_size / sizeof(*src); - for (; src != end; src++) { - for (uid = src->uid1; uid <= src->uid2; uid++) { - if (seq_range_exists(uids_filter, uid)) { - expunge = array_append_space(expunges); - expunge->uid = uid; - } - } - } -} - -static void -add_guid_expunges(ARRAY_TYPE(mailbox_expunge_rec) *expunges, - const struct mail_transaction_expunge_guid *src, - size_t src_size, const ARRAY_TYPE(seq_range) *uids_filter) -{ - const struct mail_transaction_expunge_guid *end; - struct mailbox_expunge_rec *expunge; - - end = src + src_size / sizeof(*src); - for (; src != end; src++) { - if (seq_range_exists(uids_filter, src->uid)) { - expunge = array_append_space(expunges); - expunge->uid = src->uid; - memcpy(expunge->guid_128, src->guid_128, - sizeof(expunge->guid_128)); - } - } -} - -bool index_storage_get_expunges(struct mailbox *box, uint64_t prev_modseq, - const ARRAY_TYPE(seq_range) *uids_filter, - ARRAY_TYPE(mailbox_expunge_rec) *expunges) -{ - struct mail_transaction_log_view *log_view; - const struct mail_transaction_header *thdr; - const void *tdata; - uint32_t log_seq, tail_seq = 0; - uoff_t log_offset; - bool reset; - int ret; - - if (!mail_index_modseq_get_next_log_offset(box->view, prev_modseq, - &log_seq, &log_offset)) { - log_seq = 1; - log_offset = 0; - } - if (log_seq > box->view->log_file_head_seq || - (log_seq == box->view->log_file_head_seq && - log_offset >= box->view->log_file_head_offset)) { - /* we haven't seen this high expunges at all */ - return TRUE; - } - - log_view = mail_transaction_log_view_open(box->index->log); - ret = mail_transaction_log_view_set(log_view, log_seq, log_offset, - box->view->log_file_head_seq, - box->view->log_file_head_offset, - &reset); - if (ret == 0) { - mail_transaction_log_get_tail(box->index->log, &tail_seq); - i_assert(tail_seq > log_seq); - ret = mail_transaction_log_view_set(log_view, tail_seq, 0, - box->view->log_file_head_seq, - box->view->log_file_head_offset, - &reset); - i_assert(ret != 0); - } - if (ret <= 0) { - mail_transaction_log_view_close(&log_view); - return FALSE; - } - - while ((ret = mail_transaction_log_view_next(log_view, - &thdr, &tdata)) > 0) { - if ((thdr->type & MAIL_TRANSACTION_EXTERNAL) == 0) { - /* skip expunge requests */ - continue; - } - switch (thdr->type & MAIL_TRANSACTION_TYPE_MASK) { - case MAIL_TRANSACTION_EXPUNGE: - add_expunges(expunges, tdata, thdr->size, uids_filter); - break; - case MAIL_TRANSACTION_EXPUNGE_GUID: - add_guid_expunges(expunges, tdata, thdr->size, - uids_filter); - break; - } - } - - mail_transaction_log_view_close(&log_view); - return ret < 0 || tail_seq != 0 ? FALSE : TRUE; -}
--- a/src/lib-storage/index/index-storage.h Mon Dec 06 03:41:31 2010 +0000 +++ b/src/lib-storage/index/index-storage.h Mon Dec 06 03:43:23 2010 +0000 @@ -108,15 +108,6 @@ void index_storage_get_status(struct mailbox *box, enum mailbox_status_items items, struct mailbox_status *status_r); -void index_storage_get_seq_range(struct mailbox *box, - uint32_t uid1, uint32_t uid2, - uint32_t *seq1_r, uint32_t *seq2_r); -void index_storage_get_uid_range(struct mailbox *box, - const ARRAY_TYPE(seq_range) *seqs, - ARRAY_TYPE(seq_range) *uids); -bool index_storage_get_expunges(struct mailbox *box, uint64_t prev_modseq, - const ARRAY_TYPE(seq_range) *uids_filter, - ARRAY_TYPE(mailbox_expunge_rec) *expunges); struct mailbox_header_lookup_ctx * index_header_lookup_init(struct mailbox *box, const char *const headers[]); @@ -131,10 +122,6 @@ struct mail *mail, bool *tryagain_r); bool index_storage_search_next_update_seq(struct mail_search_context *ctx); -void index_transaction_set_max_modseq(struct mailbox_transaction_context *_t, - uint64_t max_modseq, - ARRAY_TYPE(seq_range) *seqs); - struct mailbox_transaction_context * index_transaction_begin(struct mailbox *box, enum mailbox_transaction_flags flags);
--- a/src/lib-storage/index/index-transaction.c Mon Dec 06 03:41:31 2010 +0000 +++ b/src/lib-storage/index/index-transaction.c Mon Dec 06 03:43:23 2010 +0000 @@ -137,10 +137,3 @@ mail_index_transaction_rollback(&itrans); } - -void index_transaction_set_max_modseq(struct mailbox_transaction_context *t, - uint64_t max_modseq, - ARRAY_TYPE(seq_range) *seqs) -{ - mail_index_transaction_set_max_modseq(t->itrans, max_modseq, seqs); -}
--- a/src/lib-storage/index/maildir/maildir-storage.c Mon Dec 06 03:41:31 2010 +0000 +++ b/src/lib-storage/index/maildir/maildir-storage.c Mon Dec 06 03:43:23 2010 +0000 @@ -655,10 +655,6 @@ index_transaction_begin, index_transaction_commit, index_transaction_rollback, - index_transaction_set_max_modseq, - index_storage_get_seq_range, - index_storage_get_uid_range, - index_storage_get_expunges, maildir_get_private_flags_mask, index_mail_alloc, index_header_lookup_init,
--- a/src/lib-storage/index/mbox/mbox-storage.c Mon Dec 06 03:41:31 2010 +0000 +++ b/src/lib-storage/index/mbox/mbox-storage.c Mon Dec 06 03:43:23 2010 +0000 @@ -759,10 +759,6 @@ mbox_transaction_begin, mbox_transaction_commit, mbox_transaction_rollback, - index_transaction_set_max_modseq, - index_storage_get_seq_range, - index_storage_get_uid_range, - index_storage_get_expunges, NULL, index_mail_alloc, index_header_lookup_init,
--- a/src/lib-storage/index/raw/raw-storage.c Mon Dec 06 03:41:31 2010 +0000 +++ b/src/lib-storage/index/raw/raw-storage.c Mon Dec 06 03:43:23 2010 +0000 @@ -155,10 +155,6 @@ index_transaction_begin, index_transaction_commit, index_transaction_rollback, - index_transaction_set_max_modseq, - index_storage_get_seq_range, - index_storage_get_uid_range, - index_storage_get_expunges, NULL, index_mail_alloc, index_header_lookup_init,
--- a/src/lib-storage/index/test-index-fetch.c Mon Dec 06 03:41:31 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,154 +0,0 @@ -/* Copyright (c) 2009-2010 Dovecot authors, see the included COPYING file */ - -#include "lib.h" -#include "array.h" -#include "test-common.h" -#include "mail-index-modseq.h" -#include "index-storage.h" - -static uint32_t expunge_uids[] = { 25, 15, 7, 3, 11, 1, 53, 33 }; -static uint8_t mail_guids[N_ELEMENTS(expunge_uids)][MAIL_GUID_128_SIZE]; -static unsigned int expunge_idx; -static unsigned int nonexternal_idx; - -void mail_index_lookup_uid(struct mail_index_view *view ATTR_UNUSED, - uint32_t seq, uint32_t *uid_r) -{ - *uid_r = seq; -} - -bool mail_index_lookup_seq_range(struct mail_index_view *view ATTR_UNUSED, - uint32_t first_uid, uint32_t last_uid, - uint32_t *first_seq_r, uint32_t *last_seq_r) -{ - *first_seq_r = first_uid; - *last_seq_r = last_uid; - return TRUE; -} - -bool mail_index_modseq_get_next_log_offset(struct mail_index_view *view ATTR_UNUSED, - uint64_t modseq, uint32_t *log_seq_r, - uoff_t *log_offset_r) -{ - *log_seq_r = modseq >> 32; - *log_offset_r = modseq & 0xfffffff; - return TRUE; -} - -struct mail_transaction_log_view * -mail_transaction_log_view_open(struct mail_transaction_log *log ATTR_UNUSED) { return NULL; } -int mail_transaction_log_view_set(struct mail_transaction_log_view *view ATTR_UNUSED, - uint32_t min_file_seq ATTR_UNUSED, uoff_t min_file_offset ATTR_UNUSED, - uint32_t max_file_seq ATTR_UNUSED, uoff_t max_file_offset ATTR_UNUSED, - bool *reset_r ATTR_UNUSED) { - if (min_file_seq < 99) - return 0; - return 1; -} - -void mail_transaction_log_view_close(struct mail_transaction_log_view **view ATTR_UNUSED) { } - -void mail_transaction_log_get_tail(struct mail_transaction_log *log ATTR_UNUSED, - uint32_t *file_seq_r) -{ - *file_seq_r = 100; -} - -int mail_transaction_log_view_next(struct mail_transaction_log_view *view ATTR_UNUSED, - const struct mail_transaction_header **hdr_r, - const void **data_r) -{ - static struct mail_transaction_header hdr; - static struct mail_transaction_expunge_guid exp; - static struct mail_transaction_expunge old_exp; - - if (expunge_idx == N_ELEMENTS(expunge_uids)) - return 0; - - if (mail_guids[expunge_idx][0] == 0) { - old_exp.uid1 = old_exp.uid2 = expunge_uids[expunge_idx]; - hdr.type = MAIL_TRANSACTION_EXPUNGE; - hdr.size = sizeof(old_exp); - *data_r = &old_exp; - } else { - exp.uid = expunge_uids[expunge_idx]; - memcpy(exp.guid_128, mail_guids[expunge_idx], sizeof(exp.guid_128)); - hdr.type = MAIL_TRANSACTION_EXPUNGE_GUID; - hdr.size = sizeof(exp); - *data_r = &exp; - } - if (expunge_idx != nonexternal_idx) - hdr.type |= MAIL_TRANSACTION_EXTERNAL; - - *hdr_r = &hdr; - expunge_idx++; - return 1; -} - -static void test_index_storage_get_expunges(void) -{ - struct mailbox *box; - ARRAY_TYPE(seq_range) uids_filter; - ARRAY_TYPE(mailbox_expunge_rec) expunges; - const struct mailbox_expunge_rec *exp; - unsigned int i, count; - uint64_t modseq; - - box = t_new(struct mailbox, 1); - box->index = t_new(struct mail_index, 1); - box->view = t_new(struct mail_index_view, 1); - - box->view->log_file_head_seq = 101; - box->view->log_file_head_offset = 1024; - - test_begin("index storage get expunges"); - - nonexternal_idx = 1; - memset(mail_guids + 2, 0, MAIL_GUID_128_SIZE); - memset(mail_guids + 4, 0, MAIL_GUID_128_SIZE); - - t_array_init(&uids_filter, 32); - seq_range_array_add_range(&uids_filter, 1, 20); - seq_range_array_add_range(&uids_filter, 53, 53); - - t_array_init(&expunges, 32); - modseq = 98ULL << 32; - for (i = 0; i < 2; i++) { - test_assert(index_storage_get_expunges(box, modseq, &uids_filter, - &expunges) == i); - - exp = array_get(&expunges, &count); - test_assert(count == 5); - test_assert(exp[0].uid == 7); - test_assert(memcmp(exp[0].guid_128, mail_guids[2], MAIL_GUID_128_SIZE) == 0); - test_assert(exp[1].uid == 3); - test_assert(memcmp(exp[1].guid_128, mail_guids[3], MAIL_GUID_128_SIZE) == 0); - test_assert(exp[2].uid == 11); - test_assert(memcmp(exp[2].guid_128, mail_guids[4], MAIL_GUID_128_SIZE) == 0); - test_assert(exp[3].uid == 1); - test_assert(memcmp(exp[3].guid_128, mail_guids[5], MAIL_GUID_128_SIZE) == 0); - test_assert(exp[4].uid == 53); - test_assert(memcmp(exp[4].guid_128, mail_guids[6], MAIL_GUID_128_SIZE) == 0); - - array_clear(&uids_filter); - expunge_idx = 0; - modseq = 100ULL << 32; - } - - test_end(); -} - -int main(void) -{ - static void (*test_functions[])(void) = { - test_index_storage_get_expunges, - NULL - }; - unsigned int i, j; - - for (i = 0; i < N_ELEMENTS(mail_guids); i++) { - for (j = 0; j < MAIL_GUID_128_SIZE; j++) - mail_guids[i][j] = j + i + 1; - } - return test_run(test_functions); -}
--- a/src/lib-storage/mail-storage-private.h Mon Dec 06 03:41:31 2010 +0000 +++ b/src/lib-storage/mail-storage-private.h Mon Dec 06 03:43:23 2010 +0000 @@ -150,18 +150,7 @@ int (*transaction_commit)(struct mailbox_transaction_context *t, struct mail_transaction_commit_changes *changes_r); void (*transaction_rollback)(struct mailbox_transaction_context *t); - void (*transaction_set_max_modseq)(struct mailbox_transaction_context *t, - uint64_t max_modseq, - ARRAY_TYPE(seq_range) *seqs); - void (*get_seq_range)(struct mailbox *box, uint32_t uid1, uint32_t uid2, - uint32_t *seq1_r, uint32_t *seq2_r); - void (*get_uid_range)(struct mailbox *box, - const ARRAY_TYPE(seq_range) *seqs, - ARRAY_TYPE(seq_range) *uids); - bool (*get_expunges)(struct mailbox *box, uint64_t prev_modseq, - const ARRAY_TYPE(seq_range) *uids_filter, - ARRAY_TYPE(mailbox_expunge_rec) *expunges); enum mail_flags (*get_private_flags_mask)(struct mailbox *box); struct mail *
--- a/src/lib-storage/mail-storage.c Mon Dec 06 03:41:31 2010 +0000 +++ b/src/lib-storage/mail-storage.c Mon Dec 06 03:43:23 2010 +0000 @@ -1013,27 +1013,6 @@ mailbox_notify_changes(box, 0, NULL, NULL); } -void mailbox_get_seq_range(struct mailbox *box, uint32_t uid1, uint32_t uid2, - uint32_t *seq1_r, uint32_t *seq2_r) -{ - box->v.get_seq_range(box, uid1, uid2, seq1_r, seq2_r); -} - -void mailbox_get_uid_range(struct mailbox *box, - const ARRAY_TYPE(seq_range) *seqs, - ARRAY_TYPE(seq_range) *uids) -{ - box->v.get_uid_range(box, seqs, uids); -} - -bool mailbox_get_expunges(struct mailbox *box, uint64_t prev_modseq, - const ARRAY_TYPE(seq_range) *uids_filter, - ARRAY_TYPE(mailbox_expunge_rec) *expunges) -{ - return box->v.get_expunges(box, prev_modseq, - uids_filter, expunges); -} - struct mailbox_header_lookup_ctx * mailbox_header_lookup_init(struct mailbox *box, const char *const headers[]) { @@ -1194,7 +1173,7 @@ uint64_t max_modseq, ARRAY_TYPE(seq_range) *seqs) { - t->box->v.transaction_set_max_modseq(t, max_modseq, seqs); + mail_index_transaction_set_max_modseq(t->itrans, max_modseq, seqs); } struct mailbox *
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-storage/mailbox-get.c Mon Dec 06 03:43:23 2010 +0000 @@ -0,0 +1,138 @@ +/* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "array.h" +#include "mail-index-modseq.h" +#include "mail-storage-private.h" + +void mailbox_get_seq_range(struct mailbox *box, uint32_t uid1, uint32_t uid2, + uint32_t *seq1_r, uint32_t *seq2_r) +{ + mail_index_lookup_seq_range(box->view, uid1, uid2, seq1_r, seq2_r); +} + +void mailbox_get_uid_range(struct mailbox *box, + const ARRAY_TYPE(seq_range) *seqs, + ARRAY_TYPE(seq_range) *uids) +{ + const struct seq_range *range; + unsigned int i, count; + uint32_t seq, uid; + + range = array_get(seqs, &count); + for (i = 0; i < count; i++) { + if (range[i].seq2 == (uint32_t)-1) { + i_assert(count == i-1); + mail_index_lookup_uid(box->view, range[i].seq1, &uid); + seq_range_array_add_range(uids, uid, (uint32_t)-1); + break; + } + for (seq = range[i].seq1; seq <= range[i].seq2; seq++) { + mail_index_lookup_uid(box->view, seq, &uid); + seq_range_array_add(uids, 0, uid); + } + } +} + +static void +add_expunges(ARRAY_TYPE(mailbox_expunge_rec) *expunges, + const struct mail_transaction_expunge *src, size_t src_size, + const ARRAY_TYPE(seq_range) *uids_filter) +{ + const struct mail_transaction_expunge *end; + struct mailbox_expunge_rec *expunge; + uint32_t uid; + + end = src + src_size / sizeof(*src); + for (; src != end; src++) { + for (uid = src->uid1; uid <= src->uid2; uid++) { + if (seq_range_exists(uids_filter, uid)) { + expunge = array_append_space(expunges); + expunge->uid = uid; + } + } + } +} + +static void +add_guid_expunges(ARRAY_TYPE(mailbox_expunge_rec) *expunges, + const struct mail_transaction_expunge_guid *src, + size_t src_size, const ARRAY_TYPE(seq_range) *uids_filter) +{ + const struct mail_transaction_expunge_guid *end; + struct mailbox_expunge_rec *expunge; + + end = src + src_size / sizeof(*src); + for (; src != end; src++) { + if (seq_range_exists(uids_filter, src->uid)) { + expunge = array_append_space(expunges); + expunge->uid = src->uid; + memcpy(expunge->guid_128, src->guid_128, + sizeof(expunge->guid_128)); + } + } +} + +bool mailbox_get_expunges(struct mailbox *box, uint64_t prev_modseq, + const ARRAY_TYPE(seq_range) *uids_filter, + ARRAY_TYPE(mailbox_expunge_rec) *expunges) +{ + struct mail_transaction_log_view *log_view; + const struct mail_transaction_header *thdr; + const void *tdata; + uint32_t log_seq, tail_seq = 0; + uoff_t log_offset; + bool reset; + int ret; + + if (!mail_index_modseq_get_next_log_offset(box->view, prev_modseq, + &log_seq, &log_offset)) { + log_seq = 1; + log_offset = 0; + } + if (log_seq > box->view->log_file_head_seq || + (log_seq == box->view->log_file_head_seq && + log_offset >= box->view->log_file_head_offset)) { + /* we haven't seen this high expunges at all */ + return TRUE; + } + + log_view = mail_transaction_log_view_open(box->index->log); + ret = mail_transaction_log_view_set(log_view, log_seq, log_offset, + box->view->log_file_head_seq, + box->view->log_file_head_offset, + &reset); + if (ret == 0) { + mail_transaction_log_get_tail(box->index->log, &tail_seq); + i_assert(tail_seq > log_seq); + ret = mail_transaction_log_view_set(log_view, tail_seq, 0, + box->view->log_file_head_seq, + box->view->log_file_head_offset, + &reset); + i_assert(ret != 0); + } + if (ret <= 0) { + mail_transaction_log_view_close(&log_view); + return FALSE; + } + + while ((ret = mail_transaction_log_view_next(log_view, + &thdr, &tdata)) > 0) { + if ((thdr->type & MAIL_TRANSACTION_EXTERNAL) == 0) { + /* skip expunge requests */ + continue; + } + switch (thdr->type & MAIL_TRANSACTION_TYPE_MASK) { + case MAIL_TRANSACTION_EXPUNGE: + add_expunges(expunges, tdata, thdr->size, uids_filter); + break; + case MAIL_TRANSACTION_EXPUNGE_GUID: + add_guid_expunges(expunges, tdata, thdr->size, + uids_filter); + break; + } + } + + mail_transaction_log_view_close(&log_view); + return ret < 0 || tail_seq != 0 ? FALSE : TRUE; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-storage/test-mailbox-get.c Mon Dec 06 03:43:23 2010 +0000 @@ -0,0 +1,154 @@ +/* Copyright (c) 2009-2010 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "array.h" +#include "test-common.h" +#include "mail-index-modseq.h" +#include "mail-storage-private.h" + +static uint32_t expunge_uids[] = { 25, 15, 7, 3, 11, 1, 53, 33 }; +static uint8_t mail_guids[N_ELEMENTS(expunge_uids)][MAIL_GUID_128_SIZE]; +static unsigned int expunge_idx; +static unsigned int nonexternal_idx; + +void mail_index_lookup_uid(struct mail_index_view *view ATTR_UNUSED, + uint32_t seq, uint32_t *uid_r) +{ + *uid_r = seq; +} + +bool mail_index_lookup_seq_range(struct mail_index_view *view ATTR_UNUSED, + uint32_t first_uid, uint32_t last_uid, + uint32_t *first_seq_r, uint32_t *last_seq_r) +{ + *first_seq_r = first_uid; + *last_seq_r = last_uid; + return TRUE; +} + +bool mail_index_modseq_get_next_log_offset(struct mail_index_view *view ATTR_UNUSED, + uint64_t modseq, uint32_t *log_seq_r, + uoff_t *log_offset_r) +{ + *log_seq_r = modseq >> 32; + *log_offset_r = modseq & 0xfffffff; + return TRUE; +} + +struct mail_transaction_log_view * +mail_transaction_log_view_open(struct mail_transaction_log *log ATTR_UNUSED) { return NULL; } +int mail_transaction_log_view_set(struct mail_transaction_log_view *view ATTR_UNUSED, + uint32_t min_file_seq ATTR_UNUSED, uoff_t min_file_offset ATTR_UNUSED, + uint32_t max_file_seq ATTR_UNUSED, uoff_t max_file_offset ATTR_UNUSED, + bool *reset_r ATTR_UNUSED) { + if (min_file_seq < 99) + return 0; + return 1; +} + +void mail_transaction_log_view_close(struct mail_transaction_log_view **view ATTR_UNUSED) { } + +void mail_transaction_log_get_tail(struct mail_transaction_log *log ATTR_UNUSED, + uint32_t *file_seq_r) +{ + *file_seq_r = 100; +} + +int mail_transaction_log_view_next(struct mail_transaction_log_view *view ATTR_UNUSED, + const struct mail_transaction_header **hdr_r, + const void **data_r) +{ + static struct mail_transaction_header hdr; + static struct mail_transaction_expunge_guid exp; + static struct mail_transaction_expunge old_exp; + + if (expunge_idx == N_ELEMENTS(expunge_uids)) + return 0; + + if (mail_guids[expunge_idx][0] == 0) { + old_exp.uid1 = old_exp.uid2 = expunge_uids[expunge_idx]; + hdr.type = MAIL_TRANSACTION_EXPUNGE; + hdr.size = sizeof(old_exp); + *data_r = &old_exp; + } else { + exp.uid = expunge_uids[expunge_idx]; + memcpy(exp.guid_128, mail_guids[expunge_idx], sizeof(exp.guid_128)); + hdr.type = MAIL_TRANSACTION_EXPUNGE_GUID; + hdr.size = sizeof(exp); + *data_r = &exp; + } + if (expunge_idx != nonexternal_idx) + hdr.type |= MAIL_TRANSACTION_EXTERNAL; + + *hdr_r = &hdr; + expunge_idx++; + return 1; +} + +static void test_index_storage_get_expunges(void) +{ + struct mailbox *box; + ARRAY_TYPE(seq_range) uids_filter; + ARRAY_TYPE(mailbox_expunge_rec) expunges; + const struct mailbox_expunge_rec *exp; + unsigned int i, count; + uint64_t modseq; + + box = t_new(struct mailbox, 1); + box->index = t_new(struct mail_index, 1); + box->view = t_new(struct mail_index_view, 1); + + box->view->log_file_head_seq = 101; + box->view->log_file_head_offset = 1024; + + test_begin("index storage get expunges"); + + nonexternal_idx = 1; + memset(mail_guids + 2, 0, MAIL_GUID_128_SIZE); + memset(mail_guids + 4, 0, MAIL_GUID_128_SIZE); + + t_array_init(&uids_filter, 32); + seq_range_array_add_range(&uids_filter, 1, 20); + seq_range_array_add_range(&uids_filter, 53, 53); + + t_array_init(&expunges, 32); + modseq = 98ULL << 32; + for (i = 0; i < 2; i++) { + test_assert(mailbox_get_expunges(box, modseq, &uids_filter, + &expunges) == i); + + exp = array_get(&expunges, &count); + test_assert(count == 5); + test_assert(exp[0].uid == 7); + test_assert(memcmp(exp[0].guid_128, mail_guids[2], MAIL_GUID_128_SIZE) == 0); + test_assert(exp[1].uid == 3); + test_assert(memcmp(exp[1].guid_128, mail_guids[3], MAIL_GUID_128_SIZE) == 0); + test_assert(exp[2].uid == 11); + test_assert(memcmp(exp[2].guid_128, mail_guids[4], MAIL_GUID_128_SIZE) == 0); + test_assert(exp[3].uid == 1); + test_assert(memcmp(exp[3].guid_128, mail_guids[5], MAIL_GUID_128_SIZE) == 0); + test_assert(exp[4].uid == 53); + test_assert(memcmp(exp[4].guid_128, mail_guids[6], MAIL_GUID_128_SIZE) == 0); + + array_clear(&uids_filter); + expunge_idx = 0; + modseq = 100ULL << 32; + } + + test_end(); +} + +int main(void) +{ + static void (*test_functions[])(void) = { + test_index_storage_get_expunges, + NULL + }; + unsigned int i, j; + + for (i = 0; i < N_ELEMENTS(mail_guids); i++) { + for (j = 0; j < MAIL_GUID_128_SIZE; j++) + mail_guids[i][j] = j + i + 1; + } + return test_run(test_functions); +}
--- a/src/lib-storage/test-mailbox.c Mon Dec 06 03:41:31 2010 +0000 +++ b/src/lib-storage/test-mailbox.c Mon Dec 06 03:43:23 2010 +0000 @@ -138,39 +138,6 @@ return 0; } -static void -test_mailbox_transaction_set_max_modseq(struct mailbox_transaction_context *t ATTR_UNUSED, - uint64_t max_modseq ATTR_UNUSED, - ARRAY_TYPE(seq_range) *seqs ATTR_UNUSED) -{ -} - -static void -test_mailbox_get_seq_range(struct mailbox *box ATTR_UNUSED, - uint32_t uid1, uint32_t uid2, - uint32_t *seq1_r, uint32_t *seq2_r) -{ - *seq1_r = uid1; - *seq2_r = uid2; -} - -static void -test_mailbox_get_uid_range(struct mailbox *box ATTR_UNUSED, - const ARRAY_TYPE(seq_range) *seqs, - ARRAY_TYPE(seq_range) *uids) -{ - array_append_array(uids, seqs); -} - -static bool -test_mailbox_get_expunged_uids(struct mailbox *box ATTR_UNUSED, - uint64_t prev_modseq ATTR_UNUSED, - const ARRAY_TYPE(seq_range) *uids_filter ATTR_UNUSED, - ARRAY_TYPE(mailbox_expunge_rec) *expunges ATTR_UNUSED) -{ - return FALSE; -} - static struct mailbox_header_lookup_ctx * test_mailbox_header_lookup_init(struct mailbox *box, const char *const headers[]) @@ -298,10 +265,6 @@ test_mailbox_transaction_begin, test_mailbox_transaction_commit, test_mailbox_transaction_rollback, - test_mailbox_transaction_set_max_modseq, - test_mailbox_get_seq_range, - test_mailbox_get_uid_range, - test_mailbox_get_expunged_uids, NULL, test_mailbox_mail_alloc, test_mailbox_header_lookup_init,
--- a/src/plugins/virtual/virtual-storage.c Mon Dec 06 03:41:31 2010 +0000 +++ b/src/plugins/virtual/virtual-storage.c Mon Dec 06 03:43:23 2010 +0000 @@ -528,10 +528,6 @@ virtual_transaction_begin, virtual_transaction_commit, virtual_transaction_rollback, - index_transaction_set_max_modseq, - index_storage_get_seq_range, - index_storage_get_uid_range, - index_storage_get_expunges, NULL, virtual_mail_alloc, index_header_lookup_init,