Bug 790855, part 1: nsIMimeConverter needs to return AUTF8String instead of ACString, r=Neil
authorJoshua Cranmer <Pidgeot18@gmail.com>
Wed, 04 Jun 2014 09:51:27 -0500
changeset 16280 29d10e5f69abeb6109790c23b74a6e49c6755224
parent 16279 a8d1e10d39b77de6b13e9fff8843feb3d27ec12e
child 16281 8877b30a38c31bd79ef3cdde696a0392d3c5d95b
push id10173
push userPidgeot18@gmail.com
push dateWed, 04 Jun 2014 16:44:46 +0000
treeherdercomm-central@8877b30a38c3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs790855
Bug 790855, part 1: nsIMimeConverter needs to return AUTF8String instead of ACString, r=Neil
mailnews/base/util/nsMsgI18N.cpp
mailnews/base/util/nsMsgUtils.cpp
mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
mailnews/mime/public/nsIMimeConverter.idl
mailnews/mime/src/nsMimeConverter.cpp
--- a/mailnews/base/util/nsMsgI18N.cpp
+++ b/mailnews/base/util/nsMsgI18N.cpp
@@ -203,24 +203,25 @@ char * nsMsgI18NEncodeMimePartIIStr(cons
     nsAutoCString convertedStr;
     if (NS_SUCCEEDED(ConvertFromUnicode(charset, NS_ConvertUTF8toUTF16(header),
                                         convertedStr)))
       return PL_strdup(convertedStr.get());
     else
       return PL_strdup(header);
   }
 
-  char *encodedString = nullptr;
+  nsAutoCString encodedString;
   nsresult res;
   nsCOMPtr<nsIMimeConverter> converter = do_GetService(NS_MIME_CONVERTER_CONTRACTID, &res);
   if (NS_SUCCEEDED(res) && nullptr != converter)
-    res = converter->EncodeMimePartIIStr_UTF8(nsDependentCString(header), structured, charset,
-      fieldnamelen, nsIMimeConverter::MIME_ENCODED_WORD_SIZE, &encodedString);
+    res = converter->EncodeMimePartIIStr_UTF8(nsDependentCString(header),
+      structured, charset, fieldnamelen,
+      nsIMimeConverter::MIME_ENCODED_WORD_SIZE, encodedString);
 
-  return NS_SUCCEEDED(res) ? encodedString : nullptr;
+  return NS_SUCCEEDED(res) ? PL_strdup(encodedString.get()) : nullptr;
 }
 
 // Return True if a charset is stateful (e.g. JIS).
 bool nsMsgI18Nstateful_charset(const char *charset)
 {
   //TODO: use charset manager's service
   return (PL_strcasecmp(charset, "ISO-2022-JP") == 0);
 }
--- a/mailnews/base/util/nsMsgUtils.cpp
+++ b/mailnews/base/util/nsMsgUtils.cpp
@@ -715,21 +715,25 @@ bool NS_MsgStripRE(const char **stringP,
       {
         p1 += sizeof("=?")-1;         // skip "=?"
         const char *p2 = strchr(p1, '?');   // then search for '?'
         if (p2)
         {
           char charset[nsIMimeConverter::MAX_CHARSET_NAME_LENGTH] = "";
           if (nsIMimeConverter::MAX_CHARSET_NAME_LENGTH >= (p2 - p1))
             strncpy(charset, p1, p2 - p1);
-          rv = mimeConverter->EncodeMimePartIIStr_UTF8(nsDependentCString(s), false, charset,
-            sizeof("Subject:"), nsIMimeConverter::MIME_ENCODED_WORD_SIZE,
-            modifiedSubject);
+          nsAutoCString encodedString;
+          rv = mimeConverter->EncodeMimePartIIStr_UTF8(nsDependentCString(s),
+            false, charset, sizeof("Subject:"),
+            nsIMimeConverter::MIME_ENCODED_WORD_SIZE, encodedString);
           if (NS_SUCCEEDED(rv))
+          {
+            *modifiedSubject = PL_strdup(encodedString.get());
             return result;
+          }
         }
       }
     }
     else
       s = *stringP;   // no modification, set the original encoded string
   }
 
 
--- a/mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
+++ b/mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
@@ -471,17 +471,17 @@ nsresult nsMsgComposeSecure::MimeInitEnc
 
   nsCOMPtr<nsIMimeConverter> mimeConverter =
      do_GetService(NS_MIME_CONVERTER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   nsCString encodedContentDescription;
   mimeConverter->EncodeMimePartIIStr_UTF8(enc_content_desc_utf8, false, "UTF-8",
       sizeof("Content-Description: "),
       nsIMimeConverter::MIME_ENCODED_WORD_SIZE,
-      getter_Copies(encodedContentDescription));
+      encodedContentDescription);
 
   /* First, construct and write out the opaque-crypto-blob MIME header data.
    */
 
   char *s =
   PR_smprintf("Content-Type: " APPLICATION_PKCS7_MIME
           "; name=\"smime.p7m\"; smime-type=enveloped-data" CRLF
         "Content-Transfer-Encoding: " ENCODING_BASE64 CRLF
--- a/mailnews/mime/public/nsIMimeConverter.idl
+++ b/mailnews/mime/public/nsIMimeConverter.idl
@@ -3,17 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
 /**
  * Encode/decode mail headers (via libmime).
  */
-[scriptable, uuid(1f685c2d-5ac6-40a9-8415-655b408a7d42)]
+[scriptable, uuid(0d3f5531-2dbe-40d3-9280-f6ac45a6f5e0)]
 interface nsIMimeConverter : nsISupports {
   /**
    * Suggested byte length limit for use when calling
    * encodeMimePartIIStr(_UTF8).
    */
   const long MIME_ENCODED_WORD_SIZE = 72;
   const long MAX_CHARSET_NAME_LENGTH = 64;
 
@@ -28,21 +28,21 @@ interface nsIMimeConverter : nsISupports
    *     structured field bodies.)
    * @param mailCharset Charset name to convert (as an ASCII C string).
    * @param fieldnamelen Header field name lengt (ex: "From: " = 6)
    * @param encodedWordSize Byte length limit of the output, usually 72. (Use
    *     MIME_ENCODED_WORD_SIZE.)
    *
    * @return The encoded buffer (as a C string).
    */
-  string encodeMimePartIIStr_UTF8(in AUTF8String header,
-                                  in boolean     structured,
-                                  in string      mailCharset,
-                                  in long        fieldnamelen,
-                                  in long        encodedWordSize);
+  AUTF8String encodeMimePartIIStr_UTF8(in AUTF8String header,
+                                       in boolean     structured,
+                                       in string      mailCharset,
+                                       in long        fieldnamelen,
+                                       in long        encodedWordSize);
 
   /**
    * Decode a MIME header to UTF-8 if conversion is required.  Marked as
    * noscript because the return value may contain non-ASCII characters.
    *
    * @param header A (possibly encoded) header to decode.
    * @param default_charset The charset to apply to un-labeled non-UTF-8 data.
    * @param override_charset If true, default_charset is used instead of any
--- a/mailnews/mime/src/nsMimeConverter.cpp
+++ b/mailnews/mime/src/nsMimeConverter.cpp
@@ -62,20 +62,15 @@ nsMimeConverter::DecodeMimeHeader(const 
 }
 
 nsresult
 nsMimeConverter::EncodeMimePartIIStr_UTF8(const nsACString &header,
                                           bool             structured,
                                           const char       *mailCharset,
                                           int32_t          fieldnamelen,
                                           int32_t          encodedWordSize,
-                                          char             **encodedString)
+                                          nsACString       &encodedString)
 {
-  NS_ENSURE_ARG_POINTER(encodedString);
-
-  char *retString = MIME_EncodeMimePartIIStr(PromiseFlatCString(header).get(),
-                                             structured, mailCharset,
-                                             fieldnamelen, encodedWordSize);
-  NS_ENSURE_TRUE(retString, NS_ERROR_FAILURE);
-
-  *encodedString = retString;
-  return NS_OK;
+  encodedString.Adopt(MIME_EncodeMimePartIIStr(PromiseFlatCString(header).get(),
+                                               structured, mailCharset,
+                                               fieldnamelen, encodedWordSize));
+  return encodedString.IsVoid() ? NS_ERROR_FAILURE : NS_OK;
 }