]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
some more fixes
authorTimo Sirainen <tss@iki.fi>
Sun, 13 Jun 2004 07:12:24 +0000 (10:12 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 13 Jun 2004 07:12:24 +0000 (10:12 +0300)
--HG--
branch : HEAD

src/lib-storage/index/mbox/mbox-sync-parse.c
src/lib-storage/index/mbox/mbox-sync-private.h
src/lib-storage/index/mbox/mbox-sync-rewrite.c
src/lib-storage/index/mbox/mbox-sync-update.c
src/lib-storage/index/mbox/mbox-sync.c

index 40d94e161d240f2a3fa7a05b1c0fd19be09887cd..e4c2e06293733bb910c7a137b4585bb7db89340e 100644 (file)
@@ -304,7 +304,8 @@ void mbox_sync_parse_next_mail(struct istream *input,
        }
        message_parse_header_deinit(hdr_ctx);
 
-       if (ctx->seq == 1 && ctx->sync_ctx->base_uid_validity == 0) {
+       if ((ctx->seq == 1 && ctx->sync_ctx->base_uid_validity == 0) ||
+           (ctx->seq > 1 && ctx->sync_ctx->first_uid == 0)) {
                /* missing X-IMAPbase */
                ctx->need_rewrite = TRUE;
        }
index 38639492743e2e90dcf85c01e8b65140b81d6706..73a620e64d6f6a28e56a3d4e6d7d2b18d919582a 100644 (file)
@@ -52,6 +52,7 @@ struct mbox_sync_mail_context {
        unsigned int have_eoh:1;
        unsigned int need_rewrite:1;
        unsigned int seen_imapbase:1;
+       unsigned int updated:1;
 };
 
 struct mbox_sync_context {
@@ -61,7 +62,7 @@ struct mbox_sync_context {
 
        string_t *header, *from_line;
        uint32_t base_uid_validity, base_uid_last;
-       uint32_t prev_msg_uid, next_uid;
+       uint32_t prev_msg_uid, next_uid, first_uid;
        off_t expunged_space;
 };
 
index c79d9fd66a92c92b35ff536fe31e2e052f7b3269..67de7a2c10261de5671b643897dc891e7aa000bc 100644 (file)
@@ -242,7 +242,8 @@ static int mbox_sync_read_and_move(struct mbox_sync_context *sync_ctx,
                        str_append_c(mail_ctx.header, '\n');
        }
 
-       i_assert(mail_ctx.mail.space == mails[idx].space);
+       /* breaks with leftover space:
+          i_assert(mail_ctx.mail.space == mails[idx].space);*/
         sync_ctx->prev_msg_uid = old_prev_msg_uid;
 
        /* we're moving next message - update it's from_offset */
@@ -285,7 +286,7 @@ int mbox_sync_rewrite(struct mbox_sync_context *sync_ctx, buffer_t *mails_buf,
                      uint32_t first_seq, uint32_t last_seq, off_t extra_space)
 {
        /* FIXME: with mails[0] = expunged and first_seq=1, we leave the
-          \n header? */
+          \n header! */
        struct mbox_sync_mail *mails;
        size_t size;
        uoff_t offset, start_offset, end_offset, dest_offset;
@@ -303,7 +304,7 @@ int mbox_sync_rewrite(struct mbox_sync_context *sync_ctx, buffer_t *mails_buf,
           data which hasn't yet been copied backwards. to avoid too much
           complexity, we just leave all the rest of the extra space to first
           mail */
-       extra_per_mail = extra_space / (last_seq - first_seq + 1+3);
+       extra_per_mail = extra_space / (last_seq - first_seq + 1);
        idx = last_seq - first_seq;
 
        if (mails[idx].uid != 0)
index 394257cfafb4cea858e8ca857440ec327c2abc84..bdcaf51c617e6b3d56ccab330ba39b6375445aae 100644 (file)
@@ -87,7 +87,8 @@ static void mbox_sync_add_missing_headers(struct mbox_sync_mail_context *ctx)
        old_hdr_size = ctx->body_offset - ctx->hdr_offset;
        new_hdr_size = str_len(ctx->header);
 
-       if (ctx->seq == 1 && ctx->hdr_pos[MBOX_HDR_X_IMAPBASE] == (size_t)-1) {
+       if (ctx->mail.uid == ctx->sync_ctx->first_uid &&
+           ctx->hdr_pos[MBOX_HDR_X_IMAPBASE] == (size_t)-1) {
                ctx->hdr_pos[MBOX_HDR_X_IMAPBASE] = str_len(ctx->header);
                str_printfa(ctx->header, "X-IMAPbase: %u %u",
                            ctx->sync_ctx->base_uid_validity,
@@ -216,7 +217,8 @@ void mbox_sync_update_header(struct mbox_sync_mail_context *ctx,
                }
        }
 
-        mbox_sync_add_missing_headers(ctx);
+       mbox_sync_add_missing_headers(ctx);
+       ctx->updated = TRUE;
 }
 
 void mbox_sync_update_header_from(struct mbox_sync_mail_context *ctx,
index 3ef7f12eb3367ffd2faa46861462ccd620a5b86e..8d12133b17df05c312a8939a6d2cf38abf844e7f 100644 (file)
@@ -206,11 +206,11 @@ mbox_write_from_line(struct mbox_sync_mail_context *ctx, off_t move_diff)
 
 static int mbox_sync_do(struct index_mailbox *ibox,
                        struct mail_index_sync_ctx *index_sync_ctx,
-                       struct mail_index_view *sync_view)
+                       struct mail_index_view *sync_view,
+                       buffer_t *syncs, struct mail_index_sync_rec *sync_rec)
 {
        struct mbox_sync_context sync_ctx;
        struct mbox_sync_mail_context mail_ctx;
-       struct mail_index_sync_rec sync_rec;
        struct mail_index_transaction *t;
        const struct mail_index_header *hdr;
        const struct mail_index_record *rec;
@@ -219,7 +219,7 @@ static int mbox_sync_do(struct index_mailbox *ibox,
        uint8_t new_flags;
        off_t space_diff, move_diff;
        uoff_t offset, extra_space, trailer_size;
-       buffer_t *mails, *syncs;
+       buffer_t *mails;
        size_t size;
        struct stat st;
        int sync_expunge, ret = 0;
@@ -246,9 +246,7 @@ static int mbox_sync_do(struct index_mailbox *ibox,
        istream_raw_mbox_seek(input, 0);
 
        mails = buffer_create_dynamic(default_pool, 4096, (size_t)-1);
-       syncs = buffer_create_dynamic(default_pool, 256, (size_t)-1);
 
-       memset(&sync_rec, 0, sizeof(sync_rec));
        messages_count = mail_index_view_get_message_count(sync_view);
 
        space_diff = 0; need_space_seq = 0; idx_seq = 0; rec = NULL;
@@ -264,19 +262,19 @@ static int mbox_sync_do(struct index_mailbox *ibox,
                /* get all sync records related to this message */
                ret = 1; sync_expunge = FALSE;
                mbox_sync_buffer_delete_old(syncs, mail_ctx.mail.uid);
-               while (mail_ctx.mail.uid >= sync_rec.uid1 && ret > 0) {
-                       if (sync_rec.uid1 != 0) {
-                               i_assert(mail_ctx.mail.uid <= sync_rec.uid2);
-                               buffer_append(syncs, &sync_rec,
-                                             sizeof(sync_rec));
+               while (mail_ctx.mail.uid >= sync_rec->uid1 && ret > 0) {
+                       if (sync_rec->uid1 != 0) {
+                               i_assert(mail_ctx.mail.uid <= sync_rec->uid2);
+                               buffer_append(syncs, sync_rec,
+                                             sizeof(*sync_rec));
 
-                               if (sync_rec.type ==
+                               if (sync_rec->type ==
                                    MAIL_INDEX_SYNC_TYPE_EXPUNGE)
                                        sync_expunge = TRUE;
                        }
-                       ret = mail_index_sync_next(index_sync_ctx, &sync_rec);
+                       ret = mail_index_sync_next(index_sync_ctx, sync_rec);
                        if (ret == 0)
-                               memset(&sync_rec, 0, sizeof(sync_rec));
+                               memset(sync_rec, 0, sizeof(*sync_rec));
                }
                if (ret < 0)
                        break;
@@ -291,6 +289,9 @@ static int mbox_sync_do(struct index_mailbox *ibox,
                                hdr->uid_validity;
                }
 
+               if (!sync_expunge && sync_ctx.first_uid == 0)
+                       sync_ctx.first_uid = mail_ctx.mail.uid;
+
                if ((mail_ctx.need_rewrite || sync_ctx.expunged_space > 0 ||
                     buffer_get_used_size(syncs) != 0) && !ibox->readonly) {
                        if (ibox->mbox_lock_type == F_RDLCK) {
@@ -493,6 +494,9 @@ static int mbox_sync_do(struct index_mailbox *ibox,
                space_diff += sync_ctx.expunged_space;
                sync_ctx.expunged_space -= -space_diff;
 
+               if (mail_ctx.have_eoh && !mail_ctx.updated)
+                       str_append_c(mail_ctx.header, '\n');
+
                if (space_diff < 0 &&
                    mbox_sync_grow_file(&sync_ctx, &mail_ctx, -space_diff) < 0)
                        ret = -1;
@@ -541,7 +545,7 @@ static int mbox_sync_do(struct index_mailbox *ibox,
                /* only syncs left should be just appends (and their updates)
                   which weren't synced yet for some reason (crash). we'll just
                   ignore them, as we've overwritten them above. */
-               while (mail_index_sync_next(index_sync_ctx, &sync_rec) > 0)
+               while (mail_index_sync_next(index_sync_ctx, sync_rec) > 0)
                        ;
        }
 
@@ -615,7 +619,6 @@ static int mbox_sync_do(struct index_mailbox *ibox,
        str_free(sync_ctx.header);
        str_free(sync_ctx.from_line);
        buffer_free(mails);
-       buffer_free(syncs);
        return ret < 0 ? ret : 0;
 }
 
@@ -626,6 +629,8 @@ int mbox_sync(struct index_mailbox *ibox, int last_commit)
        unsigned int lock_id;
        uint32_t seq;
        uoff_t offset;
+       struct mail_index_sync_rec sync_rec;
+       buffer_t *syncs;
        int ret, lock_type;
 
        if (last_commit) {
@@ -641,11 +646,15 @@ int mbox_sync(struct index_mailbox *ibox, int last_commit)
        if (ret <= 0)
                return ret;
 
+       memset(&sync_rec, 0, sizeof(sync_rec));
+       syncs = buffer_create_dynamic(default_pool, 256, (size_t)-1);
+
        lock_type = mail_index_sync_have_more(index_sync_ctx) ?
                F_WRLCK : F_RDLCK;
        if (mbox_lock(ibox, lock_type, &lock_id) > 0 &&
            mbox_file_open_stream(ibox) == 0) {
-               ret = mbox_sync_do(ibox, index_sync_ctx, sync_view);
+               ret = mbox_sync_do(ibox, index_sync_ctx, sync_view,
+                                  syncs, &sync_rec);
                if (ret == -2) {
                        /* read lock -> write lock. do it again. */
                        (void)mbox_unlock(ibox, lock_id);
@@ -656,7 +665,7 @@ int mbox_sync(struct index_mailbox *ibox, int last_commit)
                                ret = -1;
                        else {
                                ret = mbox_sync_do(ibox, index_sync_ctx,
-                                                  sync_view);
+                                                  sync_view, syncs, &sync_rec);
                        }
                }
        } else {
@@ -669,6 +678,7 @@ int mbox_sync(struct index_mailbox *ibox, int last_commit)
                        ret = -1;
        }
 
+       buffer_free(syncs);
        return ret;
 }