mail-index-sync.c revision 0bea219e4f944cd17a9ccd1131b7fe081d1bb0a7
89a126810703c666309310d0f3189e9834d70b5bTimo Sirainen/* Copyright (c) 2003-2009 Dovecot authors, see the included COPYING file */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct mail_index_transaction *sync_trans, *ext_trans;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ARRAY_DEFINE(sync_list, struct mail_index_sync_list);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void mail_index_sync_add_expunge(struct mail_index_sync_ctx *ctx)
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen const struct mail_transaction_expunge *e = ctx->data;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen for (i = 0; i < size; i++) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen for (uid = e[i].uid1; uid <= e[i].uid2; uid++)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void mail_index_sync_add_flag_update(struct mail_index_sync_ctx *ctx)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct mail_transaction_flag_update *u = ctx->data;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen for (i = 0; i < size; i++) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (u[i].add_flags != 0) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_index_update_flags_range(ctx->sync_trans,
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen if (u[i].remove_flags != 0) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_index_update_flags_range(ctx->sync_trans,
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainenstatic void mail_index_sync_add_keyword_update(struct mail_index_sync_ctx *ctx)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct mail_transaction_keyword_update *u = ctx->data;
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen keyword_names[0] = t_strndup(u + 1, u->name_size);
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen keywords = mail_index_keywords_create(ctx->index, keyword_names);
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainen size = (ctx->hdr->size - uidset_offset) / sizeof(uint32_t);
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainen /* FIXME: mail_index_update_keywords_range() */
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainen for (uid = uids[i]; uid <= uids[i+1]; uid++) {
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainen mail_index_update_keywords(ctx->sync_trans, uid,
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainenstatic void mail_index_sync_add_keyword_reset(struct mail_index_sync_ctx *ctx)
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen const struct mail_transaction_keyword_reset *u = ctx->data;
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen keywords = mail_index_keywords_create(ctx->index, NULL);
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen for (i = 0; i < size; i++) {
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen for (uid = u[i].uid1; uid <= u[i].uid2; uid++) {
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen mail_index_update_keywords(ctx->sync_trans, uid,
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainenstatic void mail_index_sync_add_append(struct mail_index_sync_ctx *ctx)
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainen const struct mail_index_record *rec = ctx->data;
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen if (ctx->append_uid_first == 0 || rec->uid < ctx->append_uid_first)
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainen rec = CONST_PTR_OFFSET(ctx->data, ctx->hdr->size - sizeof(*rec));
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainenstatic bool mail_index_sync_add_transaction(struct mail_index_sync_ctx *ctx)
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainen switch (ctx->hdr->type & MAIL_TRANSACTION_TYPE_MASK) {
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainenstatic void mail_index_sync_add_dirty_updates(struct mail_index_sync_ctx *ctx)
df6478c4cf605bd81b3891c148b84c14eb6c4035Timo Sirainen messages_count = mail_index_view_get_messages_count(ctx->view);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if ((rec->flags & MAIL_INDEX_MAIL_FLAG_DIRTY) == 0)
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen mail_index_update_flags(ctx->sync_trans, rec->uid,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenmail_index_sync_update_mailbox_pos(struct mail_index_sync_ctx *ctx)
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen mail_transaction_log_view_get_prev_pos(ctx->view->log_view,
58be9d6bcc3800f5b3d76a064ee767fbe31a5a8aTimo Sirainen ctx->last_tail_offset = offset + ctx->hdr->size + sizeof(*ctx->hdr);
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainenmail_index_sync_read_and_sort(struct mail_index_sync_ctx *ctx)
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen struct mail_index_transaction *sync_trans = ctx->sync_trans;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct mail_index_transaction_keyword_update *keyword_updates;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen unsigned int i, keyword_count;
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen if ((ctx->view->map->hdr.flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) &&
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen (ctx->flags & MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY) != 0) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* show dirty flags as flag updates */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* read all transactions from log into a transaction in memory.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen skip the external ones, they're already synced to mailbox and
f501ad38c51cf1d8f4f84313922c785e6ae6e81fTimo Sirainen included in our view */
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen while ((ret = mail_transaction_log_view_next(ctx->view->log_view,
e192a3b1ca8ae857e7d87298ea507d32977ba570Timo Sirainen if ((ctx->hdr->type & MAIL_TRANSACTION_EXTERNAL) != 0)
f501ad38c51cf1d8f4f84313922c785e6ae6e81fTimo Sirainen /* create an array containing all expunge, flag and keyword update
8b9342aa96b2f297e23afb261f9f7dd859800952Timo Sirainen arrays so we can easily go through all of the changes. */
8b9342aa96b2f297e23afb261f9f7dd859800952Timo Sirainen keyword_count = !array_is_created(&sync_trans->keyword_updates) ? 0 :
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen i_array_init(&ctx->sync_list, keyword_count + 2);
37e6cf44d61a81c6839e3ab76234b54309d8d292Timo Sirainen if (array_is_created(&sync_trans->expunges)) {
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen synclist = array_append_space(&ctx->sync_list);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen synclist->array = (void *)&sync_trans->expunges;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen synclist = array_append_space(&ctx->sync_list);
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen synclist->array = (void *)&sync_trans->updates;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* we must return resets before keyword additions or they get lost */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (array_is_created(&sync_trans->keyword_resets)) {
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen synclist = array_append_space(&ctx->sync_list);
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen synclist->array = (void *)&sync_trans->keyword_resets;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen for (i = 0; i < keyword_count; i++) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (array_is_created(&keyword_updates[i].add_seq)) {
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen synclist = array_append_space(&ctx->sync_list);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen synclist->array = (void *)&keyword_updates[i].add_seq;
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen if (array_is_created(&keyword_updates[i].remove_seq)) {
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen synclist = array_append_space(&ctx->sync_list);
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainenmail_index_need_sync(struct mail_index *index, enum mail_index_sync_flags flags,
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen uint32_t log_file_seq, uoff_t log_file_offset)
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen const struct mail_index_header *hdr = &index->map->hdr;
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen if ((flags & MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES) == 0)
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen /* sync only if there's something to do */
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen (flags & MAIL_INDEX_SYNC_FLAG_DROP_RECENT) != 0)
f501ad38c51cf1d8f4f84313922c785e6ae6e81fTimo Sirainen if ((hdr->flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) &&
f501ad38c51cf1d8f4f84313922c785e6ae6e81fTimo Sirainen (flags & MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY) != 0)
f501ad38c51cf1d8f4f84313922c785e6ae6e81fTimo Sirainen /* we want to sync up to transaction log's head */
f501ad38c51cf1d8f4f84313922c785e6ae6e81fTimo Sirainen if ((hdr->log_file_tail_offset < log_file_offset &&
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen /* already synced */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen return mail_cache_need_compress(index->cache);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmail_index_sync_set_log_view(struct mail_index_view *view,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen uint32_t start_file_seq, uoff_t start_file_offset)
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen mail_transaction_log_get_head(view->index->log, &log_seq, &log_offset);
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen ret = mail_transaction_log_view_set(view->log_view,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* either corrupted or the file was deleted for
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen some reason. either way, we can't go forward */
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen "Unexpected transaction log desync with index %s",
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainenint mail_index_sync_begin(struct mail_index *index,
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen ret = mail_index_sync_begin_to(index, ctx_r, view_r, trans_r,
da5d50534cfca45d0aaaf0bdac17b287b4588809Timo Sirainen (flags & MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES) != 0);
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainenmail_index_sync_begin_init(struct mail_index *index,
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen uint32_t log_file_seq, uoff_t log_file_offset)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* if we require changes, don't lock transaction log yet. first check
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen if there's anything to sync. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if ((flags & MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES) == 0) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (mail_transaction_log_sync_lock(index->log,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* The view must contain what we expect the mailbox to look like
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen currently. That allows the backend to update external flag
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen changes (etc.) if the view doesn't match the mailbox.
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainen We'll update the view to contain everything that exist in the
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainen transaction log except for expunges. They're synced in
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainen mail_index_sync_commit(). */
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainen if ((ret = mail_index_map(index, MAIL_INDEX_SYNC_HANDLER_HEAD)) <= 0) {
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainen /* let's try again */
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainen if (mail_index_map(index, MAIL_INDEX_SYNC_HANDLER_HEAD) <= 0) {
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen /* it looks like we have something to sync. lock the file and
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen check again. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen flags &= ~MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return mail_index_sync_begin_init(index, flags, log_file_seq,
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen if (hdr->log_file_tail_offset > hdr->log_file_head_offset ||
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen (hdr->log_file_seq == seq && hdr->log_file_tail_offset > offset)) {
ce19e80b5a907d51a7cdf081e09699af8367dbfaTimo Sirainen /* broken sync positions. fix them. */
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen "broken sync positions in index file %s",
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenint mail_index_sync_begin_to(struct mail_index *index,
69bd816e46fdee6182d0cb2e4c6be32399a555c8Timo Sirainen uint32_t log_file_seq, uoff_t log_file_offset,
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen enum mail_index_transaction_flags trans_flags;
f239eb76f77afcbc0bfc97c9b52b4407d1bc3fe6Timo Sirainen flags |= MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES;
f239eb76f77afcbc0bfc97c9b52b4407d1bc3fe6Timo Sirainen ret = mail_index_sync_begin_init(index, flags, log_file_seq,
5196f9ea42d02000f9c3d22f20aa816140af4422Timo Sirainen ctx->last_tail_offset = hdr->log_file_tail_offset;
f239eb76f77afcbc0bfc97c9b52b4407d1bc3fe6Timo Sirainen sync_view = mail_index_dummy_view_open(index);
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen ctx->sync_trans = mail_index_transaction_begin(sync_view,
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen /* we wish to see all the changes from last mailbox sync position to
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen the end of the transaction log */
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen if (mail_index_sync_set_log_view(ctx->view, hdr->log_file_seq,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen /* if a log file is missing, there's nothing we can do except
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen to skip over it. fix the problem with fsck and try again. */
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen return mail_index_sync_begin_to(index, ctx_r, view_r, trans_r,
ba00293b85c7fb4e7a2d100991c716e17b9daaaeTimo Sirainen /* we need to have all the transactions sorted to optimize
648d24583c1574441c4fa0331a90bd4d6e7996c5Timo Sirainen caller's mailbox access patterns */
51b979b6414b940f04677a7e2d064be119345954Timo Sirainen /* create the transaction after the view has been updated with
2af769daebd83719ac696a440e06f6020471cec0Timo Sirainen external transactions and marked as sync view */
51b979b6414b940f04677a7e2d064be119345954Timo Sirainen trans_flags = MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL;
51b979b6414b940f04677a7e2d064be119345954Timo Sirainen if ((ctx->flags & MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES) != 0)
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen trans_flags |= MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES;
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen ctx->ext_trans = mail_index_transaction_begin(ctx->view, trans_flags);
5bdad39213d28ab35e615a7f4ea1712ab25b6a80Timo Sirainenstatic bool mail_index_sync_view_have_any(struct mail_index_view *view,
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen if (view->map->hdr.first_recent_uid < view->map->hdr.next_uid &&
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen (flags & MAIL_INDEX_SYNC_FLAG_DROP_RECENT) != 0)
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen if ((view->map->hdr.flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) &&
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen (flags & MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY) != 0)
2af769daebd83719ac696a440e06f6020471cec0Timo Sirainen mail_transaction_log_get_head(view->index->log, &log_seq, &log_offset);
2af769daebd83719ac696a440e06f6020471cec0Timo Sirainen if (mail_transaction_log_view_set(view->log_view,
df6478c4cf605bd81b3891c148b84c14eb6c4035Timo Sirainen /* let the actual syncing handle the error */
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen while ((ret = mail_transaction_log_view_next(view->log_view,
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainen if ((hdr->type & MAIL_TRANSACTION_EXTERNAL) != 0)
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainen switch (hdr->type & MAIL_TRANSACTION_TYPE_MASK) {
ba482d3624ca4f1b3d638e6e8470ba5134f21493Timo Sirainen /* extension record updates aren't exactly needed
ba482d3624ca4f1b3d638e6e8470ba5134f21493Timo Sirainen to be synced, but cache syncing relies on tail
df6478c4cf605bd81b3891c148b84c14eb6c4035Timo Sirainen offsets being updated. */
cf3bea6d9b57f8608bec22d98ad547a507b05f66Timo Sirainenbool mail_index_sync_have_any(struct mail_index *index,
e6e43b396799aa5704c679a3017d6c7195f9347dTimo Sirainen ret = mail_index_sync_view_have_any(view, flags);
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainenmail_index_sync_get_expunge(struct mail_index_sync_rec *rec,
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainenmail_index_sync_get_update(struct mail_index_sync_rec *rec,
a817fdcc43aedf423e2134091d5f83f91d64bcc9Timo Sirainen const struct mail_transaction_flag_update *update)
7981779f9aebd25728d3c26555d598ff842cf2e2Timo Sirainenmail_index_sync_get_keyword_update(struct mail_index_sync_rec *rec,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void mail_index_sync_get_keyword_reset(struct mail_index_sync_rec *rec,
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen rec->type = MAIL_INDEX_SYNC_TYPE_KEYWORD_RESET;
1a21e7049796c98d6d998fcf7a438d7a97193dc4Timo Sirainenbool mail_index_sync_next(struct mail_index_sync_ctx *ctx,
58be9d6bcc3800f5b3d76a064ee767fbe31a5a8aTimo Sirainen struct mail_index_transaction *sync_trans = ctx->sync_trans;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* FIXME: replace with a priority queue so we don't have to go
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen through the whole list constantly. and remember to make sure that
a817fdcc43aedf423e2134091d5f83f91d64bcc9Timo Sirainen keyword resets are sent before adds! */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen sync_list = array_get_modifiable(&ctx->sync_list, &count);
a817fdcc43aedf423e2134091d5f83f91d64bcc9Timo Sirainen for (i = 0; i < count; i++) {
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen sync_list[i].idx == array_count(sync_list[i].array))
a817fdcc43aedf423e2134091d5f83f91d64bcc9Timo Sirainen uid_range = array_idx(sync_list[i].array, sync_list[i].idx);
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen /* use this one. */
a817fdcc43aedf423e2134091d5f83f91d64bcc9Timo Sirainen /* nothing left in sync_list */
a817fdcc43aedf423e2134091d5f83f91d64bcc9Timo Sirainen uid_range = array_idx(sync_list[i].array, sync_list[i].idx);
dbd9604da561399cc6255289d5b6f6f662ab2d00Timo Sirainen if (sync_list[i].array == (void *)&sync_trans->expunges) {
dbd9604da561399cc6255289d5b6f6f662ab2d00Timo Sirainen (const struct mail_transaction_expunge *)uid_range);
dbd9604da561399cc6255289d5b6f6f662ab2d00Timo Sirainen } else if (sync_list[i].array == (void *)&sync_trans->updates) {
dbd9604da561399cc6255289d5b6f6f662ab2d00Timo Sirainen (const struct mail_transaction_flag_update *)uid_range);
dbd9604da561399cc6255289d5b6f6f662ab2d00Timo Sirainen } else if (sync_list[i].array == (void *)&sync_trans->keyword_resets) {
dbd9604da561399cc6255289d5b6f6f662ab2d00Timo Sirainen mail_index_sync_get_keyword_reset(sync_rec, uid_range);
dbd9604da561399cc6255289d5b6f6f662ab2d00Timo Sirainen mail_index_sync_get_keyword_update(sync_rec, uid_range,
dbd9604da561399cc6255289d5b6f6f662ab2d00Timo Sirainenbool mail_index_sync_have_more(struct mail_index_sync_ctx *ctx)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen unsigned int i, count;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen sync_list = array_get(&ctx->sync_list, &count);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen for (i = 0; i < count; i++) {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen sync_list[i].idx != array_count(sync_list[i].array))
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_sync_reset(struct mail_index_sync_ctx *ctx)
6f73af3a3a6ee900c7e736874587968d76a20bc0Timo Sirainen unsigned int i, count;
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen sync_list = array_get_modifiable(&ctx->sync_list, &count);
0f66f12eb4cdbf47670975044c88d8f388bf92dfTimo Sirainen for (i = 0; i < count; i++)
956f7778e413d3184d69e7b96e4a6b3cd5570bcdTimo Sirainenstatic void mail_index_sync_end(struct mail_index_sync_ctx **_ctx)
956f7778e413d3184d69e7b96e4a6b3cd5570bcdTimo Sirainen mail_transaction_log_sync_unlock(ctx->index->log);
956f7778e413d3184d69e7b96e4a6b3cd5570bcdTimo Sirainen mail_index_transaction_rollback(&ctx->sync_trans);
return TRUE;
return TRUE;
return FALSE;
bool want_rotate;
int ret = 0;
if (ret == 0 &&
return ret;
const unsigned int *keyword_indexes;
unsigned int i, count;
for (i = 0; i < count; i++) {
return FALSE;
return TRUE;
for (i = 0; i < count; i++) {
return TRUE;
return FALSE;
return FALSE;
return TRUE;
i_unreached();
return FALSE;
const char *fmt, ...)
T_BEGIN {
} T_END;