diff options
author | Michael Zucci <zucchi@src.gnome.org> | 2000-11-24 15:06:45 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2000-11-24 15:06:45 +0800 |
commit | 05aaadc66b77c9f080b590fa19938de8ec80691d (patch) | |
tree | 29a0a25e2261139de414e4a6172e678fafa4322b /camel/camel-mime-utils.c | |
parent | 189cb50426fc12b55a79c67a00064623ec964383 (diff) | |
download | gsoc2013-evolution-05aaadc66b77c9f080b590fa19938de8ec80691d.tar.gz gsoc2013-evolution-05aaadc66b77c9f080b590fa19938de8ec80691d.tar.zst gsoc2013-evolution-05aaadc66b77c9f080b590fa19938de8ec80691d.zip |
little util to scan mailboxes for any and every address they contain.
* tests/data/getaddr.pl: little util to scan mailboxes for any and
every address they contain.
* tests/message/test2.c (main): Added a bunch of stuff to test
decoding/reencoding/etc of internationalised addresses.
* tests/message/lib/address-data.h: Copy of some unicode/other
testing data. **Beware** of editing this file in emacs, it'll
probably try and convert all the characters to something
unusable.
* tests/lib/camel-test.c (camel_test_break): Add a debugger hook
point.
* camel-mime-utils.c (quoted_encode): Check for space and convert
to _ separately.
(header_decode_mailbox): Fixed the 'check comments for realname'
code, problem was the domain getting code was skipping all
whitespace/comments before we could get a look-in. This is
approximate but fairly robust.
(header_decode_text): Dont use the c-type isspace func here, we
want a specific whitespace only.
(header_decode_text): If we have decoded words next to each other,
do not insert whitespaces between them, which is what rfc2047 requires.
(header_decode_text): Make c unsigned too.
svn path=/trunk/; revision=6658
Diffstat (limited to 'camel/camel-mime-utils.c')
-rw-r--r-- | camel/camel-mime-utils.c | 70 |
1 files changed, 51 insertions, 19 deletions
diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c index 238b34156e..f1f08e25a0 100644 --- a/camel/camel-mime-utils.c +++ b/camel/camel-mime-utils.c @@ -809,9 +809,9 @@ quoted_encode(const unsigned char *in, int len, unsigned char *out, unsigned sho outptr = out; while (inptr < inend) { c = *inptr++; - if (camel_mime_special_table[c] & safemask) { - if (c==' ') - c = '_'; + if (c==' ') { + *outptr++ = '_'; + } else if (camel_mime_special_table[c] & safemask) { *outptr++ = c; } else { *outptr++ = '='; @@ -983,15 +983,17 @@ header_decode_text (const char *in, int inlen) GString *out; char *inptr, *inend, *start; char *decoded; - + unsigned char lastc = 0; + int wasdword = FALSE; + out = g_string_new (""); start = inptr = (char *) in; inend = inptr + inlen; while (inptr && inptr < inend) { - char c = *inptr++; + unsigned char c = *inptr++; - if (isspace (c)) { + if (is_lwsp(c)) { char *word, *dword; guint len; @@ -999,16 +1001,23 @@ header_decode_text (const char *in, int inlen) word = start; dword = rfc2047_decode_word (word, len); - + if (dword) { + if (!wasdword && lastc) + g_string_append_c(out, lastc); + g_string_append (out, dword); g_free (dword); + lastc = c; + wasdword = TRUE; } else { + if (lastc) + g_string_append_c(out, lastc); out = append_latin1 (out, word, len); + lastc = c; + wasdword = FALSE; } - - g_string_append_c (out, c); - + start = inptr; } } @@ -1023,9 +1032,13 @@ header_decode_text (const char *in, int inlen) dword = rfc2047_decode_word (word, len); if (dword) { + if (!wasdword && lastc) + g_string_append_c(out, lastc); g_string_append (out, dword); g_free (dword); } else { + if (lastc) + g_string_append_c(out, lastc); out = g_string_append_len (out, word, len); } } @@ -1797,6 +1810,7 @@ header_decode_mailbox(const char **in) GString *addr; GString *name = NULL; struct _header_address *address = NULL; + const char *comment = NULL; addr = g_string_new(""); @@ -1862,6 +1876,7 @@ header_decode_mailbox(const char **in) addr = g_string_append_c(addr, '.'); addr = g_string_append(addr, pre); } + comment = inptr; header_decode_lwsp(&inptr); } g_free(pre); @@ -1872,6 +1887,7 @@ header_decode_mailbox(const char **in) inptr++; addr = g_string_append_c(addr, '@'); + comment = inptr; dom = header_decode_domain(&inptr); addr = g_string_append(addr, dom); g_free(dom); @@ -1886,17 +1902,33 @@ header_decode_mailbox(const char **in) } else { w(g_warning("invalid route address, no closing '>': %s", *in)); } - } else if (name == NULL) { /* check for comment after address */ + } else if (name == NULL && comment != NULL && inptr>comment) { /* check for comment after address */ char *text, *tmp; - const char *comment = inptr; + const char *comstart, *comend; - header_decode_lwsp(&inptr); - if (inptr-comment > 3) { /* just guess ... */ - tmp = g_strndup(comment, inptr-comment); - text = header_decode_string(tmp); - name = g_string_new(text); - g_free(tmp); - g_free(text); + /* this is a bit messy, we go from the last known position, because + decode_domain/etc skip over any comments on the way */ + /* FIXME: This wont detect comments inside the domain itself, + but nobody seems to use that feature anyway ... */ + + d(printf("checking for comment from '%s'\n", comment)); + + comstart = strchr(comment, '('); + if (comstart) { + comstart++; + header_decode_lwsp(&inptr); + comend = inptr-1; + while (comend > comstart && comend[0] != ')') + comend--; + + if (comend > comstart) { + d(printf(" looking at subset '%.*s'\n", comend-comstart, comstart)); + tmp = g_strndup(comstart, comend-comstart); + text = header_decode_string(tmp); + name = g_string_new(text); + g_free(tmp); + g_free(text); + } } } |