aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Brady <rwb197@ecs.soton.ac.uk>1999-08-06 23:47:45 +0800
committerRobert Brady <rbrady@src.gnome.org>1999-08-06 23:47:45 +0800
commit85067acb32a4992410e337352f8c54b61b78709b (patch)
tree88fdde821bfecfd1a33d2c9c6d760fab8341506a
parentf3e57fa18f42e44f81f1eedc2db85a4125752d20 (diff)
downloadgsoc2013-evolution-85067acb32a4992410e337352f8c54b61b78709b.tar
gsoc2013-evolution-85067acb32a4992410e337352f8c54b61b78709b.tar.gz
gsoc2013-evolution-85067acb32a4992410e337352f8c54b61b78709b.tar.bz2
gsoc2013-evolution-85067acb32a4992410e337352f8c54b61b78709b.tar.lz
gsoc2013-evolution-85067acb32a4992410e337352f8c54b61b78709b.tar.xz
gsoc2013-evolution-85067acb32a4992410e337352f8c54b61b78709b.tar.zst
gsoc2013-evolution-85067acb32a4992410e337352f8c54b61b78709b.zip
encoder test.
1999-08-06 Robert Brady <rwb197@ecs.soton.ac.uk> * tests/test6.c: encoder test. * camel/gmime-rfc2047.c: Fixed decoder bug : sequence ?= is not always the terminator for an encoded-string. svn path=/trunk/; revision=1091
-rw-r--r--ChangeLog7
-rw-r--r--camel/gmime-rfc2047.c24
-rw-r--r--tests/test6.c50
3 files changed, 80 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 861b4a7b09..caf152633a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+1999-08-06 Robert Brady <rwb197@ecs.soton.ac.uk>
+
+ * tests/test6.c: encoder test.
+
+ * camel/gmime-rfc2047.c: Fixed decoder bug : sequence
+ ?= is not always the terminator for an encoded-string.
+
1999-08-06 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/providers/MH/camel-mh-folder.c (_list_subfolders):
diff --git a/camel/gmime-rfc2047.c b/camel/gmime-rfc2047.c
index 2a44a20dd6..ecb75d519d 100644
--- a/camel/gmime-rfc2047.c
+++ b/camel/gmime-rfc2047.c
@@ -160,6 +160,7 @@ rfc2047_decode_word (const gchar *data, const gchar *into_what)
int b_len = 4096;
iconv_t i;
strncpy(q, charset, c - charset);
+ q[c - charset] = 0;
i = unicode_iconv_open(into_what, q);
if (!i) {
g_free(q);
@@ -167,11 +168,29 @@ rfc2047_decode_word (const gchar *data, const gchar *into_what)
}
unicode_iconv(i, &cook_2, &cook_len, &b, &b_len);
unicode_iconv_close(i);
+ *b = 0;
}
return g_strdup(buffer);
}
+static gchar *
+find_end_of_encoded_word(const gchar *data) {
+ /* We can't just search for ?=,
+ because of the case :
+ "=?charset?q?=ff?=" :( */
+ if (!data) return NULL;
+ data = strstr(data, "=?");
+ if (!data) return NULL;
+ data = strchr(data+2, '?');
+ if (!data) return NULL;
+ data = strchr(data+1, '?');
+ if (!data) return NULL;
+ data = strstr(data+1, "?=");
+ if (!data) return NULL;
+ return data + 2;
+}
+
gchar *
gmime_rfc2047_decode (const gchar *data, const gchar *into_what)
{
@@ -185,6 +204,7 @@ gmime_rfc2047_decode (const gchar *data, const gchar *into_what)
char *word_start = strstr(data, "=?"), *decoded;
if (!word_start) {
strcpy(b, data);
+ b[strlen(data)] = 0;
return buffer;
}
if (word_start != data) {
@@ -192,14 +212,16 @@ gmime_rfc2047_decode (const gchar *data, const gchar *into_what)
if (strspn(data, " \t\n\r") != (word_start - data)) {
strncpy(b, data, word_start - data);
b += word_start - data;
+ *b = 0;
}
}
decoded = rfc2047_decode_word(word_start, into_what);
strcpy(b, decoded);
b += strlen(decoded);
+ *b = 0;
g_free(decoded);
- data = strstr(data, "?=") + 2;
+ data = find_end_of_encoded_word(data);
}
*b = 0;
diff --git a/tests/test6.c b/tests/test6.c
new file mode 100644
index 0000000000..ead8312c52
--- /dev/null
+++ b/tests/test6.c
@@ -0,0 +1,50 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* test for the RFC 2047 encoder */
+
+#include <string.h>
+#include <unicode.h>
+
+#include "gmime-utils.h"
+#include "stdio.h"
+#include "camel-log.h"
+#include "camel-mime-message.h"
+#include "camel-mime-part.h"
+#include "camel-stream.h"
+#include "camel-stream-fs.h"
+#include "camel.h"
+#include "gmime-rfc2047.h"
+
+#define TERMINAL_CHARSET "UTF-8"
+
+/*
+ * Info on many unicode issues, including, utf-8 xterms from :
+ *
+ * http://www.cl.cam.ac.uk/~mgk25/unicode.html
+ *
+ */
+
+const char *tests[] =
+{
+ "is is a test", "ISO-8859-1",
+ "Itrtinlation", "ISO-8859-1",
+ "Καλημέρα κόσμε", "UTF-8",
+ "コンニチハ", "UTF-8",
+ "ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeıʃn", "UTF-8",
+ NULL
+};
+
+
+int
+main (int argc, char**argv)
+{
+ const char **b = tests;
+ while (*b) {
+ char *e = gmime_rfc2047_encode(b[0], b[1]);
+ printf("%s\t%s\n", e, gmime_rfc2047_decode(e, TERMINAL_CHARSET));
+ b+=2;
+ }
+
+ return 0;
+
+}