dovecot-2.0: doveadm fetch: Don't print field name if fetching o...

dovecot at dovecot.org dovecot at dovecot.org
Fri Apr 30 15:53:25 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/6327433bccb9
changeset: 11237:6327433bccb9
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Apr 30 15:53:23 2010 +0300
description:
doveadm fetch: Don't print field name if fetching only a single field.

diffstat:

 src/doveadm/doveadm-mail-fetch.c |  15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diffs (60 lines):

diff -r 47d49b7edb4b -r 6327433bccb9 src/doveadm/doveadm-mail-fetch.c
--- a/src/doveadm/doveadm-mail-fetch.c	Fri Apr 30 15:53:07 2010 +0300
+++ b/src/doveadm/doveadm-mail-fetch.c	Fri Apr 30 15:53:23 2010 +0300
@@ -27,6 +27,8 @@
 
 	string_t *hdr;
 	const char *prefix;
+
+	bool print_field_prefix;
 };
 
 static int fetch_mailbox(struct fetch_context *ctx)
@@ -93,7 +95,8 @@
 	if (mail_get_stream(ctx->mail, &hdr_size, NULL, &input) < 0)
 		return -1;
 
-	str_append_c(ctx->hdr, '\n');
+	if (ctx->print_field_prefix)
+		str_append_c(ctx->hdr, '\n');
 	flush_hdr(ctx);
 	input = i_stream_create_limit(input, hdr_size.physical_size);
 	while (!i_stream_is_eof(input)) {
@@ -118,7 +121,8 @@
 	if (mail_get_stream(ctx->mail, &hdr_size, NULL, &input) < 0)
 		return -1;
 
-	str_append_c(ctx->hdr, '\n');
+	if (ctx->print_field_prefix)
+		str_append_c(ctx->hdr, '\n');
 	flush_hdr(ctx);
 	i_stream_skip(input, hdr_size.physical_size);
 	while (!i_stream_is_eof(input)) {
@@ -141,7 +145,8 @@
 	if (mail_get_stream(ctx->mail, NULL, NULL, &input) < 0)
 		return -1;
 
-	str_append_c(ctx->hdr, '\n');
+	if (ctx->print_field_prefix)
+		str_append_c(ctx->hdr, '\n');
 	flush_hdr(ctx);
 	while (!i_stream_is_eof(input)) {
 		if (o_stream_send_istream(ctx->output, input) <= 0)
@@ -275,6 +280,7 @@
 
 		array_append(&ctx->fields, field, 1);
 	}
+	ctx->print_field_prefix = array_count(&ctx->fields) > 1;
 }
 
 static void cmd_fetch_mail(struct fetch_context *ctx)
@@ -283,7 +289,8 @@
 	struct mail *mail = ctx->mail;
 
 	array_foreach(&ctx->fields, field) {
-		str_printfa(ctx->hdr, "%s: ", field->name);
+		if (ctx->print_field_prefix)
+			str_printfa(ctx->hdr, "%s: ", field->name);
 		if (field->print(ctx) < 0) {
 			struct mail_storage *storage =
 				mailbox_get_storage(mail->box);


More information about the dovecot-cvs mailing list