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

cras at procontrol.fi cras at procontrol.fi
Mon Jan 27 09:01:22 EET 2003


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

Modified Files:
	commands.c 
Log Message:
Fixes, seems to be working now. Only thing left is the pop3-login..



Index: commands.c
===================================================================
RCS file: /home/cvs/dovecot/src/pop3/commands.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- commands.c	27 Jan 2003 06:44:49 -0000	1.2
+++ commands.c	27 Jan 2003 07:01:20 -0000	1.3
@@ -1,6 +1,8 @@
 /* Copyright (C) 2002 Timo Sirainen */
 
 #include "common.h"
+#include "istream.h"
+#include "ostream.h"
 #include "str.h"
 #include "message-size.h"
 #include "mail-storage.h"
@@ -153,10 +155,14 @@
 			if (last == msgnum-1 && last != 0)
 				last++;
 			else {
-				if (first == last)
-					str_printfa(set, ",%u", first);
-				else
-					str_printfa(set, ",%u:%u", first, last);
+				if (first != 0) {
+					if (first == last)
+						str_printfa(set, ",%u", first);
+					else {
+						str_printfa(set, ",%u:%u",
+							    first, last);
+					}
+				}
 				first = last = msgnum;
 			}
 		}
@@ -169,9 +175,12 @@
 			str_printfa(set, ",%u:%u", first, last);
 	}
 
+	memset(&flags, 0, sizeof(flags));
+	flags.flags = MAIL_DELETED;
+
 	if (str_len(set) == 0)
 		client_send_line(client, "+OK Logging out.");
-	else if (client->mailbox->update_flags(client->mailbox, str_c(set),
+	else if (client->mailbox->update_flags(client->mailbox, str_c(set)+1,
 					       FALSE, &flags, MODIFY_ADD,
 					       FALSE, NULL) &&
 		 client->mailbox->expunge(client->mailbox, FALSE))
@@ -182,6 +191,56 @@
 	client_disconnect(client);
 }
 
+static void stream_send_escaped(struct ostream *output, struct istream *input,
+				uoff_t max_lines)
+{
+	const unsigned char *data;
+	unsigned char last, add;
+	size_t i, size;
+	int cr_skipped;
+
+	cr_skipped = FALSE; last = '\0';
+	while (max_lines > 0 &&
+	       i_stream_read_data(input, &data, &size, 0) > 0) {
+		add = '\0';
+		for (i = 0; i < size; i++) {
+			if (data[i] == '\n') {
+				if ((i == 0 && last != '\r') ||
+				    (i > 0 && data[i-1] != '\r')) {
+					/* missing CR */
+					add = '\r';
+					break;
+				}
+
+				if (--max_lines == 0) {
+					i++;
+					break;
+				}
+			} else if (data[i] == '.' &&
+				   ((i == 0 && last == '\n') ||
+				    (i > 0 && data[i-1] == '\n'))) {
+				/* escape the dot */
+				add = '.';
+				i++;
+				break;
+			}
+		}
+
+		if (o_stream_send(output, data, i) < 0)
+			return;
+
+		if (add != '\0') {
+			if (o_stream_send(output, &add, 1) < 0)
+				return;
+			last = add;
+		} else {
+			last = data[i-1];
+		}
+
+		i_stream_skip(input, i);
+	}
+}
+
 static void fetch(struct client *client, unsigned int msgnum, uoff_t max_lines)
 {
 	struct mail_fetch_context *ctx;
@@ -211,8 +270,7 @@
 			client_send_line(client, "+OK");
 		}
 
-		// FIXME: "." lines needs to be escaped
-		// FIXME: and send only max_lines
+		stream_send_escaped(client->output, stream, max_lines);
 		client_send_line(client, ".");
 	}
 
@@ -248,9 +306,11 @@
 	unsigned int msgnum;
 	uoff_t max_lines;
 
-	if (get_msgnum(client, args, &msgnum) != NULL &&
-	    get_size(client, args, &max_lines))
-		fetch(client, msgnum, max_lines);
+	args = get_msgnum(client, args, &msgnum);
+	if (args != NULL) {
+		if (get_size(client, args, &max_lines) != NULL)
+			fetch(client, msgnum, max_lines);
+	}
 }
 
 static void list_uids(struct client *client, unsigned int message)




More information about the dovecot-cvs mailing list