Follow up to Bug 656243 - Permanent orange: test_imapContentLength.js | test failed (with xpcshell return code: 3) caused by Linux notification changes; Improve detection of if we're already fetching a preview for a message or not. r=bienvenu a=Standard8
authorMike Conley <mconley@mozilla.com>
Wed, 18 May 2011 13:43:16 +0100
changeset 7785 e5dbe854dad7e759631216a9a1300aa493459bbf
parent 7784 90c3929c5b5d13d2e677fff21e64cf0831f55e79
child 7786 ceb7dae0c3118b48320b7cc848a29c4e75b86d3f
push idunknown
push userunknown
push dateunknown
reviewersbienvenu, Standard8
bugs656243
Follow up to Bug 656243 - Permanent orange: test_imapContentLength.js | test failed (with xpcshell return code: 3) caused by Linux notification changes; Improve detection of if we're already fetching a preview for a message or not. r=bienvenu a=Standard8
mailnews/base/src/nsMessengerUnixIntegration.cpp
mailnews/base/src/nsMessengerUnixIntegration.h
--- a/mailnews/base/src/nsMessengerUnixIntegration.cpp
+++ b/mailnews/base/src/nsMessengerUnixIntegration.cpp
@@ -131,17 +131,16 @@ static void openMailWindow(const nsACStr
 }
 
 nsMessengerUnixIntegration::nsMessengerUnixIntegration()
 {
   mBiffStateAtom = MsgGetAtom("BiffState");
   mNewMailReceivedAtom = MsgGetAtom("NewMailReceived");
   mAlertInProgress = PR_FALSE;
   mLastMRUTimes.Init();
-  mFetchingPreview = PR_FALSE;
   NS_NewISupportsArray(getter_AddRefs(mFoldersWithNewMail));
 }
 
 NS_IMPL_ISUPPORTS4(nsMessengerUnixIntegration, nsIFolderListener, nsIObserver,
                    nsIMessengerOSIntegration, nsIUrlListener)
 
 nsresult
 nsMessengerUnixIntegration::Init()
@@ -253,41 +252,54 @@ nsMessengerUnixIntegration::BuildNotific
   prefBranch->GetBoolPref(SHOW_ALERT_SENDER, &showSender);
   prefBranch->GetBoolPref(SHOW_ALERT_SUBJECT, &showSubject);
   prefBranch->GetIntPref(SHOW_ALERT_PREVIEW_LENGTH, &previewLength);
 
   nsCOMPtr<nsIMsgHeaderParser> parser = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID);
   if (!parser)
     return PR_FALSE;
 
+  nsCOMPtr<nsIMsgFolder> folder;
+  aHdr->GetFolder(getter_AddRefs(folder));
+
+  if (!folder)
+    return PR_FALSE;
+
+  nsCString msgURI;
+  folder->GetUriForMsg(aHdr, msgURI);
+
+  PRBool localOnly;
+
+  PRUint32 msgURIIndex = mFetchingURIs.IndexOf(msgURI);
+  if (msgURIIndex == -1)
+  {
+    localOnly = PR_FALSE;
+    mFetchingURIs.AppendElement(msgURI);
+  } 
+  else
+    localOnly = PR_TRUE;
+
   PRUint32 messageKey;
   if (NS_FAILED(aHdr->GetMessageKey(&messageKey)))
     return PR_FALSE;
 
   PRBool asyncResult = PR_FALSE;
-
-  if (!mFetchingPreview) {
-    nsCOMPtr<nsIMsgFolder> parentFolder;
-    aHdr->GetFolder(getter_AddRefs(parentFolder));
-
-    if (!parentFolder)
-      return PR_FALSE;
+  nsresult rv = folder->FetchMsgPreviewText(&messageKey, 1,
+                                            localOnly, this,
+                                            &asyncResult);
+  // If we're still waiting on getting the message previews,
+  // bail early.  We'll come back later when the async operation
+  // finishes.
+  if (NS_FAILED(rv) || asyncResult)
+    return PR_FALSE;
 
-    nsresult rv = parentFolder->FetchMsgPreviewText(&messageKey, 1,
-                                                    PR_FALSE, this,
-                                                    &asyncResult);
-    mFetchingPreview = asyncResult;
-    // If we're still waiting on getting the message previews,
-    // bail early.  We'll come back later when the async operation
-    // finishes.
-    if (NS_FAILED(rv) || asyncResult)
-      return PR_FALSE;
-
-  }
-  mFetchingPreview = PR_FALSE;
+  // If we got here, that means that we've retrieved the message preview,
+  // so we can stop tracking it with our mFetchingURIs array.
+  if (msgURIIndex != -1)
+    mFetchingURIs.RemoveElementAt(msgURIIndex);
 
   nsCString utf8previewString;
   if (showPreview &&
       NS_FAILED(aHdr->GetStringProperty("preview", getter_Copies(utf8previewString))))
     return PR_FALSE;
 
   // need listener that mailbox is remote such as IMAP
   // to generate preview message
--- a/mailnews/base/src/nsMessengerUnixIntegration.h
+++ b/mailnews/base/src/nsMessengerUnixIntegration.h
@@ -87,12 +87,12 @@ private:
   nsresult PutMRUTimestampForFolder(nsIMsgFolder *aFolder, PRUint32 aLastMRUTime);
 #endif
 
   nsCOMPtr<nsISupportsArray> mFoldersWithNewMail;  // keep track of all the root folders with pending new mail
   nsCOMPtr<nsIAtom> mBiffStateAtom;
   nsCOMPtr<nsIAtom> mNewMailReceivedAtom;
   PRBool mAlertInProgress;
   nsDataHashtable<nsCStringHashKey, PRUint32> mLastMRUTimes; // We keep track of the last time we did a new mail notification for each account
-  PRBool mFetchingPreview;
+  nsTArray<nsCString> mFetchingURIs;
 };
 
 #endif // __nsMessengerUnixIntegration_h