fix compaction of local folders not setting message offset, r=mconley,a=bienvenu part of bug 730947 SEAMONKEY_2_9b3_BUILD1
authorDavid Bienvenu <bienvenu@nventure.com>
Tue, 10 Apr 2012 08:06:00 -0700
changeset 10705 fa4685b8588ebbc5487be71d14dc1b30f680c4f4
parent 10704 62053a3b1aeebcac1b48185a336bccdf222b3b99
child 10706 04180a1fba9aa3ef5eb541e32da349c26efef0e4
child 10709 4dd5a40dde2d8e9c9575c852b0bac3d49a7632a8
child 10711 fde388f1f7ecb8b10c61e1c03fca4e415732cb5c
push idunknown
push userunknown
push dateunknown
reviewersmconley, bienvenu
bugs730947
fix compaction of local folders not setting message offset, r=mconley,a=bienvenu part of bug 730947
mailnews/base/src/nsMsgFolderCompactor.cpp
mailnews/base/test/unit/test_folderCompact.js
--- a/mailnews/base/src/nsMsgFolderCompactor.cpp
+++ b/mailnews/base/src/nsMsgFolderCompactor.cpp
@@ -1129,16 +1129,17 @@ nsFolderCompactState::EndCopy(nsISupport
   if (newMsgHdr)
   {
     if ( m_statusOffset != 0)
       newMsgHdr->SetStatusOffset(m_statusOffset);
       
     char storeToken[100];
     PR_snprintf(storeToken, sizeof(storeToken), "%lld", m_startOfNewMsg);
     newMsgHdr->SetStringProperty("storeToken", storeToken);
+    newMsgHdr->SetMessageOffset(m_startOfNewMsg);
 
     PRUint32 msgSize;
     (void) newMsgHdr->GetMessageSize(&msgSize);
     if (m_addedHeaderSize)
     {
       msgSize += m_addedHeaderSize;
       newMsgHdr->SetMessageSize(msgSize);
     }
--- a/mailnews/base/test/unit/test_folderCompact.js
+++ b/mailnews/base/test/unit/test_folderCompact.js
@@ -109,16 +109,33 @@ function calculateFolderSize(folder)
       var header = enumerator.getNext();
       if (header instanceof Components.interfaces.nsIMsgDBHdr)
         totalSize += header.messageSize;
     }
   }
   return totalSize;
 }
 
+function verifyMsgOffsets(folder)
+{
+  let msgDB = folder.msgDatabase;
+  let enumerator = msgDB.EnumerateMessages();
+  if (enumerator)
+  {
+    while (enumerator.hasMoreElements())
+    {
+      let header = enumerator.getNext();
+      if (header instanceof Components.interfaces.nsIMsgDBHdr) {
+        let storeToken = header.getStringProperty("storeToken");
+        do_check_eq(storeToken, header.messageOffset);
+      }
+    }
+  }
+}
+
 /*
  * TESTS
  */
 
 // Beware before commenting out a test -- later tests might just depend on earlier ones
 const gTestArray =
 [
   // Copying messages from files
@@ -143,16 +160,17 @@ const gTestArray =
   function compactFolder()
   {
     gExpectedFolderSize = calculateFolderSize(gLocalFolder3);
     do_check_neq(gLocalFolder3.expungedBytes, 0);
     gLocalFolder3.compact(urlListener, null);
   },
   function testDeleteMessages2() {
     do_check_eq(gExpectedFolderSize, gLocalFolder3.filePath.fileSize);
+    verifyMsgOffsets(gLocalFolder3);
     var folder2DB = gLocalFolder2.msgDatabase;
     gMsgHdrs[0].hdr = folder2DB.getMsgHdrForMessageID(gMsgHdrs[0].ID);
 
     // Now delete the message
     deleteMessages(gLocalFolder2, [gMsgHdrs[0].hdr], false, false);
   },
   function compactAllFolders()
   {
@@ -171,16 +189,19 @@ const gTestArray =
     dbPath.remove(false);
     gLocalInboxFolder.compactAll(urlListener, null, true);
   },
   function lastTestCheck()
   {
     do_check_eq(gExpectedInboxSize, gLocalInboxFolder.filePath.fileSize);
     do_check_eq(gExpectedFolder2Size, gLocalFolder2.filePath.fileSize);
     do_check_eq(gExpectedFolder3Size, gLocalFolder3.filePath.fileSize);
+    verifyMsgOffsets(gLocalFolder2);
+    verifyMsgOffsets(gLocalFolder3);
+    verifyMsgOffsets(gLocalInboxFolder);
     urlListener.OnStopRunningUrl(null, 0);
   }
 ];
 
 function run_test()
 {
   loadLocalMailAccount();
   // Load up some messages so that we can copy them in later.