dovecot-2.2: lib-mail: Moved message_skip_virtual() to message-s...

dovecot at dovecot.org dovecot at dovecot.org
Wed Oct 3 02:29:27 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/4a074827375d
changeset: 15176:4a074827375d
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Oct 03 02:28:44 2012 +0300
description:
lib-mail: Moved message_skip_virtual() to message-size.[ch] and changed API

diffstat:

 src/lib-mail/Makefile.am    |   2 -
 src/lib-mail/message-send.c |  70 ---------------------------------------------
 src/lib-mail/message-send.h |  14 ---------
 src/lib-mail/message-size.c |  45 ++++++++++++++++++++++++++++
 src/lib-mail/message-size.h |   6 +++
 5 files changed, 51 insertions(+), 86 deletions(-)

diffs (177 lines):

diff -r 5cdd5bf63c51 -r 4a074827375d src/lib-mail/Makefile.am
--- a/src/lib-mail/Makefile.am	Wed Oct 03 02:28:31 2012 +0300
+++ b/src/lib-mail/Makefile.am	Wed Oct 03 02:28:44 2012 +0300
@@ -26,7 +26,6 @@
 	message-parser.c \
 	message-part-serialize.c \
 	message-search.c \
-	message-send.c \
 	message-size.c \
 	quoted-printable.c \
 	rfc2231-parser.c \
@@ -54,7 +53,6 @@
 	message-parser.h \
 	message-part-serialize.h \
 	message-search.h \
-	message-send.h \
 	message-size.h \
 	quoted-printable.h \
 	rfc2231-parser.h \
diff -r 5cdd5bf63c51 -r 4a074827375d src/lib-mail/message-send.c
--- a/src/lib-mail/message-send.c	Wed Oct 03 02:28:31 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,70 +0,0 @@
-/* Copyright (c) 2002-2012 Dovecot authors, see the included COPYING file */
-
-#include "lib.h"
-#include "istream.h"
-#include "ostream.h"
-#include "message-parser.h"
-#include "message-send.h"
-#include "message-size.h"
-
-int message_skip_virtual(struct istream *input, uoff_t virtual_skip,
-			 struct message_size *msg_size,
-			 bool cr_skipped, bool *last_cr)
-{
-	const unsigned char *msg;
-	size_t i, size, startpos;
-	int ret;
-
-	if (virtual_skip == 0) {
-		*last_cr = cr_skipped;
-		return 0;
-	}
-
-	*last_cr = FALSE;
-	startpos = 0;
-	while ((ret = i_stream_read_data(input, &msg, &size, startpos)) > 0) {
-		for (i = startpos; i < size && virtual_skip > 0; i++) {
-			virtual_skip--;
-
-			if (msg[i] == '\r') {
-				/* CR */
-				if (virtual_skip == 0)
-					*last_cr = TRUE;
-			} else if (msg[i] == '\n') {
-				/* LF */
-				if ((i == 0 && !cr_skipped) ||
-				    (i > 0 && msg[i-1] != '\r')) {
-					/* missing CR */
-					if (msg_size != NULL)
-						msg_size->virtual_size++;
-
-					if (virtual_skip == 0) {
-						/* CR/LF boundary */
-						*last_cr = TRUE;
-						break;
-					}
-
-					virtual_skip--;
-				}
-
-				/* increase after making sure we didn't break
-				   at virtual \r */
-				if (msg_size != NULL)
-					msg_size->lines++;
-			}
-		}
-
-		i_stream_skip(input, i);
-		if (msg_size != NULL) {
-			msg_size->physical_size += i;
-			msg_size->virtual_size += i;
-		}
-
-		if (i < size)
-			return 0;
-
-		cr_skipped = msg[i-1] == '\r';
-	}
-	i_assert(ret == -1);
-	return input->stream_errno == 0 ? 0 : -1;
-}
diff -r 5cdd5bf63c51 -r 4a074827375d src/lib-mail/message-send.h
--- a/src/lib-mail/message-send.h	Wed Oct 03 02:28:31 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-#ifndef MESSAGE_SEND_H
-#define MESSAGE_SEND_H
-
-struct message_size;
-
-/* Skip number of virtual bytes from putfer. msg_size is updated if it's not
-   NULL. If cr_skipped is TRUE and first character is \n, it's not treated as
-   \r\n. last_cr is set to TRUE if last character we skipped was \r, meaning
-   that next character should be \n and you shouldn't treat it as \r\n. */
-int message_skip_virtual(struct istream *input, uoff_t virtual_skip,
-			 struct message_size *msg_size,
-			 bool cr_skipped, bool *last_cr);
-
-#endif
diff -r 5cdd5bf63c51 -r 4a074827375d src/lib-mail/message-size.c
--- a/src/lib-mail/message-size.c	Wed Oct 03 02:28:31 2012 +0300
+++ b/src/lib-mail/message-size.c	Wed Oct 03 02:28:44 2012 +0300
@@ -121,3 +121,48 @@
 	dest->physical_size += src->physical_size;
 	dest->lines += src->lines;
 }
+
+int message_skip_virtual(struct istream *input, uoff_t virtual_skip,
+			 bool *last_cr_r)
+{
+	const unsigned char *msg;
+	size_t i, size;
+	bool cr_skipped = FALSE;
+	int ret;
+
+	*last_cr_r = FALSE;
+	if (virtual_skip == 0)
+		return 0;
+
+	while ((ret = i_stream_read_data(input, &msg, &size, 0)) > 0) {
+		for (i = 0; i < size && virtual_skip > 0; i++) {
+			virtual_skip--;
+
+			if (msg[i] == '\r') {
+				/* CR */
+				if (virtual_skip == 0)
+					*last_cr_r = TRUE;
+			} else if (msg[i] == '\n') {
+				/* LF */
+				if ((i == 0 && !cr_skipped) ||
+				    (i > 0 && msg[i-1] != '\r')) {
+					if (virtual_skip == 0) {
+						/* CR/LF boundary */
+						*last_cr_r = TRUE;
+						break;
+					}
+
+					virtual_skip--;
+				}
+			}
+		}
+		i_stream_skip(input, i);
+
+		if (i < size)
+			return 0;
+
+		cr_skipped = msg[i-1] == '\r';
+	}
+	i_assert(ret == -1);
+	return input->stream_errno == 0 ? 0 : -1;
+}
diff -r 5cdd5bf63c51 -r 4a074827375d src/lib-mail/message-size.h
--- a/src/lib-mail/message-size.h	Wed Oct 03 02:28:31 2012 +0300
+++ b/src/lib-mail/message-size.h	Wed Oct 03 02:28:44 2012 +0300
@@ -19,4 +19,10 @@
 void message_size_add(struct message_size *dest,
 		      const struct message_size *src);
 
+/* Skip number of virtual bytes from buffer. last_cr_r is set to TRUE if the
+   last character we skipped was '\r', meaning that the next character should
+   be '\n', which shouldn't be treated as "\r\n". */
+int message_skip_virtual(struct istream *input, uoff_t virtual_skip,
+			 bool *last_cr_r);
+
 #endif


More information about the dovecot-cvs mailing list