# HG changeset patch # User Timo Sirainen # Date 1487508560 -7200 # Node ID 347734729a499f913d2a3efd841a3029dac91b98 # Parent 03b2c50c18af598e9a00c9bd9ccb14eac37a4fb5 imap: Code cleanup - Remove duplicate flags from imap_fetch_state All the cur_flushed, line_partial and line_finished were about the same thing. diff -r 03b2c50c18af -r 347734729a49 src/imap/imap-fetch.c --- a/src/imap/imap-fetch.c Sun Feb 19 14:34:45 2017 +0200 +++ b/src/imap/imap-fetch.c Sun Feb 19 14:49:20 2017 +0200 @@ -379,7 +379,6 @@ ctx->fetch_data, wanted_headers); ctx->state.cur_str = str_new(default_pool, 8192); ctx->state.fetching = TRUE; - ctx->state.line_finished = TRUE; if (wanted_headers != NULL) mailbox_header_lookup_unref(&wanted_headers); @@ -402,7 +401,7 @@ len--; ctx->state.cur_first = FALSE; } - ctx->state.cur_flushed = TRUE; + ctx->state.line_partial = TRUE; if (o_stream_send(ctx->client->output, data, len) < 0) return -1; @@ -431,7 +430,7 @@ static void imap_fetch_fix_empty_reply(struct imap_fetch_context *ctx) { - if (ctx->state.cur_flushed && ctx->state.cur_first) { + if (ctx->state.line_partial && ctx->state.cur_first) { /* we've flushed an empty "FETCH (" reply so far. we can't take it back, but RFC 3501 doesn't allow returning empty "FETCH ()" @@ -511,8 +510,7 @@ state->cur_mail->seq); state->cur_first = TRUE; state->cur_str_prefix_size = str_len(state->cur_str); - state->cur_flushed = FALSE; - state->line_finished = FALSE; + i_assert(!state->line_partial); } for (; state->cur_handler < count; state->cur_handler++) { @@ -520,7 +518,6 @@ !handlers[state->cur_handler].buffered) { /* first non-buffered handler. flush the buffer. */ - state->line_partial = TRUE; if (imap_fetch_flush_buffer(ctx) < 0) return -1; } @@ -559,21 +556,20 @@ imap_fetch_fix_empty_reply(ctx); if (str_len(state->cur_str) > 0 && - (state->cur_flushed || + (state->line_partial || str_len(state->cur_str) != state->cur_str_prefix_size)) { /* no non-buffered handlers */ if (imap_fetch_flush_buffer(ctx) < 0) return -1; } - state->line_finished = TRUE; - state->line_partial = FALSE; - if (state->cur_flushed) + if (state->line_partial) o_stream_nsend(client->output, ")\r\n", 3); client->last_output = ioloop_time; state->cur_mail = NULL; state->cur_handler = 0; + state->line_partial = FALSE; } return ctx->failures ? -1 : 1; @@ -611,7 +607,9 @@ ret = imap_fetch_more_int(ctx, FALSE); if (ret < 0) { ctx->state.failed = TRUE; - if (!ctx->state.line_finished) { + if (ctx->state.line_partial) { + /* we can't send any more replies to client, because + the FETCH reply wasn't fully sent. */ client_disconnect(ctx->client, "NOTIFY failed in the middle of FETCH reply"); } @@ -625,8 +623,7 @@ if (ctx->state.fetching) { ctx->state.fetching = FALSE; - if (!state->line_finished && - (!state->cur_first || state->cur_flushed)) { + if (state->line_partial) { imap_fetch_fix_empty_reply(ctx); if (imap_fetch_flush_buffer(ctx) < 0) state->failed = TRUE; diff -r 03b2c50c18af -r 347734729a49 src/imap/imap-fetch.h --- a/src/imap/imap-fetch.h Sun Feb 19 14:34:45 2017 +0200 +++ b/src/imap/imap-fetch.h Sun Feb 19 14:49:20 2017 +0200 @@ -70,9 +70,7 @@ unsigned int cur_first:1; /* TRUE if the cur_str prefix has been flushed. More data may still be added to it. */ - unsigned int cur_flushed:1; unsigned int line_partial:1; - unsigned int line_finished:1; unsigned int skipped_expunged_msgs:1; unsigned int failed:1; };