dovecot-2.2: imap: Make sure we don't return empty "* n FETCH ()...

dovecot at dovecot.org dovecot at dovecot.org
Fri May 2 08:13:26 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/99f59d6fce05
changeset: 17303:99f59d6fce05
user:      Timo Sirainen <tss at iki.fi>
date:      Fri May 02 11:12:58 2014 +0300
description:
imap: Make sure we don't return empty "* n FETCH ()" reply, which violates RFC 3501 ABNF.
It happened only during error conditions, and it would be a bit too much
trouble to try to remove the reply entirely, so just append the message UID
there.

diffstat:

 src/imap/imap-fetch.c |  14 +++++++++++++-
 src/imap/imap-fetch.h |   1 +
 2 files changed, 14 insertions(+), 1 deletions(-)

diffs (49 lines):

diff -r 197f77f6ef0d -r 99f59d6fce05 src/imap/imap-fetch.c
--- a/src/imap/imap-fetch.c	Fri May 02 11:06:27 2014 +0300
+++ b/src/imap/imap-fetch.c	Fri May 02 11:12:58 2014 +0300
@@ -403,6 +403,7 @@
 		len--;
 		ctx->state.cur_first = FALSE;
 	}
+	ctx->state.cur_flushed = TRUE;
 
 	if (o_stream_send(ctx->client->output, data, len) < 0)
 		return -1;
@@ -483,6 +484,7 @@
 			str_printfa(state->cur_str, "* %u FETCH (",
 				    state->cur_mail->seq);
 			state->cur_first = TRUE;
+			state->cur_flushed = FALSE;
 			state->line_finished = FALSE;
 		}
 
@@ -591,7 +593,17 @@
 
 	if (ctx->state.fetching) {
 		ctx->state.fetching = FALSE;
-		if (!state->line_finished) {
+		if (!state->line_finished &&
+		    (!state->cur_first || state->cur_flushed)) {
+			if (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 ()"
+				   either, so just add the current message's
+				   UID there. */
+				str_printfa(ctx->state.cur_str, "UID %u ",
+					    state->cur_mail->uid);
+			}
 			if (imap_fetch_flush_buffer(ctx) < 0)
 				state->failed = TRUE;
 			if (o_stream_send(ctx->client->output, ")\r\n", 3) < 0)
diff -r 197f77f6ef0d -r 99f59d6fce05 src/imap/imap-fetch.h
--- a/src/imap/imap-fetch.h	Fri May 02 11:06:27 2014 +0300
+++ b/src/imap/imap-fetch.h	Fri May 02 11:12:58 2014 +0300
@@ -63,6 +63,7 @@
 	unsigned int fetching:1;
 	unsigned int seen_flags_changed:1;
 	unsigned int cur_first:1;
+	unsigned int cur_flushed:1;
 	unsigned int line_partial:1;
 	unsigned int line_finished:1;
 	unsigned int skipped_expunged_msgs:1;


More information about the dovecot-cvs mailing list