X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/810d16ad4b7f172163ed4bb8adc45a3d7183659a..fc4a7f705d4c5911220cf9dbb0995d9f5dbabf02:/src/src/utf8.c diff --git a/src/src/utf8.c b/src/src/utf8.c index 6bc0c2ed5..8a7cf38a3 100644 --- a/src/src/utf8.c +++ b/src/src/utf8.c @@ -24,6 +24,7 @@ return FALSE; /**************************************************/ /* Domain conversions */ +/* the *err string pointer should be null before the call */ uschar * string_domain_utf8_to_alabel(const uschar * utf8, uschar ** err) @@ -68,20 +69,27 @@ return s; /**************************************************/ /* localpart conversions */ +/* the *err string pointer should be null before the call */ uschar * string_localpart_utf8_to_alabel(const uschar * utf8, uschar ** err) { size_t ucs4_len; -punycode_uint * p = (punycode_uint *) stringprep_utf8_to_ucs4(CCS utf8, -1, &ucs4_len); -size_t p_len = ucs4_len*4; /* this multiplier is pure guesswork */ -uschar * res = store_get(p_len+5); +punycode_uint * p; +size_t p_len; +uschar * res; int rc; +if (!string_is_utf8(utf8)) return string_copy(utf8); + +p = (punycode_uint *) stringprep_utf8_to_ucs4(CCS utf8, -1, &ucs4_len); +p_len = ucs4_len*4; /* this multiplier is pure guesswork */ +res = store_get(p_len+5); + res[0] = 'x'; res[1] = 'n'; res[2] = res[3] = '-'; -if ((rc = punycode_encode(ucs4_len, p, NULL, &p_len, res+4)) != PUNYCODE_SUCCESS) +if ((rc = punycode_encode(ucs4_len, p, NULL, &p_len, CS res+4)) != PUNYCODE_SUCCESS) { DEBUG(D_expand) debug_printf("l_u2a: bad '%s'\n", punycode_strerror(rc)); free(p); @@ -98,7 +106,7 @@ return res; uschar * string_localpart_alabel_to_utf8(const uschar * alabel, uschar ** err) { -size_t p_len = strlen(alabel); +size_t p_len = Ustrlen(alabel); punycode_uint * p; uschar * s; uschar * res; @@ -119,13 +127,48 @@ if ((rc = punycode_decode(p_len, CCS alabel+4, &p_len, p, NULL)) != PUNYCODE_SUC return NULL; } -s = stringprep_ucs4_to_utf8(p, p_len, NULL, &p_len); +s = US stringprep_ucs4_to_utf8(p, p_len, NULL, &p_len); res = string_copyn(s, p_len); free(s); return res; } +/**************************************************/ +/* whole address conversion */ +/* the *err string pointer should be null before the call */ + +uschar * +string_address_utf8_to_alabel(const uschar * utf8, uschar ** err) +{ +const uschar * s; +uschar * l; +uschar * d; + +if (!*utf8) return string_copy(utf8); + +DEBUG(D_expand) debug_printf("addr from utf8 <%s>", utf8); + +for (s = utf8; *s; s++) + if (*s == '@') + { + l = string_copyn(utf8, s - utf8); + if ( (l = string_localpart_utf8_to_alabel(l, err), err && *err) + || (d = string_domain_utf8_to_alabel(++s, err), err && *err) + ) + return NULL; + l = string_sprintf("%s@%s", l, d); + DEBUG(D_expand) debug_printf(" -> <%s>\n", l); + return l; + } + +l = string_localpart_utf8_to_alabel(utf8, err); +DEBUG(D_expand) debug_printf(" -> <%s>\n", l); +return l; +} + + + /************************************************* * Report the library versions. * *************************************************/