From 1907e8767d37ca3fd04482eaa5635cefe41732e4 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Tue, 9 Dec 2003 00:58:46 +0000 Subject: encode the address before sending it out, rather than using the raw/utf8 2003-12-09 Not Zed * providers/smtp/camel-smtp-transport.c (smtp_send_to): encode the address before sending it out, rather than using the raw/utf8 version. * camel-internet-address.c (camel_internet_address_encode_address): check for quoting the local part of the address before outputting it. (cia_encode_addrspec): quote local part if need be. (camel_internet_address_encode_address): make folding optional based on whether inlen is null or not. * camel-mime-utils.[ch]: rename is_* to camel_mime_is_* and export the type functions. 2003-12-08 Not Zed * providers/imap/camel-imap-utils.c (imap_atom_specials): add } to the atom specials list. This isn't correct, but some busted servers expect it. Bug #50728. 2003-12-02 Not Zed * providers/local/camel-local-folder.c (local_setv): remove some debug printfs. ** See bug #51576. * camel-url.c (camel_url_decode): robustify url decoding for bad input, addresses a crash. svn path=/trunk/; revision=23676 --- camel/camel-internet-address.c | 79 ++++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 19 deletions(-) (limited to 'camel/camel-internet-address.c') diff --git a/camel/camel-internet-address.c b/camel/camel-internet-address.c index bc65ea71ea..6a82393d8d 100644 --- a/camel/camel-internet-address.c +++ b/camel/camel-internet-address.c @@ -399,6 +399,43 @@ camel_internet_address_find_address(CamelInternetAddress *a, const char *address return -1; } +static void +cia_encode_addrspec(GString *out, const char *addr) +{ + const char *at, *p; + + at = strchr(addr, '@'); + if (at == NULL) + goto append; + + p = addr; + while (p < at) { + char c = *p++; + + /* strictly by rfc, we should split local parts on dots. + however i think 2822 changes this, and not many clients grok it, so + just quote the whole local part if need be */ + if (!(camel_mime_is_atom(c) || c=='.')) { + g_string_append_c(out, '"'); + + p = addr; + while (p < at) { + c = *p++; + if (c == '"' || c == '\\') + g_string_append_c(out, '\\'); + g_string_append_c(out, c); + } + g_string_append_c(out, '"'); + g_string_append(out, p); + + return; + } + } + +append: + g_string_append(out, addr); +} + /** * camel_internet_address_encode_address: * @len: The encoded length so far, of this line @@ -406,7 +443,8 @@ camel_internet_address_find_address(CamelInternetAddress *a, const char *address * @addr: * * Encode a single address ready for internet usage. Header folding - * as per rfc 822 is also performed, based on the length in len. + * as per rfc 822 is also performed, based on the length *@inlen. If @inlen + * is NULL, then no folding will occur. * * Return value: The encoded address. **/ @@ -414,14 +452,17 @@ char * camel_internet_address_encode_address(int *inlen, const char *real, const char *addr) { char *name = camel_header_encode_phrase(real); - char *ret = NULL, *addra = NULL; - int len = *inlen; + char *ret = NULL; + int len = 0; GString *out = g_string_new(""); g_assert(addr); + if (inlen != NULL) + len = *inlen; + if (name && name[0]) { - if (strlen(name) + len > CAMEL_FOLD_SIZE) { + if (inlen != NULL && (strlen(name) + len) > CAMEL_FOLD_SIZE) { char *folded = camel_header_address_fold(name, len); char *last; g_string_append(out, folded); @@ -435,32 +476,32 @@ camel_internet_address_encode_address(int *inlen, const char *real, const char * g_string_append(out, name); len += strlen(name); } - addr = addra = g_strdup_printf(" <%s>", addr); } /* NOTE: Strictly speaking, we could and should split the * internal address up if we need to, on atom or specials * boundaries - however, to aid interoperability with mailers * that will probably not handle this case, we will just move - * the whole address to its own line */ - if (strlen(addr) + len > CAMEL_FOLD_SIZE) { + * the whole address to its own line. */ + if (inlen != NULL && (strlen(addr) + len) > CAMEL_FOLD_SIZE) { g_string_append(out, "\n\t"); - g_string_append(out, addr); - len = strlen(addr)+1; - } else { - g_string_append(out, addr); - len += strlen(addr); + len = 1; } - *inlen = len; -#if 0 + len -= out->len; + if (name && name[0]) - ret = g_strdup_printf("%s <%s>", name, addr); - else - ret = g_strdup_printf("%s", addr); -#endif + g_string_append_printf(out, " <"); + cia_encode_addrspec(out, addr); + if (name && name[0]) + g_string_append_printf(out, ">"); + + len += out->len; + + if (inlen != NULL) + *inlen = len; + g_free(name); - g_free(addra); ret = out->str; g_string_free(out, FALSE); -- cgit v1.2.3