{ if (!nsCRT::strcasecmp(text->charset, "us-ascii")) SetMailCharacterSetToMsgWindow(body, NS_LITERAL_STRING("ISO-8859-1").get()); else SetMailCharacterSetToMsgWindow(body, NS_ConvertASCIItoUCS2(text->charset).get()); }
SetMailCharacterSetToMsgWindow(body, text->charset);
MimeMessage_close_headers (MimeObject *obj){  MimeMessage *msg = (MimeMessage *) obj;  int status = 0;  char *ct = 0;			/* Content-Type header */  MimeObject *body;  if (msg->hdrs)	{	  PRBool outer_p = !obj->headers; /* is this the outermost message? */#ifdef MIME_DRAFTS	  if (outer_p &&		  obj->options &&          (obj->options->decompose_file_p || obj->options->caller_need_root_headers) &&		  obj->options->decompose_headers_info_fn)		{#ifdef ENABLE_SMIME      if (obj->options->decrypt_p && !mime_crypto_object_p (msg->hdrs, PR_FALSE))        obj->options->decrypt_p = PR_FALSE;#endif /* ENABLE_SMIME */      if (!obj->options->caller_need_root_headers || (obj == obj->options->state->root))		  	status = obj->options->decompose_headers_info_fn (												 obj->options->stream_closure,															 msg->hdrs );		}#endif /* MIME_DRAFTS */	  /* If this is the outermost message, we need to run the		 `generate_header' callback.  This happens here instead of		 in `parse_begin', because it's only now that we've parsed		 our headers.  However, since this is the outermost message,		 we have yet to write any HTML, so that's fine.	   */	  if (outer_p &&		  obj->output_p &&		  obj->options &&		  obj->options->write_html_p &&		  obj->options->generate_header_html_fn)		{		  int lstatus = 0;		  char *html = 0;		  /* The generate_header_html_fn might return HTML, so it's important			 that the output stream be set up with the proper type before we			 make the MimeObject_write() call below. */		  if (!obj->options->state->first_data_written_p)			{			  lstatus = MimeObject_output_init (obj, TEXT_HTML);			  if (lstatus < 0) return lstatus;			  PR_ASSERT(obj->options->state->first_data_written_p);			}		  html = obj->options->generate_header_html_fn(NULL,												   obj->options->html_closure,													   msg->hdrs);		  if (html)			{			  lstatus = MimeObject_write(obj, html, strlen(html), PR_FALSE);			  PR_Free(html);			  if (lstatus < 0) return lstatus;			}		}	  /* Find the content-type of the body of this message.	   */	  {		PRBool ok = PR_TRUE;		char *mv = MimeHeaders_get (msg->hdrs, HEADER_MIME_VERSION,									PR_TRUE, PR_FALSE);#ifdef REQUIRE_MIME_VERSION_HEADER		/* If this is the outermost message, it must have a MIME-Version		   header with the value 1.0 for us to believe what might be in		   the Content-Type header.  If the MIME-Version header is not		   present, we must treat this message as untyped.		 */		ok = (mv && !nsCRT::strcmp(mv, "1.0"));#else		/* #### actually, we didn't check this in Mozilla 2.0, and checking		   it now could cause some compatibility nonsense, so for now, let's		   just believe any Content-Type header we see.		 */		ok = PR_TRUE;#endif		if (ok)		  {			ct = MimeHeaders_get (msg->hdrs, HEADER_CONTENT_TYPE, PR_TRUE, PR_FALSE);			/* If there is no Content-Type header, but there is a MIME-Version			   header, then assume that this *is* in fact a MIME message.			   (I've seen messages with				  MIME-Version: 1.0				  Content-Transfer-Encoding: quoted-printable			   and no Content-Type, and we should treat those as being of type			   MimeInlineTextPlain rather than MimeUntypedText.)			 */			if (mv && !ct)			  ct = nsCRT::strdup(TEXT_PLAIN);		  }		PR_FREEIF(mv);  /* done with this now. */	  }#ifdef ENABLE_SMIME    /* If this message has a body which is encrypted and we're going to       decrypt it (whithout converting it to HTML, since decrypt_p and       write_html_p are never true at the same time)    */    if (obj->output_p &&        obj->options &&        obj->options->decrypt_p &&        !mime_crypto_object_p (msg->hdrs, PR_FALSE))    {      /* The body of this message is not an encrypted object, so we need         to turn off the decrypt_p flag (to prevent us from s#$%ing the         body of the internal object up into one.) In this case,         our output will end up being identical to our input.      */      obj->options->decrypt_p = PR_FALSE;    }#endif /* ENABLE_SMIME */	  /* Emit the HTML for this message's headers.  Do this before		 creating the object representing the body.	   */	  if (obj->output_p &&		  obj->options &&		  obj->options->write_html_p)		{		  /* If citation headers are on, and this is not the outermost message,			 turn them off. */		  if (obj->options->headers == MimeHeadersCitation && !outer_p)			obj->options->headers = MimeHeadersSome;		  /* Emit a normal header block. */		  status = MimeMessage_write_headers_html(obj);		  if (status < 0) return status;		}	  else if (obj->output_p)		{		  /* Dump the headers, raw. */		  status = MimeObject_write(obj, "", 0, PR_FALSE);  /* initialize */		  if (status < 0) return status;		  status = MimeHeaders_write_raw_headers(msg->hdrs, obj->options,												 obj->options->decrypt_p);		  if (status < 0) return status;		}#ifdef XP_UNIX	  if (outer_p && obj->output_p)		/* Kludge from mimehdrs.c */		MimeHeaders_do_unix_display_hook_hack(msg->hdrs);#endif /* XP_UNIX */	}  /* Never put out a separator after a message header block. */  if (obj->options && obj->options->state)	obj->options->state->separator_suppressed_p = PR_TRUE;#ifdef MIME_DRAFTS  if ( !obj->headers &&    /* outer most message header */	   obj->options && 	   obj->options->decompose_file_p && 	   ct )	obj->options->is_multipart_msg = PL_strcasestr(ct, "multipart/") != NULL;#endif /* MIME_DRAFTS */  body = mime_create(ct, msg->hdrs, obj->options);  PR_FREEIF(ct);  if (!body) return MIME_OUT_OF_MEMORY;  status = ((MimeContainerClass *) obj->clazz)->add_child (obj, body);  if (status < 0)	{	  mime_free(body);	  return status;	}    // Only do this if this is a Text Object!  if ( mime_typep(body, (MimeObjectClass *) &mimeInlineTextClass) )  {    ((MimeInlineText *) body)->needUpdateMsgWinCharset = PR_TRUE;  }  /* Now that we've added this new object to our list of children,	 start its parser going. */  status = body->clazz->parse_begin(body);  if (status < 0) return status;  // Now notify the emitter if this is the outer most message, unless  // it is a part that is not the head of the message. If it's a part,   // we need to figure out the content type/charset of the part  //  PRBool outer_p = !obj->headers;	/* is this the outermost message? */  if (      (outer_p) &&      ( obj->options->part_to_load == NULL )     )  {    // call SetMailCharacterSetToMsgWindow() to set a menu charset    if (mime_typep(body, (MimeObjectClass *) &mimeInlineTextClass))    {      MimeInlineText  *text = (MimeInlineText *) body;      if (text && text->charset && *text->charset)      {        if (!nsCRT::strcasecmp(text->charset, "us-ascii"))          SetMailCharacterSetToMsgWindow(body, NS_LITERAL_STRING("ISO-8859-1").get());        else          SetMailCharacterSetToMsgWindow(body, NS_ConvertASCIItoUCS2(text->charset).get());      }    }    char  *msgID = MimeHeaders_get (msg->hdrs, HEADER_MESSAGE_ID,									                  PR_FALSE, PR_FALSE);    char  *outCharset = NULL;    if (!obj->options->force_user_charset)  /* Only convert if the user prefs is false */      outCharset = "UTF-8";    mimeEmitterStartBody(obj->options, (obj->options->headers == MimeHeadersNone), msgID, outCharset);    PR_FREEIF(msgID);	// setting up truncated message html fotter function	char *xmoz = MimeHeaders_get(msg->hdrs, HEADER_X_MOZILLA_STATUS, PR_FALSE,								 PR_FALSE);	if (xmoz)	{		PRUint32 flags = 0;		char dummy = 0;		if (sscanf(xmoz, " %lx %c", &flags, &dummy) == 1 &&			flags & MSG_FLAG_PARTIAL)			obj->options->generate_footer_html_fn =				MimeMessage_partial_message_html;		PR_FREEIF(xmoz);	}  }  return 0;}