int prev;
static int rfc2047_encode (const char *d, size_t dlen,			   const char *fromcode, const char *charsets,			   char **e, size_t *elen){  char *buf = 0;  size_t bufpos = 0, buflen = 0;  char *u0, *u;  size_t ulen;  char *tocode;  int prev;  /* Convert to UTF-8. */  if (convert_string (d, dlen, fromcode, "UTF-8", &u, &ulen))    return 1;  u0 = u;  /* Choose target charset. */  tocode = choose_charset (charsets, u, ulen);  if (!tocode)  {    free (u);    return 2;  }  for (prev = 0; ulen; prev = 1) {    char *t;    size_t n, wlen, r;    encoder_t encoder;    /* Decide where to start encoding. */    if (prev && ulen && !HSPACE (*u))      t = u;    else    {      /* Look for a non-us-ascii chararcter or "=?". */      for (t = u; t < u + ulen - 1; t++)	if ((*t & 0x80) || (*t == '=' && t[1] == '?'))	  break;      if (t == u + ulen - 1 && !(*t & 0x80))	break;      /* Find start of that word. */      while (t > u && !HSPACE(*(t-1)))	--t;      if (prev) {	/* Include preceding characters if they are all spaces. */	const char *x;	for (x = u; x < t && HSPACE(*x); x++)	  ;	if (x >= t)	  t = u;      }    }    /* Convert some data and add encoded word to buffer. */    n = choose_block (t, (u + ulen) - t, tocode, &wlen, &encoder);    buflen = bufpos + (t == u && prev) + (t - u) + wlen;    safe_realloc ((void **) &buf, buflen);    if (t == u && prev)      buf[bufpos++] = ' ';    memcpy (buf + bufpos, u, t - u);    bufpos += t - u;    r = encode_block (buf + bufpos, t, n, tocode, encoder);    assert (r == wlen);    bufpos += wlen;    n += t - u;    u += n;    ulen -= n;  }  /* Add remaining us-ascii characters to buffer. */  buflen = bufpos + ulen;  safe_realloc ((void **) &buf, buflen);  memcpy (buf + bufpos, u, ulen);  free (tocode);  free (u0);  *e = buf;  *elen = buflen;  return 0;}