Skip to content

Commit

Permalink
imap: Code cleanup - use istream-sized for GETMETADATA reply
Browse files Browse the repository at this point in the history
This avoids doing the same work explicitly.
  • Loading branch information
sirainen authored and GitLab committed May 18, 2016
1 parent 6f187ae commit 0e0fe9b
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/imap/cmd-getmetadata.c
Expand Up @@ -3,6 +3,7 @@
#include "imap-common.h"
#include "str.h"
#include "istream.h"
#include "istream-sized.h"
#include "ostream.h"
#include "mailbox-list-iter.h"
#include "imap-utf7.h"
Expand All @@ -22,7 +23,6 @@ struct imap_getmetadata_context {
unsigned int depth;

struct istream *cur_stream;
uoff_t cur_stream_size;

struct imap_metadata_iter *iter;
string_t *iter_entry_prefix;
Expand Down Expand Up @@ -203,39 +203,31 @@ static void cmd_getmetadata_send_entry(struct imap_getmetadata_context *ctx,
str_printfa(str, " ~{%"PRIuUOFF_T"}\r\n", value_len);
o_stream_nsend(client->output, str_data(str), str_len(str));

i_assert(value.value_stream->v_offset == 0);
ctx->cur_stream_size = value_len;
ctx->cur_stream = value.value_stream;
ctx->cur_stream = i_stream_create_sized(value.value_stream, value_len);
i_stream_unref(&value.value_stream);
}
}

static bool
cmd_getmetadata_stream_continue(struct imap_getmetadata_context *ctx)
{
int ret;

o_stream_set_max_buffer_size(ctx->cmd->client->output, 0);
(void)o_stream_send_istream(ctx->cmd->client->output, ctx->cur_stream);
ret = o_stream_send_istream(ctx->cmd->client->output, ctx->cur_stream);
o_stream_set_max_buffer_size(ctx->cmd->client->output, (size_t)-1);

if (ctx->cur_stream->stream_errno != 0) {
if (ret > 0) {
/* finished */
return TRUE;
} else if (ret < 0) {
i_error("read(%s) failed: %s",
i_stream_get_name(ctx->cur_stream),
i_stream_get_error(ctx->cur_stream));
client_disconnect(ctx->cmd->client,
"Internal GETMETADATA failure");
return TRUE;
}
if (ctx->cur_stream->v_offset == ctx->cur_stream_size) {
/* finished */
return TRUE;
}
if (!i_stream_have_bytes_left(ctx->cur_stream)) {
/* Input stream gave less data than expected */
i_error("read(%s): GETMETADATA stream had less data than expected",
i_stream_get_name(ctx->cur_stream));
client_disconnect(ctx->cmd->client,
"Internal GETMETADATA failure");
return TRUE;
}
o_stream_set_flush_pending(ctx->cmd->client->output, TRUE);
return FALSE;
}
Expand Down

0 comments on commit 0e0fe9b

Please sign in to comment.