Recycle(citeTagsResultCStr);
MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj){  int status;  PRBool quoting = ( obj->options    && ( obj->options->format_out == nsMimeOutput::nsMimeMessageQuoting ||         obj->options->format_out == nsMimeOutput::nsMimeMessageBodyQuoting       )           );  // see above  PRBool plainHTML = quoting || (obj->options &&       obj->options->format_out == nsMimeOutput::nsMimeMessageSaveAs);       // see above  // this routine gets called for every line of data that comes through the  // mime converter. It's important to make sure we are efficient with   // how we allocate memory in this routine. be careful if you go to add  // more to this routine.  NS_ASSERTION(length > 0, "zero length");  if (length <= 0) return 0;  mozITXTToHTMLConv *conv = GetTextConverter(obj->options);  MimeInlineTextPlain *text = (MimeInlineTextPlain *) obj;  PRBool skipConversion = !conv ||                          (obj->options && obj->options->force_user_charset);  if (!skipConversion)  {    nsString lineSourceStr;    lineSourceStr.AssignWithConversion(line, length);    nsresult rv;    nsCAutoString prefaceResultStr;  // Quoting stuff before the real text    // Recognize quotes    PRUint32 oldCiteLevel = text->mCiteLevel;    PRUint32 logicalLineStart = 0;    rv = conv->CiteLevelTXT(lineSourceStr.get(),                            &logicalLineStart, &(text->mCiteLevel));    if (NS_FAILED(rv))      return -1;    // Find out, which recognitions to do    PRBool whattodo = obj->options->whattodo;    if (plainHTML)    {      if (quoting)        whattodo = 0;  // This is done on Send. Don't do it twice.      else        whattodo = whattodo & ~mozITXTToHTMLConv::kGlyphSubstitution;                   /* Do recognition for the case, the result is viewed in                      Mozilla, but not GlyphSubstitution, because other UAs                      might not be able to display the glyphs. */      if (!text->mBlockquoting)        text->mCiteLevel = 0;    }    // Write blockquote    if (text->mCiteLevel > oldCiteLevel)    {      prefaceResultStr += "</pre>";      for (PRUint32 i = 0; i < text->mCiteLevel - oldCiteLevel; i++)      {        char *style = MimeTextBuildPrefixCSS(text->mQuotedSizeSetting,                                             text->mQuotedStyleSetting,                                             text->mCitationColor);        if (!plainHTML && style && nsCRT::strlen(style))        {          prefaceResultStr += "<blockquote type=cite style=\"";          prefaceResultStr += style;          prefaceResultStr += "\">";        }        else          prefaceResultStr += "<blockquote type=cite>";        Recycle(style);      }      prefaceResultStr += "<pre wrap>";    }    else if (text->mCiteLevel < oldCiteLevel)    {      prefaceResultStr += "</pre>";      for (PRUint32 i = 0; i < oldCiteLevel - text->mCiteLevel; i++)        prefaceResultStr += "</blockquote>";      prefaceResultStr += "<pre wrap>";      if (text->mCiteLevel == 0)        prefaceResultStr += "<!---->";   /* Make sure, NGLayout puts out                                            a linebreak */    }    // Write plain text quoting tags    if (logicalLineStart != 0 && !(plainHTML && text->mBlockquoting))    {      if (!plainHTML)        prefaceResultStr += "<span class=\"moz-txt-citetags\">";      nsAutoString citeTagsSource;      lineSourceStr.Mid(citeTagsSource, 0, logicalLineStart);      NS_ASSERTION(citeTagsSource.IsASCII(), "Non-ASCII-Chars are about to be "                   "added to nsCAutoString prefaceResultStr. "                   "Change the latter to nsAutoString.");        /* I'm currently using nsCAutoString, because currently citeTagsSource           is always ASCII and I save 2 conversions this way. */      // Convert to HTML      PRUnichar* citeTagsResultUnichar = nsnull;      rv = conv->ScanTXT(citeTagsSource.get(), 0 /* no recognition */,                         &citeTagsResultUnichar);      if (NS_FAILED(rv)) return -1;      // Convert to char* and write out      nsSubsumeStr citeTagsResultStr(citeTagsResultUnichar,                                     PR_TRUE /* assume ownership */);      char* citeTagsResultCStr = citeTagsResultStr.ToNewCString();      prefaceResultStr += citeTagsResultCStr;      Recycle(citeTagsResultCStr);      if (!plainHTML)        prefaceResultStr += "</span>";    }    // recognize signature    if ((lineSourceStr.Length() >= 4)        && lineSourceStr.First() == '-'        && lineSourceStr.EqualsWithConversion("-- ", PR_FALSE, 3)        && (lineSourceStr[3] == '\r' || lineSourceStr[3] == '\n') )    {      text->mIsSig = PR_TRUE;      if (!quoting)        prefaceResultStr += "<div class=\"moz-txt-sig\">";    }    // Get a mail charset of this message.    MimeInlineText  *inlinetext = (MimeInlineText *) obj;    char *mailCharset = NULL;    if (inlinetext->charset && *(inlinetext->charset))      mailCharset = inlinetext->charset;    /* This is the main TXT to HTML conversion:       escaping (very important), eventually recognizing etc. */    PRUnichar* lineResultUnichar = nsnull;    if (obj->options->format_out != nsMimeOutput::nsMimeMessageSaveAs ||        !mailCharset || !nsMsgI18Nstateful_charset(mailCharset))    {      rv = conv->ScanTXT(lineSourceStr.get() + logicalLineStart,                         whattodo, &lineResultUnichar);      if (NS_FAILED(rv)) return -1;    }    else    {      // If nsMimeMessageSaveAs, the string is in mail charset (and stateful, e.g. ISO-2022-JP).      // convert to unicode so it won't confuse ScanTXT.      nsAutoString ustr;      nsCAutoString cstr(line, length);      nsCAutoString mailCharsetStr(mailCharset);      rv = nsMsgI18NConvertToUnicode(mailCharsetStr, cstr, ustr);      if (NS_SUCCEEDED(rv))      {        PRUnichar *u;        rv = conv->ScanTXT(ustr.get() + logicalLineStart, whattodo, &u);        if (NS_SUCCEEDED(rv))        {          ustr.Assign(u);          Recycle(u);          rv = nsMsgI18NConvertFromUnicode(mailCharsetStr, ustr, cstr);          if (NS_SUCCEEDED(rv))          {            // create PRUnichar* which contains NON unicode             // as the following code expecting it            ustr.AssignWithConversion(cstr);                                                              lineResultUnichar = ustr.ToNewUnicode();            if (!lineResultUnichar) return -1;          }        }      }      if (NS_FAILED(rv))        return -1;    }    // avoid an extra string copy by using nsSubsumeStr, this transfers    // ownership of wresult to strresult so don't try to free wresult later.    nsSubsumeStr lineResultStr(lineResultUnichar,                               PR_TRUE /* assume ownership */);    if (!(text->mIsSig && quoting))    {      char* tmp = prefaceResultStr.ToNewCString();      status = MimeObject_write(obj, tmp, prefaceResultStr.Length(), PR_TRUE);      if (status < 0) return status;      Recycle(tmp);      tmp = lineResultStr.ToNewCString();      status = MimeObject_write(obj, tmp, lineResultStr.Length(), PR_TRUE);      if (status < 0) return status;      Recycle(tmp);    }    else    {      status = NS_OK;    }  }  else  {    status = MimeObject_write(obj, line, length, PR_TRUE);    if (status < 0) return status;  }  return status;}