Bug 1408175 - pass nsCString to MsgStripQuotedPrintable() instead of a raw char pointer. r=bz a=jorgk
authorJorg K <jorgk@jorgk.com>
Tue, 05 Dec 2017 23:20:37 +0100
changeset 29408 687a73125ba9c067434966d5ae4196b6c7742237
parent 29407 ecedc478a8c9a00b1bd40a00a44382bd1e7e6971
child 29409 d5ce77d49fb1392ad023c98df987609ef858621b
push id2089
push usermozilla@jorgk.com
push dateThu, 07 Dec 2017 21:03:03 +0000
treeherdercomm-beta@d5ce77d49fb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, jorgk
bugs1408175
Bug 1408175 - pass nsCString to MsgStripQuotedPrintable() instead of a raw char pointer. r=bz a=jorgk
mailnews/base/search/src/nsMsgSearchTerm.cpp
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/base/util/nsMsgUtils.cpp
mailnews/base/util/nsMsgUtils.h
--- a/mailnews/base/search/src/nsMsgSearchTerm.cpp
+++ b/mailnews/base/search/src/nsMsgSearchTerm.cpp
@@ -961,23 +961,21 @@ nsresult nsMsgSearchTerm::MatchBody (nsI
   {
     if (bodyHan->GetNextLine(buf) >= 0)
     {
       bool softLineBreak = false;
       // Do in-place decoding of quoted printable
       if (isQuotedPrintable)
       {
         softLineBreak = StringEndsWith(buf, NS_LITERAL_CSTRING("="));
-        MsgStripQuotedPrintable ((unsigned char*)buf.get());
-        // in case the string shrunk, reset the length. If soft line break,
-        // chop off the last char as well.
-        size_t bufLength = strlen(buf.get());
+        MsgStripQuotedPrintable(buf);
+        // If soft line break, chop off the last char as well.
+        size_t bufLength = buf.Length();
         if ((bufLength > 0) && softLineBreak)
-          --bufLength;
-        buf.SetLength(bufLength);
+          buf.SetLength(bufLength - 1);
       }
       compare.Append(buf);
       // If this line ends with a soft line break, loop around
       // and get the next line before looking for the search string.
       // This assumes the message can't end on a QP soft-line break.
       // That seems like a pretty safe assumption.
       if (softLineBreak)
         continue;
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -5694,19 +5694,17 @@ void nsMsgDBFolder::decodeMsgSnippet(con
     if (aIsComplete)
       base64Len -= base64Len % 4;
     char *decodedBody = PL_Base64Decode(aMsgSnippet.get(), base64Len, nullptr);
     if (decodedBody)
       aMsgSnippet.Adopt(decodedBody);
   }
   else if (MsgLowerCaseEqualsLiteral(aEncodingType, ENCODING_QUOTED_PRINTABLE))
   {
-    // giant hack - decode in place, and truncate string.
-    MsgStripQuotedPrintable((unsigned char *) aMsgSnippet.get());
-    aMsgSnippet.SetLength(strlen(aMsgSnippet.get()));
+    MsgStripQuotedPrintable(aMsgSnippet);
   }
 }
 
 /**
  * stripQuotesFromMsgSnippet - Reduces quoted reply text including the citation (Scott wrote:) from
  *                             the message snippet to " ... ". Assumes the snippet has been decoded and converted to
  *                             plain text.
  * @param aMsgSnippet in/out argument. The string to strip quotes from.
--- a/mailnews/base/util/nsMsgUtils.cpp
+++ b/mailnews/base/util/nsMsgUtils.cpp
@@ -1544,23 +1544,25 @@ nsresult MsgGetLocalFileFromURI(const ns
   nsCOMPtr<nsIFile> argFile;
   rv = argFileURL->GetFile(getter_AddRefs(argFile));
   NS_ENSURE_SUCCESS(rv, rv);
 
   argFile.forget(aFile);
   return NS_OK;
 }
 
-NS_MSG_BASE void MsgStripQuotedPrintable (unsigned char *src)
+NS_MSG_BASE void MsgStripQuotedPrintable (nsCString& aSrc)
 {
   // decode quoted printable text in place
 
-  if (!*src)
+  if (aSrc.IsEmpty())
     return;
-  unsigned char *dest = src;
+
+  char *src = aSrc.BeginWriting();
+  char *dest = src;
   int srcIdx = 0, destIdx = 0;
 
   while (src[srcIdx] != 0)
   {
     // Decode sequence of '=XY' into a character with code XY.
     if (src[srcIdx] == '=')
     {
       if (MsgIsHex((const char*)src + srcIdx + 1, 2)) {
@@ -1591,16 +1593,17 @@ NS_MSG_BASE void MsgStripQuotedPrintable
         continue;
       }
     }
     else
       dest[destIdx++] = src[srcIdx++];
   }
 
   dest[destIdx] = src[srcIdx]; // null terminate
+  aSrc.SetLength(destIdx);
 }
 
 NS_MSG_BASE nsresult MsgEscapeString(const nsACString &aStr,
                                      uint32_t aType, nsACString &aResult)
 {
   nsresult rv;
   nsCOMPtr<nsINetUtil> nu = do_GetService(NS_NETUTIL_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/mailnews/base/util/nsMsgUtils.h
+++ b/mailnews/base/util/nsMsgUtils.h
@@ -201,17 +201,17 @@ NS_MSG_BASE nsresult MsgNewSafeBufferedF
 // and returns false if the keyword isn't present
 NS_MSG_BASE bool MsgFindKeyword(const nsCString &keyword, nsCString &keywords, int32_t *aStartOfKeyword, int32_t *aLength);
 
 NS_MSG_BASE bool MsgHostDomainIsTrusted(nsCString &host, nsCString &trustedMailDomains);
 
 // gets an nsIFile from a UTF-8 file:// path
 NS_MSG_BASE nsresult MsgGetLocalFileFromURI(const nsACString &aUTF8Path, nsIFile **aFile);
 
-NS_MSG_BASE void MsgStripQuotedPrintable (unsigned char *src);
+NS_MSG_BASE void MsgStripQuotedPrintable (nsCString& aSrc);
 
 /*
  * Utility function copied from nsReadableUtils
  */
 NS_MSG_BASE bool MsgIsUTF8(const nsACString& aString);
 
 /*
  * Utility functions that call functions from nsINetUtil