if (override_charset && 0 != nsCRT::strcasecmp(charset, "UTF-8")) {
if ((override_charset && 0 != nsCRT::strcasecmp(charset, "UTF-8")) || (default_charset && 0 == nsCRT::strcasecmp(charset, "UNKNOWN-8BIT"))) {
char *intl_decode_mime_part2_str(const char *header,  const char *default_charset, PRBool override_charset){  char *output_p = NULL;  char *retbuff = NULL;  const char *p, *q, *r;  char *decoded_text;  const char *begin; /* tracking pointer for where we are in the input buffer */  PRInt32 last_saw_encoded_word = 0;  const char *charset_start, *charset_end;  char charset[80];  nsAutoString tempUnicodeString;  // initialize charset name to an empty string  charset[0] = '\0';  /* Assume no more than 3X expansion due to UTF-8 conversion */  retbuff = (char *)PR_Malloc(3*strlen(header)+1);  if (retbuff == NULL)    return NULL;  output_p = retbuff;  begin = header;  while ((p = PL_strstr(begin, "=?")) != 0) {    if (last_saw_encoded_word) {      /* See if it's all whitespace. */      for (q = begin; q < p; q++) {        if (!PL_strchr(" \t\r\n", *q)) break;      }    }    if (!last_saw_encoded_word || q < p) {      /* copy the part before the encoded-word */      intl_copy_uncoded_header(&output_p, begin, p - begin, default_charset);      begin = p;    }    p += 2;    /* Get charset info */    charset_start = p;    charset_end = 0;    for (q = p; *q != '?'; q++) {      if (*q <= ' ' || PL_strchr(especials, *q)) {        goto badsyntax;      }      /* RFC 2231 section 5 */      if (!charset_end && *q == '*') {        charset_end = q;       }    }    if (!charset_end) {      charset_end = q;    }    /* Check for too-long charset name */    if ((unsigned)(charset_end - charset_start) >= sizeof(charset)) goto badsyntax;        memcpy(charset, charset_start, charset_end - charset_start);    charset[charset_end - charset_start] = 0;    q++;    if (*q != 'Q' && *q != 'q' && *q != 'B' && *q != 'b')      goto badsyntax;    if (q[1] != '?')      goto badsyntax;    r = q;    for (r = q + 2; *r != '?'; r++) {      if (*r < ' ') goto badsyntax;    }    if (r[1] != '=')	    goto badsyntax;    else if (r == q + 2) {	    // it's empty, skip	    begin = r + 2;	    last_saw_encoded_word = 1;	    continue;    }    if(*q == 'Q' || *q == 'q')      decoded_text = intlmime_decode_q(q+2, r - (q+2));    else      decoded_text = intlmime_decode_b(q+2, r - (q+2));    if (decoded_text == NULL)      goto badsyntax;    // Override charset if requested.  Never override labeled UTF-8.    if (override_charset && 0 != nsCRT::strcasecmp(charset, "UTF-8")) {      PL_strncpy(charset, default_charset, sizeof(charset)-1);      charset[sizeof(charset)-1] = '\0';    }    if (NS_SUCCEEDED(ConvertToUnicode(charset, decoded_text, tempUnicodeString))) {      NS_ConvertUCS2toUTF8 utf8_text(tempUnicodeString.get());      PRInt32 utf8_len = utf8_text.Length();      memcpy(output_p, utf8_text.get(), utf8_len);      output_p += utf8_len;    } else {      PL_strcpy(output_p, "\347\277\275"); /* UTF-8 encoding of U+FFFD */      output_p += 3;    }    PR_Free(decoded_text);    begin = r + 2;    last_saw_encoded_word = 1;    continue;  badsyntax:    /* copy the part before the encoded-word */    PL_strncpy(output_p, begin, p - begin);    output_p += p - begin;    begin = p;    last_saw_encoded_word = 0;  }  /* put the tail back  */  intl_copy_uncoded_header(&output_p, begin, strlen(begin), default_charset);  *output_p = '\0';  convert_htab(retbuff);  return retbuff;}