Re: [evolution-patches] fix for bug #62771 (User-Agent doesn't get decoded in mail view)
- From: Not Zed <notzed ximian com>
- To: Jeffrey Stedfast <fejj ximian com>
- Cc: evolution-patches ximian com
- Subject: Re: [evolution-patches] fix for bug #62771 (User-Agent doesn't get decoded in mail view)
- Date: Wed, 11 Aug 2004 11:06:51 +0800
Don't like this, it just duplicates a bunch of code. See attached (totally untested but i think the logic is right).
I don't really like it as a ctext decoder anyway, it isn't actually decoding to the rfc, it is just a simplistic scanner which will 'probably work in most cases'. e.g. it doesn't handle \ properly in comments. Then again, this is hardly a major issue.
The other problem is that it is necessarily a one-way conversion (you will have to lose the comment structure), perhaps it should be called _format rather than _decode, to match the rest of the api (i put this in the patch).
Index: camel/camel-mime-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-mime-utils.c,v
retrieving revision 1.212
diff -u -3 -r1.212 camel-mime-utils.c
--- camel/camel-mime-utils.c 30 Jul 2004 15:30:38 -0000 1.212
+++ camel/camel-mime-utils.c 11 Aug 2004 03:03:33 -0000
@@ -57,6 +57,9 @@
#include "broken-date-parser.h"
#endif
+/* syntactic helper for more direct table lookups */
+#define cm_is_mask(x, m) ((camel_mime_special_table[(unsigned char)(x)] & (m)) == 0)
+
#if 0
int strdup_count = 0;
int malloc_count = 0;
@@ -1119,13 +1122,15 @@
}
/* decodes a simple text, rfc822 + rfc2047 */
+/* If ctext is set, look for rfc2047 encoded words not separated by whitespace */
static char *
-header_decode_text (const char *in, size_t inlen, const char *default_charset)
+header_decode_text (const char *in, size_t inlen, const char *default_charset, int ctext)
{
GString *out;
const char *inptr, *inend, *start, *chunk, *locale_charset;
char *dword = NULL;
-
+ int mask;
+
locale_charset = e_iconv_locale_charset ();
out = g_string_new ("");
@@ -1133,9 +1138,14 @@
inend = inptr + inlen;
chunk = NULL;
+ if (ctext)
+ mask = (CAMEL_MIME_IS_SPECIAL|CAMEL_MIME_IS_SPACE|CAMEL_MIME_IS_CTRL);
+ else
+ mask = (CAMEL_MIME_IS_LWSP);
+
while (inptr < inend) {
start = inptr;
- while (inptr < inend && camel_mime_is_lwsp(*inptr))
+ while (inptr < inend && !cm_is_mask(*inptr, mask))
inptr++;
if (inptr == inend) {
@@ -1148,7 +1158,7 @@
}
start = inptr;
- while (inptr < inend && !camel_mime_is_lwsp(*inptr))
+ while (inptr < inend && cm_is_mask(*inptr, mask))
inptr++;
dword = rfc2047_decode_word(start, inptr-start);
@@ -1178,7 +1188,15 @@
{
if (in == NULL)
return NULL;
- return header_decode_text (in, strlen (in), default_charset);
+ return header_decode_text (in, strlen (in), default_charset, FALSE);
+}
+
+char *
+camel_header_format_ctext(const char *in, const char *default_charset)
+{
+ if (in == NULL)
+ return NULL;
+ return header_decode_text (in, strlen (in), default_charset, TRUE);
}
/* how long a sequence of pre-encoded words should be less than, to attempt to
@@ -2830,7 +2848,7 @@
node->next = NULL;
node->name = name;
if (strncmp(value, "=?", 2) == 0
- && (node->value = header_decode_text(value, strlen(value), NULL))) {
+ && (node->value = header_decode_text(value, strlen(value), NULL, FALSE))) {
g_free(value);
} else if (!g_utf8_validate(value, -1, NULL)) {
const char * charset = e_iconv_locale_charset();
Index: camel/camel-mime-utils.h
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-mime-utils.h,v
retrieving revision 1.56
diff -u -3 -r1.56 camel-mime-utils.h
--- camel/camel-mime-utils.h 18 Jun 2004 20:07:09 -0000 1.56
+++ camel/camel-mime-utils.h 11 Aug 2004 03:03:33 -0000
@@ -193,6 +193,8 @@
/* decode/encode a string type, like a subject line */
char *camel_header_decode_string (const char *in, const char *default_charset);
char *camel_header_encode_string (const unsigned char *in);
+/* decode ( text | comment ), this is a one-way op */
+char *camel_header_format_ctext(const char *in, const char *default_charset);
/* encode a phrase, like the real name of an address */
char *camel_header_encode_phrase (const unsigned char *in);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]