mail-index-view-sync.c revision 7761758f43d6150be4b07f4c54457ce662f78c4c
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (C) 2003-2004 Timo Sirainen */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmail_transaction_log_sort_expunges(ARRAY_TYPE(seq_range) *expunges,
4b058f90f9e8a2c6b2eed275de4eb8cc5195a71dTimo Sirainen /* Note that all the sequences are actually still UIDs at this point */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* @UNSAFE */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen dest = array_get_modifiable(expunges, &dest_count);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen array_append(expunges, src, src_size / sizeof(*src));
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen /* src[] must be sorted. */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen (src+1 != src_end && src->seq2 >= src[1].seq1))
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen for (; i < dest_count; i++) {
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen while (i < dest_count && src->seq2 >= dest[i].seq1-1) {
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen /* we can/must merge with next record */
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen if (first > 0 && new_exp.seq1 <= dest[first-1].seq2+1) {
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen /* continue previous record */
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen } else if (i == first) {
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen dest = array_get_modifiable(expunges, &dest_count);
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen /* use next record */
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen dest = array_get_modifiable(expunges, &dest_count);
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenstatic void view_sync_get_tail(struct mail_index_view *view,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen i_assert(!LOG_IS_BEFORE(view->log_file_head_seq,
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainenstatic int view_sync_set_log_view_range(struct mail_index_view *view)
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen const struct mail_index_header *hdr = view->index->hdr;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen view_sync_get_tail(view, &tail_seq, &tail_offset);
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen /* the view begins from the first non-synced transaction */
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen ret = mail_transaction_log_view_set(view->log_view,
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* FIXME: use the new index to get needed changes */
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen "Transaction log got desynced for index %s",
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenview_sync_get_expunges(struct mail_index_view *view,
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen unsigned int count;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen /* get a list of expunge transactions. there may be some that we have
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen already synced, but it doesn't matter because they'll get dropped
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen out when converting to sequences */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen while ((ret = mail_transaction_log_view_next(view->log_view,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen if ((hdr->type & MAIL_TRANSACTION_EXPUNGE) == 0)
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen if ((hdr->type & MAIL_TRANSACTION_EXTERNAL) == 0) {
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen /* this is simply a request for expunge */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen if (mail_transaction_log_sort_expunges(expunges_r, data,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen mail_transaction_log_view_set_corrupted(view->log_view,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen "Corrupted expunge record");
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* convert UIDs to sequences */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen src = dest = array_get_modifiable(expunges_r, &count);
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen ret = mail_index_lookup_uid_range(view, src->seq1,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen array_delete(expunges_r, count, array_count(expunges_r) - count);
7c95b03620a03a43dd72d39608cea5fc77393ad6Timo Sirainenstatic void mail_index_view_hdr_drop_appends(struct mail_index_view *view,
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* Keep message count the same. */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen map->hdr.messages_count = view->hdr.messages_count;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen /* Keep the old message flag counts also, although they may be
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen somewhat stale already. We just don't want them to be more than
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen our old messages_count. */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen map->hdr.recent_messages_count = view->hdr.recent_messages_count;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen map->hdr.seen_messages_count = view->hdr.seen_messages_count;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen map->hdr.deleted_messages_count = view->hdr.deleted_messages_count;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenstatic void mail_index_view_check(struct mail_index_view *view)
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen unsigned int i, del = 0, recent = 0, seen = 0;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen i_assert(view->hdr.messages_count == view->map->records_count);
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen for (i = 0; i < view->map->records_count; i++) {
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen i_assert(rec->uid >= view->hdr.first_deleted_uid_lowwater);
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen i_assert(rec->uid >= view->hdr.first_recent_uid_lowwater);
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen i_assert(rec->uid >= view->hdr.first_unseen_uid_lowwater);
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen i_assert(del == view->hdr.deleted_messages_count);
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen i_assert(recent == view->hdr.recent_messages_count);
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen i_assert(seen == view->hdr.seen_messages_count);
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD | MAIL_INDEX_SYNC_TYPE_KEYWORD_REMOVE)
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen (MAIL_TRANSACTION_EXPUNGE | MAIL_TRANSACTION_APPEND | \
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen MAIL_TRANSACTION_FLAG_UPDATE | MAIL_TRANSACTION_KEYWORD_UPDATE | \
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen#define VIEW_IS_SYNCED_TO_SAME(hdr, tail_seq, tail_offset) \
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenint mail_index_view_sync_begin(struct mail_index_view *view,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if ((flags & MAIL_INDEX_VIEW_SYNC_FLAG_NOEXPUNGES) == 0) {
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen /* get list of all expunges first */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (view_sync_get_expunges(view, &expunges) < 0)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen visible_mask = MAIL_TRANSACTION_VISIBLE_SYNC_MASK;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen visible_mask = MAIL_TRANSACTION_VISIBLE_SYNC_MASK &
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ctx = i_new(struct mail_index_view_sync_ctx, 1);
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen mail_index_sync_map_init(&ctx->sync_map_ctx, view,
92888ef30960c30ccc9e030fe7eab5d4d04a7d1cTimo Sirainen if ((flags & MAIL_INDEX_VIEW_SYNC_FLAG_NOEXPUNGES) == 0) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* since we're syncing everything, the counters get fixed */
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen /* keep the old mapping without expunges until we're
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen fully synced */
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen /* We need a private copy of the map if we don't want to
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen sync expunges.
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen If view's map is the head map, it means that it contains
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen already all the latest changes and there's no need for us
7e94cf9d70ce9fdeccb7a85ff400b899e6386f36Timo Sirainen to apply any changes to it. This can only happen if there
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen hadn't been any expunges. */
7e94cf9d70ce9fdeccb7a85ff400b899e6386f36Timo Sirainen uint32_t old_records_count = view->map->records_count;
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen /* Using non-head mapping. We have to apply
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen transactions to it to get latest changes into it. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Unless map was synced at the exact same position as
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainen view, the message flags can't be reliably used to
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainen update flag counters. note that map->hdr may contain
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen old information if another process updated the
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen index file since. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen view_sync_get_tail(view, &tail_seq, &tail_offset);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Copy only the mails that we see currently, since
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen we're going to append the new ones when we see
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen their transactions. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen view->map->records_count = view->hdr.messages_count;
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen /* Start the sync using our old view's header.
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen The old view->hdr may differ from map->hdr if
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen another view sharing the map with us had synced
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen i_assert(map->hdr_base == map->hdr_copy_buf->data);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen i_assert(map->records_count == map->hdr.messages_count);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen /* Syncing the view invalidates all previous looked up records.
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen Unreference the mappings this view keeps because of them. */
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainenstatic bool view_sync_area_find(ARRAY_TYPE(view_log_sync_area) *sync_arr,
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainen const struct mail_index_view_log_sync_area *syncs;
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainen unsigned int i, count;
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen for (i = 0; i < count; i++) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen offset - syncs[i].log_file_offset < syncs[i].length &&
5a4ab3d6e108a899c8b51bebd0094a37b738d5a1Timo Sirainenmail_index_view_sync_want(struct mail_index_view_sync_ctx *ctx,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_transaction_log_view_get_prev_pos(view->log_view, &seq, &offset);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen next_offset = offset + sizeof(*hdr) + hdr->size;
91b5eae18db48ebb70eee5407a7ab52bf798ee12Timo Sirainen switch (hdr->type & MAIL_TRANSACTION_TYPE_MASK) {
91b5eae18db48ebb70eee5407a7ab52bf798ee12Timo Sirainen if ((ctx->visible_sync_mask & MAIL_TRANSACTION_APPEND) == 0) {
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen if (LOG_IS_BEFORE(seq, offset, view->log_file_append_seq,
7e94cf9d70ce9fdeccb7a85ff400b899e6386f36Timo Sirainen /* already synced */
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen if ((hdr->type & MAIL_TRANSACTION_EXTERNAL) == 0) {
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen /* expunge request. this will be ignored */
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen if ((ctx->visible_sync_mask & MAIL_TRANSACTION_EXPUNGE) == 0) {
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen if (LOG_IS_BEFORE(seq, offset, view->log_file_expunge_seq,
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen /* already synced */
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen if ((hdr->type & ctx->visible_sync_mask) != 0)
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen if ((hdr->type & MAIL_TRANSACTION_VISIBLE_SYNC_MASK) == 0)
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen /* visible record that we want to skip */
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen if (LOG_IS_BEFORE(seq, offset, view->log_file_head_seq,
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen /* already synced */
4c1827d5d718d6f610df3209a2eb95a6591698afTimo Sirainenmail_index_view_sync_get_next_transaction(struct mail_index_view_sync_ctx *ctx)
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen struct mail_transaction_log_view *log_view = ctx->view->log_view;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* Get the next transaction from log. */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen ret = mail_transaction_log_view_next(log_view, &ctx->hdr,
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen /* This is a visible record that we don't want to
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen mail_transaction_log_view_get_prev_pos(log_view, &seq, &offset);
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* If we started from a map that we didn't create ourself,
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen some of the transactions may already be synced. at the end
7e94cf9d70ce9fdeccb7a85ff400b899e6386f36Timo Sirainen of this view sync we'll update file_seq=0 so that this check
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen always becomes FALSE for subsequent syncs. */
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen synced_to_map = view->map->hdr.log_file_seq != 0 &&
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen /* Apply transaction to view's mapping if needed (meaning we
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen didn't just re-map the view to head mapping). */
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen i_assert((hdr->type & MAIL_TRANSACTION_EXPUNGE) == 0 ||
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen (hdr->type & MAIL_TRANSACTION_EXTERNAL) == 0);
28dd1eeb9fdb93051bb5899c80cf300d69ba9f9eTimo Sirainen if (mail_index_sync_record(&ctx->sync_map_ctx,
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen if ((hdr->type & ctx->visible_sync_mask) == 0) {
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* non-visible change that we just wanted to update
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen /* skip changes committed by hidden transactions (eg. in IMAP
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen store +flags.silent command) */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen if (view_sync_area_find(&view->syncs_hidden, seq, offset))
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen ~(MAIL_INDEX_MAIL_FLAG_DIRTY | MAIL_RECENT)) == 0)
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainenmail_index_view_sync_get_rec(struct mail_index_view_sync_ctx *ctx,
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen const struct mail_transaction_header *hdr = ctx->hdr;
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen switch (hdr->type & MAIL_TRANSACTION_TYPE_MASK) {
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen /* data contains the appended records, but we don't care */
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen if ((hdr->type & MAIL_TRANSACTION_EXTERNAL) == 0) {
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen /* this is simply a request for expunge */
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen /* data contains mail_transaction_expunge[] */
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen const struct mail_transaction_flag_update *update =
45edf6cad665a5c270322516c587708a0c630b80Timo Sirainen /* data contains mail_transaction_flag_update[] */
45edf6cad665a5c270322516c587708a0c630b80Timo Sirainen /* skip internal flag changes */
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen update = CONST_PTR_OFFSET(data, ctx->data_offset);
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen const struct mail_transaction_keyword_update *update = data;
45edf6cad665a5c270322516c587708a0c630b80Timo Sirainen /* data contains mail_transaction_keyword_update header,
45edf6cad665a5c270322516c587708a0c630b80Timo Sirainen the keyword name and an array of { uint32_t uid1, uid2; } */
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen /* skip over the header and name */
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen ctx->data_offset = sizeof(*update) + update->name_size;
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen ctx->data_offset += 4 - (ctx->data_offset % 4);
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen uids = CONST_PTR_OFFSET(data, ctx->data_offset);
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen const struct mail_transaction_keyword_reset *reset =
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen /* data contains mail_transaction_keyword_reset[] */
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen rec->type = MAIL_INDEX_SYNC_TYPE_KEYWORD_RESET;
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainenint mail_index_view_sync_next(struct mail_index_view_sync_ctx *ctx,
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen if (ctx->hdr == NULL || ctx->data_offset == ctx->hdr->size) {
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen ret = mail_index_view_sync_get_next_transaction(ctx);
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen } while (!mail_index_view_sync_get_rec(ctx, sync_rec));
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainenvoid mail_index_view_sync_get_expunges(struct mail_index_view_sync_ctx *ctx,
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainenmail_index_view_sync_clean_log_syncs(struct mail_index_view *view)
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen const struct mail_index_view_log_sync_area *syncs;
45edf6cad665a5c270322516c587708a0c630b80Timo Sirainen unsigned int i, count;
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen /* Clean up to view's tail */
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen view_sync_get_tail(view, &tail_seq, &tail_offset);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen syncs = array_get(&view->syncs_hidden, &count);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen for (i = 0; i < count; i++) {
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen if ((syncs[i].log_file_offset + syncs[i].length > tail_offset &&
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainenvoid mail_index_view_sync_end(struct mail_index_view_sync_ctx **_ctx)
e2ea49bd487d76b425e270321e9cf1e546642de0Timo Sirainen /* we didn't sync everything */
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen view->log_file_expunge_seq = view->log_file_head_seq;
e2ea49bd487d76b425e270321e9cf1e546642de0Timo Sirainen view->log_file_expunge_offset = view->log_file_head_offset;
e2ea49bd487d76b425e270321e9cf1e546642de0Timo Sirainen view->log_file_append_seq = view->log_file_head_seq;
e2ea49bd487d76b425e270321e9cf1e546642de0Timo Sirainen view->log_file_append_offset = view->log_file_head_offset;
e2ea49bd487d76b425e270321e9cf1e546642de0Timo Sirainen /* log offsets have no meaning in views. make sure they're not
e2ea49bd487d76b425e270321e9cf1e546642de0Timo Sirainen tried to be used wrong by setting them to zero. */
e2ea49bd487d76b425e270321e9cf1e546642de0Timo Sirainen mail_index_sync_map_deinit(&ctx->sync_map_ctx);
e2ea49bd487d76b425e270321e9cf1e546642de0Timo Sirainen mail_index_view_sync_clean_log_syncs(ctx->view);
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen if (!view->broken_counters && !ctx->sync_map_ctx.unreliable_flags)
e2ea49bd487d76b425e270321e9cf1e546642de0Timo Sirainen /* set log view to empty range so unneeded memory gets freed */
e2ea49bd487d76b425e270321e9cf1e546642de0Timo Sirainen (void)mail_transaction_log_view_set(view->log_view,
c48140ca508ebc9642737e7fd6c8d9e52f95df32Timo Sirainenvoid mail_index_view_add_hidden_transaction(struct mail_index_view *view,
c48140ca508ebc9642737e7fd6c8d9e52f95df32Timo Sirainen unsigned int length)