*e = u, *elen = ulen;
*e = u; *elen = ulen;
static int rfc2047_encode (const char *d, size_t dlen, int col,			   const char *fromcode, const char *charsets,			   char **e, size_t *elen){  int ret = 0;  char *buf;  size_t bufpos, buflen;  char *u, *t0, *t1, *t;  size_t ulen, r, n, wlen;  encoder_t encoder;  char *tocode1 = 0;  const char *tocode;  char *icode = "UTF-8";  /* Try to convert to UTF-8. */  if (convert_string (d, dlen, fromcode, icode, &u, &ulen))  {    ret = 1, icode = 0;    u = safe_malloc (ulen = dlen), memcpy (u, d, dlen);  }  /* Find earliest and latest things we must encode. */  t0 = t1 = 0;  for (t = u; t < u + ulen - 1; t++)    if ((*t & 0x80) ||	(*t == '=' && t[1] == '?' && (t == u || HSPACE(*(t-1)))))      t0 = t0 ? t0 : t, t1 = t;  if (t == u + ulen - 1 && (*t & 0x80))    t0 = t0 ? t0 : t, t1 = t;  if (!t0)  {    /* No encoding is required. */    *e = u, *elen = ulen;    return ret;  }  /* Choose target charset. */  tocode = fromcode;  if (icode)  {    if ((tocode1 = mutt_choose_charset (icode, charsets, u, ulen, 0, 0)))      tocode = tocode1;    else      ret = 2, icode = 0;  }  /* Hack to avoid labelling 8-bit data as us-ascii. */  if (!icode && mutt_is_us_ascii (tocode))    tocode = "unknown-8bit";    /* Adjust t0 for maximum length of line. */  t = u + (ENCWORD_LEN_MAX + 1) - col - ENCWORD_LEN_MIN;  t = t > u ? t : u;  t0 = t < t0 ? t : t0;  /* Adjust t0 until we can encode a character after a space. */  for (; t0 > u; t0--)  {    if (!HSPACE(*(t0-1)))      continue;    for (t = t0 + 1; t < u + ulen && (*t & 0xc0) == 0x80; t++)      ;    if (!try_block (t0, t - t0, icode, tocode, &encoder, &wlen) &&	col + (t0 - u) + wlen <= ENCWORD_LEN_MAX + 1)      break;  }  /* Adjust t1 until we can encode a character before a space. */  for (; t1 < u + ulen; t1++)  {    if (!HSPACE(*t1))      continue;    for (t = t1 - 1; (*t & 0xc0) == 0x80; t--)      ;    if (!try_block (t, t1 - t, icode, tocode, &encoder, &wlen) &&	1 + wlen + (u + ulen - t1) <= ENCWORD_LEN_MAX + 1)      break;  }  /* We shall encode the region [t0,t1). */  /* Initialise the output buffer with the us-ascii prefix. */  buflen = 2 * ulen;  buf = safe_malloc (buflen);  bufpos = t0 - u;  memcpy (buf, u, t0 - u);  col += t0 - u;  t = t0;  for (;;)  {    /* Find how much we can encode. */    n = choose_block (t, t1 - t, col, icode, tocode, &encoder, &wlen);    if (n == t1 - t)    {      /* See if we can fit the us-ascii suffix, too. */      if (col + wlen + (u + ulen - t1) <= ENCWORD_LEN_MAX + 1)	break;      for (n = t1 - t - 1; (t[n] & 0xc0) == 0x80; n--)	;      assert (t + n >= t);      if (!n)      {	/* This should only happen in the really stupid case where the	   only word that needs encoding is one character long, but	   there is too much us-ascii stuff after it to use a single	   encoded word. We add the next word to the encoded region	   and try again. */	assert (t1 < u + ulen);	for (t1++; t1 < u + ulen && !HSPACE(*t1); t1++)	  ;	continue;      }      n = choose_block (t, n, col, icode, tocode, &encoder, &wlen);    }    /* Add to output buffer. */#define LINEBREAK "\n\t"    if (bufpos + wlen + strlen (LINEBREAK) > buflen)    {      buflen = bufpos + wlen + strlen (LINEBREAK);      safe_realloc ((void **) &buf, buflen);    }    r = encode_block (buf + bufpos, t, n, icode, tocode, encoder);    assert (r == wlen);    bufpos += wlen;    memcpy (buf + bufpos, LINEBREAK, strlen (LINEBREAK));    bufpos += strlen (LINEBREAK);#undef LINEBREAK    col = 1;    t += n;  }  /* Add last encoded word and us-ascii suffix to buffer. */  buflen = bufpos + wlen + (u + ulen - t1);  safe_realloc ((void **) &buf, buflen);  r = encode_block (buf + bufpos, t, t1 - t, icode, tocode, encoder);  assert (r == wlen);  bufpos += wlen;  memcpy (buf + bufpos, t1, u + ulen - t1);  free (tocode1);  free (u);  *e = buf;  *elen = buflen;  return ret;}