[dovecot-cvs] dovecot/src/imap common.h, 1.15, 1.16 imap-fetch-body.c, 1.3, 1.4 imap-fetch.h, 1.8, 1.9 main.c, 1.54, 1.55

cras at dovecot.org cras at dovecot.org
Sun Aug 22 12:52:13 EEST 2004


Update of /home/cvs/dovecot/src/imap
In directory talvi:/tmp/cvs-serv3212/src/imap

Modified Files:
	common.h imap-fetch-body.c imap-fetch.h main.c 
Log Message:
Added netscape-eoh workaround.



Index: common.h
===================================================================
RCS file: /home/cvs/dovecot/src/imap/common.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- common.h	15 Aug 2004 03:40:30 -0000	1.15
+++ common.h	22 Aug 2004 09:52:11 -0000	1.16
@@ -25,7 +25,8 @@
 
 enum client_workarounds {
 	WORKAROUND_OE6_FETCH_NO_NEWMAIL		= 0x01,
-	WORKAROUND_OUTLOOK_IDLE			= 0x02
+	WORKAROUND_OUTLOOK_IDLE			= 0x02,
+	WORKAROUND_NETSCAPE_EOH			= 0x04
 };
 
 extern struct ioloop *ioloop;

Index: imap-fetch-body.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/imap-fetch-body.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- imap-fetch-body.c	22 Aug 2004 05:54:54 -0000	1.3
+++ imap-fetch-body.c	22 Aug 2004 09:52:11 -0000	1.4
@@ -119,7 +119,8 @@
 }
 
 static off_t imap_fetch_send(struct ostream *output, struct istream *input,
-			     int cr_skipped, uoff_t virtual_size, int *last_cr)
+			     int cr_skipped, uoff_t virtual_size,
+			     int add_missing_eoh, int *last_cr)
 {
 	const unsigned char *msg;
 	size_t i, size;
@@ -173,6 +174,14 @@
 		}
 	}
 
+	if (add_missing_eoh && sent + 2 == virtual_size) {
+		/* Netscape missing EOH workaround. */
+		o_stream_set_max_buffer_size(output, (size_t)-1);
+		if (o_stream_send(output, "\r\n", 2) < 0)
+			return -1;
+		sent += 2;
+	}
+
 	if ((uoff_t)sent != virtual_size && !blocks) {
 		/* Input stream gave less data then we expected. Two choices
 		   here: either we fill the missing data with spaces or we
@@ -201,7 +210,7 @@
 	o_stream_set_max_buffer_size(ctx->client->output, 0);
 	ret = imap_fetch_send(ctx->client->output, ctx->cur_input,
 			      ctx->skip_cr, ctx->cur_size - ctx->cur_offset,
-			      &ctx->skip_cr);
+			      ctx->cur_append_eoh, &ctx->skip_cr);
 	o_stream_set_max_buffer_size(ctx->client->output, (size_t)-1);
 
 	if (ret < 0)
@@ -230,6 +239,15 @@
 		return -1;
 
 	ctx->cur_offset += ret;
+
+	if (ctx->cur_append_eoh && ctx->cur_offset + 2 == ctx->cur_size) {
+		/* Netscape missing EOH workaround. */
+		if (o_stream_send(ctx->client->output, "\r\n", 2) < 0)
+			return -1;
+		ctx->cur_offset += 2;
+		ctx->cur_append_eoh = FALSE;
+	}
+
 	return ctx->cur_offset == ctx->cur_size;
 }
 
@@ -316,12 +334,28 @@
 	return fetch_data(ctx, body, fetch_size);
 }
 
+static void header_filter_eoh(struct message_header_line *hdr,
+			      int *matched __attr_unused__, void *context)
+{
+	struct imap_fetch_context *ctx = context;
+
+	if (hdr != NULL && hdr->eoh)
+		ctx->cur_have_eoh = TRUE;
+}
+
 static void header_filter_mime(struct message_header_line *hdr,
-			       int *matched, void *context __attr_unused__)
+			       int *matched, void *context)
 {
+	struct imap_fetch_context *ctx = context;
+
 	if (hdr == NULL)
 		return;
 
+	if (hdr->eoh) {
+		ctx->cur_have_eoh = TRUE;
+		return;
+	}
+
 	*matched = strncasecmp(hdr->name, "Content-", 8) == 0 ||
 		strcasecmp(hdr->name, "Mime-Version") == 0;
 }
@@ -337,26 +371,27 @@
 
 	/* MIME, HEADER.FIELDS (list), HEADER.FIELDS.NOT (list) */
 
+	ctx->cur_have_eoh = FALSE;
 	if (strncmp(header_section, "HEADER.FIELDS ", 14) == 0) {
 		fields = imap_fetch_get_body_fields(header_section + 14,
 						    &fields_count);
 		input = i_stream_create_header_filter(ctx->cur_input,
 						      FALSE, TRUE,
 						      fields, fields_count,
-						      NULL, NULL);
+						      header_filter_eoh, ctx);
 	} else if (strncmp(header_section, "HEADER.FIELDS.NOT ", 18) == 0) {
 		fields = imap_fetch_get_body_fields(header_section + 18,
 						    &fields_count);
 		input = i_stream_create_header_filter(ctx->cur_input,
 						      TRUE, TRUE,
 						      fields, fields_count,
-						      NULL, NULL);
+						      header_filter_eoh, ctx);
 	} else if (strcmp(header_section, "MIME") == 0) {
 		/* Mime-Version + Content-* fields */
 		input = i_stream_create_header_filter(ctx->cur_input,
 						      FALSE, TRUE,
 						      NULL, 0,
-						      header_filter_mime, NULL);
+						      header_filter_mime, ctx);
 	} else {
 		i_error("BUG: Accepted invalid section from user: '%s'",
 			header_section);
@@ -367,16 +402,17 @@
 	ctx->cur_input = input;
 	ctx->update_partial = FALSE;
 
-	/* FIXME: We'll just always add the end of headers mark now.
-	   mail-storage should rather include it in the header stream..
-	   however, not much of a problem since all non-broken mails have it.
-
-	   Also, Netscape 4.x seems to require this or it won't show the
-	   mail.. So if we do make this as RFC says, we'll need to add
-	   netscape-workaround. */
 	message_get_header_size(ctx->cur_input, &msg_size, NULL);
 	i_stream_seek(ctx->cur_input, 0);
 
+	if (!ctx->cur_have_eoh &&
+	    (client_workarounds & WORKAROUND_NETSCAPE_EOH) != 0) {
+		/* Netscape 4.x doesn't like if end of headers line is
+		   missing. */
+		msg_size.virtual_size += 2;
+		ctx->cur_append_eoh = TRUE;
+	}
+
 	return fetch_data(ctx, body, &msg_size);
 }
 
@@ -411,6 +447,11 @@
 	message_get_body_size(ctx->cur_input, &size, NULL);
 	i_stream_seek(ctx->cur_input, 0);
 
+	/* FIXME: We'll just always add the end of headers line now.
+	   ideally mail-storage would have a way to tell us if it exists. */
+	size.virtual_size += 2;
+	ctx->cur_append_eoh = TRUE;
+
 	return fetch_data(ctx, body, &size);
 }
 

Index: imap-fetch.h
===================================================================
RCS file: /home/cvs/dovecot/src/imap/imap-fetch.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- imap-fetch.h	15 Aug 2004 03:40:30 -0000	1.8
+++ imap-fetch.h	22 Aug 2004 09:52:11 -0000	1.9
@@ -49,6 +49,8 @@
 	unsigned int flags_update_seen:1;
 	unsigned int flags_show_only_seen_changes:1;
 	unsigned int update_partial:1;
+	unsigned int cur_have_eoh:1;
+	unsigned int cur_append_eoh:1;
 	unsigned int first:1;
 	unsigned int failed:1;
 };

Index: main.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/main.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- main.c	22 Aug 2004 05:54:54 -0000	1.54
+++ main.c	22 Aug 2004 09:52:11 -0000	1.55
@@ -29,6 +29,7 @@
 struct client_workaround_list client_workaround_list[] = {
 	{ "oe6-fetch-no-newmail", WORKAROUND_OE6_FETCH_NO_NEWMAIL },
 	{ "outlook-idle", WORKAROUND_OUTLOOK_IDLE },
+	{ "netscape-eoh", WORKAROUND_NETSCAPE_EOH },
 	{ NULL, 0 }
 };
 



More information about the dovecot-cvs mailing list