nsAllocator::Free(msgUri);
nsMessenger::ForwardMessages(nsIDOMNodeList *domNodeList,                              PRInt32 type){  nsresult rv = NS_ERROR_NULL_POINTER;  nsCOMPtr<nsISupportsArray> messageArray;  if (!domNodeList) return rv;  rv = ConvertDOMListToResourceArray(domNodeList,                                     getter_AddRefs(messageArray));  if (NS_FAILED(rv)) return rv;  PRUint32 cnt = 0, i;  rv = messageArray->Count(&cnt);  if (NS_FAILED(rv)) return rv;  if (!cnt) return NS_ERROR_NULL_POINTER;    if (type < 0 || type > 2)  {    NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);    if (NS_FAILED(rv)) return rv;    rv = prefs->GetIntPref("mail.forward_message_mode", &type);    // use forward as attachment if failed    if (NS_FAILED(rv))      type = 0;  }  NS_WITH_SERVICE(nsIMsgMailSession, mailSession, kCMsgMailSessionCID, &rv);  if (NS_FAILED(rv)) return rv;    nsCOMPtr<nsIMsgIdentity> identity;  rv = mailSession->GetCurrentIdentity(getter_AddRefs(identity));  if (NS_FAILED(rv)) return rv;  NS_WITH_SERVICE (nsIMsgComposeService, composeService,                   kMsgComposeServiceCID, &rv);  if (NS_FAILED(rv)) return rv;  NS_WITH_SERVICE (nsIComponentManager, compMgr, kComponentManagerCID, &rv);  if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIMsgCompFields> compFields;  nsCOMPtr<nsIRDFResource> rdfResource;  nsCOMPtr<nsISupports> msgSupport;  char *msgUri = nsnull;    switch (type)  {      default:      case 0: // forward as attachments      {          if (NS_SUCCEEDED(rv))          {              rv = compMgr->CreateInstance(kMsgCompFieldsCID, nsnull,                                            nsCOMTypeInfo<nsIMsgCompFields>::GetIID(),                                           getter_AddRefs(compFields));              if (NS_FAILED(rv)) return rv;          }          nsString attachments;          for (i=0; i<cnt; i++)          {              msgSupport = getter_AddRefs(messageArray->ElementAt(i));              if (msgSupport)              {                  rdfResource = do_QueryInterface(msgSupport, &rv);                  if (NS_SUCCEEDED(rv))                  {                      rv = rdfResource->GetValue(&msgUri);                      if (msgUri)                      {                          if (attachments.Length())                              attachments += ',';                          attachments += msgUri;                          nsCRT::free(msgUri);                      }                  }              }          }          nsString subject;          nsString fwdSubject;          msgSupport = getter_AddRefs(messageArray->ElementAt(0));          nsCOMPtr<nsIDBMessage> aMessage = do_QueryInterface(msgSupport);          if (aMessage)          {            nsCOMPtr<nsIMsgDBHdr> aMsgHdr;            aMessage->GetMsgDBHdr(getter_AddRefs(aMsgHdr));            if (aMsgHdr)            {              aMsgHdr->GetSubject(&subject);              fwdSubject = "[Fwd: ";              fwdSubject += subject;              fwdSubject += "]";            }          }          if (fwdSubject.Length())            compFields->SetSubject(fwdSubject.ToNewUnicode());          compFields->SetAttachments(attachments.ToNewUnicode());          rv = composeService->OpenComposeWindowWithCompFields(nsnull,                                     nsIMsgCompFormat::Default, compFields);          break;      }      case 1: // forward as quoted; obsolete, treat it as inline      case 2: // forward as inline      {          for (i=0; i<cnt; i++)          {              msgSupport = getter_AddRefs(messageArray->ElementAt(i));              if (msgSupport)              {                  rdfResource = do_QueryInterface(msgSupport, &rv);                  if(NS_SUCCEEDED(rv))                  {                      rv = rdfResource->GetValue(&msgUri);                      if (NS_SUCCEEDED(rv) && msgUri)                      {                        nsAutoString str (msgUri);                        nsCOMPtr<nsIMsgDraft> pMsgDraft;                        rv = compMgr->CreateInstance(kMsgDraftCID,                                                     nsnull,                                                     nsCOMTypeInfo<nsIMsgDraft>::GetIID(),                                                      getter_AddRefs(pMsgDraft));                        if (NS_SUCCEEDED(rv) && pMsgDraft)                          pMsgDraft->OpenDraftMsg(str.ToNewUnicode(),                                                  nsnull, PR_TRUE);                      }                  }              }          }          break;      }  }  return rv;}