nsresult rv; NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv); if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIPref> prefs; nsresult rv = nsServiceManager::GetService(kPrefServiceCID, nsIPref::GetIID(), (nsISupports**)&prefs);
nsHTMLEditor::InsertAsPlaintextQuotation(const nsString& aQuotedText,                                         nsIDOMNode **aNodeInserted){  // Now we have the text.  Cite it appropriately:  nsCOMPtr<nsICiter> citer;  nsresult rv;  NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);  if (NS_FAILED(rv)) return rv;  char *citationType = 0;  rv = prefs->CopyCharPref("mail.compose.citationType", &citationType);                            if (NS_SUCCEEDED(rv) && citationType[0])  {    if (!strncmp(citationType, "aol", 3))      citer = new nsAOLCiter;    else      citer = new nsInternetCiter;    PL_strfree(citationType);  }  else    citer = new nsInternetCiter;    // Let the citer quote it for us:  nsString quotedStuff;  rv = citer->GetCiteString(aQuotedText, quotedStuff);  if (!NS_SUCCEEDED(rv))    return rv;  // Insert blank lines after the quoted text:  quotedStuff += "\n\n";  nsAutoEditBatch beginBatching(this);  // get selection  nsCOMPtr<nsIDOMSelection> selection;  rv = GetSelection(getter_AddRefs(selection));  if (NS_FAILED(rv)) return rv;  if (!selection) return NS_ERROR_NULL_POINTER;  // give rules a chance to handle or cancel  nsTextRulesInfo ruleInfo(nsHTMLEditRules::kInsertElement);  PRBool cancel, handled;  rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);  if (NS_FAILED(rv)) return rv;  if (cancel) return NS_OK; // rules canceled the operation  if (!handled)  {    // Wrap the inserted quote in a <pre> so it won't be wrapped:    nsCOMPtr<nsIDOMNode> preNode;    nsAutoString tag("pre");    rv = DeleteSelectionAndCreateNode(tag, getter_AddRefs(preNode));        // If this succeeded, then set selection inside the pre    // so the inserted text will end up there.    // If it failed, we don't care what the return value was,    // but we'll fall through and try to insert the text anyway.    if (NS_SUCCEEDED(rv) && preNode)    {      selection->Collapse(preNode, 0);    }    rv = InsertText(quotedStuff);    if (aNodeInserted)    {      if (NS_SUCCEEDED(rv))      {        *aNodeInserted = preNode;        NS_IF_ADDREF(*aNodeInserted);      }    }    // Set the selection to just after the inserted node:    if (NS_SUCCEEDED(rv) && preNode)    {      nsCOMPtr<nsIDOMNode> parent;      PRInt32 offset;      if (NS_SUCCEEDED(GetNodeLocation(preNode, &parent, &offset)) && parent)        selection->Collapse(parent, offset+1);    }  }  return rv;}