FixURL(newURL);
FixURL(newURL + 5);
DoRFC822toHTMLConversion(char *filename, int numArgs){  nsresult          rv;  char              newURL[1024] = ""; // URL for filename  nsIURI            *theURI = nsnull;  nsMimeOutputType  outFormat;  char              *contentType = nsnull;  if (numArgs >= 3)    outFormat = nsMimeOutput::nsMimeMessageXULDisplay;  else    outFormat = nsMimeOutput::nsMimeMessagePrintOutput;  char *opts = PL_strchr(filename, '?');  char save;  if (opts)  {    save = *opts;    *opts = '\0';  }  nsFilePath      inFilePath(filename, PR_TRUE); // relative path.  nsFileSpec      mySpec(inFilePath);  if (!mySpec.Exists())  {    printf("Unable to open input file %s\n", filename);    return NS_ERROR_FAILURE;  }  if (opts)    *opts = save;  // Create a mime parser (nsIStreamConverter)!  nsCOMPtr<nsIStreamConverter> mimeParser;  rv = nsComponentManager::CreateInstance(kStreamConverterCID,                                           NULL, nsIStreamConverter::GetIID(),                                           (void **) getter_AddRefs(mimeParser));   if (NS_FAILED(rv) || !mimeParser)  {    printf("Failed to create MIME stream converter...\n");    return rv;  }    nsCOMPtr<nsIStreamListener> out = nsnull;  ConsoleOutputStreamListener   *ptr = nsnull;  if (outFormat != nsMimeOutput::nsMimeMessageDraftOrTemplate)  {    // Create the consumer output stream.. this will receive all the HTML from libmime    ptr = new ConsoleOutputStreamListener();    out = do_QueryInterface(ptr);    if (!out)    {      printf("Failed to create nsIOutputStream\n");      return NS_ERROR_FAILURE;    }  }   // This is the producer stream that will deliver data from the disk file...  FileInputStreamImpl   *ptr2 = new FileInputStreamImpl();  nsCOMPtr<FileInputStreamImpl> in = do_QueryInterface(ptr2);  if (!in )  {    printf("Failed to create nsIInputStream\n");    return NS_ERROR_FAILURE;  }  if (NS_FAILED(in->OpenDiskFile(mySpec)))  {    printf("Unable to open input file %s\n", filename);    return NS_ERROR_FAILURE;  }    // Create an nsIURI object needed for stream IO...  PR_snprintf(newURL, sizeof(newURL), "file:///%s", filename);  FixURL(newURL);  if (NS_FAILED(NewURI(&theURI, newURL)))  {    printf("Unable to open input file\n");    return NS_ERROR_FAILURE;  }  // Set us as the output stream for HTML data from libmime...  nsCOMPtr<nsIMimeStreamConverter> mimeStream = do_QueryInterface(mimeParser);  mimeStream->SetMimeOutputType(outFormat);  nsIChannel    *tChannel = nsnull;  NewChannel(&tChannel, theURI);  mimeParser->AsyncConvertData(nsString2("message/rfc822").GetUnicode(),                                nsString2("text/xul").GetUnicode(),                               out, tChannel);//  rv = mimeParser->Init(theURI, out, nsnull);  if (NS_FAILED(rv) || !mimeParser)  {    printf("Unable to set the output stream for the mime parser...\ncould be failure to create internal libmime data\n");    return NS_ERROR_FAILURE;  }  if (contentType)  {    printf("Content type for output = %s\n", contentType);    PR_FREEIF(contentType);  }  if (ptr)    ptr->SetFormat(outFormat);  // Assuming this is an RFC822 message...  mimeParser->OnStartRequest(nsnull, theURI);  // Just pump all of the data from the file into libmime...  while (NS_SUCCEEDED(in->PumpFileStream()))  {    PRUint32    len;    in->GetLength(&len);    if (mimeParser->OnDataAvailable(nsnull, theURI, in, 0, len) != NS_OK)      break;  }  mimeParser->OnStopRequest(nsnull, theURI, NS_OK, nsnull);  NS_RELEASE(theURI);  return NS_OK;}