Bug 1383847 - fix nsImapService::IsMsgInMemCache(). r=rkent
authorJorg K <jorgk@jorgk.com>
Thu, 27 Jul 2017 23:20:21 +0200
changeset 28498 a1f96ca2ed84ec4a4c01c6a896ae62f2132b43e6
parent 28497 f593d2d106c15ad9682a35eaa1a8679e7127acd6
child 28499 db038d905a4e979933f7a7cd134710bed8339235
push id1986
push userclokep@gmail.com
push dateWed, 02 Aug 2017 14:43:31 +0000
treeherdercomm-beta@b51c9adf2c9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrkent
bugs1383847
Bug 1383847 - fix nsImapService::IsMsgInMemCache(). r=rkent
mailnews/base/public/nsIMsgMessageService.idl
mailnews/imap/src/nsImapService.cpp
--- a/mailnews/base/public/nsIMsgMessageService.idl
+++ b/mailnews/base/public/nsIMsgMessageService.idl
@@ -207,16 +207,18 @@ interface nsIMsgMessageService : nsISupp
    */
   nsIURI streamHeaders(in string aMessageURI, in nsIStreamListener aConsumer,
                        in nsIUrlListener aUrlListener, 
                        [optional] in boolean aLocalOnly);
 
   /**
    * Determines whether a message is in the memory cache. Local folders
    * don't implement this.
+   * The URL needs to address a message, not a message part, all query
+   * qualifiers will be stripped before looking up the entry in the cache.
    *
    * @param aUrl The URL of the message, possibly with an appropriate command in it
    * @param aFolder The folder this message is in
    * 
    * @return TRUE if the message is in mem cache; FALSE if it is not.
    */
   boolean isMsgInMemCache(in nsIURI aUrl,
                           in nsIMsgFolder aFolder);
--- a/mailnews/imap/src/nsImapService.cpp
+++ b/mailnews/imap/src/nsImapService.cpp
@@ -1262,35 +1262,52 @@ NS_IMETHODIMP nsImapService::IsMsgInMemC
 {
   NS_ENSURE_ARG_POINTER(aUrl);
   NS_ENSURE_ARG_POINTER(aImapMailFolder);
   *aResult = false;
 
   // Poke around in the memory cache
   if (mCacheStorage)
   {
-    // XXX: No truncation after a possible '?' done here?
     nsAutoCString urlSpec;
-    aUrl->GetAsciiSpec(urlSpec);
-    if (urlSpec.RFindChar('?') != kNotFound)
-      NS_WARNING ("nsImapService::IsMsgInMemCache found ? in URL");
+    aUrl->GetSpec(urlSpec);
+
+    // Strip any query qualifiers.
+    bool truncated = false;
+    int32_t ind = urlSpec.FindChar('?');
+    if (ind != kNotFound) {
+      urlSpec.SetLength(ind);
+      truncated = true;
+    }
+    ind = urlSpec.Find("/;");
+    if (ind != kNotFound) {
+      urlSpec.SetLength(ind);
+      truncated = true;
+    }
 
     nsresult rv;
     nsCOMPtr<nsIImapMailFolderSink> folderSink(do_QueryInterface(aImapMailFolder, &rv));
     NS_ENSURE_SUCCESS(rv, rv);
 
     int32_t uidValidity = -1;
     folderSink->GetUidValidity(&uidValidity);
     // stick the uid validity in front of the url, so that if the uid validity
     // changes, we won't re-use the wrong cache entries.
     nsAutoCString extension;
     extension.AppendInt(uidValidity, 16);
 
     bool exists;
-    rv = mCacheStorage->Exists(aUrl, extension, &exists);
+    if (truncated) {
+      nsCOMPtr<nsIURI> newUri;
+      aUrl->Clone(getter_AddRefs(newUri));
+      newUri->SetSpec(urlSpec);
+      rv = mCacheStorage->Exists(newUri, extension, &exists);
+    } else {
+      rv = mCacheStorage->Exists(aUrl, extension, &exists);
+    }
     if (NS_SUCCEEDED(rv) && exists) {
       *aResult = true;
     }
   }
 
   return NS_OK;
 }