mail-index-sync-update.c revision 287ba82a8da3eaa473b5735d4eeac2fb4c5d8117
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco/* Copyright (C) 2004 Timo Sirainen */
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscovoid mail_index_sync_replace_map(struct mail_index_sync_map_ctx *ctx,
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco /* if map still exists after this, it's only in views. */
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen mail_index_unmap(view->index, view->map);
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco mail_index_unmap(view->index, view->index->map);
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen if (ctx->type == MAIL_INDEX_SYNC_HANDLER_INDEX)
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Koscomail_index_header_update_counts(struct mail_index_header *hdr,
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco if (((old_flags ^ new_flags) & MAIL_RECENT) != 0) {
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco /* different recent-flag */
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco if (((old_flags ^ new_flags) & MAIL_SEEN) != 0) {
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco /* different seen-flag */
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco else if (++hdr->seen_messages_count == hdr->messages_count)
b6ada49236374a1f4ae462c384d69bab7e6f0a1dGustavo Lopes hdr->first_unseen_uid_lowwater = hdr->next_uid;
bfc104f8240fac5b59d4347db4c27be705f6dfc2Knut Anders Hatlen if (((old_flags ^ new_flags) & MAIL_DELETED) != 0) {
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen /* different deleted-flag */
b6ada49236374a1f4ae462c384d69bab7e6f0a1dGustavo Lopes hdr->first_deleted_uid_lowwater = hdr->next_uid;
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlenmail_index_header_update_lowwaters(struct mail_index_header *hdr,
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen rec->uid < hdr->first_recent_uid_lowwater)
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen hdr->first_recent_uid_lowwater = rec->uid;
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen rec->uid < hdr->first_unseen_uid_lowwater)
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen hdr->first_unseen_uid_lowwater = rec->uid;
bfc104f8240fac5b59d4347db4c27be705f6dfc2Knut Anders Hatlen rec->uid < hdr->first_deleted_uid_lowwater)
bfc104f8240fac5b59d4347db4c27be705f6dfc2Knut Anders Hatlen hdr->first_deleted_uid_lowwater = rec->uid;
bfc104f8240fac5b59d4347db4c27be705f6dfc2Knut Anders Hatlenstatic int sync_expunge(const struct mail_transaction_expunge *e,
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco const struct mail_index_expunge_handler *expunge_handlers, *eh;
b310c0aeaec52a0246021104b8f52cbb31b68480Lubos Kosco mail_transaction_log_view_set_corrupted(ctx->view->log_view,
ff5eba819da0cf7964d884630fb13262ef12c505Trond Norbye "Invalid UID range in expunge (%u .. %u)",
6d7c6f82e644c205bc679ee5b1fa2929ec949963Lubos Kosco if (!view->map->write_to_disk || view->map->refcount != 1) {
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco /* expunges have to be atomic. so we'll have to copy
6d7c6f82e644c205bc679ee5b1fa2929ec949963Lubos Kosco the mapping, do the changes there and then finally
6d7c6f82e644c205bc679ee5b1fa2929ec949963Lubos Kosco replace the whole index file. to avoid extra disk
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco I/O we copy the index into memory rather than to
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco temporary file */
b6ada49236374a1f4ae462c384d69bab7e6f0a1dGustavo Lopes map = mail_index_map_clone(map, map->hdr.record_size);
b6ada49236374a1f4ae462c384d69bab7e6f0a1dGustavo Lopes if (mail_index_lookup_uid_range(view, e->uid1, e->uid2,
for (i = 0; i < expunge_handlers_count; i++) {
void *dest;
if (seq1 == 0)
unsigned int count)
void *hdr_copy;
t_push();
t_pop();
t_pop();
const int max_days =
int i, days;
const void *data)
int ret = 0;
t_push();
case MAIL_TRANSACTION_APPEND: {
if (ret <= 0)
case MAIL_TRANSACTION_EXPUNGE:
if (ret <= 0)
case MAIL_TRANSACTION_FLAG_UPDATE: {
if (ret <= 0)
case MAIL_TRANSACTION_HEADER_UPDATE: {
if (ret <= 0)
case MAIL_TRANSACTION_EXT_INTRO: {
if (ret <= 0)
case MAIL_TRANSACTION_EXT_RESET: {
case MAIL_TRANSACTION_EXT_HDR_UPDATE: {
if (ret <= 0)
case MAIL_TRANSACTION_EXT_REC_UPDATE: {
unsigned int record_size;
if (ret <= 0)
case MAIL_TRANSACTION_KEYWORD_UPDATE: {
case MAIL_TRANSACTION_KEYWORD_RESET: {
i_unreached();
t_pop();
return ret;
int sync_only_external)
const void *data;
if (had_dirty)
first_append_uid = 0;
if (sync_only_external) {
} else if (check_ext_offsets) {
&prev_seq,
&prev_offset);
if (first_append_uid == 0)
if (ret < 0) {
if (!sync_only_external)
if (first_append_uid != 0)
had_dirty) {
return ret;