dovecot: Moved tee stream handling to index-mail code.
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jul 18 09:36:27 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/1b0ef7a74448
changeset: 6083:1b0ef7a74448
user: Timo Sirainen <tss at iki.fi>
date: Wed Jul 18 09:36:22 2007 +0300
description:
Moved tee stream handling to index-mail code.
diffstat:
4 files changed, 30 insertions(+), 32 deletions(-)
src/lib-storage/index/cydir/cydir-save.c | 23 ++++++++---------------
src/lib-storage/index/index-mail-headers.c | 12 +++++++++++-
src/lib-storage/index/index-mail.h | 3 ++-
src/lib-storage/index/maildir/maildir-save.c | 24 +++++++++---------------
diffs (203 lines):
diff -r d62bddb414ef -r 1b0ef7a74448 src/lib-storage/index/cydir/cydir-save.c
--- a/src/lib-storage/index/cydir/cydir-save.c Wed Jul 18 09:36:04 2007 +0300
+++ b/src/lib-storage/index/cydir/cydir-save.c Wed Jul 18 09:36:22 2007 +0300
@@ -3,7 +3,6 @@
#include "lib.h"
#include "hostpid.h"
#include "istream.h"
-#include "istream-tee.h"
#include "ostream.h"
#include "ostream-crlf.h"
#include "str.h"
@@ -27,7 +26,7 @@ struct cydir_save_context {
/* updated for each appended mail: */
uint32_t seq;
- struct istream *input, *input2;
+ struct istream *input;
struct ostream *output;
struct mail *mail, *cur_dest_mail;
int fd;
@@ -70,7 +69,6 @@ int cydir_save_init(struct mailbox_trans
struct cydir_save_context *ctx = t->save_ctx;
enum mail_flags save_flags;
struct ostream *output;
- struct tee_istream *tee;
const char *path;
i_assert((t->ictx.flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
@@ -129,12 +127,8 @@ int cydir_save_init(struct mailbox_trans
if (mail_set_seq(dest_mail, ctx->seq) < 0)
i_unreached();
- tee = tee_i_stream_create(input, default_pool);
- ctx->input = tee_i_stream_create_child(tee, default_pool);
- ctx->input2 = tee_i_stream_create_child(tee, default_pool);
-
ctx->cur_dest_mail = dest_mail;
- index_mail_cache_parse_init(dest_mail, ctx->input2);
+ ctx->input = index_mail_cache_parse_init(dest_mail, input);
*ctx_r = &ctx->ctx;
return ctx->failed ? -1 : 0;
@@ -149,8 +143,6 @@ int cydir_save_continue(struct mail_save
return -1;
do {
- index_mail_cache_parse_continue(ctx->cur_dest_mail);
-
if (o_stream_send_istream(ctx->output, ctx->input) < 0) {
if (!mail_storage_set_error_from_errno(storage)) {
mail_storage_set_critical(storage,
@@ -160,10 +152,12 @@ int cydir_save_continue(struct mail_save
ctx->failed = TRUE;
return -1;
}
- /* both input and input2 readers may consume data from our
- primary input stream. we'll have to handle all the data
- here. */
- } while (i_stream_read(ctx->input2) > 0);
+ index_mail_cache_parse_continue(ctx->cur_dest_mail);
+
+ /* both tee input readers may consume data from our primary
+ input stream. we'll have to make sure we don't return with
+ one of the streams still having data in them. */
+ } while (i_stream_read(ctx->input) > 0);
return 0;
}
@@ -202,7 +196,6 @@ int cydir_save_finish(struct mail_save_c
index_mail_cache_parse_deinit(ctx->cur_dest_mail);
i_stream_unref(&ctx->input);
- i_stream_unref(&ctx->input2);
return ctx->failed ? -1 : 0;
}
diff -r d62bddb414ef -r 1b0ef7a74448 src/lib-storage/index/index-mail-headers.c
--- a/src/lib-storage/index/index-mail-headers.c Wed Jul 18 09:36:04 2007 +0300
+++ b/src/lib-storage/index/index-mail-headers.c Wed Jul 18 09:36:22 2007 +0300
@@ -7,6 +7,7 @@
#include "str.h"
#include "message-date.h"
#include "message-parser.h"
+#include "istream-tee.h"
#include "istream-header-filter.h"
#include "imap-envelope.h"
#include "imap-bodystructure.h"
@@ -339,16 +340,25 @@ index_mail_parse_header_cb(struct messag
index_mail_parse_header(mail->data.parts, hdr, mail);
}
-void index_mail_cache_parse_init(struct mail *_mail, struct istream *input)
+struct istream *index_mail_cache_parse_init(struct mail *_mail,
+ struct istream *input)
{
struct index_mail *mail = (struct index_mail *)_mail;
+ struct tee_istream *tee;
+ struct istream *input2;
i_assert(mail->data.parser_ctx == NULL);
+
+ tee = tee_i_stream_create(input, default_pool);
+ input = tee_i_stream_create_child(tee, default_pool);
+ input2 = tee_i_stream_create_child(tee, default_pool);
index_mail_parse_header_init(mail, NULL);
mail->data.parser_ctx =
message_parser_init(mail->data_pool, input,
hdr_parser_flags, msg_parser_flags);
+ i_stream_unref(&input);
+ return input2;
}
static void index_mail_init_parser(struct index_mail *mail)
diff -r d62bddb414ef -r 1b0ef7a74448 src/lib-storage/index/index-mail.h
--- a/src/lib-storage/index/index-mail.h Wed Jul 18 09:36:04 2007 +0300
+++ b/src/lib-storage/index/index-mail.h Wed Jul 18 09:36:22 2007 +0300
@@ -182,7 +182,8 @@ void index_mail_cache_add_idx(struct ind
void index_mail_cache_add_idx(struct index_mail *mail, unsigned int field_idx,
const void *data, size_t data_size);
-void index_mail_cache_parse_init(struct mail *mail, struct istream *input);
+struct istream *index_mail_cache_parse_init(struct mail *mail,
+ struct istream *input);
void index_mail_cache_parse_continue(struct mail *mail);
void index_mail_cache_parse_deinit(struct mail *mail);
diff -r d62bddb414ef -r 1b0ef7a74448 src/lib-storage/index/maildir/maildir-save.c
--- a/src/lib-storage/index/maildir/maildir-save.c Wed Jul 18 09:36:04 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-save.c Wed Jul 18 09:36:22 2007 +0300
@@ -5,7 +5,6 @@
#include "array.h"
#include "buffer.h"
#include "istream.h"
-#include "istream-tee.h"
#include "ostream.h"
#include "ostream-crlf.h"
#include "str.h"
@@ -51,7 +50,7 @@ struct maildir_save_context {
buffer_t *keywords_buffer;
ARRAY_TYPE(keyword_indexes) keywords_array;
- struct istream *input, *input2;
+ struct istream *input;
struct ostream *output;
int fd;
time_t received_date;
@@ -144,7 +143,6 @@ uint32_t maildir_save_add(struct maildir
{
struct maildir_save_context *ctx = t->save_ctx;
struct maildir_filename *mf;
- struct tee_istream *tee;
/* 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
@@ -204,11 +202,7 @@ uint32_t maildir_save_add(struct maildir
cached data directly */
ctx->cur_dest_mail = NULL;
} else {
- tee = tee_i_stream_create(ctx->input, default_pool);
- ctx->input = tee_i_stream_create_child(tee, default_pool);
- ctx->input2 = tee_i_stream_create_child(tee, default_pool);
-
- index_mail_cache_parse_init(dest_mail, ctx->input2);
+ ctx->input = index_mail_cache_parse_init(dest_mail, ctx->input);
ctx->cur_dest_mail = dest_mail;
}
return ctx->seq;
@@ -410,8 +404,6 @@ int maildir_save_continue(struct mail_sa
return -1;
do {
- if (ctx->cur_dest_mail != NULL)
- index_mail_cache_parse_continue(ctx->cur_dest_mail);
if (o_stream_send_istream(ctx->output, ctx->input) < 0) {
if (!mail_storage_set_error_from_errno(storage)) {
mail_storage_set_critical(storage,
@@ -422,10 +414,13 @@ int maildir_save_continue(struct mail_sa
ctx->failed = TRUE;
return -1;
}
- /* both input and input2 readers may consume data from our
- primary input stream. we'll have to handle all the data
- here. */
- } while (i_stream_read(ctx->input2) > 0);
+ if (ctx->cur_dest_mail != NULL)
+ index_mail_cache_parse_continue(ctx->cur_dest_mail);
+
+ /* both tee input readers may consume data from our primary
+ input stream. we'll have to make sure we don't return with
+ one of the streams still having data in them. */
+ } while (i_stream_read(ctx->input) > 0);
return 0;
}
@@ -439,7 +434,6 @@ int maildir_save_finish(struct mail_save
if (ctx->cur_dest_mail != NULL) {
index_mail_cache_parse_deinit(ctx->cur_dest_mail);
i_stream_unref(&ctx->input);
- i_stream_unref(&ctx->input2);
}
ctx->finished = TRUE;
More information about the dovecot-cvs
mailing list