]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dbox: Figure out internally when message's "physical size" doesn't match "written...
authorTimo Sirainen <tss@iki.fi>
Wed, 26 May 2010 15:13:15 +0000 (16:13 +0100)
committerTimo Sirainen <tss@iki.fi>
Wed, 26 May 2010 15:13:15 +0000 (16:13 +0100)
--HG--
branch : HEAD

src/lib-storage/index/dbox-common/dbox-save.c
src/lib-storage/index/dbox-common/dbox-save.h
src/lib-storage/index/dbox-multi/mdbox-save.c
src/lib-storage/index/dbox-single/sdbox-save.c

index b210bfe87459c22b653fb06b1a1179746b483689..da86e7da49de6934685c440af2ac5f7032d4a4f0 100644 (file)
@@ -103,11 +103,12 @@ void dbox_save_end(struct dbox_save_context *ctx)
        ctx->ctx.output = dbox_output;
 }
 
-void dbox_save_write_metadata(struct mail_save_context *ctx,
-                             struct ostream *output,
+void dbox_save_write_metadata(struct mail_save_context *_ctx,
+                             struct ostream *output, uoff_t output_msg_size,
                              const char *orig_mailbox_name,
                              uint8_t guid_128[MAIL_GUID_128_SIZE])
 {
+       struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
        struct dbox_metadata_header metadata_hdr;
        const char *guid;
        string_t *str;
@@ -119,22 +120,26 @@ void dbox_save_write_metadata(struct mail_save_context *ctx,
        o_stream_send(output, &metadata_hdr, sizeof(metadata_hdr));
 
        str = t_str_new(256);
-       if (ctx->saved_physical_size != 0) {
+       if (output_msg_size != ctx->input->v_offset) {
+               /* a plugin changed the data written to disk, so the
+                  "message size" dbox header doesn't contain the actual
+                  "physical" message size. we need to save it as a
+                  separate metadata header. */
                str_printfa(str, "%c%llx\n", DBOX_METADATA_PHYSICAL_SIZE,
-                           (unsigned long long)ctx->saved_physical_size);
+                           (unsigned long long)ctx->input->v_offset);
        }
        str_printfa(str, "%c%lx\n", DBOX_METADATA_RECEIVED_TIME,
-                   (unsigned long)ctx->received_date);
-       if (mail_get_virtual_size(ctx->dest_mail, &vsize) < 0)
+                   (unsigned long)_ctx->received_date);
+       if (mail_get_virtual_size(_ctx->dest_mail, &vsize) < 0)
                i_unreached();
        str_printfa(str, "%c%llx\n", DBOX_METADATA_VIRTUAL_SIZE,
                    (unsigned long long)vsize);
-       if (ctx->pop3_uidl != NULL) {
+       if (_ctx->pop3_uidl != NULL) {
                str_printfa(str, "%c%s\n", DBOX_METADATA_POP3_UIDL,
-                           ctx->pop3_uidl);
+                           _ctx->pop3_uidl);
        }
 
-       guid = ctx->guid;
+       guid = _ctx->guid;
        if (guid != NULL)
                mail_generate_guid_128_hash(guid, guid_128);
        else {
index cc61dd0879a27c66b453a9f889fec5976573e7be..904e97176155f8c584db4b34f26b0feba55886ed 100644 (file)
@@ -24,7 +24,7 @@ int dbox_save_continue(struct mail_save_context *_ctx);
 void dbox_save_end(struct dbox_save_context *ctx);
 
 void dbox_save_write_metadata(struct mail_save_context *ctx,
-                             struct ostream *output,
+                             struct ostream *output, uoff_t output_msg_size,
                              const char *orig_mailbox_name,
                              uint8_t guid_128_r[MAIL_GUID_128_SIZE]);
 
index 807312ac5d573028cfeb9cc79f1fb2745b4eb5fd..0cbbf6865be3e6117ace7384fab1a681749457e7 100644 (file)
@@ -168,7 +168,7 @@ static int mdbox_save_mail_write_metadata(struct mdbox_save_context *ctx,
                mail->append_offset - mail->file_append->file->msg_header_size;
 
        dbox_save_write_metadata(&ctx->ctx.ctx, ctx->ctx.dbox_output,
-                                ctx->mbox->box.name, guid_128);
+                                message_size, ctx->mbox->box.name, guid_128);
        /* save the 128bit GUID to index so if the map index gets corrupted
           we can still find the message */
        mail_index_update_ext(ctx->ctx.trans, ctx->ctx.seq,
index 86db14dcd4b866ce10a1d432a696900a9bbeeb13..d2f345ba9760e63bb17fc0e42a6ca33766b52461 100644 (file)
@@ -116,7 +116,8 @@ static int dbox_save_mail_write_metadata(struct dbox_save_context *ctx,
        message_size = ctx->dbox_output->offset -
                file->msg_header_size - file->file_header_size;
 
-       dbox_save_write_metadata(&ctx->ctx, ctx->dbox_output, NULL, guid_128);
+       dbox_save_write_metadata(&ctx->ctx, ctx->dbox_output,
+                                message_size, NULL, guid_128);
        dbox_msg_header_fill(&dbox_msg_hdr, message_size);
        if (o_stream_pwrite(ctx->dbox_output, &dbox_msg_hdr,
                            sizeof(dbox_msg_hdr),