mMsgCompFields->SetCharacterSet(INTL_GetDefaultMailCharset(), NULL);
default_mail_charset = INTL_GetDefaultMailCharset(); if (NULL != default_mail_charset) { mMsgCompFields->SetCharacterSet(default_mail_charset, NULL); PR_Free(default_mail_charset); }
nsComposeAppCore::NewMessage(nsAutoString& aUrl,							 nsAutoString& args,                             nsIDOMXULTreeElement *tree,                             nsIDOMNodeList *nodeList,                             nsIDOMMsgAppCore * msgAppCore,                             PRInt32 messageType){	nsresult rv;	nsString controllerCID;	mArgs = args;	NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);     if (NS_FAILED(rv)) return rv;	nsIURL* url = nsnull;	NS_WITH_SERVICE(nsINetService, pNetService, kNetServiceCID, &rv); 	if (NS_SUCCEEDED(rv) && pNetService) 	{		rv = pNetService->CreateURL(&url, aUrl);		if (NS_FAILED(rv))			goto done;	}	else		goto done;	controllerCID = "6B75BB61-BD41-11d2-9D31-00805F8ADDDF";	appShell->CreateTopLevelWindow(nsnull,      // parent                                   url,                                   controllerCID,                                   mWebShellWindow,   // result widget                                   nsnull,      // observer                                   this,      // callbacks                                   615,         // width                                   650);        // height		// Get the default charset from pref, use this as a mail charset.	// TODO: For reply/forward, original charset need to be used instead.	mMsgCompFields->SetCharacterSet(INTL_GetDefaultMailCharset(), NULL);	if (tree && nodeList && msgAppCore) {		nsCOMPtr<nsISupports> object;		rv = msgAppCore->GetRDFResourceForMessage(tree, nodeList,                                                   getter_AddRefs(object));		if ((NS_SUCCEEDED(rv)) && object) {			nsCOMPtr<nsIMessage> message;			rv = object->QueryInterface(nsIMessage::GetIID(),                                         getter_AddRefs(message));			if ((NS_SUCCEEDED(rv)) && message) {				nsString aString = "";				nsString bString = "";        nsString aCharset = "";        nsString decodedString;        nsString encodedCharset;  // we don't use this        char *aCString;        message->GetCharSet(aCharset);				message->GetSubject(aString);                switch (messageType)                {                default:                        case 0:         // reply to sender                case 1:         // reply to all                {                    // get an original charset, used for a label, UTF-8 is used for the internal processing                    if (!aCharset.Equals("")) {                      mMsgCompFields->SetCharacterSet(nsAutoCString(aCharset), NULL);                    }                    bString += "Re: ";                    bString += aString;					mMsgCompFields->SetSubject(nsAutoCString(bString), NULL);                    if (NS_SUCCEEDED(INTL_DecodeMimePartIIStr(bString, encodedCharset, decodedString))) {                      if (NS_SUCCEEDED(ConvertFromUnicode(msgCompHeaderInternalCharset(), decodedString, &aCString))) {                        mMsgCompFields->SetSubject(aCString, NULL);                        PR_Free(aCString);                      }                    }                    					message->GetAuthor(aString);							mMsgCompFields->SetTo(nsAutoCString(aString), NULL);                    if (NS_SUCCEEDED(INTL_DecodeMimePartIIStr(aString, encodedCharset, decodedString))) {                      if (NS_SUCCEEDED(ConvertFromUnicode(msgCompHeaderInternalCharset(), decodedString, &aCString))) {                        mMsgCompFields->SetTo(aCString, NULL);                        PR_Free(aCString);                      }                    }                    if (messageType == 1)                    {                        nsString cString, dString;                        message->GetRecipients(cString);                        message->GetCCList(dString);                        if (cString.Length() > 0 && dString.Length() > 0)                            cString = cString + ", ";                        cString = cString + dString;						mMsgCompFields->SetCc(nsAutoCString(cString), NULL);                        if (NS_SUCCEEDED(INTL_DecodeMimePartIIStr(cString, encodedCharset, decodedString))) {                          if (NS_SUCCEEDED(ConvertFromUnicode(msgCompHeaderInternalCharset(), decodedString, &aCString))) {                            mMsgCompFields->SetTo(aCString, NULL);                            PR_Free(aCString);                          }                        }                    }                    HackToGetBody(1);                    break;                }                case 2:         // forward as attachment                case 3:         // forward as inline                case 4:         // forward as quoted                {                    if (!aCharset.Equals("")) {                      mMsgCompFields->SetCharacterSet(nsAutoCString(aCharset), NULL);                    }                    bString += "[Fwd: ";                    bString += aString;                    bString += "]";					mMsgCompFields->SetSubject(nsAutoCString(bString), NULL);                    if (NS_SUCCEEDED(INTL_DecodeMimePartIIStr(bString, encodedCharset, decodedString))) {                      if (NS_SUCCEEDED(ConvertFromUnicode(msgCompHeaderInternalCharset(), decodedString, &aCString))) {                        mMsgCompFields->SetSubject(aCString, NULL);                        PR_Free(aCString);                      }                    }                    /* We need to get more information out from the message. */                    nsCOMPtr<nsIRDFResource> rdfResource;                    rv = object->QueryInterface(kIRDFResourceIID,                                                getter_AddRefs(rdfResource));                    if (rdfResource)                    {	                        nsXPIDLCString uri;                        rdfResource->GetValue( getter_Copies(uri) );                        nsString messageUri(uri);                    }                    if (messageType == 2)                        HackToGetBody(0);                    else if (messageType == 3)                        HackToGetBody(2);                    else                        HackToGetBody(1);                    break;                }                }                                }        }	}done:	NS_IF_RELEASE(url);	return NS_OK;}