diff options
author | Jeffrey Stedfast <fejj@novell.com> | 2004-08-13 00:33:25 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2004-08-13 00:33:25 +0800 |
commit | b58176fd489aaac131e27c9d091c4f6c8b228d49 (patch) | |
tree | f595df0260f6eee94bc589e4d8d41b0f7fb7c840 /camel | |
parent | 56e481b2441a23bdc08fb19ad355f2a1490cdcac (diff) | |
download | gsoc2013-evolution-b58176fd489aaac131e27c9d091c4f6c8b228d49.tar.gz gsoc2013-evolution-b58176fd489aaac131e27c9d091c4f6c8b228d49.tar.zst gsoc2013-evolution-b58176fd489aaac131e27c9d091c4f6c8b228d49.zip |
Fix for bug #62771
2004-08-11 Jeffrey Stedfast <fejj@novell.com>
Fix for bug #62771
* camel-mime-utils.c (append_quoted_pair): New function to append
a string of text that may contain quoted-pairs.
(header_decode_text): Now takes a ctext argument specifying
whether or not to expect comments and to handle them.
(camel_header_decode_string): Pass FALSE as ctext argument.
(camel_header_format_ctext): New function to format text|comment
header field bodies.
svn path=/trunk/; revision=26888
Diffstat (limited to 'camel')
-rw-r--r-- | camel/ChangeLog | 12 | ||||
-rw-r--r-- | camel/camel-mime-utils.c | 48 | ||||
-rw-r--r-- | camel/camel-mime-utils.h | 3 |
3 files changed, 56 insertions, 7 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index c4c1bf546c..c11eb08c67 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,15 @@ +2004-08-11 Jeffrey Stedfast <fejj@novell.com> + + Fix for bug #62771 + + * camel-mime-utils.c (append_quoted_pair): New function to append + a string of text that may contain quoted-pairs. + (header_decode_text): Now takes a ctext argument specifying + whether or not to expect comments and to handle them. + (camel_header_decode_string): Pass FALSE as ctext argument. + (camel_header_format_ctext): New function to format text|comment + header field bodies. + 2004-08-10 Not Zed <NotZed@Ximian.com> * providers/groupwise/camel-gw-listener.c diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c index 798da0d3fd..314359c654 100644 --- a/camel/camel-mime-utils.c +++ b/camel/camel-mime-utils.c @@ -1118,16 +1118,42 @@ append_8bit (GString *out, const char *inbuf, size_t inlen, const char *charset) } +static void +append_quoted_pair (GString *str, const char *in, int inlen) +{ + register const char *inptr = in; + const char *inend = in + inlen; + char c; + + while (inptr < inend) { + c = *inptr++; + if (c == '\\' && inptr < inend) + g_string_append_c (str, *inptr++); + else + g_string_append_c (str, c); + } +} + /* decodes a simple text, rfc822 + rfc2047 */ static char * -header_decode_text (const char *in, size_t inlen, const char *default_charset) +header_decode_text (const char *in, size_t inlen, int ctext, const char *default_charset) { GString *out; const char *inptr, *inend, *start, *chunk, *locale_charset; + void (* append) (GString *, const char *, int); char *dword = NULL; + guint32 mask; locale_charset = e_iconv_locale_charset (); + if (ctext) { + mask = (CAMEL_MIME_IS_SPECIAL | CAMEL_MIME_IS_SPACE | CAMEL_MIME_IS_CTRL); + append = append_quoted_pair; + } else { + mask = (CAMEL_MIME_IS_LWSP); + append = g_string_append; + } + out = g_string_new (""); inptr = in; inend = inptr + inlen; @@ -1135,20 +1161,20 @@ header_decode_text (const char *in, size_t inlen, const char *default_charset) while (inptr < inend) { start = inptr; - while (inptr < inend && camel_mime_is_lwsp(*inptr)) + while (inptr < inend && camel_mime_is_type (*inptr, mask)) inptr++; if (inptr == inend) { - g_string_append_len(out, start, inptr-start); + append (out, start, inptr - start); break; } else if (dword == NULL) { - g_string_append_len(out, start, inptr-start); + append (out, start, inptr - start); } else { chunk = start; } start = inptr; - while (inptr < inend && !camel_mime_is_lwsp(*inptr)) + while (inptr < inend && !camel_mime_is_type (*inptr, mask)) inptr++; dword = rfc2047_decode_word(start, inptr-start); @@ -1178,7 +1204,15 @@ camel_header_decode_string (const char *in, const char *default_charset) { if (in == NULL) return NULL; - return header_decode_text (in, strlen (in), default_charset); + return header_decode_text (in, strlen (in), FALSE, default_charset); +} + +char * +camel_header_format_ctext (const char *in, const char *default_charset) +{ + if (in == NULL) + return NULL; + return header_decode_text (in, strlen (in), TRUE, default_charset); } /* how long a sequence of pre-encoded words should be less than, to attempt to @@ -2830,7 +2864,7 @@ header_append_param(struct _camel_header_param *last, char *name, char *value) 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), FALSE, NULL))) { g_free(value); } else if (!g_utf8_validate(value, -1, NULL)) { const char * charset = e_iconv_locale_charset(); diff --git a/camel/camel-mime-utils.h b/camel/camel-mime-utils.h index 23987a5c16..c75b8461c5 100644 --- a/camel/camel-mime-utils.h +++ b/camel/camel-mime-utils.h @@ -194,6 +194,9 @@ int camel_header_decode_int (const char **in); char *camel_header_decode_string (const char *in, const char *default_charset); char *camel_header_encode_string (const unsigned char *in); +/* decode (text | comment) - 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); |