dovecot-2.2: lib-mail: Removed quoted_printable_decode*()

dovecot at dovecot.org dovecot at dovecot.org
Sun May 3 13:28:46 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/780a8f4544ec
changeset: 18507:780a8f4544ec
user:      Timo Sirainen <tss at iki.fi>
date:      Sun May 03 16:26:46 2015 +0300
description:
lib-mail: Removed quoted_printable_decode*()
quoted_printable_q_decode() was still left in quoted-printable.h, but maybe
it should be moved to qp-decoder.c as well.

diffstat:

 src/lib-mail/quoted-printable.c      |  110 -----------------------------------
 src/lib-mail/quoted-printable.h      |   13 ----
 src/lib-mail/test-quoted-printable.c |   88 ----------------------------
 3 files changed, 0 insertions(+), 211 deletions(-)

diffs (248 lines):

diff -r b10aebbb42df -r 780a8f4544ec src/lib-mail/quoted-printable.c
--- a/src/lib-mail/quoted-printable.c	Sun May 03 16:23:41 2015 +0300
+++ b/src/lib-mail/quoted-printable.c	Sun May 03 16:26:46 2015 +0300
@@ -5,116 +5,6 @@
 #include "hex-binary.h"
 #include "quoted-printable.h"
 
-#define QP_IS_TRAILING_SPACE(c) \
-	((c) == ' ' || (c) == '\t')
-
-static int
-qp_is_end_of_line(const unsigned char *src, size_t *src_pos, size_t size)
-{
-	size_t i = *src_pos;
-
-	i_assert(src[i] == '=');
-	for (i++; i < size; i++) {
-		if (QP_IS_TRAILING_SPACE(src[i]) || src[i] == '\r')
-			continue;
-
-		if (src[i] != '\n')
-			return 0;
-
-		*src_pos = i;
-		return 1;
-	}
-	return -1;
-}
-
-static int
-quoted_printable_decode_full(const unsigned char *src, size_t src_size,
-			     size_t *src_pos_r, buffer_t *dest, bool eof)
-{
-	char hexbuf[3];
-	size_t src_pos, pos, next;
-	bool errors = FALSE;
-	int ret;
-
-	hexbuf[2] = '\0';
-
-	next = 0;
-	for (src_pos = 0; src_pos < src_size; src_pos++) {
-		if (src[src_pos] != '=' && src[src_pos] != '\n')
-			continue;
-
-		if (src[src_pos] == '\n') {
-			/* drop trailing whitespace */
-			pos = src_pos;
-			if (pos > 0 && src[pos-1] == '\r')
-				pos--;
-			while (pos > 0 && QP_IS_TRAILING_SPACE(src[pos-1]))
-				pos--;
-			buffer_append(dest, src + next, pos - next);
-			next = src_pos+1;
-			buffer_append_c(dest, '\r');
-			buffer_append_c(dest, '\n');
-			continue;
-		}
-
-		/* '=' */
-		buffer_append(dest, src + next, src_pos - next);
-		next = src_pos;
-
-		if ((ret = qp_is_end_of_line(src, &src_pos, src_size)) > 0) {
-			/* =[whitespace][\r]\n */
-			next = src_pos+1;
-			continue;
-		}
-		if (ret < 0) {
-			/* '=' was followed only by whitespace */
-			break;
-		}
-		if (src_pos+2 >= src_size) {
-			/* '=' was followed by non-whitespace */
-			if (eof)
-				errors = TRUE;
-			break;
-		}
-
-		/* =<hex> */
-		hexbuf[0] = src[src_pos+1];
-		hexbuf[1] = src[src_pos+2];
-
-		if (hex_to_binary(hexbuf, dest) == 0) {
-			src_pos += 2;
-			next = src_pos + 1;
-		} else {
-			/* non-hex data, show as-is */
-			errors = TRUE;
-			next = src_pos;
-		}
-	}
-	if (src_pos == src_size) {
-		/* add everything but trailing spaces */
-		if (src_pos > 0 && src[src_pos-1] == '\r')
-			src_pos--;
-		while (src_pos > 0 && QP_IS_TRAILING_SPACE(src[src_pos-1]))
-			src_pos--;
-		buffer_append(dest, src + next, src_pos - next);
-		next = src_pos;
-	}
-	*src_pos_r = next;
-	return errors ? -1 : 0;
-}
-
-int quoted_printable_decode(const unsigned char *src, size_t src_size,
-			    size_t *src_pos_r, buffer_t *dest)
-{
-	return quoted_printable_decode_full(src, src_size, src_pos_r, dest, FALSE);
-}
-
-int quoted_printable_decode_final(const unsigned char *src, size_t src_size,
-				  size_t *src_pos_r, buffer_t *dest)
-{
-	return quoted_printable_decode_full(src, src_size, src_pos_r, dest, TRUE);
-}
-
 int quoted_printable_q_decode(const unsigned char *src, size_t src_size,
 			      buffer_t *dest)
 {
diff -r b10aebbb42df -r 780a8f4544ec src/lib-mail/quoted-printable.h
--- a/src/lib-mail/quoted-printable.h	Sun May 03 16:23:41 2015 +0300
+++ b/src/lib-mail/quoted-printable.h	Sun May 03 16:26:46 2015 +0300
@@ -1,19 +1,6 @@
 #ifndef QUOTED_PRINTABLE_H
 #define QUOTED_PRINTABLE_H
 
-/* Translates quoted printable data into binary. dest must be at least the
-   size of src, and may be same as src. Returns 0 if input was valid, -1 if
-   there were some decoding errors (which were skipped over). LFs without
-   preceding CR are returned as CRLF (but =0A isn't).
-
-   This function may be called multiple times for parsing the same stream.
-   src_pos is updated to first non-translated character in src. */
-int quoted_printable_decode(const unsigned char *src, size_t src_size,
-			    size_t *src_pos_r, buffer_t *dest);
-/* Like quoted_printable_decode(), but handle src as the final block.
-   This allows src to end without LF. */
-int quoted_printable_decode_final(const unsigned char *src, size_t src_size,
-				  size_t *src_pos_r, buffer_t *dest);
 /* Decode MIME "Q" encoding. */
 int quoted_printable_q_decode(const unsigned char *src, size_t src_size,
 			      buffer_t *dest);
diff -r b10aebbb42df -r 780a8f4544ec src/lib-mail/test-quoted-printable.c
--- a/src/lib-mail/test-quoted-printable.c	Sun May 03 16:23:41 2015 +0300
+++ b/src/lib-mail/test-quoted-printable.c	Sun May 03 16:26:46 2015 +0300
@@ -6,92 +6,6 @@
 #include "quoted-printable.h"
 #include "test-common.h"
 
-struct test_quoted_printable_decode_data {
-	const char *input;
-	const char *output;
-	int end_skip;
-	int ret;
-};
-
-static void test_quoted_printable_decode(void)
-{
-	static struct test_quoted_printable_decode_data data[] = {
-		{ "foo  \r\nbar=", "foo\r\nbar", 1, 0 },
-		{ "foo\t=\nbar", "foo\tbar", 0, 0 },
-		{ "foo = \n=01", "foo \001", 0, 0 },
-		{ "foo =\t\r\nbar", "foo bar", 0, 0 },
-		{ "foo =\r\n=01", "foo \001", 0, 0 },
-		{ "foo  \nbar=", "foo\r\nbar", 1, 0 },
-		{ "=0A=0D  ", "\n\r", 2, 0 },
-		{ "foo_bar", "foo_bar", 0, 0 },
-		{ "foo=", "foo", 1, 0 },
-		{ "foo=  ", "foo", 3, 0 },
-		{ "foo=A", "foo", 2, 0 },
-		{ "foo=Ax", "foo=Ax", 0, -1 },
-		{ "foo=Ax=xy", "foo=Ax=xy", 0, -1 }
-	};
-	buffer_t *buf;
-	unsigned int i, start, end, len;
-	size_t src_pos;
-	int ret;
-
-	test_begin("quoted printable decode");
-	buf = buffer_create_dynamic(pool_datastack_create(), 128);
-	for (i = 0; i < N_ELEMENTS(data); i++) {
-		len = strlen(data[i].input);
-		ret = quoted_printable_decode((const void *)data[i].input, len,
-					      &src_pos, buf);
-		test_assert(ret == data[i].ret);
-		test_assert(src_pos + data[i].end_skip == len);
-		test_assert(strcmp(data[i].output, str_c(buf)) == 0);
-
-		buffer_set_used_size(buf, 0);
-		for (start = 0, end = 1; end <= len; ) {
-			quoted_printable_decode(CONST_PTR_OFFSET(data[i].input, start),
-						end - start, &src_pos, buf);
-			src_pos += start;
-			start = src_pos;
-			if (src_pos <= end)
-				end++;
-			else
-				end = src_pos + 1;
-		}
-		test_assert(src_pos + data[i].end_skip == len);
-		test_assert(strcmp(data[i].output, str_c(buf)) == 0);
-		buffer_set_used_size(buf, 0);
-	}
-	test_end();
-}
-
-static void test_quoted_printable_decode_final(void)
-{
-	static struct test_quoted_printable_decode_data data[] = {
-		{ "=0A=0D  ", "\n\r", 2, 0 },
-		{ "foo=", "foo", 1, 0 },
-		{ "foo  ", "foo", 2, 0 },
-		{ "foo=  ", "foo", 3, 0 },
-		{ "foo=A", "foo", 2, -1 }
-	};
-	buffer_t *buf;
-	unsigned int i, len;
-	size_t src_pos;
-	int ret;
-
-	test_begin("quoted printable decode final");
-	buf = buffer_create_dynamic(pool_datastack_create(), 128);
-	for (i = 0; i < N_ELEMENTS(data); i++) {
-		len = strlen(data[i].input);
-		ret = quoted_printable_decode_final((const void *)data[i].input,
-						    len, &src_pos, buf);
-		test_assert(ret == data[i].ret);
-		test_assert(src_pos + data[i].end_skip == len);
-		test_assert(strcmp(data[i].output, str_c(buf)) == 0);
-
-		buffer_set_used_size(buf, 0);
-	}
-	test_end();
-}
-
 static void test_quoted_printable_q_decode(void)
 {
 	const char *data[] = {
@@ -119,8 +33,6 @@
 int main(void)
 {
 	static void (*test_functions[])(void) = {
-		test_quoted_printable_decode,
-		test_quoted_printable_decode_final,
 		test_quoted_printable_q_decode,
 		NULL
 	};


More information about the dovecot-cvs mailing list