PR_FREEIF(bodyString);
NS_IMETHODIMP nsComposeAppCore::SendMsg(nsAutoString& aAddrTo,                                        nsAutoString& aAddrCc,                                        nsAutoString& aAddrBcc,                                        nsAutoString& aAddrNewsgroup,                                        nsAutoString& aSubject,                                        nsAutoString& aMsg){	nsMsgCompPrefs pCompPrefs;	char* pUserEmail = nsnull;	if (nsnull == mScriptContext)		return NS_ERROR_FAILURE;#ifdef DEBUG	  printf("----------------------------\n");	  printf("-- Sending Mail Message\n");	  printf("----------------------------\n");	  printf("To: %s  Cc: %s  Bcc: %s\n", aAddrTo.ToNewCString(), aAddrCc.ToNewCString(), aAddrBcc.ToNewCString());	  printf("Subject: %s  \nMsg: %s\n", aSubject.ToNewCString(), aMsg.ToNewCString());	  printf("----------------------------\n");#endif //DEBUG//	nsIMsgCompose *pMsgCompose; 	if (mMsgCompFields) 	{ 		nsString aString;		nsString aCharset(msgCompHeaderInternalCharset());		char *outCString;		// Pref values are supposed to be stored as UTF-8, so no conversion		mMsgCompFields->SetFrom((char *)pCompPrefs.GetUserEmail(), NULL);		mMsgCompFields->SetReplyTo((char *)pCompPrefs.GetReplyTo(), NULL);		mMsgCompFields->SetOrganization((char *)pCompPrefs.GetOrganization(), NULL);		// Convert fields to UTF-8		if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aAddrTo, &outCString))) 		{			mMsgCompFields->SetTo(outCString, NULL);			PR_Free(outCString);		}		else 			mMsgCompFields->SetTo(nsAutoCString(aAddrTo), NULL);		if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aAddrCc, &outCString))) 		{			mMsgCompFields->SetCc(outCString, NULL);			PR_Free(outCString);		}		else 			mMsgCompFields->SetCc(nsAutoCString(aAddrCc), NULL);		if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aAddrBcc, &outCString))) 		{			mMsgCompFields->SetBcc(outCString, NULL);			PR_Free(outCString);		}		else 			mMsgCompFields->SetBcc(nsAutoCString(aAddrBcc), NULL);		if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aAddrNewsgroup, &outCString))) 		{			mMsgCompFields->SetNewsgroups(outCString, NULL);			PR_Free(outCString);		}		else 			mMsgCompFields->SetNewsgroups(nsAutoCString(aAddrNewsgroup), NULL);        		if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aSubject, &outCString))) 		{			mMsgCompFields->SetSubject(outCString, NULL);			PR_Free(outCString);		}		else 			mMsgCompFields->SetSubject(nsAutoCString(aSubject), NULL);		// Convert body to mail charset not to utf-8 (because we don't manipulate body text)		char *mail_charset;		mMsgCompFields->GetCharacterSet(&mail_charset);		aCharset.SetString(mail_charset);		if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aMsg, &outCString))) 		{			mMsgCompFields->SetBody(outCString, NULL);			PR_Free(outCString);		}		else			mMsgCompFields->SetBody(nsAutoCString(aMsg), NULL);		if (mMsgSend)    {        char    *bodyString = NULL;        PRInt32 bodyLength;        if (!NS_SUCCEEDED(mMsgCompFields->GetBody(&bodyString)))          bodyString = aMsg.ToNewCString();        bodyLength = PL_strlen(bodyString);        mMsgSend->SendMessage(mMsgCompFields,         			"",               				// const char *smtp,					PR_FALSE,         				// PRBool                            digest_p,					PR_FALSE,         				// PRBool                            dont_deliver_p,					nsMsgDeliverNow,   				// nsMsgDeliverMode                  mode,					mUseHtml?TEXT_HTML:TEXT_PLAIN,  // const char                        *attachment1_type,					bodyString,               // const char                        *attachment1_body,        	bodyLength,               // PRUint32                          attachment1_body_length,					NULL,             				// const struct nsMsgAttachmentData   *attachments,					NULL,             				// const struct nsMsgAttachedFile     *preloaded_attachments,					NULL,             				// nsMsgSendPart                     *relatedPart,					NULL);            				// void  (*message_delivery_done_callback)(MWContext *context, void *fe_data,								             			//                                         int status, const char *error_message))        PR_FREEIF(bodyString);    }	}	if (nsnull != mScriptContext) {		const char* url = "";		PRBool isUndefined = PR_FALSE;		nsString rVal;		mScriptContext->EvaluateString(mScript, url, 0, rVal, &isUndefined);	}	if (mWindow)	{//		mWindow->Close();//ducarroz: mWindow->Close doesn't work yet because mopener wasn't set!//		if (mWebShellWindow)//			mWebShellWindow->Close();//ducarroz: mWebShellWindow->Close doesn't work too!	}	PR_FREEIF(pUserEmail);	return NS_OK;}