if (mutt_is_utf8 (dest) && !mutt_is_utf8 (src)) { mutt_error (_("We can't currently handle utf-8 at this point.")); return -1; }
int mutt_recode_file (const char *fname, const char *src, const char *dest){  FILE *fp, *tmpfp;  char tempfile[_POSIX_PATH_MAX];  char buffer[1024];  char tmp[1024];  int c;  int rv = -1;  int source_file_is_unchanged = 1;  size_t lf, lpu, lpo;  char *t;  DECODER *dec;  if (mutt_is_utf8 (dest) && !mutt_is_utf8 (src))  {    mutt_error (_("We can't currently handle utf-8 at this point."));    return -1;  }  if ((fp = fopen (fname, "r+")) == NULL)  {    mutt_error (_("Can't open %s: %s."), fname, strerror (errno));    return -1;  }    mutt_mktemp (tempfile);  if ((tmpfp = safe_fopen (tempfile, "w+")) == NULL)  {    mutt_error (_("Can't open %s: %s."), tempfile, strerror (errno));    fclose (fp);    return -1;  }  dec = mutt_open_decoder (src, dest);    while ((lf = fread (buffer, 1, sizeof (buffer), fp)) > 0)  {    for (t = buffer; lf; t += lpu)    {      mutt_decoder_push (dec, t, lf, &lpu);      lf -= lpu;            do      {	mutt_decoder_pop (dec, tmp, sizeof (tmp), &lpo);	if (lpo)	{	  if (fwrite (tmp, lpo, 1, tmpfp) == EOF)	    goto bail;	}      }       while (lpo);    }  }  if (lf == EOF && !feof(fp))  {    goto bail;  }  mutt_decoder_push (dec, NULL, 0, NULL);  do   {    mutt_decoder_pop (dec, tmp, sizeof (tmp), &lpo);    if (lpo)    {      if (fwrite (tmp, lpo, 1, tmpfp) == EOF)	goto bail;    }  }  while (lpo);  mutt_free_decoder (&dec);  fclose (fp); fp = NULL;  rewind (tmpfp);  source_file_is_unchanged = 0;  /* don't use safe_fopen here - we're just going   * to overwrite the old file.   */  if ((fp = fopen (fname, "w")) == NULL)    goto bail;    while ((c = fgetc (tmpfp)) != EOF)    if (fputc (c, fp) == EOF)      goto bail;  rv = 0;  unlink (tempfile);  bail:  if (rv == -1)  {    if (source_file_is_unchanged)    {      mutt_error (_("Error while recoding %s. "		    "Leave it unchanged."),		  fname);    }    else    {      mutt_error (_("Error while recoding %s. "		    "See %s for recovering your data."),		  fname, tempfile);    }  }  if (fp) fclose (fp);  if (tmpfp) fclose (tmpfp);  return rv;}