smtp input
[exim.git] / src / src / utf8.c
index 2f8173dc1ad219d1d07e51e6fb6f69450c5ee9b3..32d2eaed043080fd9e8322ab05d1a60eb037fb2a 100644 (file)
@@ -82,10 +82,12 @@ res[0] = 'x'; res[1] = 'n'; res[2] = res[3] = '-';
 
 if ((rc = punycode_encode(ucs4_len, p, NULL, &p_len, res+4)) != PUNYCODE_SUCCESS)
   {
+  DEBUG(D_expand) debug_printf("l_u2a: bad '%s'\n", punycode_strerror(rc));
   free(p);
   if (err) *err = US punycode_strerror(rc);
   return NULL;
   }
+p_len += 4;
 free(p);
 res[p_len] = '\0';
 return res;
@@ -97,6 +99,8 @@ string_localpart_alabel_to_utf8(const uschar * alabel, uschar ** err)
 {
 size_t p_len = strlen(alabel);
 punycode_uint * p;
+uschar * s;
+uschar * res;
 int rc;
 
 if (alabel[0] != 'x' || alabel[1] != 'n' || alabel[2] != '-' || alabel[3] != '-')
@@ -104,8 +108,8 @@ if (alabel[0] != 'x' || alabel[1] != 'n' || alabel[2] != '-' || alabel[3] != '-'
   if (err) *err = US"bad alabel prefix";
   return NULL;
   }
-p_len -= 4;
 
+p_len -= 4;
 p = (punycode_uint *) store_get((p_len+1) * sizeof(*p));
 
 if ((rc = punycode_decode(p_len, CCS alabel+4, &p_len, p, NULL)) != PUNYCODE_SUCCESS)
@@ -113,8 +117,11 @@ if ((rc = punycode_decode(p_len, CCS alabel+4, &p_len, p, NULL)) != PUNYCODE_SUC
   if (err) *err = US punycode_strerror(rc);
   return NULL;
   }
-p[p_len] = 0;
-return US p;
+
+s = stringprep_ucs4_to_utf8(p, p_len, NULL, &p_len);
+res = string_copyn(s, p_len);
+free(s);
+return res;
 }