Bug 1528496 - Introduce EncodedHeaderW() using ParseEncodedHeaderW(). r=alta88 a=jorgk
authorJorg K <jorgk@jorgk.com>
Thu, 21 Feb 2019 12:42:24 +0100
changeset 33513 8eed72033464
parent 33512 071ea9f37f83
child 33514 2960e4a6cec0
push id2384
push usermozilla@jorgk.com
push dateWed, 06 Mar 2019 00:14:50 +0000
treeherdercomm-beta@33baca79596d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersalta88, jorgk
bugs1528496
Bug 1528496 - Introduce EncodedHeaderW() using ParseEncodedHeaderW(). r=alta88 a=jorgk
mailnews/compose/src/nsMsgCompFields.cpp
mailnews/compose/src/nsMsgCompose.cpp
mailnews/mime/public/MimeHeaderParser.h
mailnews/mime/src/MimeHeaderParser.cpp
--- a/mailnews/compose/src/nsMsgCompFields.cpp
+++ b/mailnews/compose/src/nsMsgCompFields.cpp
@@ -607,17 +607,17 @@ nsMsgCompFields::SplitRecipients(const n
                                  char16_t*** aResult)
 {
   NS_ENSURE_ARG_POINTER(aLength);
   NS_ENSURE_ARG_POINTER(aResult);
 
   *aLength = 0;
   *aResult = nullptr;
 
-  nsCOMArray<msgIAddressObject> header(EncodedHeader(NS_ConvertUTF16toUTF8(aRecipients)));
+  nsCOMArray<msgIAddressObject> header(EncodedHeaderW(aRecipients));
   nsTArray<nsString> results;
   if (aEmailAddressOnly)
     ExtractEmails(header, results);
   else
     ExtractDisplayAddresses(header, results);
 
   uint32_t count = results.Length();
   char16_t **result = (char16_t **)moz_xmalloc(sizeof(char16_t *) * count);
@@ -630,18 +630,17 @@ nsMsgCompFields::SplitRecipients(const n
 }
 
 
 // This method is called during the sending of message from nsMsgCompose::CheckAndPopulateRecipients()
 nsresult nsMsgCompFields::SplitRecipientsEx(const nsAString &recipients,
                                             nsTArray<nsMsgRecipient> &aResult)
 {
   nsTArray<nsString> names, addresses;
-  ExtractAllAddresses(EncodedHeader(NS_ConvertUTF16toUTF8(recipients)), names,
-    addresses);
+  ExtractAllAddresses(EncodedHeaderW(recipients), names, addresses);
 
   uint32_t numAddresses = names.Length();
   for (uint32_t i = 0; i < numAddresses; ++i)
   {
     nsMsgRecipient msgRecipient;
     msgRecipient.mEmail = addresses[i];
     msgRecipient.mName = names[i];
     aResult.AppendElement(msgRecipient);
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -2597,25 +2597,23 @@ NS_IMETHODIMP QuotingOutputStreamListene
         if (endPos > startPos)
         {
           const uint32_t mailtoLen = strlen("<mailto:");
           listPost = Substring(listPost, startPos + mailtoLen, endPos - (startPos + mailtoLen));
         }
       }
 
       nsCString fromEmailAddress;
-      ExtractEmail(EncodedHeader(NS_ConvertUTF16toUTF8(from)), fromEmailAddress);
+      ExtractEmail(EncodedHeaderW(from), fromEmailAddress);
 
       nsTArray<nsCString> toEmailAddresses;
-      ExtractEmails(EncodedHeader(NS_ConvertUTF16toUTF8(to)),
-        UTF16ArrayAdapter<>(toEmailAddresses));
+      ExtractEmails(EncodedHeaderW(to), UTF16ArrayAdapter<>(toEmailAddresses));
 
       nsTArray<nsCString> ccEmailAddresses;
-      ExtractEmails(EncodedHeader(NS_ConvertUTF16toUTF8(cc)),
-        UTF16ArrayAdapter<>(ccEmailAddresses));
+      ExtractEmails(EncodedHeaderW(cc), UTF16ArrayAdapter<>(ccEmailAddresses));
 
       nsCOMPtr<nsIPrefBranch> prefs (do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
       NS_ENSURE_SUCCESS(rv, rv);
       bool replyToSelfCheckAll = false;
       prefs->GetBoolPref("mailnews.reply_to_self_check_all_ident",
                          &replyToSelfCheckAll);
 
       nsCOMPtr<nsIMsgAccountManager> accountManager =
--- a/mailnews/mime/public/MimeHeaderParser.h
+++ b/mailnews/mime/public/MimeHeaderParser.h
@@ -25,16 +25,20 @@ nsCOMArray<msgIAddressObject> DecodedHea
 /**
  * This is used to signal that the input header value needs to be decoded
  * according to RFC 2047. The charset parameter indicates the charset to assume
  * that non-ASCII data is in; if the value is null (the default), then the
  * charset is assumed to be UTF-8.
  */
 nsCOMArray<msgIAddressObject> EncodedHeader(const nsACString &aHeader,
                                             const char *aCharset = nullptr);
+/**
+ * Same deal, but we're starting with an nsAString.
+ */
+nsCOMArray<msgIAddressObject> EncodedHeaderW(const nsAString &aHeader);
 
 namespace detail {
 void DoConversion(const nsTArray<nsString> &aUTF16, nsTArray<nsCString> &aUTF8);
 };
 /**
  * This is a class designed for use as temporaries so that methods can pass
  * an nsTArray<nsCString> into methods that expect nsTArray<nsString> for out
  * parameters (this does not work for in-parameters).
--- a/mailnews/mime/src/MimeHeaderParser.cpp
+++ b/mailnews/mime/src/MimeHeaderParser.cpp
@@ -102,16 +102,34 @@ nsCOMArray<msgIAddressObject> EncodedHea
     false, &length, &addresses);
   MOZ_ASSERT(NS_SUCCEEDED(rv), "This should never fail!");
   if (NS_SUCCEEDED(rv) && length > 0 && addresses) {
     retval.Adopt(addresses, length);
   }
   return retval;
 }
 
+nsCOMArray<msgIAddressObject> EncodedHeaderW(const nsAString &aHeader)
+{
+  nsCOMArray<msgIAddressObject> retval;
+  if (aHeader.IsEmpty()) {
+    return retval;
+  }
+  nsCOMPtr<nsIMsgHeaderParser> headerParser(services::GetHeaderParser());
+  NS_ENSURE_TRUE(headerParser, retval);
+  msgIAddressObject **addresses = nullptr;
+  uint32_t length;
+  nsresult rv = headerParser->ParseEncodedHeaderW(aHeader, &length, &addresses);
+  MOZ_ASSERT(NS_SUCCEEDED(rv), "This should never fail!");
+  if (NS_SUCCEEDED(rv) && length > 0 && addresses) {
+    retval.Adopt(addresses, length);
+  }
+  return retval;
+}
+
 void ExtractAllAddresses(const nsCOMArray<msgIAddressObject> &aHeader,
                          nsTArray<nsString> &names, nsTArray<nsString> &emails)
 {
   uint32_t count = aHeader.Length();
 
   // Prefill arrays before we start
   names.SetLength(count);
   emails.SetLength(count);