[dovecot-cvs] dovecot/src/pop3 commands.c,1.3,1.4

cras at procontrol.fi cras at procontrol.fi
Thu Jan 30 19:50:08 EET 2003


Update of /home/cvs/dovecot/src/pop3
In directory danu:/tmp/cvs-serv32356

Modified Files:
	commands.c 
Log Message:
bugfixes



Index: commands.c
===================================================================
RCS file: /home/cvs/dovecot/src/pop3/commands.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- commands.c	27 Jan 2003 07:01:20 -0000	1.3
+++ commands.c	30 Jan 2003 17:50:05 -0000	1.4
@@ -34,12 +34,12 @@
 		args++;
 	}
 
-	if (num > client->messages_count) {
+	if (num == 0 || num > client->messages_count) {
 		client_send_line(client,
-				 "-ERR There's only %u messages.",
-				 client->messages_count);
+				 "-ERR There's no message %u.", num);
 		return NULL;
 	}
+	num--;
 
 	if (client->deleted) {
 		if (client->deleted_bitmask[num / CHAR_BIT] &
@@ -109,15 +109,15 @@
 				 client->messages_count);
 		for (i = 0; i < client->messages_count; i++) {
 			client_send_line(client, "%u %"PRIuUOFF_T,
-					 i, client->message_sizes[i]);
+					 i+1, client->message_sizes[i]);
 		}
 		client_send_line(client, ".");
 	} else {
 		unsigned int msgnum;
 
 		if (get_msgnum(client, args, &msgnum) != NULL) {
-			client_send_line(client, "+OK %u %"PRIuUOFF_T,
-					 msgnum, client->message_sizes[msgnum]);
+			client_send_line(client, "+OK %u %"PRIuUOFF_T, msgnum+1,
+					 client->message_sizes[msgnum]);
 		}
 	}
 }
@@ -192,18 +192,28 @@
 }
 
 static void stream_send_escaped(struct ostream *output, struct istream *input,
-				uoff_t max_lines)
+				uoff_t body_lines)
 {
 	const unsigned char *data;
 	unsigned char last, add;
 	size_t i, size;
-	int cr_skipped;
+	int cr_skipped, in_header;
 
-	cr_skipped = FALSE; last = '\0';
-	while (max_lines > 0 &&
+	if (body_lines != (uoff_t)-1)
+		body_lines++; /* internally we count the empty line too */
+
+	cr_skipped = FALSE; in_header = TRUE; last = '\0';
+	while ((body_lines > 0 || in_header) &&
 	       i_stream_read_data(input, &data, &size, 0) > 0) {
 		add = '\0';
 		for (i = 0; i < size; i++) {
+			if (in_header && (data[i] == '\r' || data[i] == '\n')) {
+				if (i == 0 && (last == '\0' || last == '\n'))
+					in_header = FALSE;
+				else if (i > 0 && data[i-1] == '\n')
+					in_header = FALSE;
+			}
+
 			if (data[i] == '\n') {
 				if ((i == 0 && last != '\r') ||
 				    (i > 0 && data[i-1] != '\r')) {
@@ -212,9 +222,11 @@
 					break;
 				}
 
-				if (--max_lines == 0) {
-					i++;
-					break;
+				if (!in_header) {
+					if (--body_lines == 0) {
+						i++;
+						break;
+					}
 				}
 			} else if (data[i] == '.' &&
 				   ((i == 0 && last == '\n') ||
@@ -241,7 +253,8 @@
 	}
 }
 
-static void fetch(struct client *client, unsigned int msgnum, uoff_t max_lines)
+static void fetch(struct client *client, unsigned int msgnum,
+		  uoff_t body_lines)
 {
 	struct mail_fetch_context *ctx;
 	struct mail *mail;
@@ -250,7 +263,7 @@
 	ctx = client->mailbox->fetch_init(client->mailbox,
 					  MAIL_FETCH_STREAM_HEADER |
 					  MAIL_FETCH_STREAM_BODY,
-					  NULL, t_strdup_printf("%u", msgnum),
+					  NULL, dec2str(msgnum+1),
 					  FALSE);
 	if (ctx == NULL) {
 		client_send_storage_error(client);
@@ -263,14 +276,14 @@
 	else {
 		stream = mail->get_stream(mail, NULL, NULL);
 
-		if (max_lines == (uoff_t)-1) {
+		if (body_lines == (uoff_t)-1) {
 			client_send_line(client, "+OK %"PRIuUOFF_T" octets",
 					 client->message_sizes[msgnum]);
 		} else {
 			client_send_line(client, "+OK");
 		}
 
-		stream_send_escaped(client->output, stream, max_lines);
+		stream_send_escaped(client->output, stream, body_lines);
 		client_send_line(client, ".");
 	}
 
@@ -357,7 +370,7 @@
 		unsigned int msgnum;
 
 		if (get_msgnum(client, args, &msgnum) != NULL)
-			list_uids(client, msgnum);
+			list_uids(client, msgnum+1);
 	}
 }
 




More information about the dovecot-cvs mailing list