summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2005-03-01 02:37:22 +0000
committerMichael Zucci <zucchi@src.gnome.org>2005-03-01 02:37:22 +0000
commit84cf8625d73aaf4b367c80be224f6b7aa712e715 (patch)
treeea19e7bf0fa74ab8ce2cf48a11a8689e3dbde4e9
parent43c9adec54899b74dc0392ef85f824b2904e0060 (diff)
downloadevolution-data-server-84cf8625d73aaf4b367c80be224f6b7aa712e715.tar.gz
** See bug #72609
2005-02-28 Not Zed <NotZed@Ximian.com> ** See bug #72609 * camel-mime-utils.c (header_encode_param): just call camel_charset_best once to get the best charset, and handle a NULL charset name case properly. * camel-charset-map.c (camel_charset_step): use the camel utf8 functions for robustness (&fix possible buffer-read-overflow). Perform some short-circuit optimisation when we can.
-rw-r--r--camel/ChangeLog12
-rw-r--r--camel/camel-charset-map.c45
-rw-r--r--camel/camel-mime-utils.c40
3 files changed, 40 insertions, 57 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 431fafe64..1149b683d 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,5 +1,17 @@
2005-02-28 Not Zed <NotZed@Ximian.com>
+ ** See bug #72609
+
+ * camel-mime-utils.c (header_encode_param): just call
+ camel_charset_best once to get the best charset, and handle a NULL
+ charset name case properly.
+
+ * camel-charset-map.c (camel_charset_step): use the camel utf8
+ functions for robustness (&fix possible buffer-read-overflow).
+ Perform some short-circuit optimisation when we can.
+
+2005-02-28 Not Zed <NotZed@Ximian.com>
+
** See bug #70590
* camel-filter-driver.c (do_move): Make this copy+delete, and
diff --git a/camel/camel-charset-map.c b/camel/camel-charset-map.c
index 74ab90bc5..3cfcf1740 100644
--- a/camel/camel-charset-map.c
+++ b/camel/camel-charset-map.c
@@ -200,19 +200,18 @@ int main (void)
#else
-#include "camel-charset-map.h"
-#include "camel-charset-map-private.h"
-
-#include <libedataserver/e-iconv.h>
-
#include <glib.h>
#include <locale.h>
-#include <ctype.h>
-#include <pthread.h>
#ifdef HAVE_CODESET
#include <langinfo.h>
#endif
+#include "camel-charset-map.h"
+#include "camel-charset-map-private.h"
+#include "camel-utf8.h"
+
+#include <libedataserver/e-iconv.h>
+
void
camel_charset_init (CamelCharset *c)
{
@@ -221,42 +220,34 @@ camel_charset_init (CamelCharset *c)
}
void
-camel_charset_step (CamelCharset *c, const char *in, int len)
+camel_charset_step (CamelCharset *cc, const char *in, int len)
{
register unsigned int mask;
register int level;
- const char *inptr = in, *inend = in+len;
+ const unsigned char *inptr = in, *inend = in+len;
+ register guint32 c;
- mask = c->mask;
- level = c->level;
+ mask = cc->mask;
+ level = cc->level;
/* check what charset a given string will fit in */
- while (inptr < inend) {
- gunichar c;
- const char *newinptr;
- newinptr = g_utf8_next_char(inptr);
- c = g_utf8_get_char(inptr);
- if (newinptr == NULL || !g_unichar_validate (c)) {
- inptr++;
- continue;
- }
-
- inptr = newinptr;
- if (c<=0xffff) {
+ while ( (c = camel_utf8_getc_limit(&inptr, inend)) != 0xffff) {
+ if (c < 0xffff) {
mask &= charset_mask(c);
if (c>=128 && c<256)
level = MAX(level, 1);
else if (c>=256)
- level = MAX(level, 2);
+ level = 2;
} else {
mask = 0;
- level = MAX(level, 2);
+ level = 2;
+ break;
}
}
- c->mask = mask;
- c->level = level;
+ cc->mask = mask;
+ cc->level = level;
}
/* gets the best charset from the mask of chars in it */
diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c
index 54d6d8513..6df5ed49f 100644
--- a/camel/camel-mime-utils.c
+++ b/camel/camel-mime-utils.c
@@ -2938,44 +2938,24 @@ header_encode_param (const unsigned char *in, gboolean *encoded)
const unsigned char *inptr = in;
unsigned char *outbuf = NULL;
const char *charset;
- int encoding;
GString *out;
guint32 c;
*encoded = FALSE;
g_return_val_if_fail (in != NULL, NULL);
-
- /* do a quick us-ascii check (the common case?) */
- while (*inptr) {
- if (*inptr > 127)
- break;
- inptr++;
- }
-
- if (*inptr == '\0')
- return g_strdup (in);
-
- inptr = in;
- encoding = 0;
- while ( encoding !=2 && (c = camel_utf8_getc(&inptr)) ) {
- if (c > 127 && c < 256)
- encoding = MAX (encoding, 1);
- else if (c >= 256)
- encoding = MAX (encoding, 2);
- }
- if (encoding == 2)
- charset = camel_charset_best(in, strlen(in));
- else
- charset = "iso-8859-1";
+ /* if we have really broken utf8 passed in, we just treat it as binary data */
+
+ charset = camel_charset_best(in, strlen(in));
+ if (charset == NULL)
+ return g_strdup(in);
- if (strcasecmp(charset, "UTF-8") != 0
- && (outbuf = header_convert(charset, "UTF-8", in, strlen(in)))) {
- inptr = outbuf;
- } else {
- charset = "UTF-8";
- inptr = in;
+ if (g_ascii_strcasecmp(charset, "UTF-8") != 0) {
+ if ((outbuf = header_convert(charset, "UTF-8", in, strlen(in))))
+ inptr = outbuf;
+ else
+ return g_strdup(in);
}
/* FIXME: set the 'language' as well, assuming we can get that info...? */