Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6528:aedda93baa2c HEAD
Use crlf input streams instead of output streams so message parser doesn't
end up saving broken offsets.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 06 Oct 2007 01:48:16 +0300 |
parents | ba65c858b7dd |
children | aee441840b5a |
files | src/lib-storage/index/cydir/cydir-save.c src/lib-storage/index/dbox/dbox-save.c src/lib-storage/index/index-mail.c src/lib-storage/index/maildir/maildir-save.c src/lib-storage/index/mbox/mbox-save.c |
diffstat | 5 files changed, 41 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/cydir/cydir-save.c Sat Oct 06 01:46:22 2007 +0300 +++ b/src/lib-storage/index/cydir/cydir-save.c Sat Oct 06 01:48:16 2007 +0300 @@ -3,8 +3,8 @@ #include "lib.h" #include "hostpid.h" #include "istream.h" +#include "istream-crlf.h" #include "ostream.h" -#include "ostream-crlf.h" #include "str.h" #include "index-mail.h" #include "cydir-storage.h" @@ -69,7 +69,7 @@ struct cydir_mailbox *mbox = (struct cydir_mailbox *)t->ictx.ibox; struct cydir_save_context *ctx = t->save_ctx; enum mail_flags save_flags; - struct ostream *output; + struct istream *crlf_input; const char *path; i_assert((t->ictx.flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0); @@ -86,9 +86,7 @@ path = cydir_get_save_path(ctx, ctx->mail_count); ctx->fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0660); if (ctx->fd != -1) { - output = o_stream_create_fd_file(ctx->fd, 0, FALSE); - ctx->output = o_stream_create_crlf(output); - o_stream_unref(&output); + ctx->output = o_stream_create_fd_file(ctx->fd, 0, FALSE); o_stream_cork(ctx->output); } else { mail_storage_set_critical(_t->box->storage, @@ -116,8 +114,11 @@ } mail_set_seq(dest_mail, ctx->seq); + crlf_input = i_stream_create_crlf(input); + ctx->input = index_mail_cache_parse_init(dest_mail, crlf_input); + i_stream_unref(&crlf_input); + ctx->cur_dest_mail = dest_mail; - ctx->input = index_mail_cache_parse_init(dest_mail, input); ctx->cur_received_date = received_date; *ctx_r = &ctx->ctx;
--- a/src/lib-storage/index/dbox/dbox-save.c Sat Oct 06 01:46:22 2007 +0300 +++ b/src/lib-storage/index/dbox/dbox-save.c Sat Oct 06 01:48:16 2007 +0300 @@ -5,8 +5,8 @@ #include "hex-dec.h" #include "str.h" #include "istream.h" +#include "istream-crlf.h" #include "ostream.h" -#include "ostream-crlf.h" #include "write-full.h" #include "index-mail.h" #include "dbox-storage.h" @@ -71,9 +71,9 @@ (struct dbox_transaction_context *)_t; struct dbox_mailbox *mbox = (struct dbox_mailbox *)t->ictx.ibox; struct dbox_save_context *ctx = t->save_ctx; - struct ostream *output; struct dbox_message_header dbox_msg_hdr; struct dbox_save_mail *save_mail; + struct istream *crlf_input; enum mail_flags save_flags; const struct stat *st; uoff_t mail_size; @@ -117,7 +117,10 @@ mail_set_seq(dest_mail, ctx->seq); ctx->cur_dest_mail = dest_mail; - ctx->input = index_mail_cache_parse_init(dest_mail, input); + + crlf_input = i_stream_create_lf(input); + ctx->input = index_mail_cache_parse_init(dest_mail, crlf_input); + i_stream_unref(&crlf_input); save_mail = array_append_space(&ctx->mails); save_mail->file = ctx->cur_file; @@ -130,10 +133,6 @@ o_stream_cork(ctx->cur_output); o_stream_send(ctx->cur_output, &dbox_msg_hdr, sizeof(dbox_msg_hdr)); - output = o_stream_create_lf(ctx->cur_output); - o_stream_unref(&ctx->cur_output); - ctx->cur_output = output; - ctx->cur_received_date = received_date != (time_t)-1 ? received_date : ioloop_time; ctx->cur_flags = flags;
--- a/src/lib-storage/index/index-mail.c Sat Oct 06 01:46:22 2007 +0300 +++ b/src/lib-storage/index/index-mail.c Sat Oct 06 01:48:16 2007 +0300 @@ -584,17 +584,10 @@ } static void index_mail_parse_body_finish(struct index_mail *mail, - enum index_cache_field field, - bool appended_mail) + enum index_cache_field field) { mail->data.parts = message_parser_deinit(&mail->data.parser_ctx); - if (appended_mail) { - bool use_crlf = (mail->ibox->box.storage->flags & - MAIL_STORAGE_FLAG_SAVE_CRLF) != 0; - message_parser_set_crlfs(mail->data.parts, use_crlf); - } - (void)get_cached_msgpart_sizes(mail); index_mail_body_parsed_cache_flags(mail); @@ -640,7 +633,7 @@ null_message_part_header_callback, NULL); } ret = index_mail_stream_check_failure(mail); - index_mail_parse_body_finish(mail, field, FALSE); + index_mail_parse_body_finish(mail, field); i_stream_seek(data->stream, old_offset); return ret; @@ -1181,7 +1174,7 @@ mail->data.save_bodystructure_body = FALSE; mail->data.parsed_bodystructure = TRUE; - index_mail_parse_body_finish(mail, 0, TRUE); + index_mail_parse_body_finish(mail, 0); index_mail_cache_dates(mail); }
--- a/src/lib-storage/index/maildir/maildir-save.c Sat Oct 06 01:46:22 2007 +0300 +++ b/src/lib-storage/index/maildir/maildir-save.c Sat Oct 06 01:48:16 2007 +0300 @@ -5,8 +5,8 @@ #include "array.h" #include "buffer.h" #include "istream.h" +#include "istream-crlf.h" #include "ostream.h" -#include "ostream-crlf.h" #include "str.h" #include "index-mail.h" #include "maildir-storage.h" @@ -143,6 +143,7 @@ { struct maildir_save_context *ctx = t->save_ctx; struct maildir_filename *mf; + struct istream *input; /* now, we want to be able to rollback the whole append session, so we'll just store the name of this temp file and move it later @@ -201,7 +202,9 @@ cached data directly */ ctx->cur_dest_mail = NULL; } else { - ctx->input = index_mail_cache_parse_init(dest_mail, ctx->input); + input = index_mail_cache_parse_init(dest_mail, ctx->input); + i_stream_unref(&ctx->input); + ctx->input = input; ctx->cur_dest_mail = dest_mail; } return ctx->seq; @@ -354,7 +357,6 @@ (struct maildir_transaction_context *)_t; struct maildir_save_context *ctx; struct maildir_mailbox *mbox = (struct maildir_mailbox *)t->ictx.ibox; - struct ostream *output; const char *fname; i_assert((t->ictx.flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0); @@ -374,13 +376,11 @@ } ctx->received_date = received_date; - ctx->input = input; + ctx->input = (ctx->mbox->storage->storage.flags & + MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ? + i_stream_create_crlf(input) : i_stream_create_lf(input); - output = o_stream_create_fd_file(ctx->fd, 0, FALSE); - ctx->output = (ctx->mbox->storage->storage.flags & - MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ? - o_stream_create_crlf(output) : o_stream_create_lf(output); - o_stream_unref(&output); + ctx->output = o_stream_create_fd_file(ctx->fd, 0, FALSE); o_stream_cork(ctx->output); flags &= ~MAIL_RECENT; @@ -479,8 +479,8 @@ if (ctx->cur_dest_mail != NULL) { index_mail_cache_parse_deinit(ctx->cur_dest_mail, ctx->received_date); - i_stream_unref(&ctx->input); } + i_stream_unref(&ctx->input); /* remember the size in case we want to add it to filename */ ctx->file_last->size = ctx->output->offset;
--- a/src/lib-storage/index/mbox/mbox-save.c Sat Oct 06 01:46:22 2007 +0300 +++ b/src/lib-storage/index/mbox/mbox-save.c Sat Oct 06 01:48:16 2007 +0300 @@ -11,7 +11,7 @@ #include "str.h" #include "write-full.h" #include "istream-header-filter.h" -#include "ostream-crlf.h" +#include "istream-crlf.h" #include "message-parser.h" #include "index-mail.h" #include "mbox-storage.h" @@ -46,7 +46,7 @@ uint32_t seq, next_uid, uid_validity, first_saved_uid; struct istream *input; - struct ostream *output, *body_output; + struct ostream *output; uoff_t extra_hdr_offset, eoh_offset; char last_char; @@ -465,17 +465,18 @@ if (write_from_line(ctx, received_date, from_envelope) < 0) ctx->failed = TRUE; else { - ctx->input = i_stream_create_header_filter(input, + input = i_stream_create_header_filter(input, HEADER_FILTER_EXCLUDE | HEADER_FILTER_NO_CR, mbox_save_drop_headers, mbox_save_drop_headers_count, save_header_callback, ctx); - ctx->body_output = - (mbox->storage->storage.flags & - MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ? - o_stream_create_crlf(ctx->output) : - o_stream_create_lf(ctx->output); + ctx->input = (mbox->storage->storage.flags & + MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ? + i_stream_create_crlf(input) : + i_stream_create_lf(input); + i_stream_unref(&input); + if (ctx->mail != NULL) { input = index_mail_cache_parse_init(ctx->mail, ctx->input); @@ -510,7 +511,7 @@ return 0; data = i_stream_get_data(ctx->input, &size); - if (o_stream_send(ctx->body_output, data, size) < 0) + if (o_stream_send(ctx->output, data, size) < 0) return write_error(ctx); ctx->last_char = data[size-1]; i_stream_skip(ctx->input, size); @@ -521,7 +522,11 @@ otherwise some mbox parsers don't like the result. this makes it impossible to save a mail that doesn't end with LF though. */ - if (o_stream_send(ctx->body_output, "\n", 1) < 0) + const char *linefeed = + (ctx->mbox->storage->storage.flags & + MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ? + "\r\n" : "\n"; + if (o_stream_send_str(ctx->output, linefeed) < 0) return write_error(ctx); } return 0; @@ -618,8 +623,6 @@ index_mail_cache_parse_deinit(ctx->mail, ctx->received_date); if (ctx->input != NULL) i_stream_destroy(&ctx->input); - if (ctx->body_output != NULL) - o_stream_destroy(&ctx->body_output); if (ctx->failed && ctx->mail_offset != (uoff_t)-1) { /* saving this mail failed - truncate back to beginning of it */ @@ -641,8 +644,6 @@ static void mbox_transaction_save_deinit(struct mbox_save_context *ctx) { - i_assert(ctx->body_output == NULL); - if (ctx->output != NULL) o_stream_destroy(&ctx->output); if (ctx->mail != NULL)