Part of Bug 326809 - modernize nsIMsgHeaderParser - |string| and |wstring| vs AString and AUTF8String - Fix nsIMsgHeaderParser::removeDuplicateAddresses. r/sr=bienvenu
authorMark Banner <bugzilla@standard8.plus.com>
Thu, 14 May 2009 21:31:49 +0100
changeset 2638 80d58da1901c0e5cb0757340a0a806e3d002b41d
parent 2637 bb38d33f5744524ac4536a4c124d47bbb002f2cd
child 2639 b98b14c1e4ea0a44150af3165866b05988466447
push idunknown
push userunknown
push dateunknown
bugs326809
Part of Bug 326809 - modernize nsIMsgHeaderParser - |string| and |wstring| vs AString and AUTF8String - Fix nsIMsgHeaderParser::removeDuplicateAddresses. r/sr=bienvenu
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgSend.cpp
mailnews/compose/src/nsSmtpProtocol.cpp
mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
mailnews/extensions/smime/src/nsSMimeJSHelper.cpp
mailnews/mime/public/nsIMsgHeaderParser.idl
mailnews/mime/src/nsMsgHeaderParser.cpp
mailnews/mime/test/unit/test_nsIMsgHeaderParser3.js
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -134,30 +134,16 @@ static void GetReplyHeaderInfo(PRInt32* 
     NS_GetLocalizedUnicharPreferenceWithDefault(prefBranch, "mailnews.reply_header_authorwrote", NS_LITERAL_STRING("%s wrote"), reply_header_authorwrote);
     NS_GetLocalizedUnicharPreferenceWithDefault(prefBranch, "mailnews.reply_header_ondate", NS_LITERAL_STRING("On %s"), reply_header_ondate);
     NS_GetUnicharPreferenceWithDefault(prefBranch, "mailnews.reply_header_separator", NS_LITERAL_STRING(", "), reply_header_separator);
     NS_GetUnicharPreferenceWithDefault(prefBranch, "mailnews.reply_header_colon", NS_LITERAL_STRING(":"), reply_header_colon);
     NS_GetLocalizedUnicharPreferenceWithDefault(prefBranch, "mailnews.reply_header_originalmessage", NS_LITERAL_STRING("--- Original Message ---"), reply_header_originalmessage);
   }
 }
 
-static nsresult RemoveDuplicateAddresses(const char * addresses, const char * anothersAddresses, PRBool removeAliasesToMe, char** newAddress)
-{
-  nsresult rv;
-
-  nsCOMPtr<nsIMsgHeaderParser> parser (do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID));
-  if (parser)
-    rv = parser->RemoveDuplicateAddresses(addresses, anothersAddresses,
-                                          removeAliasesToMe, newAddress);
-  else
-    rv = NS_ERROR_FAILURE;
-
-  return rv;
-}
-
 static void TranslateLineEnding(nsString& data)
 {
   PRUnichar* rPtr;   //Read pointer
   PRUnichar* wPtr;   //Write pointer
   PRUnichar* sPtr;   //Start data pointer
   PRUnichar* ePtr;   //End data pointer
 
   rPtr = wPtr = sPtr = data.BeginWriting();
@@ -1625,57 +1611,53 @@ nsresult nsMsgCompose::CreateMessage(con
   {
     NS_NEWXPCOM(m_compFields, nsMsgCompFields);
     if (m_compFields)
       NS_ADDREF(m_compFields);
     else
       return NS_ERROR_OUT_OF_MEMORY;
   }
 
+  nsCOMPtr<nsIMsgHeaderParser> parser =
+    do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
   if (m_identity)
   {
     /* Setup reply-to field */
     nsCString replyTo;
     m_identity->GetReplyTo(replyTo);
     if (!replyTo.IsEmpty())
     {
-      char *resultStr = nsnull;
-      rv = RemoveDuplicateAddresses(m_compFields->GetReplyTo(),
-                                    replyTo.get(), PR_TRUE, &resultStr);
-      if (NS_SUCCEEDED(rv) && resultStr)
+      nsCString resultStr;
+      rv = parser->RemoveDuplicateAddresses(nsDependentCString(m_compFields->GetReplyTo()),
+                                            replyTo, resultStr);
+      if (NS_SUCCEEDED(rv) && !resultStr.IsEmpty())
       {
-        if (*resultStr)
-        {
-          replyTo.Append(',');
-          replyTo.Append(resultStr);
-        }
-        PR_Free(resultStr);
+        replyTo.Append(',');
+        replyTo.Append(resultStr);
       }
       m_compFields->SetReplyTo(replyTo.get());
     }
 
     /* Setup bcc field */
     PRBool doBcc;
     m_identity->GetDoBcc(&doBcc);
     if (doBcc) 
     {
       nsCString bccList;
       m_identity->GetDoBccList(bccList);
 
-      char *resultStr = nsnull;
-      rv = RemoveDuplicateAddresses(m_compFields->GetBcc(),
-                                    bccList.get(), PR_TRUE, &resultStr);
-      if (NS_SUCCEEDED(rv) && resultStr)
+      nsCString resultStr;
+      rv = parser->RemoveDuplicateAddresses(nsDependentCString(m_compFields->GetBcc()),
+                                            bccList, resultStr);
+      if (NS_SUCCEEDED(rv) && !resultStr.IsEmpty())
       {
-        if (*resultStr)
-        {
-          bccList.Append(',');
-          bccList.Append(resultStr);
-        }
-        PR_Free(resultStr);
+        bccList.Append(',');
+        bccList.Append(resultStr);
       }
       m_compFields->SetBcc(bccList.get());
     }
   }
 
   if (mType == nsIMsgCompType::Draft)
   {
     nsCString curDraftIdURL;
@@ -2612,47 +2594,44 @@ NS_IMETHODIMP QuotingOutputStreamListene
 
         if (! references.IsEmpty())
           references.Append(PRUnichar(' '));
         references += messageId;
         compFields->SetReferences(NS_LossyConvertUTF16toASCII(references).get());
 
         if (needToRemoveDup)
         {
-          //Remove duplicate addresses between TO && CC
-          char * resultStr;
-          nsMsgCompFields* _compFields = (nsMsgCompFields*)compFields.get();  // XXX what is this?
-          if (NS_SUCCEEDED(rv))
+          // Remove duplicate addresses between TO && CC
+          nsCString resultStr;
+          nsCOMPtr<nsIMsgHeaderParser> parser =
+            do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID, &rv);
+          NS_ENSURE_SUCCESS(rv, rv);
+
+          nsMsgCompFields* _compFields = static_cast<nsMsgCompFields*>(compFields.get());  // XXX what is this?
+          nsCString addressToBeRemoved(_compFields->GetTo());
+          if (mIdentity)
           {
-            nsCString addressToBeRemoved(_compFields->GetTo());
-            if (mIdentity)
+            nsCString email;
+            mIdentity->GetEmail(email);
+            addressToBeRemoved.AppendLiteral(", ");
+            addressToBeRemoved.Append(email);
+            // Remove my own address if using Mail-Followup-To (see bug 325429)
+            if (type == nsIMsgCompType::ReplyAll && !mailFollowupTo.IsEmpty())
             {
-              nsCString email;
-              mIdentity->GetEmail(email);
-              addressToBeRemoved.AppendLiteral(", ");
-              addressToBeRemoved.Append(email);
-              // Remove my own address if using Mail-Followup-To (see bug 325429)
-              if (type == nsIMsgCompType::ReplyAll && !mailFollowupTo.IsEmpty())
-              {
-                rv = RemoveDuplicateAddresses(_compFields->GetTo(), email.get(), PR_TRUE, &resultStr);
-                if (NS_SUCCEEDED(rv))
-                {
-                  _compFields->SetTo(resultStr);
-                  PR_Free(resultStr);
-                }
-              }
-            }
-
-            rv= RemoveDuplicateAddresses(_compFields->GetCc(), addressToBeRemoved.get(), PR_TRUE, &resultStr);
-            if (NS_SUCCEEDED(rv))
-            {
-              _compFields->SetCc(resultStr);
-              PR_Free(resultStr);
+              rv = parser->RemoveDuplicateAddresses(nsDependentCString(_compFields->GetTo()),
+                                                    email, resultStr);
+              if (NS_SUCCEEDED(rv))
+                _compFields->SetTo(resultStr.get());
             }
           }
+
+          rv = parser->RemoveDuplicateAddresses(nsDependentCString(_compFields->GetCc()),
+                                                addressToBeRemoved, resultStr);
+          if (NS_SUCCEEDED(rv))
+            _compFields->SetCc(resultStr.get());
         }
       }
     }
 
 #ifdef MSGCOMP_TRACE_PERFORMANCE
     nsCOMPtr<nsIMsgComposeService> composeService (do_GetService(NS_MSGCOMPOSESERVICE_CONTRACTID));
     composeService->TimeStamp("Done with MIME. Now we're updating the UI elements", PR_FALSE);
 #endif
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -3219,25 +3219,25 @@ nsMsgComposeAndSend::AddMailFollowupToHe
   }
 
   // Create nsIMsgHeaderParser object
   nsCOMPtr<nsIMsgHeaderParser> headerParser =
     do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Remove duplicate addresses in recipients
-  nsCAutoString recipients_no_dups;
-  rv = headerParser->RemoveDuplicateAddresses(recipients.get(),
-    nsnull, PR_FALSE, getter_Copies(recipients_no_dups));
+  nsCString recipients_no_dups;
+  rv = headerParser->RemoveDuplicateAddresses(recipients, EmptyCString(),
+                                              recipients_no_dups);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Remove subscribed mailing lists from recipients...
-  nsCAutoString recipients_without_mailing_lists;
-  rv = headerParser->RemoveDuplicateAddresses(recipients_no_dups.get(),
-    mailing_lists.get(), PR_FALSE, getter_Copies(recipients_without_mailing_lists));
+  nsCString recipients_without_mailing_lists;
+  rv = headerParser->RemoveDuplicateAddresses(recipients_no_dups, mailing_lists,
+                                              recipients_without_mailing_lists);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // ... If the result is equal to the input, we don't write to a subscribed
   // mailing list and therefore we don't add Mail-Followup-To
   if (recipients_no_dups == recipients_without_mailing_lists)
     return NS_OK;
 
   // Set Mail-Followup-To
@@ -3303,25 +3303,26 @@ nsMsgComposeAndSend::AddMailReplyToHeade
     }
 
     // Create nsIMsgHeaderParser object
     nsCOMPtr<nsIMsgHeaderParser> headerParser =
       do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Remove duplicate addresses in recipients
-    nsCAutoString recipients_no_dups;
-    rv = headerParser->RemoveDuplicateAddresses(recipients.get(),
-      nsnull, PR_FALSE, getter_Copies(recipients_no_dups));
+    nsCString recipients_no_dups;
+    rv = headerParser->RemoveDuplicateAddresses(recipients, EmptyCString(),
+                                                recipients_no_dups);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Remove reply-to mangling mailing lists from recipients...
-    nsCAutoString recipients_without_mailing_lists;
-    rv = headerParser->RemoveDuplicateAddresses(recipients_no_dups.get(),
-      mailing_lists.get(), PR_FALSE, getter_Copies(recipients_without_mailing_lists));
+    nsCString recipients_without_mailing_lists;
+    rv = headerParser->RemoveDuplicateAddresses(recipients_no_dups,
+                                                mailing_lists,
+                                                recipients_without_mailing_lists);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // ... If the result is equal to the input, none of the recipients
     // occure in the MRT addresses and therefore we stop here.
     if (recipients_no_dups == recipients_without_mailing_lists)
       return NS_OK;
   }
 
--- a/mailnews/compose/src/nsSmtpProtocol.cpp
+++ b/mailnews/compose/src/nsSmtpProtocol.cpp
@@ -1563,99 +1563,90 @@ PRInt32 nsSmtpProtocol::SendQuit()
   SendData(url, "QUIT"CRLF); // send a quit command to close the connection with the server.
   m_nextState = SMTP_RESPONSE;
   m_nextStateAfterResponse = SMTP_DONE;
   return(0);
 }
 
 nsresult nsSmtpProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer )
 {
-  nsresult rv = NS_OK;
+  if (!aURL)
+    return NS_OK;
 
-  PRInt32 status = 0;
-	m_continuationResponse = -1;  /* init */
-	if (aURL)
-	{
-		m_runningURL = do_QueryInterface(aURL);
+  m_continuationResponse = -1;  /* init */
+  m_runningURL = do_QueryInterface(aURL);
+  if (!m_runningURL)
+    return NS_ERROR_FAILURE;
 
-    // we had a bug where we failed to bring up an alert if the host
-    // name was empty....so throw up an alert saying we don't have
-    // a host name and inform the caller that we are not going to
-    // run the url...
-
-    nsCAutoString hostName;
-    aURL->GetHost(hostName);
-    if (hostName.IsEmpty())
+  // we had a bug where we failed to bring up an alert if the host
+  // name was empty....so throw up an alert saying we don't have
+  // a host name and inform the caller that we are not going to
+  // run the url...
+  nsCAutoString hostName;
+  aURL->GetHost(hostName);
+  if (hostName.IsEmpty())
+  {
+    nsCOMPtr <nsIMsgMailNewsUrl> aMsgUrl = do_QueryInterface(aURL);
+    if (aMsgUrl)
     {
-       nsCOMPtr <nsIMsgMailNewsUrl> aMsgUrl = do_QueryInterface(aURL);
-       if (aMsgUrl)
-       {
-           aMsgUrl->SetUrlState(PR_TRUE, NS_OK);
-           rv = aMsgUrl->SetUrlState(PR_FALSE /* we aren't running the url */, NS_ERROR_COULD_NOT_LOGIN_TO_SMTP_SERVER); // set the url as a url currently being run...
-       }
-        return NS_ERROR_BUT_DONT_SHOW_ALERT;
+      aMsgUrl->SetUrlState(PR_TRUE, NS_OK);
+      // set the url as a url currently being run...
+      aMsgUrl->SetUrlState(PR_FALSE /* we aren't running the url */,
+                           NS_ERROR_COULD_NOT_LOGIN_TO_SMTP_SERVER); 
     }
-
-		PRBool postMessage = PR_FALSE;
-		m_runningURL->GetPostMessage(&postMessage);
+    return NS_ERROR_BUT_DONT_SHOW_ALERT;
+  }
 
-		if(postMessage)
-		{
-			char *addrs1 = 0;
-			char *addrs2 = 0;
-            m_nextState = SMTP_RESPONSE;
-            m_nextStateAfterResponse = SMTP_EXTN_LOGIN_RESPONSE;
+  PRBool postMessage = PR_FALSE;
+  m_runningURL->GetPostMessage(&postMessage);
 
-			/* Remove duplicates from the list, to prevent people from getting
-				more than one copy (the SMTP host may do this too, or it may not.)
-				This causes the address list to be parsed twice; this probably
-				doesn't matter.
-			*/
+  if (postMessage)
+  {
+    nsCString addrs1;
+    char *addrs2 = 0;
+    m_nextState = SMTP_RESPONSE;
+    m_nextStateAfterResponse = SMTP_EXTN_LOGIN_RESPONSE;
 
-			nsCString addresses;
-			nsCOMPtr<nsIMsgHeaderParser> parser = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID);
-
-			m_runningURL->GetRecipients(getter_Copies(addresses));
+    // Remove duplicates from the list, to prevent people from getting
+    // more than one copy (the SMTP host may do this too, or it may not.)
+    // This causes the address list to be parsed twice; this probably
+    // doesn't matter.
+    nsCString addresses;
+    nsCOMPtr<nsIMsgHeaderParser> parser =
+      do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID);
 
-			if (NS_SUCCEEDED(rv) && parser)
-			{
-                parser->RemoveDuplicateAddresses(addresses.get(), nsnull,
-                                                 PR_FALSE, &addrs1);
+    m_runningURL->GetRecipients(getter_Copies(addresses));
+
+    if (parser)
+    {
+      parser->RemoveDuplicateAddresses(addresses, EmptyCString(), addrs1);
 
-				/* Extract just the mailboxes from the full RFC822 address list.
-				   This means that people can post to mailto: URLs which contain
-				   full RFC822 address specs, and we will still send the right
-				   thing in the SMTP RCPT command.
-				*/
-				if (addrs1 && *addrs1)
-				{
-                    rv = parser->ParseHeaderAddresses(addrs1, nsnull, &addrs2,
-                                                      &m_addressesLeft);
-					PR_FREEIF (addrs1);
-				}
+      // Extract just the mailboxes from the full RFC822 address list.
+      // This means that people can post to mailto: URLs which contain
+      // full RFC822 address specs, and we will still send the right
+      // thing in the SMTP RCPT command.
+      if (!addrs1.IsEmpty())
+        parser->ParseHeaderAddresses(addrs1.get(), nsnull, &addrs2,
+                                     &m_addressesLeft);
 
-        // hmm no addresses to send message to...
-				if (m_addressesLeft == 0 || addrs2 == nsnull)
-				{
-					m_nextState = SMTP_ERROR_DONE;
-					ClearFlag(SMTP_PAUSE_FOR_READ);
-					status = NS_MSG_NO_RECIPIENTS;
-          m_urlErrorState = NS_MSG_NO_RECIPIENTS;
-					return(status);
-				}
+      // hmm no addresses to send message to...
+      if (m_addressesLeft == 0 || !addrs2)
+      {
+        m_nextState = SMTP_ERROR_DONE;
+        ClearFlag(SMTP_PAUSE_FOR_READ);
+        m_urlErrorState = NS_MSG_NO_RECIPIENTS;
+        return NS_MSG_NO_RECIPIENTS;
+      }
 
-				m_addressCopy = addrs2;
-				m_addresses = m_addressCopy;
-			} // if parser
-		} // if post message
+      m_addressCopy = addrs2;
+      m_addresses = m_addressCopy;
+    } // if parser
+  } // if post message
 
-		rv = nsMsgProtocol::LoadUrl(aURL, aConsumer);
-	} // if we received a url!
-
-	return rv;
+  return nsMsgProtocol::LoadUrl(aURL, aConsumer);
 }
 
 /*
  * returns negative if the transfer is finished or error'd out
  *
  * returns zero or more if the transfer needs to be continued.
  */
  nsresult nsSmtpProtocol::ProcessProtocolState(nsIURI * url, nsIInputStream * inputStream,
--- a/mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
+++ b/mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
@@ -869,18 +869,18 @@ nsresult nsMsgComposeSecure::MimeFinishE
 
 /* Used to figure out what certs should be used when encrypting this message.
  */
 nsresult nsMsgComposeSecure::MimeCryptoHackCerts(const char *aRecipients,
                                                  nsIMsgSendReport *sendReport,
                                                  PRBool aEncrypt,
                                                  PRBool aSign)
 {
-  char *mailboxes = 0, *mailbox_list = 0;
-  nsCString all_mailboxes;
+  char *mailbox_list = 0;
+  nsCString all_mailboxes, mailboxes;
   const char *mailbox = 0;
   PRUint32 count = 0;
   nsCOMPtr<nsIX509CertDB> certdb = do_GetService(NS_X509CERTDB_CONTRACTID);
   nsresult res;
   nsCOMPtr<nsIMsgHeaderParser> pHeader = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID, &res);
   NS_ENSURE_SUCCESS(res,res);
 
   mCerts = do_CreateInstance(NS_ARRAY_CONTRACTID, &res);
@@ -902,23 +902,20 @@ nsresult nsMsgComposeSecure::MimeCryptoH
   if ((mSelfEncryptionCert == nsnull) && aEncrypt) {
     SetError(sendReport, NS_LITERAL_STRING("NoSenderEncryptionCert").get());
     res = NS_ERROR_FAILURE;
     goto FAIL;
   }
 
   pHeader->ExtractHeaderAddressMailboxes(nsDependentCString(aRecipients),
                                          all_mailboxes);
-  pHeader->RemoveDuplicateAddresses(all_mailboxes.get(), 0, PR_FALSE, &mailboxes);
+  pHeader->RemoveDuplicateAddresses(all_mailboxes, EmptyCString(), mailboxes);
 
-  if (mailboxes) {
-    pHeader->ParseHeaderAddresses(mailboxes, 0, &mailbox_list, &count);
-    nsMemory::Free(mailboxes);
-    mailboxes = nsnull;
-  }
+  pHeader->ParseHeaderAddresses(mailboxes.get(), 0, &mailbox_list, &count);
+
   if (count < 0) return count;
 
   if (aEncrypt && mSelfEncryptionCert) {
     // Make sure self's configured cert is prepared for being used
     // as an email recipient cert.
     
     nsCOMPtr<nsISMimeCert> sc = do_QueryInterface(mSelfEncryptionCert);
     if (sc) {
--- a/mailnews/extensions/smime/src/nsSMimeJSHelper.cpp
+++ b/mailnews/extensions/smime/src/nsSMimeJSHelper.cpp
@@ -426,26 +426,19 @@ nsresult nsSMimeJSHelper::getMailboxList
     if (!bcc.IsEmpty()) {
       all_recipients.Append(NS_ConvertUTF16toUTF8(bcc));
       all_recipients.Append(',');
     }
 
     if (!ng.IsEmpty())
       all_recipients.Append(NS_ConvertUTF16toUTF8(ng));
 
-    char *unique_mailboxes = nsnull;
-
+    nsCString unique_mailboxes;
     nsCString all_mailboxes;
     parser->ExtractHeaderAddressMailboxes(all_recipients, all_mailboxes);
-    parser->RemoveDuplicateAddresses(all_mailboxes.get(), 0, PR_FALSE,
-                                     &unique_mailboxes);
-    if (unique_mailboxes)
-    {
-      parser->ParseHeaderAddresses(unique_mailboxes, 0, mailbox_list,
-                                   mailbox_count);
-    }
-    if (unique_mailboxes) {
-      nsMemory::Free(unique_mailboxes);
-    }
+    parser->RemoveDuplicateAddresses(all_mailboxes, EmptyCString(),
+                                     unique_mailboxes);
+    parser->ParseHeaderAddresses(unique_mailboxes.get(), 0, mailbox_list,
+                                 mailbox_count);
   }
 
   return NS_OK;
 }
--- a/mailnews/mime/public/nsIMsgHeaderParser.idl
+++ b/mailnews/mime/public/nsIMsgHeaderParser.idl
@@ -44,17 +44,17 @@ interface nsISimpleEnumerator;
 
 #define NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID \
   "@mozilla.org/messenger/headerparser;1"
 %}
 
 /* 
  * nsIMsgRFCParser Interface declaration 
  */ 
-[scriptable, uuid(392ba09d-5a3a-4f24-bd15-782cab25fdb2)]
+[scriptable, uuid(a67d4d96-e5cb-458d-9311-794d5d1a9832)]
 interface nsIMsgHeaderParser : nsISupports {
 
   void parseHeadersWithArray(in wstring aLine, 
                              [array, size_is(count)] out wstring aEmailAddresses,
                              [array, size_is(count)] out wstring aNames,
                              [array, size_is(count)] out wstring aFullNames,
                              [retval] out unsigned long count);
 
@@ -129,26 +129,21 @@ interface nsIMsgHeaderParser : nsISuppor
    * Addresses are considered to be the same if they contain the same mailbox
    * part (case-insensitive.)  Real names and other comments are not compared.
    *
    * @param aAddrs              The addresses to remove duplicates from.
    * @param aOtherAddrs         Other addresses that the duplicate removal
    *                            process also checks for duplicates against.
    *                            Addresses in this list will not be added to the
    *                            result.
-   * @param aRemoveAliasesToMe  Allows the address parser to use the preference
-   *                            which contains regular expressions which also
-   *                            mean 'me' for the purpose of stripping the
-   *                            user's email address(es) out of addrs.
    * @return                    A string based on the original without the
    *                            duplicate addresses.
    */
-  [noscript] string removeDuplicateAddresses(in string aAddrs,
-                                             in string aOtherAddrs,
-                                             in boolean aRemoveAliasesToMe);
+  AUTF8String removeDuplicateAddresses(in AUTF8String aAddrs,
+                                       in AUTF8String aOtherAddrs);
 
   /**
    * Given an e-mail address and a person's name, cons them together into a
    * single string, doing all the necessary quoting.
    *
    * @param  aName     The name of the sender.
    * @param  aAddress  The address of the sender.
    * @return           A string of the form name <address>.
--- a/mailnews/mime/src/nsMsgHeaderParser.cpp
+++ b/mailnews/mime/src/nsMsgHeaderParser.cpp
@@ -71,18 +71,18 @@ static int msg_parse_Header_addresses(co
 static int msg_quote_phrase_or_addr(char *address, PRInt32 length, PRBool addr_p);
 static nsresult msg_unquote_phrase_or_addr(const char *line, PRBool strict, char **lineout);
 #if 0
 static char *msg_format_Header_addresses(const char *addrs, int count,
                                          PRBool wrap_lines_p);
 #endif
 static char *msg_reformat_Header_addresses(const char *line);
 
-static char *msg_remove_duplicate_addresses(const char *addrs, const char *other_addrs,
-                                            PRBool removeAliasesToMe);
+static char *msg_remove_duplicate_addresses(const nsACString &addrs,
+                                            const nsACString &other_addrs);
 static char *msg_make_full_address(const char* name, const char* addr);
 
 /*
  * nsMsgHeaderParser definitions....
  */
 
 nsMsgHeaderParser::nsMsgHeaderParser()
 {
@@ -202,24 +202,21 @@ nsMsgHeaderParser::ReformatHeaderAddress
                                            char **aReformattedAddress)
 {
   NS_ENSURE_ARG_POINTER(aReformattedAddress);
   *aReformattedAddress = msg_reformat_Header_addresses(aLine);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMsgHeaderParser::RemoveDuplicateAddresses(const char *aAddrs,
-                                            const char *aOtherAddrs,
-                                            PRBool aRemoveAliasesToMe,
-                                            char **aResult)
+nsMsgHeaderParser::RemoveDuplicateAddresses(const nsACString &aAddrs,
+                                            const nsACString &aOtherAddrs,
+                                            nsACString &aResult)
 {
-  NS_ENSURE_ARG_POINTER(aResult);
-  *aResult = msg_remove_duplicate_addresses(aAddrs, aOtherAddrs,
-                                            aRemoveAliasesToMe);
+  aResult.Adopt(msg_remove_duplicate_addresses(aAddrs, aOtherAddrs));
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgHeaderParser::MakeFullAddressString(const char *aName,
                                          const char *aAddress, char **aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
@@ -1373,73 +1370,44 @@ msg_reformat_Header_addresses(const char
  * Returns a copy of ADDRS which may have had some addresses removed.
  * Addresses are removed if they are already in either ADDRS or OTHER_ADDRS.
  * (If OTHER_ADDRS contain addresses which are not in ADDRS, they are not
  * added.  That argument is for passing in addresses that were already
  * mentioned in other header fields.)
  *
  * Addresses are considered to be the same if they contain the same mailbox
  * part (case-insensitive.)  Real names and other comments are not compared.
- *
- * removeAliasesToMe allows the address parser to use the preference which
- * contains regular expressions which also mean 'me' for the purpose of
- * stripping the user's email address(es) out of addrs
  */
 static char *
-msg_remove_duplicate_addresses(const char *addrs, const char *other_addrs,
-                               PRBool removeAliasesToMe)
+msg_remove_duplicate_addresses(const nsACString &addrs,
+                               const nsACString &other_addrs)
 {
-  if (!addrs) return 0;
-
   /* This is probably way more complicated than it should be... */
   char *s1 = 0, *s2 = 0;
   char *output = 0, *out = 0;
   char *result = 0;
   int count1 = 0, count2 = 0, count3 = 0;
-  int size1 = 0, size2 = 0, size3 = 0;
+  int size3 = 0;
   char *names1 = 0, *names2 = 0;
   char *addrs1 = 0, *addrs2 = 0;
   char **a_array1 = 0, **a_array2 = 0, **a_array3 = 0;
   char **n_array1 = 0,                 **n_array3 = 0;
   int i, j;
   PRUint32 addedlen = 0;
 
-  count1 = msg_parse_Header_addresses(addrs, &names1, &addrs1);
+  count1 = msg_parse_Header_addresses(nsCString(addrs).get(), &names1, &addrs1);
   if (count1 < 0) goto FAIL;
   if (count1 == 0)
   {
     result = strdup("");
     goto FAIL;
   }
-  if (other_addrs)
-    count2 = msg_parse_Header_addresses(other_addrs, &names2, &addrs2);
+  count2 = msg_parse_Header_addresses(nsCString(other_addrs).get(), &names2, &addrs2);
   if (count2 < 0) goto FAIL;
 
-  s1 = names1;
-  s2 = addrs1;
-  for (i = 0; i < count1; i++)
-  {
-    PRUint32 len1 = strlen(s1);
-    PRUint32 len2 = strlen(s2);
-    s1 += len1 + 1;
-    s2 += len2 + 1;
-    size1 += len1 + len2 + 10;
-  }
-
-  s1 = names2;
-  s2 = addrs2;
-  for (i = 0; i < count2; i++)
-  {
-    PRUint32 len1 = strlen(s1);
-    PRUint32 len2 = strlen(s2);
-    s1 += len1 + 1;
-    s2 += len2 + 1;
-    size2 += len1 + len2 + 10;
-  }
-
   a_array1 = (char **)PR_Malloc(count1 * sizeof(char *));
   if (!a_array1) goto FAIL;
   n_array1 = (char **)PR_Malloc(count1 * sizeof(char *));
   if (!n_array1) goto FAIL;
 
   if (count2 > 0)
   {
     a_array2 = (char **)PR_Malloc(count2 * sizeof(char *));
@@ -1486,25 +1454,17 @@ msg_remove_duplicate_addresses(const cha
 
     if (!found)
       for (j = 0; j < count3; j++)
         if (!PL_strcasecmp(a_array1[i], a_array3[j]))
         {
           found = PR_TRUE;
           break;
         }
-/* HACK ALERT!!!! TEMPORARILY COMMENTING OUT UNTIL WE PORT MSG_PREFS INTO THE MOZILLA TREE!!!!!! */
-#if 0
-    if (!found && removeAliasesToMe)
-    {
-      found = MSG_Prefs::IsEmailAddressAnAliasForMe(a_array1[i]);
-      if (found)
-        break;
-    }
-#endif
+
     if (!found)
     {
       n_array3[count3] = n_array1[i];
       a_array3[count3] = a_array1[i];
       size3 += (strlen(n_array3[count3]) + strlen(a_array3[count3]) + 10);
       count3++;
       NS_ASSERTION (count3 <= count1, "");
       if (count3 > count1) break;
new file mode 100644
--- /dev/null
+++ b/mailnews/mime/test/unit/test_nsIMsgHeaderParser3.js
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Test suite for nsIMsgHeaderParser function removeDuplicateAddresses:
+ */
+
+function run_test() {
+  const checks =
+  [
+    { addrs: "test@invalid.com",
+      otherAddrs: "",
+      expectedResult: "test@invalid.com" },
+    { addrs: "foo bar <test@invalid.com>",
+      otherAddrs: "",
+      expectedResult: "foo bar <test@invalid.com>" },
+    { addrs: "foo bar <test@invalid.com>, abc@invalid.com",
+      otherAddrs: "",
+      expectedResult: "foo bar <test@invalid.com>, abc@invalid.com" },
+    { addrs: "foo bar <test@invalid.com>, abc@invalid.com, test <test@invalid.com>",
+      otherAddrs: "",
+      expectedResult: "foo bar <test@invalid.com>, abc@invalid.com" },
+    { addrs: "foo bar <test@invalid.com>",
+      otherAddrs: "abc@invalid.com",
+      expectedResult: "foo bar <test@invalid.com>" },
+    { addrs: "foo bar <test@invalid.com>",
+      otherAddrs: "foo bar <test@invalid.com>",
+      expectedResult: null },
+    { addrs: "foo bar <test@invalid.com>, abc@invalid.com",
+      otherAddrs: "foo bar <test@invalid.com>",
+      expectedResult: "abc@invalid.com" },
+    { addrs: "foo bar <test@invalid.com>, abc@invalid.com",
+      otherAddrs: "abc@invalid.com",
+      expectedResult: "foo bar <test@invalid.com>" },
+    { addrs: "foo bar <test@invalid.com>, abc@invalid.com, test <test@invalid.com>",
+      otherAddrs: "abc@invalid.com",
+      expectedResult: "foo bar <test@invalid.com>" },
+    // UTF-8 names
+    { addrs: "foo\u00D0 bar <foo@bar.invalid>, \u00F6foo <ghj@invalid.com>",
+      otherAddrs: "",
+      expectedResult: "foo\u00D0 bar <foo@bar.invalid>, \u00F6foo <ghj@invalid.com>" },
+    { addrs: "foo\u00D0 bar <foo@bar.invalid>, \u00F6foo <ghj@invalid.com>",
+      otherAddrs: "foo\u00D0 bar <foo@bar.invalid>",
+      expectedResult: "\u00F6foo <ghj@invalid.com>" },
+    { addrs: "foo\u00D0 bar <foo@bar.invalid>, \u00F6foo <ghj@invalid.com>, foo\u00D0 bar <foo@bar.invalid>",
+      otherAddrs: "\u00F6foo <ghj@invalid.com>",
+      expectedResult: "foo\u00D0 bar <foo@bar.invalid>" }
+  ];
+
+  // Test - empty strings
+
+  var parser = Components.classes["@mozilla.org/messenger/headerparser;1"]
+                         .getService(Components.interfaces.nsIMsgHeaderParser);
+
+  do_check_eq(parser.removeDuplicateAddresses("", ""), "");
+  do_check_eq(parser.removeDuplicateAddresses("", "test@invalid.com"), "");
+
+  // Test - removeDuplicateAddresses
+
+  for (let i = 0; i < checks.length; ++i) {
+    dump("Test " + i + "\n");
+    do_check_eq(parser.removeDuplicateAddresses(checks[i].addrs,
+						checks[i].otherAddrs),
+		checks[i].expectedResult);
+  }
+}