dovecot-2.1: doveadm fetch: Added text.utf8 field, which transla...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jan 26 20:20:50 EET 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/89a637820edd
changeset: 13999:89a637820edd
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jan 26 20:19:32 2012 +0200
description:
doveadm fetch: Added text.utf8 field, which translates headers/body to UTF-8.

diffstat:

 src/doveadm/doveadm-mail-fetch.c |  55 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)

diffs (79 lines):

diff -r 3235e903dc97 -r 89a637820edd src/doveadm/doveadm-mail-fetch.c
--- a/src/doveadm/doveadm-mail-fetch.c	Thu Jan 26 16:37:40 2012 +0200
+++ b/src/doveadm/doveadm-mail-fetch.c	Thu Jan 26 20:19:32 2012 +0200
@@ -6,6 +6,8 @@
 #include "ostream.h"
 #include "str.h"
 #include "message-size.h"
+#include "message-parser.h"
+#include "message-decoder.h"
 #include "imap-util.h"
 #include "mail-user.h"
 #include "mail-storage.h"
@@ -199,6 +201,57 @@
 	return ret;
 }
 
+static int fetch_text_utf8(struct fetch_cmd_context *ctx)
+{
+	struct istream *input;
+	struct message_parser_ctx *parser;
+	struct message_decoder_context *decoder;
+	struct message_block raw_block, block;
+	struct message_part *parts;
+	int ret = 0;
+
+	if (mail_get_stream(ctx->mail, NULL, NULL, &input) < 0)
+		return -1;
+
+	parser = message_parser_init(pool_datastack_create(), input,
+				     MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE,
+				     0);
+	decoder = message_decoder_init(0);
+
+	while ((ret = message_parser_parse_next_block(parser, &raw_block)) > 0) {
+		if (!message_decoder_decode_next_block(decoder, &raw_block,
+						       &block))
+			continue;
+
+		if (block.hdr == NULL) {
+			if (block.size > 0)
+				doveadm_print_stream(block.data, block.size);
+		} else if (block.hdr->eoh)
+			doveadm_print_stream("\n", 1);
+		else {
+			i_assert(block.hdr->name_len > 0);
+			doveadm_print_stream(block.hdr->name,
+					     block.hdr->name_len);
+			doveadm_print_stream(": ", 2);
+			if (block.hdr->full_value_len > 0) {
+				doveadm_print_stream(block.hdr->full_value,
+						     block.hdr->full_value_len);
+			}
+			doveadm_print_stream("\n", 1);
+		}
+	}
+	i_assert(ret != 0);
+	message_decoder_deinit(&decoder);
+	(void)message_parser_deinit(&parser, &parts);
+
+	if (input->stream_errno != 0) {
+		i_error("read() failed: %m");
+		ret = -1;
+	}
+	doveadm_print_stream(NULL, 0);
+	return ret;
+}
+
 static int fetch_size_physical(struct fetch_cmd_context *ctx)
 {
 	uoff_t size;
@@ -306,6 +359,8 @@
 	{ "body",          MAIL_FETCH_STREAM_BODY,   fetch_body },
 	{ "text",          MAIL_FETCH_STREAM_HEADER |
 	                   MAIL_FETCH_STREAM_BODY,   fetch_text },
+	{ "text.utf8",     MAIL_FETCH_STREAM_HEADER |
+	                   MAIL_FETCH_STREAM_BODY,   fetch_text_utf8 },
 	{ "size.physical", MAIL_FETCH_PHYSICAL_SIZE, fetch_size_physical },
 	{ "size.virtual",  MAIL_FETCH_VIRTUAL_SIZE,  fetch_size_virtual },
 	{ "date.received", MAIL_FETCH_RECEIVED_DATE, fetch_date_received },


More information about the dovecot-cvs mailing list