--- dovecot-2.0-pure/src/lib/istream.c	2010-08-16 09:24:27.000000000 +0200
+++ dovecot-2.0/src/lib/istream.c	2010-09-01 12:31:35.000000000 +0200
@@ -337,7 +337,7 @@
 {
 	struct istream_private *_stream = stream->real_stream;
 	char *ret_buf;
-        size_t i;
+	unsigned char *data, *found;
 
 	if (_stream->skip >= _stream->pos) {
 		stream->stream_errno = 0;
@@ -352,13 +352,15 @@
 
 	/* @UNSAFE */
 	ret_buf = NULL;
-	for (i = _stream->skip; i < _stream->pos; i++) {
-		if (_stream->buffer[i] == 10) {
-			/* got it */
-			ret_buf = i_stream_next_line_finish(_stream, i);
-                        break;
-		}
+
+	data = _stream->buffer + _stream->skip;
+	found = memchr(data, '\n', _stream->pos - _stream->skip);
+
+	if (found != NULL) {
+		/* got it */
+		ret_buf = i_stream_next_line_finish(_stream, found - _stream->buffer);
 	}
+
 	if (ret_buf == NULL)
 		return i_stream_last_line(_stream);
         return ret_buf;