dovecot-2.0: lmtp: Don't lose first 128k of data with >128k mails.

dovecot at dovecot.org dovecot at dovecot.org
Tue Dec 15 20:44:20 EET 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/1aea146d39e1
changeset: 10490:1aea146d39e1
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Dec 15 13:44:15 2009 -0500
description:
lmtp: Don't lose first 128k of data with >128k mails.

diffstat:

1 file changed, 14 insertions(+), 6 deletions(-)
src/lmtp/commands.c |   20 ++++++++++++++------

diffs (48 lines):

diff -r 5df19422d561 -r 1aea146d39e1 src/lmtp/commands.c
--- a/src/lmtp/commands.c	Mon Dec 14 20:34:44 2009 -0500
+++ b/src/lmtp/commands.c	Tue Dec 15 13:44:15 2009 -0500
@@ -694,12 +694,14 @@ static int client_input_add_file(struct 
 static int client_input_add_file(struct client *client,
 				 const unsigned char *data, size_t size)
 {
+	struct client_state *state = &client->state;
 	string_t *path;
+	ssize_t ret;
 	int fd;
 
-	if (client->state.mail_data_output != NULL) {
+	if (state->mail_data_output != NULL) {
 		/* continue writing to file */
-		if (o_stream_send(client->state.mail_data_output,
+		if (o_stream_send(state->mail_data_output,
 				  data, size) != (ssize_t)size)
 			return -1;
 		return 0;
@@ -721,9 +723,14 @@ static int client_input_add_file(struct 
 		return -1;
 	}
 
-	client->state.mail_data_fd = fd;
-	client->state.mail_data_output = o_stream_create_fd_file(fd, 0, FALSE);
-	o_stream_cork(client->state.mail_data_output);
+	state->mail_data_fd = fd;
+	state->mail_data_output = o_stream_create_fd_file(fd, 0, FALSE);
+	o_stream_cork(state->mail_data_output);
+
+	ret = o_stream_send(state->mail_data_output,
+			    state->mail_data->data, state->mail_data->used);
+	if (ret != (ssize_t)state->mail_data->used)
+		return -1;
 	if (o_stream_send(client->state.mail_data_output,
 			  data, size) != (ssize_t)size)
 		return -1;
@@ -734,7 +741,8 @@ client_input_add(struct client *client, 
 client_input_add(struct client *client, const unsigned char *data, size_t size)
 {
 	if (client->state.mail_data->used + size <=
-	    CLIENT_MAIL_DATA_MAX_INMEMORY_SIZE) {
+	    CLIENT_MAIL_DATA_MAX_INMEMORY_SIZE &&
+	    client->state.mail_data_output == NULL) {
 		buffer_append(client->state.mail_data, data, size);
 		return 0;
 	} else {


More information about the dovecot-cvs mailing list