Bug 1385573 - whitespace only changes for nsMsgThreadedDBView.cpp, nsMsgXFViewThread.cpp, nsMsgXFVirtualFolderDBView.cpp. r=jorgk
authoralta88 <alta88>
Fri, 22 Sep 2017 12:57:00 +0200
changeset 29030 16c7195a1573d4df9fe392153467fa21664ae12f
parent 29029 2fd8773a88edfdb49aaf9f5532d8f35ca2f6f80f
child 29031 00c6dfa4467952eab4dfd3fbdf097fe89232c399
push id2068
push userclokep@gmail.com
push dateMon, 13 Nov 2017 19:02:14 +0000
treeherdercomm-beta@9c7e7ce8672b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk
bugs1385573
Bug 1385573 - whitespace only changes for nsMsgThreadedDBView.cpp, nsMsgXFViewThread.cpp, nsMsgXFVirtualFolderDBView.cpp. r=jorgk
mailnews/base/src/nsMsgThreadedDBView.cpp
mailnews/base/src/nsMsgXFViewThread.cpp
mailnews/base/src/nsMsgXFVirtualFolderDBView.cpp
--- a/mailnews/base/src/nsMsgThreadedDBView.cpp
+++ b/mailnews/base/src/nsMsgThreadedDBView.cpp
@@ -6,68 +6,81 @@
 #include "msgCore.h"
 #include "nsMsgThreadedDBView.h"
 #include "nsIMsgHdr.h"
 #include "nsIMsgThread.h"
 #include "nsIDBFolderInfo.h"
 #include "nsIMsgSearchSession.h"
 #include "nsMsgMessageFlags.h"
 
-#define MSGHDR_CACHE_LOOK_AHEAD_SIZE  25    // Allocate this more to avoid reallocation on new mail.
-#define MSGHDR_CACHE_MAX_SIZE         8192  // Max msghdr cache entries.
+// Allocate this more to avoid reallocation on new mail.
+#define MSGHDR_CACHE_LOOK_AHEAD_SIZE  25
+// Max msghdr cache entries.
+#define MSGHDR_CACHE_MAX_SIZE         8192
 #define MSGHDR_CACHE_DEFAULT_SIZE     100
 
 nsMsgThreadedDBView::nsMsgThreadedDBView()
 {
   /* member initializers and constructor code */
   m_havePrevView = false;
 }
 
 nsMsgThreadedDBView::~nsMsgThreadedDBView()
 {
   /* destructor code */
 }
 
-NS_IMETHODIMP nsMsgThreadedDBView::Open(nsIMsgFolder *folder, nsMsgViewSortTypeValue sortType, nsMsgViewSortOrderValue sortOrder, nsMsgViewFlagsTypeValue viewFlags, int32_t *pCount)
+NS_IMETHODIMP
+nsMsgThreadedDBView::Open(nsIMsgFolder *folder,
+                          nsMsgViewSortTypeValue sortType,
+                          nsMsgViewSortOrderValue sortOrder,
+                          nsMsgViewFlagsTypeValue viewFlags,
+                          int32_t *pCount)
 {
   nsresult rv = nsMsgDBView::Open(folder, sortType, sortOrder, viewFlags, pCount);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!m_db)
     return NS_ERROR_NULL_POINTER;
+
   // Preset msg hdr cache size for performance reason.
   int32_t totalMessages, unreadMessages;
   nsCOMPtr <nsIDBFolderInfo> dbFolderInfo;
   PersistFolderInfo(getter_AddRefs(dbFolderInfo));
   NS_ENSURE_SUCCESS(rv, rv);
-  // save off sort type and order, view type and flags
+
+  // Save off sort type and order, view type and flags.
   dbFolderInfo->GetNumUnreadMessages(&unreadMessages);
   dbFolderInfo->GetNumMessages(&totalMessages);
   if (m_viewFlags & nsMsgViewFlagsType::kUnreadOnly)
   {
     // Set unread msg size + extra entries to avoid reallocation on new mail.
     totalMessages = (uint32_t)unreadMessages+MSGHDR_CACHE_LOOK_AHEAD_SIZE;
   }
   else
   {
     if (totalMessages > MSGHDR_CACHE_MAX_SIZE)
-      totalMessages = MSGHDR_CACHE_MAX_SIZE;        // use max default
+      // Use max default.
+      totalMessages = MSGHDR_CACHE_MAX_SIZE;
     else if (totalMessages > 0)
-      totalMessages += MSGHDR_CACHE_LOOK_AHEAD_SIZE;// allocate extra entries to avoid reallocation on new mail.
+      // Allocate extra entries to avoid reallocation on new mail.
+      totalMessages += MSGHDR_CACHE_LOOK_AHEAD_SIZE;
   }
-  // if total messages is 0, then we probably don't have any idea how many headers are in the db
-  // so we have no business setting the cache size.
+
+  // If total messages is 0, then we probably don't have any idea how many
+  // headers are in the db so we have no business setting the cache size.
   if (totalMessages > 0)
     m_db->SetMsgHdrCacheSize((uint32_t)totalMessages);
 
   if (pCount)
     *pCount = 0;
+
   rv = InitThreadedView(pCount);
 
-  // this is a hack, but we're trying to find a way to correct
+  // This is a hack, but we're trying to find a way to correct
   // incorrect total and unread msg counts w/o paying a big
   // performance penalty. So, if we're not threaded, just add
   // up the total and unread messages in the view and see if that
   // matches what the db totals say. Except ignored threads are
   // going to throw us off...hmm. Unless we just look at the
   // unread counts which is what mostly tweaks people anyway...
   int32_t unreadMsgsInView = 0;
   if (!(m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))
@@ -76,116 +89,139 @@ NS_IMETHODIMP nsMsgThreadedDBView::Open(
     {
       if (!(m_flags[--i] & nsMsgMessageFlags::Read))
         ++unreadMsgsInView;
     }
 
     if (unreadMessages != unreadMsgsInView)
       m_db->SyncCounts();
   }
+
   m_db->SetMsgHdrCacheSize(MSGHDR_CACHE_DEFAULT_SIZE);
 
   return rv;
 }
 
-NS_IMETHODIMP nsMsgThreadedDBView::Close()
+NS_IMETHODIMP
+nsMsgThreadedDBView::Close()
 {
   return nsMsgDBView::Close();
 }
 
-nsresult nsMsgThreadedDBView::InitThreadedView(int32_t *pCount)
+nsresult
+nsMsgThreadedDBView::InitThreadedView(int32_t *pCount)
 {
   nsresult rv;
 
   m_keys.Clear();
   m_flags.Clear();
   m_levels.Clear();
   m_prevKeys.Clear();
   m_prevFlags.Clear();
   m_prevLevels.Clear();
   m_havePrevView = false;
-  nsresult getSortrv = NS_OK; // ### TODO m_db->GetSortInfo(&sortType, &sortOrder);
+  nsresult getSortrv = NS_OK;
+  // XXX TODO m_db->GetSortInfo(&sortType, &sortOrder);
 
-  // list all the ids into m_keys.
+  // List all the ids into m_keys.
   nsMsgKey startMsg = 0;
   do
   {
     const int32_t kIdChunkSize = 400;
     int32_t  numListed = 0;
     nsMsgKey idArray[kIdChunkSize];
     int32_t  flagArray[kIdChunkSize];
     char     levelArray[kIdChunkSize];
 
-    rv = ListThreadIds(&startMsg, (m_viewFlags & nsMsgViewFlagsType::kUnreadOnly) != 0, idArray, flagArray,
-      levelArray, kIdChunkSize, &numListed, nullptr);
+    rv = ListThreadIds(&startMsg,
+                       (m_viewFlags & nsMsgViewFlagsType::kUnreadOnly) != 0,
+                       idArray,
+                       flagArray,
+                       levelArray,
+                       kIdChunkSize,
+                       &numListed,
+                       nullptr);
+
     if (NS_SUCCEEDED(rv))
     {
       int32_t numAdded = AddKeys(idArray, flagArray, levelArray, m_sortType, numListed);
       if (pCount)
         *pCount += numAdded;
     }
 
   } while (NS_SUCCEEDED(rv) && startMsg != nsMsgKey_None);
 
   if (NS_SUCCEEDED(getSortrv))
   {
     rv = InitSort(m_sortType, m_sortOrder);
     SaveSortInfo(m_sortType, m_sortOrder);
 
   }
+
   return rv;
 }
 
-nsresult nsMsgThreadedDBView::SortThreads(nsMsgViewSortTypeValue sortType, nsMsgViewSortOrderValue sortOrder)
+nsresult
+nsMsgThreadedDBView::SortThreads(nsMsgViewSortTypeValue sortType,
+                                 nsMsgViewSortOrderValue sortOrder)
 {
-  NS_PRECONDITION(m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay, "trying to sort unthreaded threads");
+  NS_PRECONDITION(m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay,
+                  "trying to sort unthreaded threads");
 
   uint32_t numThreads = 0;
-  // the idea here is that copy the current view,  then build up an m_keys and m_flags array of just the top level
-  // messages in the view, and then call nsMsgDBView::Sort(sortType, sortOrder).
-  // Then, we expand the threads in the result array that were expanded in the original view (perhaps by copying
-  // from the original view, but more likely just be calling expand).
+  // The idea here is that copy the current view, then build up an m_keys and
+  // m_flags array of just the top level messages in the view, and then call
+  // nsMsgDBView::Sort(sortType, sortOrder).
+  // Then, we expand the threads in the result array that were expanded in the
+  // original view (perhaps by copying from the original view, but more likely
+  // just be calling expand).
   for (uint32_t i = 0; i < m_keys.Length(); i++)
   {
     if (m_flags[i] & MSG_VIEW_FLAG_ISTHREAD)
     {
       if (numThreads < i)
       {
         m_keys[numThreads] = m_keys[i];
         m_flags[numThreads] = m_flags[i];
       }
+
       m_levels[numThreads] = 0;
       numThreads++;
     }
   }
+
   m_keys.SetLength(numThreads);
   m_flags.SetLength(numThreads);
   m_levels.SetLength(numThreads);
   //m_viewFlags &= ~nsMsgViewFlagsType::kThreadedDisplay;
   m_sortType = nsMsgViewSortType::byNone; // sort from scratch
   nsMsgDBView::Sort(sortType, sortOrder);
   m_viewFlags |= nsMsgViewFlagsType::kThreadedDisplay;
   SetSuppressChangeNotifications(true);
-  // Loop through the original array, for each thread that's expanded, find it in the new array
-  // and expand the thread. We have to update MSG_VIEW_FLAG_HAS_CHILDREN because
-  // we may be going from a flat sort, which doesn't maintain that flag,
-  // to a threaded sort, which requires that flag.
+
+  // Loop through the original array, for each thread that's expanded,
+  // find it in the new array and expand the thread. We have to update
+  // MSG_VIEW_FLAG_HAS_CHILDREN because we may be going from a flat sort,
+  // which doesn't maintain that flag, to a threaded sort, which requires
+  // that flag.
   for (uint32_t j = 0; j < m_keys.Length(); j++)
   {
     uint32_t flags = m_flags[j];
-    if ((flags & (MSG_VIEW_FLAG_HASCHILDREN | nsMsgMessageFlags::Elided)) == MSG_VIEW_FLAG_HASCHILDREN)
+    if ((flags & (MSG_VIEW_FLAG_HASCHILDREN |
+                  nsMsgMessageFlags::Elided)) == MSG_VIEW_FLAG_HASCHILDREN)
     {
       uint32_t numExpanded;
       m_flags[j] = flags | nsMsgMessageFlags::Elided;
       ExpandByIndex(j, &numExpanded);
       j += numExpanded;
       if (numExpanded > 0)
         m_flags[j - numExpanded] = flags | MSG_VIEW_FLAG_HASCHILDREN;
     }
-    else if (flags & MSG_VIEW_FLAG_ISTHREAD && ! (flags & MSG_VIEW_FLAG_HASCHILDREN))
+    else if (flags & MSG_VIEW_FLAG_ISTHREAD &&
+             !(flags & MSG_VIEW_FLAG_HASCHILDREN))
     {
       nsCOMPtr <nsIMsgDBHdr> msgHdr;
       nsCOMPtr <nsIMsgThread> pThread;
       m_db->GetMsgHdrForKey(m_keys[j], getter_AddRefs(msgHdr));
       if (msgHdr)
       {
         m_db->GetThreadContainingMsgHdr(msgHdr, getter_AddRefs(pThread));
         if (pThread)
@@ -193,408 +229,508 @@ nsresult nsMsgThreadedDBView::SortThread
           uint32_t numChildren;
           pThread->GetNumChildren(&numChildren);
           if (numChildren > 1)
             m_flags[j] = flags | MSG_VIEW_FLAG_HASCHILDREN | nsMsgMessageFlags::Elided;
         }
       }
     }
   }
+
   SetSuppressChangeNotifications(false);
 
   return NS_OK;
 }
 
-int32_t nsMsgThreadedDBView::AddKeys(nsMsgKey *pKeys, int32_t *pFlags, const char *pLevels, nsMsgViewSortTypeValue sortType, int32_t numKeysToAdd)
-
+int32_t
+nsMsgThreadedDBView::AddKeys(nsMsgKey *pKeys,
+                             int32_t *pFlags,
+                             const char *pLevels,
+                             nsMsgViewSortTypeValue sortType,
+                             int32_t numKeysToAdd)
 {
-  int32_t	numAdded = 0;
+  int32_t numAdded = 0;
   // Allocate enough space first to avoid memory allocation/deallocation.
   m_keys.SetCapacity(m_keys.Length() + numKeysToAdd);
   m_flags.SetCapacity(m_flags.Length() + numKeysToAdd);
   m_levels.SetCapacity(m_levels.Length() + numKeysToAdd);
   for (int32_t i = 0; i < numKeysToAdd; i++)
   {
     int32_t threadFlag = pFlags[i];
     int32_t flag = threadFlag;
 
-    // skip ignored threads.
+    // Skip ignored threads.
     if ((threadFlag & nsMsgMessageFlags::Ignored) && !(m_viewFlags & nsMsgViewFlagsType::kShowIgnored))
       continue;
 
-    // skip ignored subthreads
+    // Skip ignored subthreads
     nsCOMPtr <nsIMsgDBHdr> msgHdr;
     m_db->GetMsgHdrForKey(pKeys[i], getter_AddRefs(msgHdr));
     if (!(m_viewFlags & nsMsgViewFlagsType::kShowIgnored))
     {
       bool killed;
       msgHdr->GetIsKilled(&killed);
       if (killed)
         continue;
     }
 
-    // by default, make threads collapsed, unless we're in only viewing new msgs
+    // By default, make threads collapsed unless we're only viewing new msgs.
 
     if (flag & MSG_VIEW_FLAG_HASCHILDREN)
       flag |= nsMsgMessageFlags::Elided;
-    // should this be persistent? Doesn't seem to need to be.
+
+    // Should this be persistent? Doesn't seem to need to be.
     flag |= MSG_VIEW_FLAG_ISTHREAD;
     m_keys.AppendElement(pKeys[i]);
     m_flags.AppendElement(flag);
     m_levels.AppendElement(pLevels[i]);
     numAdded++;
-    // we expand as we build the view, which allows us to insert at the end of the key array,
-    // instead of the middle, and is much faster.
-    if ((!(m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay) || m_viewFlags & nsMsgViewFlagsType::kExpandAll) && flag & nsMsgMessageFlags::Elided)
+
+    // We expand as we build the view, which allows us to insert at the end
+    // of the key array, instead of the middle, and is much faster.
+    if ((!(m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay) ||
+         m_viewFlags & nsMsgViewFlagsType::kExpandAll) &&
+        flag & nsMsgMessageFlags::Elided)
+    {
        ExpandByIndex(m_keys.Length() - 1, NULL);
+    }
   }
+
   return numAdded;
 }
 
-NS_IMETHODIMP nsMsgThreadedDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgViewSortOrderValue sortOrder)
+NS_IMETHODIMP
+nsMsgThreadedDBView::Sort(nsMsgViewSortTypeValue sortType,
+                          nsMsgViewSortOrderValue sortOrder)
 {
   nsresult rv;
 
   int32_t rowCountBeforeSort = GetSize();
 
   if (!rowCountBeforeSort)
   {
-    // still need to setup our flags even when no articles - bug 98183.
+    // Still need to setup our flags even when no articles - bug 98183.
     m_sortType = sortType;
-    if (sortType == nsMsgViewSortType::byThread && ! (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))
+    if (sortType == nsMsgViewSortType::byThread &&
+        !(m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))
+    {
       SetViewFlags(m_viewFlags | nsMsgViewFlagsType::kThreadedDisplay);
+    }
+
     SaveSortInfo(sortType, sortOrder);
     return NS_OK;
   }
 
   if (!m_checkedCustomColumns && CustomColumnsInSortAndNotRegistered())
     return NS_OK;
 
-  // sort threads by sort order
-  bool sortThreads = m_viewFlags & (nsMsgViewFlagsType::kThreadedDisplay | nsMsgViewFlagsType::kGroupBySort);
+  // Sort threads by sort order.
+  bool sortThreads = m_viewFlags & (nsMsgViewFlagsType::kThreadedDisplay |
+                                    nsMsgViewFlagsType::kGroupBySort);
 
-  // if sort type is by thread, and we're already threaded, change sort type to byId
-  if (sortType == nsMsgViewSortType::byThread && (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay) != 0)
+  // If sort type is by thread, and we're already threaded, change sort type
+  // to byId.
+  if (sortType == nsMsgViewSortType::byThread &&
+      (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay) != 0)
+  {
     sortType = nsMsgViewSortType::byId;
+  }
 
   nsMsgKey preservedKey;
   AutoTArray<nsMsgKey, 1> preservedSelection;
   SaveAndClearSelection(&preservedKey, preservedSelection);
-  // if the client wants us to forget our cached id arrays, they
+  // If the client wants us to forget our cached id arrays, they
   // should build a new view. If this isn't good enough, we
   // need a method to do that.
   if (sortType != m_sortType || !m_sortValid || sortThreads)
   {
     SaveSortInfo(sortType, sortOrder);
     if (sortType == nsMsgViewSortType::byThread)
     {
       m_sortType = sortType;
       m_viewFlags |= nsMsgViewFlagsType::kThreadedDisplay;
       m_viewFlags &= ~nsMsgViewFlagsType::kGroupBySort;
       if ( m_havePrevView)
       {
-        // restore saved id array and flags array
+        // Restore saved id array and flags array.
         m_keys = m_prevKeys;
         m_flags = m_prevFlags;
         m_levels = m_prevLevels;
         m_sortValid = true;
 
-        // the sort may have changed the number of rows
+        // The sort may have changed the number of rows
         // before we restore the selection, tell the tree
         // do this before we call restore selection
         // this is safe when there is no selection.
         rv = AdjustRowCount(rowCountBeforeSort, GetSize());
 
         RestoreSelection(preservedKey, preservedSelection);
-        if (mTree) mTree->Invalidate();
+        if (mTree)
+          mTree->Invalidate();
+
         return NS_OK;
       }
       else
       {
-        // set sort info in anticipation of what Init will do.
-        InitThreadedView(nullptr);	// build up thread list.
+        // Set sort info in anticipation of what Init will do.
+        // Build up thread list.
+        InitThreadedView(nullptr);
         if (sortOrder != nsMsgViewSortOrder::ascending)
           Sort(sortType, sortOrder);
 
-        // the sort may have changed the number of rows
+        // The sort may have changed the number of rows
         // before we update the selection, tell the tree
         // do this before we call restore selection
         // this is safe when there is no selection.
         rv = AdjustRowCount(rowCountBeforeSort, GetSize());
 
         RestoreSelection(preservedKey, preservedSelection);
-        if (mTree) mTree->Invalidate();
+        if (mTree)
+          mTree->Invalidate();
+
         return NS_OK;
       }
     }
-    else if (sortType  != nsMsgViewSortType::byThread && (m_sortType == nsMsgViewSortType::byThread  || sortThreads)/* && !m_havePrevView*/)
+    else if (sortType  != nsMsgViewSortType::byThread &&
+             (m_sortType == nsMsgViewSortType::byThread  || sortThreads)
+             /* && !m_havePrevView*/)
     {
       if (sortThreads)
       {
         SortThreads(sortType, sortOrder);
-        sortType = nsMsgViewSortType::byThread; // hack so base class won't do anything
+        // Hack so base class won't do anything.
+        sortType = nsMsgViewSortType::byThread;
       }
       else
       {
-        // going from SortByThread to non-thread sort - must build new key, level,and flags arrays
+        // Going from SortByThread to non-thread sort - must build new key,
+        // level, and flags arrays.
         m_prevKeys = m_keys;
         m_prevFlags = m_flags;
         m_prevLevels = m_levels;
-        // do this before we sort, so that we'll use the cheap method
+        // Do this before we sort, so that we'll use the cheap method
         // of expanding.
         m_viewFlags &= ~(nsMsgViewFlagsType::kThreadedDisplay | nsMsgViewFlagsType::kGroupBySort);
         ExpandAll();
-        //			m_idArray.RemoveAll();
-        //			m_flags.Clear();
+        // m_idArray.RemoveAll();
+        // m_flags.Clear();
         m_havePrevView = true;
       }
     }
   }
-  else if (m_sortOrder != sortOrder)// check for toggling the sort
+  else if (m_sortOrder != sortOrder)
   {
+    // Check for toggling the sort.
     nsMsgDBView::Sort(sortType, sortOrder);
   }
+
   if (!sortThreads)
   {
-    // call the base class in case we're not sorting by thread
+    // Call the base class in case we're not sorting by thread.
     rv = nsMsgDBView::Sort(sortType, sortOrder);
     SaveSortInfo(sortType, sortOrder);
   }
-  // the sort may have changed the number of rows
+
+  // The sort may have changed the number of rows
   // before we restore the selection, tell the tree
   // do this before we call restore selection
   // this is safe when there is no selection.
   rv = AdjustRowCount(rowCountBeforeSort, GetSize());
 
   RestoreSelection(preservedKey, preservedSelection);
-  if (mTree) mTree->Invalidate();
+  if (mTree)
+    mTree->Invalidate();
+
   NS_ENSURE_SUCCESS(rv,rv);
   return NS_OK;
 }
 
-// list the ids of the top-level thread ids starting at id == startMsg. This actually returns
-// the ids of the first message in each thread.
-nsresult nsMsgThreadedDBView::ListThreadIds(nsMsgKey *startMsg, bool unreadOnly, nsMsgKey *pOutput, int32_t *pFlags, char *pLevels,
-									 int32_t numToList, int32_t *pNumListed, int32_t *pTotalHeaders)
+// List the ids of the top-level thread ids starting at id == startMsg.
+// This actually returns the ids of the first message in each thread.
+nsresult
+nsMsgThreadedDBView::ListThreadIds(nsMsgKey *startMsg,
+                                   bool unreadOnly,
+                                   nsMsgKey *pOutput,
+                                   int32_t *pFlags,
+                                   char *pLevels,
+                                   int32_t numToList,
+                                   int32_t *pNumListed,
+                                   int32_t *pTotalHeaders)
 {
   nsresult rv = NS_OK;
-  // N.B..don't ret before assigning numListed to *pNumListed
-  int32_t	numListed = 0;
+  // N.B..don't ret before assigning numListed to *pNumListed.
+  int32_t numListed = 0;
 
   if (*startMsg > 0)
   {
-    NS_ASSERTION(m_threadEnumerator != nullptr, "where's our iterator?");	// for now, we'll just have to rely on the caller leaving
+    // For now, we'll just have to rely on the caller leaving
     // the iterator in the right place.
+    NS_ASSERTION(m_threadEnumerator != nullptr, "where's our iterator?");
   }
   else
   {
     NS_ASSERTION(m_db, "no db");
-    if (!m_db) return NS_ERROR_UNEXPECTED;
+    if (!m_db)
+      return NS_ERROR_UNEXPECTED;
+
     rv = m_db->EnumerateThreads(getter_AddRefs(m_threadEnumerator));
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   bool hasMore = false;
 
   nsCOMPtr <nsIMsgThread> threadHdr ;
-  int32_t	threadsRemoved = 0;
+  int32_t threadsRemoved = 0;
   while (numListed < numToList &&
          NS_SUCCEEDED(rv = m_threadEnumerator->HasMoreElements(&hasMore)) &&
          hasMore)
   {
     nsCOMPtr <nsISupports> supports;
     rv = m_threadEnumerator->GetNext(getter_AddRefs(supports));
     if (NS_FAILED(rv))
     {
       threadHdr = nullptr;
       break;
     }
+
     threadHdr = do_QueryInterface(supports);
     if (!threadHdr)
       break;
+
     nsCOMPtr <nsIMsgDBHdr> msgHdr;
     uint32_t numChildren;
     if (unreadOnly)
       threadHdr->GetNumUnreadChildren(&numChildren);
     else
       threadHdr->GetNumChildren(&numChildren);
+
     uint32_t threadFlags;
     threadHdr->GetFlags(&threadFlags);
-    if (numChildren != 0)	// not empty thread
+    if (numChildren != 0)
     {
+      // Not an empty thread.
       int32_t unusedRootIndex;
       if (pTotalHeaders)
         *pTotalHeaders += numChildren;
+
       if (unreadOnly)
         rv = threadHdr->GetFirstUnreadChild(getter_AddRefs(msgHdr));
       else
         rv = threadHdr->GetRootHdr(&unusedRootIndex, getter_AddRefs(msgHdr));
+
       if (NS_SUCCEEDED(rv) && msgHdr != nullptr && WantsThisThread(threadHdr))
       {
         uint32_t msgFlags;
         uint32_t newMsgFlags;
         nsMsgKey msgKey;
         msgHdr->GetMessageKey(&msgKey);
         msgHdr->GetFlags(&msgFlags);
-        // turn off high byte of msg flags - used for view flags.
+        // Turn off high byte of msg flags - used for view flags.
         msgFlags &= ~MSG_VIEW_FLAGS;
         pOutput[numListed] = msgKey;
         pLevels[numListed] = 0;
-        // turn off these flags on msg hdr - they belong in thread
+        // Turn off these flags on msg hdr - they belong in thread.
         msgHdr->AndFlags(~(nsMsgMessageFlags::Watched), &newMsgFlags);
         AdjustReadFlag(msgHdr, &msgFlags);
-        // try adding in MSG_VIEW_FLAG_ISTHREAD flag for unreadonly view.
+        // Try adding in MSG_VIEW_FLAG_ISTHREAD flag for unreadonly view.
         pFlags[numListed] = msgFlags | MSG_VIEW_FLAG_ISTHREAD | threadFlags;
         if (numChildren > 1)
           pFlags[numListed] |= MSG_VIEW_FLAG_HASCHILDREN;
 
         numListed++;
       }
       else
-        NS_ASSERTION(NS_SUCCEEDED(rv) && msgHdr, "couldn't get header for some reason");
+      {
+        NS_ASSERTION(NS_SUCCEEDED(rv) && msgHdr,
+                     "couldn't get header for some reason");
+      }
     }
-    else if (threadsRemoved < 10 && !(threadFlags & (nsMsgMessageFlags::Watched | nsMsgMessageFlags::Ignored)))
+    else if (threadsRemoved < 10 &&
+             !(threadFlags & (nsMsgMessageFlags::Watched |
+                              nsMsgMessageFlags::Ignored)))
     {
       // ### remove thread.
-      threadsRemoved++;	// don't want to remove all empty threads first time
-      // around as it will choke preformance for upgrade.
+      // Don't want to remove all empty threads first time around as it will
+      // choke preformance for upgrade.
+      threadsRemoved++;
 #ifdef DEBUG_bienvenu
       printf("removing empty non-ignored non-watched thread\n");
 #endif
     }
   }
 
   if (hasMore && threadHdr)
   {
     threadHdr->GetThreadKey(startMsg);
   }
   else
   {
     *startMsg = nsMsgKey_None;
     nsCOMPtr <nsIDBChangeListener> dbListener = do_QueryInterface(m_threadEnumerator);
-    // this is needed to make the thread enumerator release its reference to the db.
+    // This is needed to make the thread enumerator release its reference
+    // to the db.
     if (dbListener)
       dbListener->OnAnnouncerGoingAway(nullptr);
+
     m_threadEnumerator = nullptr;
   }
+
   *pNumListed = numListed;
   return rv;
 }
 
-void	nsMsgThreadedDBView::OnExtraFlagChanged(nsMsgViewIndex index, uint32_t extraFlag)
+void
+nsMsgThreadedDBView::OnExtraFlagChanged(nsMsgViewIndex index,
+                                        uint32_t extraFlag)
 {
   if (IsValidIndex(index))
   {
     if (m_havePrevView)
     {
       nsMsgKey keyChanged = m_keys[index];
       nsMsgViewIndex prevViewIndex = m_prevKeys.IndexOf(keyChanged);
       if (prevViewIndex != nsMsgViewIndex_None)
       {
         uint32_t prevFlag = m_prevFlags[prevViewIndex];
-        // don't want to change the elided bit, or has children or is thread
+        // Don't want to change the elided bit, or has children or is thread.
         if (prevFlag & nsMsgMessageFlags::Elided)
           extraFlag |= nsMsgMessageFlags::Elided;
         else
           extraFlag &= ~nsMsgMessageFlags::Elided;
+
         if (prevFlag & MSG_VIEW_FLAG_ISTHREAD)
           extraFlag |= MSG_VIEW_FLAG_ISTHREAD;
         else
           extraFlag &= ~MSG_VIEW_FLAG_ISTHREAD;
+
         if (prevFlag & MSG_VIEW_FLAG_HASCHILDREN)
           extraFlag |= MSG_VIEW_FLAG_HASCHILDREN;
         else
           extraFlag &= ~MSG_VIEW_FLAG_HASCHILDREN;
-        m_prevFlags[prevViewIndex] = extraFlag; // will this be right?
+
+        // Will this be right?
+        m_prevFlags[prevViewIndex] = extraFlag;
       }
     }
   }
-  // we don't really know what's changed, but to be on the safe side, set the sort invalid
-  // so that reverse sort will pick it up.
-  if (m_sortType == nsMsgViewSortType::byStatus || m_sortType == nsMsgViewSortType::byFlagged ||
-    m_sortType == nsMsgViewSortType::byUnread || m_sortType == nsMsgViewSortType::byPriority)
+
+  // We don't really know what's changed, but to be on the safe side, set the
+  // sort invalid so that reverse sort will pick it up.
+  if (m_sortType == nsMsgViewSortType::byStatus ||
+      m_sortType == nsMsgViewSortType::byFlagged ||
+      m_sortType == nsMsgViewSortType::byUnread ||
+      m_sortType == nsMsgViewSortType::byPriority)
+  {
     m_sortValid = false;
+  }
 }
 
-void nsMsgThreadedDBView::OnHeaderAddedOrDeleted()
+void
+nsMsgThreadedDBView::OnHeaderAddedOrDeleted()
 {
   ClearPrevIdArray();
 }
 
-void nsMsgThreadedDBView::ClearPrevIdArray()
+void
+nsMsgThreadedDBView::ClearPrevIdArray()
 {
   m_prevKeys.Clear();
   m_prevLevels.Clear();
   m_prevFlags.Clear();
   m_havePrevView = false;
 }
 
-nsresult nsMsgThreadedDBView::InitSort(nsMsgViewSortTypeValue sortType, nsMsgViewSortOrderValue sortOrder)
+nsresult
+nsMsgThreadedDBView::InitSort(nsMsgViewSortTypeValue sortType,
+                              nsMsgViewSortOrderValue sortOrder)
 {
+  // Nothing to do.
   if (m_viewFlags & nsMsgViewFlagsType::kGroupBySort)
-    return NS_OK; // nothing to do.
+    return NS_OK;
 
   if (sortType == nsMsgViewSortType::byThread)
   {
-    nsMsgDBView::Sort(nsMsgViewSortType::byId, sortOrder); // sort top level threads by id.
+    // Sort top level threads by id.
+    nsMsgDBView::Sort(nsMsgViewSortType::byId, sortOrder);
     m_sortType = nsMsgViewSortType::byThread;
     m_viewFlags |= nsMsgViewFlagsType::kThreadedDisplay;
     m_viewFlags &= ~nsMsgViewFlagsType::kGroupBySort;
-    SetViewFlags(m_viewFlags); // persist the view flags.
-    //		m_db->SetSortInfo(m_sortType, sortOrder);
+    // Persist the view flags.
+    SetViewFlags(m_viewFlags);
+    // m_db->SetSortInfo(m_sortType, sortOrder);
   }
 //  else
 //    m_viewFlags &= ~nsMsgViewFlagsType::kThreadedDisplay;
 
-  // by default, the unread only view should have all threads expanded.
-  if ((m_viewFlags & (nsMsgViewFlagsType::kUnreadOnly|nsMsgViewFlagsType::kExpandAll))
-      && (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))
+
+  // By default, the unread only view should have all threads expanded.
+  if ((m_viewFlags & (nsMsgViewFlagsType::kUnreadOnly |
+                      nsMsgViewFlagsType::kExpandAll)) &&
+      (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))
+  {
     ExpandAll();
-  if (! (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))
-    ExpandAll(); // for now, expand all and do a flat sort.
+  }
+
+  if (!(m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))
+  {
+    // For now, expand all and do a flat sort.
+    ExpandAll();
+  }
 
   Sort(sortType, sortOrder);
-  if (sortType != nsMsgViewSortType::byThread)	// forget prev view, since it has everything expanded.
+  if (sortType != nsMsgViewSortType::byThread)
+  {
+    // Forget prev view, since it has everything expanded.
     ClearPrevIdArray();
+  }
+
   return NS_OK;
 }
 
-nsresult nsMsgThreadedDBView::OnNewHeader(nsIMsgDBHdr *newHdr, nsMsgKey aParentKey, bool ensureListed)
+nsresult
+nsMsgThreadedDBView::OnNewHeader(nsIMsgDBHdr *newHdr,
+                                 nsMsgKey aParentKey,
+                                 bool ensureListed)
 {
   if (m_viewFlags & nsMsgViewFlagsType::kGroupBySort)
     return nsMsgGroupView::OnNewHeader(newHdr, aParentKey, ensureListed);
 
   NS_ENSURE_TRUE(newHdr, NS_MSG_MESSAGE_NOT_FOUND);
 
   nsMsgKey newKey;
   newHdr->GetMessageKey(&newKey);
 
-  // views can override this behaviour, which is to append to view.
+  // Views can override this behaviour, which is to append to view.
   // This is the mail behaviour, but threaded views want
   // to insert in order...
   uint32_t msgFlags;
   newHdr->GetFlags(&msgFlags);
-  if ((m_viewFlags & nsMsgViewFlagsType::kUnreadOnly) && !ensureListed &&
-      (msgFlags & nsMsgMessageFlags::Read))
+  if (m_viewFlags & nsMsgViewFlagsType::kUnreadOnly &&
+      !ensureListed &&
+      msgFlags & nsMsgMessageFlags::Read)
+  {
     return NS_OK;
+  }
+
   // Currently, we only add the header in a threaded view if it's a thread.
   // We used to check if this was the first header in the thread, but that's
   // a bit harder in the unreadOnly view. But we'll catch it below.
 
-  // if not threaded display just add it to the view.
+  // If not threaded display just add it to the view.
   if (!(m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))
     return AddHdr(newHdr);
 
-  // need to find the thread we added this to so we can change the hasnew flag
-  // added message to existing thread, but not to view
+  // Need to find the thread we added this to so we can change the hasnew flag
+  // added message to existing thread, but not to view.
   // Fix flags on thread header.
   int32_t threadCount;
   uint32_t threadFlags;
   bool moveThread = false;
-  nsMsgViewIndex threadIndex = ThreadIndexOfMsg(newKey, nsMsgViewIndex_None, &threadCount, &threadFlags);
+  nsMsgViewIndex threadIndex = ThreadIndexOfMsg(newKey, nsMsgViewIndex_None,
+                                                &threadCount, &threadFlags);
   bool threadRootIsDisplayed = false;
 
   nsCOMPtr <nsIMsgThread> threadHdr;
   m_db->GetThreadContainingMsgHdr(newHdr, getter_AddRefs(threadHdr));
   if (threadHdr && m_sortType == nsMsgViewSortType::byDate)
   {
     uint32_t newestMsgInThread = 0, msgDate = 0;
     threadHdr->GetNewestMsgDate(&newestMsgInThread);
@@ -606,39 +742,43 @@ nsresult nsMsgThreadedDBView::OnNewHeade
   {
     threadRootIsDisplayed = (m_currentlyDisplayedViewIndex == threadIndex);
     uint32_t flags = m_flags[threadIndex];
     if (!(flags & MSG_VIEW_FLAG_HASCHILDREN))
     {
       flags |= MSG_VIEW_FLAG_HASCHILDREN | MSG_VIEW_FLAG_ISTHREAD;
       if (!(m_viewFlags & nsMsgViewFlagsType::kUnreadOnly))
         flags |= nsMsgMessageFlags::Elided;
+
       m_flags[threadIndex] = flags;
     }
 
     if (!(flags & nsMsgMessageFlags::Elided))
-    { // thread is expanded
-      // insert child into thread
-      // levels of other hdrs may have changed!
+    {
+      // Thread is expanded.
+      // Insert child into thread.
+      // Levels of other hdrs may have changed!
       uint32_t newFlags = msgFlags;
       int32_t level = 0;
       nsMsgViewIndex insertIndex = threadIndex;
       if (aParentKey == nsMsgKey_None)
       {
         newFlags |= MSG_VIEW_FLAG_ISTHREAD | MSG_VIEW_FLAG_HASCHILDREN;
       }
       else
       {
         nsMsgViewIndex parentIndex = FindParentInThread(aParentKey, threadIndex);
         level = m_levels[parentIndex] + 1;
         insertIndex = GetInsertInfoForNewHdr(newHdr, parentIndex, level);
       }
+
       InsertMsgHdrAt(insertIndex, newHdr, newKey, newFlags, level);
-      // the call to NoteChange() has to happen after we add the key
-      // as NoteChange() will call RowCountChanged() which will call our GetRowCount()
+      // The call to NoteChange() has to happen after we add the key as
+      // NoteChange() will call RowCountChanged() which will call our
+      // GetRowCount().
       NoteChange(insertIndex, 1, nsMsgViewNotificationCode::insertOrDelete);
 
       if (aParentKey == nsMsgKey_None)
       {
         // this header is the new king! try collapsing the existing thread,
         // removing it, installing this header as king, and expanding it.
         CollapseByIndex(threadIndex, nullptr);
         // call base class, so child won't get promoted.
@@ -663,77 +803,95 @@ nsresult nsMsgThreadedDBView::OnNewHeade
 
     if (moveThread)
       MoveThreadAt(threadIndex);
     else
       // note change, to update the parent thread's unread and total counts
       NoteChange(threadIndex, 1, nsMsgViewNotificationCode::changed);
   }
   else if (threadHdr)
-    // adding msg to thread that's not in view.
+  {
+    // Adding msg to thread that's not in view.
     AddMsgToThreadNotInView(threadHdr, newHdr, ensureListed);
+  }
 
   return NS_OK;
 }
 
-
-NS_IMETHODIMP nsMsgThreadedDBView::OnParentChanged (nsMsgKey aKeyChanged, nsMsgKey oldParent, nsMsgKey newParent, nsIDBChangeListener *aInstigator)
+NS_IMETHODIMP
+nsMsgThreadedDBView::OnParentChanged (nsMsgKey aKeyChanged,
+                                      nsMsgKey oldParent,
+                                      nsMsgKey newParent,
+                                      nsIDBChangeListener *aInstigator)
 {
-  // we need to adjust the level of the hdr whose parent changed, and invalidate that row,
-  // iff we're in threaded mode.
+  // We need to adjust the level of the hdr whose parent changed, and
+  // invalidate that row, iff we're in threaded mode.
 #if 0
   // This code never runs due to the if (false) and Clang complains about it
   // so it is ifdefed out for now.
   if (false && m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay)
   {
     nsMsgViewIndex childIndex = FindViewIndex(aKeyChanged);
     if (childIndex != nsMsgViewIndex_None)
     {
       nsMsgViewIndex parentIndex = FindViewIndex(newParent);
-      int32_t newParentLevel = (parentIndex == nsMsgViewIndex_None) ? -1 : m_levels[parentIndex];
+      int32_t newParentLevel =
+        (parentIndex == nsMsgViewIndex_None) ? -1 : m_levels[parentIndex];
+
       nsMsgViewIndex oldParentIndex = FindViewIndex(oldParent);
-      int32_t oldParentLevel = (oldParentIndex != nsMsgViewIndex_None || newParent == nsMsgKey_None)
-        ? m_levels[oldParentIndex] : -1 ;
+
+      int32_t oldParentLevel =
+        (oldParentIndex != nsMsgViewIndex_None ||
+         newParent == nsMsgKey_None) ? m_levels[oldParentIndex] : -1 ;
+
       int32_t levelChanged = m_levels[childIndex];
       int32_t parentDelta = oldParentLevel - newParentLevel;
       m_levels[childIndex] = (newParent == nsMsgKey_None) ? 0 : newParentLevel + 1;
       if (parentDelta > 0)
       {
-        for (nsMsgViewIndex viewIndex = childIndex + 1; viewIndex < GetSize() && m_levels[viewIndex] > levelChanged;  viewIndex++)
+        for (nsMsgViewIndex viewIndex = childIndex + 1;
+             viewIndex < GetSize() && m_levels[viewIndex] > levelChanged;
+             viewIndex++)
         {
           m_levels[viewIndex] = m_levels[viewIndex] - parentDelta;
           NoteChange(viewIndex, 1, nsMsgViewNotificationCode::changed);
         }
       }
+
       NoteChange(childIndex, 1, nsMsgViewNotificationCode::changed);
     }
   }
 #endif
   return NS_OK;
 }
 
-
-nsMsgViewIndex nsMsgThreadedDBView::GetInsertInfoForNewHdr(nsIMsgDBHdr *newHdr, nsMsgViewIndex parentIndex, int32_t targetLevel)
+nsMsgViewIndex
+nsMsgThreadedDBView::GetInsertInfoForNewHdr(nsIMsgDBHdr *newHdr,
+                                            nsMsgViewIndex parentIndex,
+                                            int32_t targetLevel)
 {
   uint32_t viewSize = GetSize();
   while (++parentIndex < viewSize)
   {
-    // loop until we find a message at a level less than or equal to the parent level
+    // Loop until we find a message at a level less than or equal to the
+    // parent level
     if (m_levels[parentIndex] < targetLevel)
       break;
   }
+
   return parentIndex;
 }
 
 // This method removes the thread at threadIndex from the view
 // and puts it back in its new position, determined by the sort order.
 // And, if the selection is affected, save and restore the selection.
-void nsMsgThreadedDBView::MoveThreadAt(nsMsgViewIndex threadIndex)
+void
+nsMsgThreadedDBView::MoveThreadAt(nsMsgViewIndex threadIndex)
 {
-  // we need to check if the thread is collapsed or not...
+  // We need to check if the thread is collapsed or not...
   // We want to turn off tree notifications so that we don't
   // reload the current message.
   // We also need to invalidate the range between where the thread was
   // and where it ended up.
   bool changesDisabled = mSuppressChangeNotification;
   if (!changesDisabled)
     SetSuppressChangeNotifications(true);
 
@@ -742,111 +900,126 @@ void nsMsgThreadedDBView::MoveThreadAt(n
   GetMsgHdrForViewIndex(threadIndex, getter_AddRefs(threadHdr));
   int32_t childCount = 0;
 
   nsMsgKey preservedKey;
   AutoTArray<nsMsgKey, 1> preservedSelection;
   int32_t selectionCount;
   int32_t currentIndex;
   bool hasSelection = mTree && mTreeSelection &&
-                        ((NS_SUCCEEDED(mTreeSelection->GetCurrentIndex(&currentIndex)) &&
-                         currentIndex >= 0 && (uint32_t)currentIndex < GetSize()) ||
-                         (NS_SUCCEEDED(mTreeSelection->GetRangeCount(&selectionCount)) &&
-                          selectionCount > 0));
+                      ((NS_SUCCEEDED(mTreeSelection->GetCurrentIndex(&currentIndex)) &&
+                        currentIndex >= 0 && (uint32_t)currentIndex < GetSize()) ||
+                       (NS_SUCCEEDED(mTreeSelection->GetRangeCount(&selectionCount)) &&
+                        selectionCount > 0));
   if (hasSelection)
     SaveAndClearSelection(&preservedKey, preservedSelection);
+
   uint32_t saveFlags = m_flags[threadIndex];
   bool threadIsExpanded = !(saveFlags & nsMsgMessageFlags::Elided);
 
   if (threadIsExpanded)
   {
     ExpansionDelta(threadIndex, &childCount);
     childCount = -childCount;
   }
+
   nsTArray<nsMsgKey> threadKeys;
   nsTArray<uint32_t> threadFlags;
   nsTArray<uint8_t> threadLevels;
 
   if (threadIsExpanded)
   {
     threadKeys.SetCapacity(childCount);
     threadFlags.SetCapacity(childCount);
     threadLevels.SetCapacity(childCount);
     for (nsMsgViewIndex index = threadIndex + 1;
-        index < GetSize() && m_levels[index]; index++)
+         index < GetSize() && m_levels[index];
+         index++)
     {
       threadKeys.AppendElement(m_keys[index]);
       threadFlags.AppendElement(m_flags[index]);
       threadLevels.AppendElement(m_levels[index]);
     }
+
     uint32_t collapseCount;
     CollapseByIndex(threadIndex, &collapseCount);
   }
+
   nsMsgDBView::RemoveByIndex(threadIndex);
   nsMsgViewIndex newIndex = nsMsgViewIndex_None;
   AddHdr(threadHdr, &newIndex);
 
   // AddHdr doesn't always set newIndex, and getting it to do so
   // is going to require some refactoring.
   if (newIndex == nsMsgViewIndex_None)
     newIndex = FindHdr(threadHdr);
 
   if (threadIsExpanded)
   {
     m_keys.InsertElementsAt(newIndex + 1, threadKeys);
     m_flags.InsertElementsAt(newIndex + 1, threadFlags);
     m_levels.InsertElementsAt(newIndex + 1, threadLevels);
   }
+
   if (newIndex == nsMsgViewIndex_None)
   {
      NS_WARNING("newIndex=-1 in MoveThreadAt");
      newIndex = 0;
   }
+
   m_flags[newIndex] = saveFlags;
-  // unfreeze selection.
+  // Unfreeze selection.
   if (hasSelection)
     RestoreSelection(preservedKey, preservedSelection);
 
   if (!changesDisabled)
     SetSuppressChangeNotifications(false);
+
   nsMsgViewIndex lowIndex = threadIndex < newIndex ? threadIndex : newIndex;
   nsMsgViewIndex highIndex = lowIndex == threadIndex ? newIndex : threadIndex;
+
   NoteChange(lowIndex, highIndex - lowIndex + childCount + 1,
              nsMsgViewNotificationCode::changed);
 }
-nsresult nsMsgThreadedDBView::AddMsgToThreadNotInView(nsIMsgThread *threadHdr, nsIMsgDBHdr *msgHdr, bool ensureListed)
+
+nsresult
+nsMsgThreadedDBView::AddMsgToThreadNotInView(nsIMsgThread *threadHdr,
+                                             nsIMsgDBHdr *msgHdr,
+                                             bool ensureListed)
 {
   nsresult rv = NS_OK;
   uint32_t threadFlags;
   threadHdr->GetFlags(&threadFlags);
   if (!(threadFlags & nsMsgMessageFlags::Ignored))
   {
     bool msgKilled;
     msgHdr->GetIsKilled(&msgKilled);
     if (!msgKilled)
       rv = nsMsgDBView::AddHdr(msgHdr);
   }
+
   return rv;
 }
 
 // This method just removes the specified line from the view. It does
 // NOT delete it from the database.
-nsresult nsMsgThreadedDBView::RemoveByIndex(nsMsgViewIndex index)
+nsresult
+nsMsgThreadedDBView::RemoveByIndex(nsMsgViewIndex index)
 {
   nsresult rv = NS_OK;
   int32_t flags;
 
   if (!IsValidIndex(index))
     return NS_MSG_INVALID_DBVIEW_INDEX;
 
   OnHeaderAddedOrDeleted();
 
   flags = m_flags[index];
 
-  if (! (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))
+  if (!(m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))
     return nsMsgDBView::RemoveByIndex(index);
 
   nsCOMPtr<nsIMsgThread> threadHdr;
   GetThreadContainingIndex(index, getter_AddRefs(threadHdr));
   NS_ENSURE_SUCCESS(rv, rv);
   uint32_t numThreadChildren = 0;
   // If we can't get a thread, it's already deleted and thus has 0 children.
   if (threadHdr)
@@ -876,16 +1049,17 @@ nsresult nsMsgThreadedDBView::RemoveByIn
           if (numThreadChildren > 1)
             flag |= MSG_VIEW_FLAG_ISTHREAD | MSG_VIEW_FLAG_HASCHILDREN;
 
           m_flags[index] = flag;
           m_levels[index] = 0;
         }
       }
     }
+
     return rv;
   }
   else if (!(flags & MSG_VIEW_FLAG_ISTHREAD))
   {
     // We're not deleting the top level msg, but top level msg might be the
     // only msg in thread now.
     if (threadHdr && numThreadChildren == 1)
     {
@@ -901,79 +1075,88 @@ nsresult nsMsgThreadedDBView::RemoveByIn
                      nsMsgMessageFlags::Elided |
                      MSG_VIEW_FLAG_HASCHILDREN);
           m_flags[threadIndex] = flags;
           NoteChange(threadIndex, 1, nsMsgViewNotificationCode::changed);
         }
       }
 
     }
+
     return nsMsgDBView::RemoveByIndex(index);
   }
+
   // Deleting collapsed thread header is special case. Child will be promoted,
   // so just tell FE that line changed, not that it was deleted.
   // Header has aleady been deleted from thread.
   if (threadHdr && numThreadChildren > 0)
   {
-    // change the id array and flags array to reflect the child header.
+    // Change the id array and flags array to reflect the child header.
     // If we're not deleting the header, we want the second header,
     // Otherwise, the first one (which just got promoted).
     nsCOMPtr<nsIMsgDBHdr> msgHdr;
     rv = threadHdr->GetChildHdrAt(0, getter_AddRefs(msgHdr));
     if (msgHdr != nullptr)
     {
       msgHdr->GetMessageKey(&m_keys[index]);
-
       uint32_t flag = 0;
       msgHdr->GetFlags(&flag);
       flag |= MSG_VIEW_FLAG_ISTHREAD;
 
-      // if only hdr in thread (with one about to be deleted)
+      // If only hdr in thread (with one about to be deleted).
       if (numThreadChildren == 1)
       {
-        // adjust flags.
+        // Adjust flags.
         flag &=  ~MSG_VIEW_FLAG_HASCHILDREN;
         flag &= ~nsMsgMessageFlags::Elided;
-        // tell FE that thread header needs to be repainted.
+        // Tell FE that thread header needs to be repainted.
         NoteChange(index, 1, nsMsgViewNotificationCode::changed);
       }
       else
       {
         flag |= MSG_VIEW_FLAG_HASCHILDREN;
         flag |= nsMsgMessageFlags::Elided;
       }
+
       m_flags[index] = flag;
       mIndicesToNoteChange.RemoveElement(index);
     }
     else
-      NS_ASSERTION(false, "couldn't find thread child");	
+    {
+      NS_ASSERTION(false, "couldn't find thread child");
+    }
 
-    NoteChange(index, 1, nsMsgViewNotificationCode::changed);	
+    NoteChange(index, 1, nsMsgViewNotificationCode::changed);
   }
   else
   {
-    // we may have deleted a whole, collapsed thread - if so,
+    // We may have deleted a whole, collapsed thread - if so,
     // ensure that the current index will be noted as changed.
     if (!mIndicesToNoteChange.Contains(index))
       mIndicesToNoteChange.AppendElement(index);
 
     rv = nsMsgDBView::RemoveByIndex(index);
   }
+
   return rv;
 }
 
-NS_IMETHODIMP nsMsgThreadedDBView::GetViewType(nsMsgViewTypeValue *aViewType)
+NS_IMETHODIMP
+nsMsgThreadedDBView::GetViewType(nsMsgViewTypeValue *aViewType)
 {
-    NS_ENSURE_ARG_POINTER(aViewType);
-    *aViewType = nsMsgViewType::eShowAllThreads;
-    return NS_OK;
+  NS_ENSURE_ARG_POINTER(aViewType);
+  *aViewType = nsMsgViewType::eShowAllThreads;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMsgThreadedDBView::CloneDBView(nsIMessenger *aMessengerInstance, nsIMsgWindow *aMsgWindow, nsIMsgDBViewCommandUpdater *aCmdUpdater, nsIMsgDBView **_retval)
+nsMsgThreadedDBView::CloneDBView(nsIMessenger *aMessengerInstance,
+                                 nsIMsgWindow *aMsgWindow,
+                                 nsIMsgDBViewCommandUpdater *aCmdUpdater,
+                                 nsIMsgDBView **_retval)
 {
   nsMsgThreadedDBView* newMsgDBView = new nsMsgThreadedDBView();
 
   if (!newMsgDBView)
     return NS_ERROR_OUT_OF_MEMORY;
 
   nsresult rv = CopyDBView(newMsgDBView, aMessengerInstance, aMsgWindow, aCmdUpdater);
   NS_ENSURE_SUCCESS(rv,rv);
--- a/mailnews/base/src/nsMsgXFViewThread.cpp
+++ b/mailnews/base/src/nsMsgXFViewThread.cpp
@@ -5,97 +5,109 @@
 
 #include "msgCore.h"
 #include "nsMsgXFViewThread.h"
 #include "nsMsgSearchDBView.h"
 #include "nsMsgMessageFlags.h"
 
 NS_IMPL_ISUPPORTS(nsMsgXFViewThread, nsIMsgThread)
 
-nsMsgXFViewThread::nsMsgXFViewThread(nsMsgSearchDBView *view, nsMsgKey threadId)
+nsMsgXFViewThread::nsMsgXFViewThread(nsMsgSearchDBView *view,
+                                     nsMsgKey threadId)
 {
   m_numUnreadChildren = 0;
   m_numChildren = 0;
   m_flags = 0;
   m_newestMsgDate = 0;
   m_view = view;
   m_threadId = threadId;
 }
 
 nsMsgXFViewThread::~nsMsgXFViewThread()
 {
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::SetThreadKey(nsMsgKey threadKey)
+NS_IMETHODIMP
+nsMsgXFViewThread::SetThreadKey(nsMsgKey threadKey)
 {
   m_threadId = threadKey;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::GetThreadKey(nsMsgKey *aResult)
+NS_IMETHODIMP
+nsMsgXFViewThread::GetThreadKey(nsMsgKey *aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
   *aResult = m_threadId;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::GetFlags(uint32_t *aFlags)
+NS_IMETHODIMP
+nsMsgXFViewThread::GetFlags(uint32_t *aFlags)
 {
   NS_ENSURE_ARG_POINTER(aFlags);
   *aFlags = m_flags;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::SetFlags(uint32_t aFlags)
+NS_IMETHODIMP
+nsMsgXFViewThread::SetFlags(uint32_t aFlags)
 {
   m_flags = aFlags;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::SetSubject(const nsACString& aSubject)
+NS_IMETHODIMP
+nsMsgXFViewThread::SetSubject(const nsACString& aSubject)
 {
   NS_ASSERTION(false, "shouldn't call this");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::GetSubject(nsACString& result)
+NS_IMETHODIMP
+nsMsgXFViewThread::GetSubject(nsACString& result)
 {
   NS_ASSERTION(false, "shouldn't call this");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::GetNumChildren(uint32_t *aNumChildren)
+NS_IMETHODIMP
+nsMsgXFViewThread::GetNumChildren(uint32_t *aNumChildren)
 {
   NS_ENSURE_ARG_POINTER(aNumChildren);
   *aNumChildren = m_keys.Length();
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::GetNumUnreadChildren (uint32_t *aNumUnreadChildren)
+NS_IMETHODIMP
+nsMsgXFViewThread::GetNumUnreadChildren (uint32_t *aNumUnreadChildren)
 {
   NS_ENSURE_ARG_POINTER(aNumUnreadChildren);
   *aNumUnreadChildren = m_numUnreadChildren;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMsgXFViewThread::AddChild(nsIMsgDBHdr *aNewHdr, nsIMsgDBHdr *aInReplyTo,
-                            bool aThreadInThread, nsIDBChangeAnnouncer *aAnnouncer)
+nsMsgXFViewThread::AddChild(nsIMsgDBHdr *aNewHdr,
+                            nsIMsgDBHdr *aInReplyTo,
+                            bool aThreadInThread,
+                            nsIDBChangeAnnouncer *aAnnouncer)
 {
   uint32_t whereInserted;
   return AddHdr(aNewHdr, false, whereInserted, nullptr);
 }
 
 // Returns the parent of the newly added header. If reparentChildren
 // is true, we believe that the new header is a parent of an existing
 // header, and we should find it, and reparent it.
-nsresult nsMsgXFViewThread::AddHdr(nsIMsgDBHdr *newHdr,
-                                   bool reparentChildren,
-                                   uint32_t &whereInserted,
-                                   nsIMsgDBHdr **outParent)
+nsresult
+nsMsgXFViewThread::AddHdr(nsIMsgDBHdr *newHdr,
+                          bool reparentChildren,
+                          uint32_t &whereInserted,
+                          nsIMsgDBHdr **outParent)
 {
   nsCOMPtr<nsIMsgFolder> newHdrFolder;
   newHdr->GetFolder(getter_AddRefs(newHdrFolder));
 
   uint32_t newHdrFlags = 0;
   uint32_t msgDate;
   nsMsgKey newHdrKey = 0;
 
@@ -114,16 +126,17 @@ nsresult nsMsgXFViewThread::AddHdr(nsIMs
 
   if (m_numChildren == 1)
   {
     m_keys.InsertElementAt(0, newHdrKey);
     m_levels.InsertElementAt(0, 0);
     m_folders.InsertObjectAt(newHdrFolder, 0);
     if (outParent)
       *outParent = nullptr;
+
     whereInserted = 0;
     return NS_OK;
   }
 
   // Find our parent, if any, in the thread. Starting at the newest
   // reference, and working our way back, see if we've mapped that reference
   // to this thread.
   uint16_t numReferences;
@@ -145,88 +158,98 @@ nsresult nsMsgXFViewThread::AddHdr(nsIMs
     if (parent)
     {
       parentIndex = HdrIndex(parent);
       if (parentIndex == -1)
       {
         NS_ERROR("how did we get in the wrong thread?");
         parent = nullptr;
       }
+
       break;
     }
   }
+
   if (parent)
   {
     uint32_t parentLevel = m_levels[parentIndex];
     nsMsgKey parentKey;
     parent->GetMessageKey(&parentKey);
     nsCOMPtr<nsIMsgFolder> parentFolder;
     parent->GetFolder(getter_AddRefs(parentFolder));
 
     if (outParent)
       parent.forget(outParent);
 
-    // iterate over our parents' children until we find one we're older than,
+    // Iterate over our parents' children until we find one we're older than,
     // and insert ourselves before it, or as the last child. In other words,
     // insert, sorted by date.
     uint32_t msgDate, childDate;
     newHdr->GetDateInSeconds(&msgDate);
     nsCOMPtr<nsIMsgDBHdr> child;
     nsMsgViewIndex i;
     nsMsgViewIndex insertIndex = m_keys.Length();
     uint32_t insertLevel = parentLevel + 1;
     for (i = parentIndex;
-         i < m_keys.Length() && (i == (nsMsgViewIndex)parentIndex || m_levels[i] >= parentLevel);
+         i < m_keys.Length() &&
+           (i == (nsMsgViewIndex)parentIndex || m_levels[i] >= parentLevel);
          i++)
     {
       GetChildHdrAt(i, getter_AddRefs(child));
       if (child)
       {
         if (reparentChildren && IsHdrParentOf(newHdr, child))
         {
           insertIndex = i;
-          // bump all the children of the current child, and the child
+          // Bump all the children of the current child, and the child.
           nsMsgViewIndex j = insertIndex;
           uint8_t childLevel = m_levels[insertIndex];
           do
           {
             m_levels[j] = m_levels[j] + 1;
             j++;
           }
           while (j < m_keys.Length() && m_levels[j] > childLevel);
           break;
         }
-        else if (m_levels[i] == parentLevel + 1) // possible sibling
+        else if (m_levels[i] == parentLevel + 1)
         {
+          // Possible sibling.
           child->GetDateInSeconds(&childDate);
           if (msgDate < childDate)
           {
-            // if we think we need to reparent, remember this
-            // insert index, but keep looking for children.
+            // If we think we need to reparent, remember this insert index,
+            // but keep looking for children.
             insertIndex = i;
             insertLevel = m_levels[i];
-            // if the sibling we're inserting after has children, we need
+            // If the sibling we're inserting after has children, we need
             // to go after the children.
-            while (insertIndex + 1 < m_keys.Length() && m_levels[insertIndex + 1] > insertLevel)
+            while (insertIndex + 1 < m_keys.Length() &&
+                   m_levels[insertIndex + 1] > insertLevel)
+            {
               insertIndex++;
+            }
+
             if (!reparentChildren)
               break;
           }
         }
       }
     }
+
     m_keys.InsertElementAt(insertIndex, newHdrKey);
     m_levels.InsertElementAt(insertIndex, insertLevel);
     m_folders.InsertObjectAt(newHdrFolder, insertIndex);
     whereInserted = insertIndex;
   }
   else
   {
     if (outParent)
       *outParent = nullptr;
+
     nsCOMPtr<nsIMsgDBHdr> rootHdr;
     GetChildHdrAt(0, getter_AddRefs(rootHdr));
     // If the new header is a parent of the root then it should be promoted.
     if (rootHdr && IsHdrParentOf(newHdr, rootHdr))
     {
       m_keys.InsertElementAt(0, newHdrKey);
       m_levels.InsertElementAt(0, 0);
       m_folders.InsertObjectAt(newHdrFolder, 0);
@@ -237,16 +260,17 @@ nsresult nsMsgXFViewThread::AddHdr(nsIMs
     }
     else
     {
       m_keys.AppendElement(newHdrKey);
       m_levels.AppendElement(1);
       m_folders.AppendObject(newHdrFolder);
       if (outParent)
         rootHdr.forget(outParent);
+
       whereInserted = m_keys.Length() -1;
     }
   }
 
   // ### TODO handle the case where the root header starts
   // with Re, and the new one doesn't, and is earlier. In that
   // case, we want to promote the new header to root.
 
@@ -261,152 +285,181 @@ nsresult nsMsgXFViewThread::AddHdr(nsIMs
 //    rv = GetRootHdr(nullptr, getter_AddRefs(topLevelHdr));
 //    if (NS_SUCCEEDED(rv) && topLevelHdr)
 //    {
 //      topLevelHdr->GetDate(&topLevelHdrDate);
 //      if (newHdrDate < topLevelHdrDate)
 
 //    }
 //  }
+
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::GetChildHdrAt(uint32_t aIndex, nsIMsgDBHdr **aResult)
+NS_IMETHODIMP
+nsMsgXFViewThread::GetChildHdrAt(uint32_t aIndex,
+                                 nsIMsgDBHdr **aResult)
 {
   if (aIndex >= m_keys.Length())
     return NS_MSG_MESSAGE_NOT_FOUND;
+
   nsCOMPtr<nsIMsgDatabase> db;
   nsresult rv = m_folders[aIndex]->GetMsgDatabase(getter_AddRefs(db));
   NS_ENSURE_SUCCESS(rv, rv);
   return db->GetMsgHdrForKey(m_keys[aIndex], aResult);
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::RemoveChildAt(uint32_t aIndex)
+NS_IMETHODIMP
+nsMsgXFViewThread::RemoveChildAt(uint32_t aIndex)
 {
   m_keys.RemoveElementAt(aIndex);
   m_levels.RemoveElementAt(aIndex);
   m_folders.RemoveObjectAt(aIndex);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::RemoveChildHdr(nsIMsgDBHdr *child, nsIDBChangeAnnouncer *announcer)
+NS_IMETHODIMP
+nsMsgXFViewThread::RemoveChildHdr(nsIMsgDBHdr *child,
+                                  nsIDBChangeAnnouncer *announcer)
 {
   NS_ENSURE_ARG_POINTER(child);
   nsMsgKey msgKey;
   uint32_t msgFlags;
   child->GetMessageKey(&msgKey);
   child->GetFlags(&msgFlags);
   nsCOMPtr<nsIMsgFolder> msgFolder;
   child->GetFolder(getter_AddRefs(msgFolder));
-  // if this was the newest msg, clear the newest msg date so we'll recalc.
+  // If this was the newest msg, clear the newest msg date so we'll recalc.
   uint32_t date;
   child->GetDateInSeconds(&date);
   if (date == m_newestMsgDate)
     SetNewestMsgDate(0);
 
   for (uint32_t childIndex = 0; childIndex < m_keys.Length(); childIndex++)
   {
     if (m_keys[childIndex] == msgKey && m_folders[childIndex] == msgFolder)
     {
       uint8_t levelRemoved = m_keys[childIndex];
-      // Adjust the levels of all the children of this header
+      // Adjust the levels of all the children of this header.
       nsMsgViewIndex i;
       for (i = childIndex + 1;
-               i < m_keys.Length() && m_levels[i] > levelRemoved; i++)
-            m_levels[i] = m_levels[i] - 1;
+           i < m_keys.Length() && m_levels[i] > levelRemoved;
+           i++)
+      {
+        m_levels[i] = m_levels[i] - 1;
+      }
 
       m_view->NoteChange(childIndex + 1, i - childIndex + 1,
                          nsMsgViewNotificationCode::changed);
       m_keys.RemoveElementAt(childIndex);
       m_levels.RemoveElementAt(childIndex);
       m_folders.RemoveObjectAt(childIndex);
       if (!(msgFlags & nsMsgMessageFlags::Read))
         ChangeUnreadChildCount(-1);
+
       ChangeChildCount(-1);
       return NS_OK;
     }
   }
+
   return NS_ERROR_FAILURE;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::GetRootHdr(int32_t *aResultIndex, nsIMsgDBHdr **aResult)
+NS_IMETHODIMP
+nsMsgXFViewThread::GetRootHdr(int32_t *aResultIndex,
+                              nsIMsgDBHdr **aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
   if (aResultIndex)
     *aResultIndex = 0;
+
   return GetChildHdrAt(0, aResult);
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::GetChildKeyAt(uint32_t aIndex, nsMsgKey *aResult)
+NS_IMETHODIMP
+nsMsgXFViewThread::GetChildKeyAt(uint32_t aIndex,
+                                 nsMsgKey *aResult)
 {
   NS_ASSERTION(false, "shouldn't call this");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::GetChild(nsMsgKey msgKey, nsIMsgDBHdr **aResult)
+NS_IMETHODIMP
+nsMsgXFViewThread::GetChild(nsMsgKey msgKey,
+                            nsIMsgDBHdr **aResult)
 {
   NS_ASSERTION(false, "shouldn't call this");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 
-int32_t nsMsgXFViewThread::HdrIndex(nsIMsgDBHdr *hdr)
+int32_t
+nsMsgXFViewThread::HdrIndex(nsIMsgDBHdr *hdr)
 {
   nsMsgKey msgKey;
   nsCOMPtr<nsIMsgFolder> folder;
   hdr->GetMessageKey(&msgKey);
   hdr->GetFolder(getter_AddRefs(folder));
   for (uint32_t i = 0; i < m_keys.Length(); i++)
   {
     if (m_keys[i] == msgKey && m_folders[i] == folder)
       return i;
   }
+
   return -1;
 }
 
-void nsMsgXFViewThread::ChangeUnreadChildCount(int32_t delta)
+void
+nsMsgXFViewThread::ChangeUnreadChildCount(int32_t delta)
 {
   m_numUnreadChildren += delta;
 }
 
-void nsMsgXFViewThread::ChangeChildCount(int32_t delta)
+void
+nsMsgXFViewThread::ChangeChildCount(int32_t delta)
 {
   m_numChildren += delta;
 }
 
-bool nsMsgXFViewThread::IsHdrParentOf(nsIMsgDBHdr *possibleParent,
-                                        nsIMsgDBHdr *possibleChild)
+bool
+nsMsgXFViewThread::IsHdrParentOf(nsIMsgDBHdr *possibleParent,
+                                 nsIMsgDBHdr *possibleChild)
 {
   uint16_t referenceToCheck = 0;
   possibleChild->GetNumReferences(&referenceToCheck);
   nsAutoCString reference;
 
   nsCString messageId;
   possibleParent->GetMessageId(getter_Copies(messageId));
 
   while (referenceToCheck > 0)
   {
     possibleChild->GetStringReference(referenceToCheck - 1, reference);
 
     if (reference.Equals(messageId))
       return true;
-    // if reference didn't match, check if this ref is for a non-existent
+
+    // If reference didn't match, check if this ref is for a non-existent
     // header. If it is, continue looking at ancestors.
     nsCOMPtr<nsIMsgDBHdr> refHdr;
     m_view->GetMsgHdrFromHash(reference, getter_AddRefs(refHdr));
     if (refHdr)
       break;
+
     referenceToCheck--;
   }
+
   return false;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::GetNewestMsgDate(uint32_t *aResult)
+NS_IMETHODIMP
+nsMsgXFViewThread::GetNewestMsgDate(uint32_t *aResult)
 {
-  // if this hasn't been set, figure it out by enumerating the msgs in the thread.
+  // If this hasn't been set, figure it out by enumerating the msgs in the
+  // thread.
   if (!m_newestMsgDate)
   {
     uint32_t numChildren;
     nsresult rv = NS_OK;
 
     GetNumChildren(&numChildren);
 
     if ((int32_t) numChildren < 0)
@@ -420,33 +473,37 @@ NS_IMETHODIMP nsMsgXFViewThread::GetNewe
       {
         uint32_t msgDate;
         child->GetDateInSeconds(&msgDate);
         if (msgDate > m_newestMsgDate)
           m_newestMsgDate = msgDate;
       }
     }
   }
+
   *aResult = m_newestMsgDate;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::SetNewestMsgDate(uint32_t aNewestMsgDate)
+NS_IMETHODIMP
+nsMsgXFViewThread::SetNewestMsgDate(uint32_t aNewestMsgDate)
 {
   m_newestMsgDate = aNewestMsgDate;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::MarkChildRead(bool aRead)
+NS_IMETHODIMP
+nsMsgXFViewThread::MarkChildRead(bool aRead)
 {
   ChangeUnreadChildCount(aRead ? -1 : 1);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgXFViewThread::GetFirstUnreadChild(nsIMsgDBHdr **aResult)
+NS_IMETHODIMP
+nsMsgXFViewThread::GetFirstUnreadChild(nsIMsgDBHdr **aResult)
 {
   NS_ENSURE_ARG(aResult);
   uint32_t numChildren;
   nsresult rv = NS_OK;
 
   GetNumChildren(&numChildren);
 
   if ((int32_t) numChildren < 0)
@@ -461,23 +518,27 @@ NS_IMETHODIMP nsMsgXFViewThread::GetFirs
       nsMsgKey msgKey;
       child->GetMessageKey(&msgKey);
 
       bool isRead;
       nsCOMPtr<nsIMsgDatabase> db;
       nsresult rv = m_folders[childIndex]->GetMsgDatabase(getter_AddRefs(db));
       if (NS_SUCCEEDED(rv))
         rv = db->IsRead(msgKey, &isRead);
+
       if (NS_SUCCEEDED(rv) && !isRead)
       {
         child.forget(aResult);
         break;
       }
     }
   }
+
   return rv;
 }
-NS_IMETHODIMP nsMsgXFViewThread::EnumerateMessages(nsMsgKey aParentKey,
-                                                   nsISimpleEnumerator **aResult)
+
+NS_IMETHODIMP
+nsMsgXFViewThread::EnumerateMessages(nsMsgKey aParentKey,
+                                     nsISimpleEnumerator **aResult)
 {
   NS_ERROR("shouldn't call this");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
--- a/mailnews/base/src/nsMsgXFVirtualFolderDBView.cpp
+++ b/mailnews/base/src/nsMsgXFVirtualFolderDBView.cpp
@@ -27,57 +27,66 @@ nsMsgXFVirtualFolderDBView::nsMsgXFVirtu
   m_doingQuickSearch = false;
   m_totalMessagesInView = 0;
 }
 
 nsMsgXFVirtualFolderDBView::~nsMsgXFVirtualFolderDBView()
 {
 }
 
-NS_IMETHODIMP nsMsgXFVirtualFolderDBView::Open(nsIMsgFolder *folder,
-                                               nsMsgViewSortTypeValue sortType,
-                                               nsMsgViewSortOrderValue sortOrder,
-                                               nsMsgViewFlagsTypeValue viewFlags,
-                                               int32_t *pCount)
+NS_IMETHODIMP
+nsMsgXFVirtualFolderDBView::Open(nsIMsgFolder *folder,
+                                 nsMsgViewSortTypeValue sortType,
+                                 nsMsgViewSortOrderValue sortOrder,
+                                 nsMsgViewFlagsTypeValue viewFlags,
+                                 int32_t *pCount)
 {
   m_viewFolder = folder;
   return nsMsgSearchDBView::Open(folder, sortType, sortOrder, viewFlags, pCount);
 }
 
-void nsMsgXFVirtualFolderDBView::RemovePendingDBListeners()
+void
+nsMsgXFVirtualFolderDBView::RemovePendingDBListeners()
 {
   nsresult rv;
-  nsCOMPtr<nsIMsgDBService> msgDBService = do_GetService(NS_MSGDB_SERVICE_CONTRACTID, &rv);
-  // UnregisterPendingListener will return an error when there are no more instances
-  // of this object registered as pending listeners.
+  nsCOMPtr<nsIMsgDBService> msgDBService =
+    do_GetService(NS_MSGDB_SERVICE_CONTRACTID, &rv);
+
+  // UnregisterPendingListener will return an error when there are no more
+  // instances of this object registered as pending listeners.
   while (NS_SUCCEEDED(rv))
     rv = msgDBService->UnregisterPendingListener(this);
 }
 
-NS_IMETHODIMP nsMsgXFVirtualFolderDBView::Close()
+NS_IMETHODIMP
+nsMsgXFVirtualFolderDBView::Close()
 {
   RemovePendingDBListeners();
   return nsMsgSearchDBView::Close();
 }
 
 NS_IMETHODIMP
-nsMsgXFVirtualFolderDBView::CloneDBView(nsIMessenger *aMessengerInstance, nsIMsgWindow *aMsgWindow,
-                                        nsIMsgDBViewCommandUpdater *aCmdUpdater, nsIMsgDBView **_retval)
+nsMsgXFVirtualFolderDBView::CloneDBView(nsIMessenger *aMessengerInstance,
+                                        nsIMsgWindow *aMsgWindow,
+                                        nsIMsgDBViewCommandUpdater *aCmdUpdater,
+                                        nsIMsgDBView **_retval)
 {
   nsMsgXFVirtualFolderDBView* newMsgDBView = new nsMsgXFVirtualFolderDBView();
   nsresult rv = CopyDBView(newMsgDBView, aMessengerInstance, aMsgWindow, aCmdUpdater);
   NS_ENSURE_SUCCESS(rv,rv);
 
   NS_IF_ADDREF(*_retval = newMsgDBView);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMsgXFVirtualFolderDBView::CopyDBView(nsMsgDBView *aNewMsgDBView, nsIMessenger *aMessengerInstance,
-                                       nsIMsgWindow *aMsgWindow, nsIMsgDBViewCommandUpdater *aCmdUpdater)
+nsMsgXFVirtualFolderDBView::CopyDBView(nsMsgDBView *aNewMsgDBView,
+                                       nsIMessenger *aMessengerInstance,
+                                       nsIMsgWindow *aMsgWindow,
+                                       nsIMsgDBViewCommandUpdater *aCmdUpdater)
 {
   nsMsgSearchDBView::CopyDBView(aNewMsgDBView, aMessengerInstance, aMsgWindow, aCmdUpdater);
 
   nsMsgXFVirtualFolderDBView* newMsgDBView = (nsMsgXFVirtualFolderDBView *) aNewMsgDBView;
 
   newMsgDBView->m_viewFolder = m_viewFolder;
   newMsgDBView->m_searchSession = m_searchSession;
 
@@ -98,251 +107,288 @@ nsMsgXFVirtualFolderDBView::CopyDBView(n
     searchSession->GetNthSearchScope(i, &scopeId, getter_AddRefs(searchFolder));
     if (searchFolder)
       msgDBService->RegisterPendingListener(searchFolder, newMsgDBView);
   }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgXFVirtualFolderDBView::GetViewType(nsMsgViewTypeValue *aViewType)
+NS_IMETHODIMP
+nsMsgXFVirtualFolderDBView::GetViewType(nsMsgViewTypeValue *aViewType)
 {
-    NS_ENSURE_ARG_POINTER(aViewType);
-    *aViewType = nsMsgViewType::eShowVirtualFolderResults;
-    return NS_OK;
+  NS_ENSURE_ARG_POINTER(aViewType);
+  *aViewType = nsMsgViewType::eShowVirtualFolderResults;
+  return NS_OK;
 }
 
-nsresult nsMsgXFVirtualFolderDBView::OnNewHeader(nsIMsgDBHdr *newHdr, nsMsgKey aParentKey, bool /*ensureListed*/)
+nsresult
+nsMsgXFVirtualFolderDBView::OnNewHeader(nsIMsgDBHdr *newHdr,
+                                        nsMsgKey aParentKey,
+                                        bool /*ensureListed*/)
 {
   if (newHdr)
   {
     bool match = false;
-    nsCOMPtr <nsIMsgSearchSession> searchSession = do_QueryReferent(m_searchSession);
+    nsCOMPtr <nsIMsgSearchSession> searchSession =
+      do_QueryReferent(m_searchSession);
+
     if (searchSession)
       searchSession->MatchHdr(newHdr, m_db, &match);
+
     if (!match)
       match = WasHdrRecentlyDeleted(newHdr);
+
     if (match)
     {
       nsCOMPtr <nsIMsgFolder> folder;
       newHdr->GetFolder(getter_AddRefs(folder));
       bool saveDoingSearch = m_doingSearch;
       m_doingSearch = false;
       OnSearchHit(newHdr, folder);
       m_doingSearch = saveDoingSearch;
     }
   }
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgXFVirtualFolderDBView::OnHdrPropertyChanged(nsIMsgDBHdr *aHdrChanged,
-                bool aPreChange, uint32_t *aStatus, nsIDBChangeListener *aInstigator)
+NS_IMETHODIMP
+nsMsgXFVirtualFolderDBView::OnHdrPropertyChanged(nsIMsgDBHdr *aHdrChanged,
+                                                 bool aPreChange,
+                                                 uint32_t *aStatus,
+                                                 nsIDBChangeListener *aInstigator)
 {
   // If the junk mail plugin just activated on a message, then
   // we'll allow filters to remove from view.
   // Otherwise, just update the view line.
   //
   // Note this will not add newly matched headers to the view. This is
   // probably a bug that needs fixing.
 
   NS_ENSURE_ARG_POINTER(aStatus);
   NS_ENSURE_ARG_POINTER(aHdrChanged);
 
   nsMsgViewIndex index = FindHdr(aHdrChanged);
-  if (index == nsMsgViewIndex_None) // message does not appear in view
+  // Message does not appear in view.
+  if (index == nsMsgViewIndex_None)
     return NS_OK;
 
   nsCString originStr;
   (void) aHdrChanged->GetStringProperty("junkscoreorigin", getter_Copies(originStr));
-  // check for "plugin" with only first character for performance
+  // Check for "plugin" with only first character for performance.
   bool plugin = (originStr.get()[0] == 'p');
 
   if (aPreChange)
   {
-    // first call, done prior to the change
+    // First call, done prior to the change.
     *aStatus = plugin;
     return NS_OK;
   }
 
-  // second call, done after the change
+  // Second call, done after the change.
   bool wasPlugin = *aStatus;
 
   bool match = true;
   nsCOMPtr<nsIMsgSearchSession> searchSession(do_QueryReferent(m_searchSession));
   if (searchSession)
     searchSession->MatchHdr(aHdrChanged, m_db, &match);
 
   if (!match && plugin && !wasPlugin)
-    RemoveByIndex(index); // remove hdr from view
+    // Remove hdr from view.
+    RemoveByIndex(index);
   else
     NoteChange(index, 1, nsMsgViewNotificationCode::changed);
 
   return NS_OK;
 }
 
-void nsMsgXFVirtualFolderDBView::UpdateCacheAndViewForFolder(nsIMsgFolder *folder, nsMsgKey *newHits, uint32_t numNewHits)
+void
+nsMsgXFVirtualFolderDBView::UpdateCacheAndViewForFolder(nsIMsgFolder *folder,
+                                                        nsMsgKey *newHits,
+                                                        uint32_t numNewHits)
 {
   nsCOMPtr <nsIMsgDatabase> db;
   nsresult rv = folder->GetMsgDatabase(getter_AddRefs(db));
   if (NS_SUCCEEDED(rv) && db)
   {
     nsCString searchUri;
     m_viewFolder->GetURI(searchUri);
     uint32_t numBadHits;
     nsMsgKey *badHits;
-    rv = db->RefreshCache(searchUri.get(), numNewHits, newHits,
-                     &numBadHits, &badHits);
+    rv = db->RefreshCache(searchUri.get(),
+                          numNewHits,
+                          newHits,
+                          &numBadHits,
+                          &badHits);
     if (NS_SUCCEEDED(rv))
     {
       nsCOMPtr<nsIMsgDBHdr> badHdr;
       for (uint32_t badHitIndex = 0; badHitIndex < numBadHits; badHitIndex++)
       {
         // ### of course, this isn't quite right, since we should be
         // using FindHdr, and we shouldn't be expanding the threads.
         db->GetMsgHdrForKey(badHits[badHitIndex], getter_AddRefs(badHdr));
-        // let nsMsgSearchDBView decide what to do about this header
+        // Let nsMsgSearchDBView decide what to do about this header
         // getting removed.
         if (badHdr)
           OnHdrDeleted(badHdr, nsMsgKey_None, 0, this);
       }
+
       delete [] badHits;
     }
   }
 }
 
-void nsMsgXFVirtualFolderDBView::UpdateCacheAndViewForPrevSearchedFolders(nsIMsgFolder *curSearchFolder)
+void
+nsMsgXFVirtualFolderDBView::UpdateCacheAndViewForPrevSearchedFolders(nsIMsgFolder *curSearchFolder)
 {
   // Handle the most recent folder with hits, if any.
   if (m_curFolderGettingHits)
   {
     uint32_t count = m_hdrHits.Count();
     nsTArray<nsMsgKey> newHits;
     newHits.SetLength(count);
     for (uint32_t i = 0; i < count; i++)
       m_hdrHits[i]->GetMessageKey(&newHits[i]);
 
     newHits.Sort();
-    UpdateCacheAndViewForFolder(m_curFolderGettingHits, newHits.Elements(), newHits.Length());
+    UpdateCacheAndViewForFolder(m_curFolderGettingHits,
+                                newHits.Elements(),
+                                newHits.Length());
     m_foldersSearchingOver.RemoveObject(m_curFolderGettingHits);
   }
 
   while (m_foldersSearchingOver.Count() > 0)
   {
-    // this new folder has cached hits.
+    // This new folder has cached hits.
     if (m_foldersSearchingOver[0] == curSearchFolder)
     {
       m_curFolderHasCachedHits = true;
       m_foldersSearchingOver.RemoveObjectAt(0);
       break;
     }
     else
     {
-      // this must be a folder that had no hits with the current search.
+      // This must be a folder that had no hits with the current search.
       // So all cached hits, if any, need to be removed.
       UpdateCacheAndViewForFolder(m_foldersSearchingOver[0], nullptr, 0);
       m_foldersSearchingOver.RemoveObjectAt(0);
     }
   }
 }
 NS_IMETHODIMP
-nsMsgXFVirtualFolderDBView::OnSearchHit(nsIMsgDBHdr* aMsgHdr, nsIMsgFolder *aFolder)
+nsMsgXFVirtualFolderDBView::OnSearchHit(nsIMsgDBHdr* aMsgHdr,
+                                        nsIMsgFolder *aFolder)
 {
   NS_ENSURE_ARG(aMsgHdr);
   NS_ENSURE_ARG(aFolder);
 
   nsCOMPtr<nsIMsgDatabase> dbToUse;
   nsCOMPtr<nsIDBFolderInfo> folderInfo;
   aFolder->GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(dbToUse));
 
   if (m_curFolderGettingHits != aFolder && m_doingSearch && !m_doingQuickSearch)
   {
     m_curFolderHasCachedHits = false;
-    // since we've gotten a hit for a new folder, the searches for
+    // Since we've gotten a hit for a new folder, the searches for
     // any previous folders are done, so deal with stale cached hits
     // for those folders now.
     UpdateCacheAndViewForPrevSearchedFolders(aFolder);
     m_curFolderGettingHits = aFolder;
     m_hdrHits.Clear();
     m_curFolderStartKeyIndex = m_keys.Length();
   }
+
   bool hdrInCache = false;
   nsCString searchUri;
   if (!m_doingQuickSearch)
   {
     m_viewFolder->GetURI(searchUri);
     dbToUse->HdrIsInCache(searchUri.get(), aMsgHdr, &hdrInCache);
   }
+
   if (!m_doingSearch || !m_curFolderHasCachedHits || !hdrInCache)
   {
     if (m_viewFlags & nsMsgViewFlagsType::kGroupBySort)
       nsMsgGroupView::OnNewHeader(aMsgHdr, nsMsgKey_None, true);
     else if (m_sortValid)
       InsertHdrFromFolder(aMsgHdr, aFolder);
     else
       AddHdrFromFolder(aMsgHdr, aFolder);
   }
+
   m_hdrHits.AppendObject(aMsgHdr);
   m_totalMessagesInView++;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgXFVirtualFolderDBView::OnSearchDone(nsresult status)
 {
   NS_ENSURE_TRUE(m_viewFolder, NS_ERROR_NOT_INITIALIZED);
 
-  // handle any non verified hits we haven't handled yet.
+  // Handle any non verified hits we haven't handled yet.
   if (NS_SUCCEEDED(status) && !m_doingQuickSearch && status != NS_MSG_SEARCH_INTERRUPTED)
     UpdateCacheAndViewForPrevSearchedFolders(nullptr);
 
   m_doingSearch = false;
-  //we want to set imap delete model once the search is over because setting next
-  //message after deletion will happen before deleting the message and search scope
-  //can change with every search.
-  mDeleteModel = nsMsgImapDeleteModels::MoveToTrash;  //set to default in case it is non-imap folder
+  // We want to set imap delete model once the search is over because setting
+  // next message after deletion will happen before deleting the message and
+  // search scope can change with every search.
+
+  // Set to default in case it is non-imap folder.
+  mDeleteModel = nsMsgImapDeleteModels::MoveToTrash;
   nsIMsgFolder *curFolder = m_folders.SafeObjectAt(0);
   if (curFolder)
     GetImapDeleteModel(curFolder);
 
   nsCOMPtr<nsIMsgDatabase> virtDatabase;
   nsCOMPtr<nsIDBFolderInfo> dbFolderInfo;
-  nsresult rv = m_viewFolder->GetDBFolderInfoAndDB(getter_AddRefs(dbFolderInfo), getter_AddRefs(virtDatabase));
+  nsresult rv = m_viewFolder->GetDBFolderInfoAndDB(getter_AddRefs(dbFolderInfo),
+                                                   getter_AddRefs(virtDatabase));
   NS_ENSURE_SUCCESS(rv, rv);
-  // count up the number of unread and total messages from the view, and set those in the
-  // folder - easier than trying to keep the count up to date in the face of
-  // search hits coming in while the user is reading/deleting messages.
+  // Count up the number of unread and total messages from the view, and set
+  // those in the folder - easier than trying to keep the count up to date in
+  // the face of search hits coming in while the user is reading/deleting
+  // messages.
   uint32_t numUnread = 0;
   for (uint32_t i = 0; i < m_flags.Length(); i++)
+  {
     if (m_flags[i] & nsMsgMessageFlags::Elided)
     {
       nsCOMPtr<nsIMsgThread> thread;
       GetThreadContainingIndex(i, getter_AddRefs(thread));
       if (thread)
       {
         uint32_t unreadInThread;
         thread->GetNumUnreadChildren(&unreadInThread);
         numUnread += unreadInThread;
       }
     }
     else
     {
       if (!(m_flags[i] & nsMsgMessageFlags::Read))
         numUnread++;
     }
+  }
+
   dbFolderInfo->SetNumUnreadMessages(numUnread);
   dbFolderInfo->SetNumMessages(m_totalMessagesInView);
-  m_viewFolder->UpdateSummaryTotals(true); // force update from db.
+  // Force update from db.
+  m_viewFolder->UpdateSummaryTotals(true);
   virtDatabase->Commit(nsMsgDBCommitType::kLargeCommit);
   if (!m_sortValid && m_sortType != nsMsgViewSortType::byThread &&
       !(m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))
   {
-    m_sortValid = false;       //sort the results
+    // Sort the results.
+    m_sortValid = false;
     Sort(m_sortType, m_sortOrder);
   }
+
   m_foldersSearchingOver.Clear();
   m_curFolderGettingHits = nullptr;
   return rv;
 }
 
 
 NS_IMETHODIMP
 nsMsgXFVirtualFolderDBView::OnNewSearch()
@@ -352,54 +398,60 @@ nsMsgXFVirtualFolderDBView::OnNewSearch(
   RemovePendingDBListeners();
   m_doingSearch = true;
   m_totalMessagesInView = 0;
   m_folders.Clear();
   m_keys.Clear();
   m_levels.Clear();
   m_flags.Clear();
 
-  // needs to happen after we remove the keys, since RowCountChanged() will call our GetRowCount()
+  // Needs to happen after we remove the keys, since RowCountChanged() will
+  // call our GetRowCount().
   if (mTree)
     mTree->RowCountChanged(0, -oldSize);
 
-  // to use the search results cache, we'll need to iterate over the scopes in the
-  // search session, calling getNthSearchScope for i = 0; i < searchSession.countSearchScopes; i++
-  // and for each folder, then open the db and pull out the cached hits, add them to the view.
-  // For each hit in a new folder, we'll then clean up the stale hits from the previous folder(s).
+  // To use the search results cache, we'll need to iterate over the scopes
+  // in the search session, calling getNthSearchScope
+  // for i = 0; i < searchSession.countSearchScopes; i++
+  // and for each folder, then open the db and pull out the cached hits,
+  // add them to the view. For each hit in a new folder, we'll then clean up
+  // the stale hits from the previous folder(s).
 
   int32_t scopeCount;
   nsCOMPtr<nsIMsgSearchSession> searchSession = do_QueryReferent(m_searchSession);
-  NS_ENSURE_TRUE(searchSession, NS_OK); // just ignore
+  // Just ignore.
+  NS_ENSURE_TRUE(searchSession, NS_OK);
   nsCOMPtr<nsIMsgDBService> msgDBService = do_GetService(NS_MSGDB_SERVICE_CONTRACTID);
   searchSession->CountSearchScopes(&scopeCount);
 
   // Figure out how many search terms the virtual folder has.
   nsCOMPtr<nsIMsgDatabase> virtDatabase;
   nsCOMPtr<nsIDBFolderInfo> dbFolderInfo;
-  nsresult rv = m_viewFolder->GetDBFolderInfoAndDB(getter_AddRefs(dbFolderInfo), getter_AddRefs(virtDatabase));
+  nsresult rv = m_viewFolder->GetDBFolderInfoAndDB(getter_AddRefs(dbFolderInfo),
+                                                   getter_AddRefs(virtDatabase));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCString terms;
   dbFolderInfo->GetCharProperty("searchStr", terms);
   nsCOMPtr<nsIMutableArray> searchTerms;
   rv = searchSession->GetSearchTerms(getter_AddRefs(searchTerms));
   NS_ENSURE_SUCCESS(rv, rv);
   nsCString curSearchAsString;
 
   rv = MsgTermListToString(searchTerms, curSearchAsString);
   // Trim off the initial AND/OR, which is irrelevant and inconsistent between
   // what searchSpec.js generates, and what's in virtualFolders.dat.
-  curSearchAsString.Cut(0, StringBeginsWith(curSearchAsString, NS_LITERAL_CSTRING("AND")) ? 3 : 2);
+  curSearchAsString.Cut(0, StringBeginsWith(curSearchAsString,
+                                            NS_LITERAL_CSTRING("AND")) ? 3 : 2);
   terms.Cut(0, StringBeginsWith(terms, NS_LITERAL_CSTRING("AND")) ? 3 : 2);
 
   NS_ENSURE_SUCCESS(rv, rv);
-  // If the search session search string doesn't match the vf search str, then we're doing
-  // quick search, which means we don't want to invalidate cached results, or
-  // used cached results.
+  // If the search session search string doesn't match the vf search str,
+  // then we're doing quick search, which means we don't want to invalidate
+  // cached results, or used cached results.
   m_doingQuickSearch = !curSearchAsString.Equals(terms);
 
   if (mTree && !m_doingQuickSearch)
     mTree->BeginUpdateBatch();
 
   for (int32_t i = 0; i < scopeCount; i++)
   {
     nsMsgSearchScopeValue scopeId;
@@ -413,18 +465,20 @@ nsMsgXFVirtualFolderDBView::OnNewSearch(
       m_viewFolder->GetURI(searchUri);
       nsresult rv = searchFolder->GetMsgDatabase(getter_AddRefs(searchDB));
       if (NS_SUCCEEDED(rv) && searchDB)
       {
         if (msgDBService)
           msgDBService->RegisterPendingListener(searchFolder, this);
 
         m_foldersSearchingOver.AppendObject(searchFolder);
-        if (m_doingQuickSearch) // ignore cached hits in quick search case.
+        // Ignore cached hits in quick search case.
+        if (m_doingQuickSearch)
           continue;
+
         searchDB->GetCachedHits(searchUri.get(), getter_AddRefs(cachedHits));
         bool hasMore;
         if (cachedHits)
         {
           cachedHits->HasMoreElements(&hasMore);
           if (hasMore)
           {
             mozilla::DebugOnly<nsMsgKey> prevKey = nsMsgKey_None;
@@ -441,69 +495,78 @@ nsMsgXFVirtualFolderDBView::OnNewSearch(
                 NS_ASSERTION(prevKey == nsMsgKey_None || msgKey > prevKey,
                              "cached Hits not sorted");
 #ifdef DEBUG
                 prevKey = msgKey;
 #endif
                 AddHdrFromFolder(pHeader, searchFolder);
               }
               else
+              {
                 break;
+              }
+
               cachedHits->HasMoreElements(&hasMore);
             }
           }
         }
       }
     }
   }
+
   if (mTree && !m_doingQuickSearch)
     mTree->EndUpdateBatch();
 
   m_curFolderStartKeyIndex = 0;
   m_curFolderGettingHits = nullptr;
   m_curFolderHasCachedHits = false;
 
-  // if we have cached hits, sort them.
+  // If we have cached hits, sort them.
   if (GetSize() > 0)
   {
-    // currently, we keep threaded views sorted while we build them.
+    // Currently, we keep threaded views sorted while we build them.
     if (m_sortType != nsMsgViewSortType::byThread &&
       !(m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))
     {
-      m_sortValid = false;       //sort the results
+      // Sort the results.
+      m_sortValid = false;
       Sort(m_sortType, m_sortOrder);
     }
   }
+
   return NS_OK;
 }
 
-
-NS_IMETHODIMP nsMsgXFVirtualFolderDBView::DoCommand(nsMsgViewCommandTypeValue command)
+NS_IMETHODIMP
+nsMsgXFVirtualFolderDBView::DoCommand(nsMsgViewCommandTypeValue command)
 {
-    return nsMsgSearchDBView::DoCommand(command);
+  return nsMsgSearchDBView::DoCommand(command);
 }
 
-
-
-NS_IMETHODIMP nsMsgXFVirtualFolderDBView::GetMsgFolder(nsIMsgFolder **aMsgFolder)
+NS_IMETHODIMP
+nsMsgXFVirtualFolderDBView::GetMsgFolder(nsIMsgFolder **aMsgFolder)
 {
   NS_ENSURE_ARG_POINTER(aMsgFolder);
   NS_IF_ADDREF(*aMsgFolder = m_viewFolder);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgXFVirtualFolderDBView::SetViewFlags(nsMsgViewFlagsTypeValue aViewFlags)
+NS_IMETHODIMP
+nsMsgXFVirtualFolderDBView::SetViewFlags(nsMsgViewFlagsTypeValue aViewFlags)
 {
   nsresult rv = NS_OK;
-  // if the grouping/threading has changed, rebuild the view
+  // If the grouping/threading has changed, rebuild the view.
   if ((m_viewFlags & (nsMsgViewFlagsType::kGroupBySort |
                       nsMsgViewFlagsType::kThreadedDisplay)) !=
       (aViewFlags & (nsMsgViewFlagsType::kGroupBySort |
                      nsMsgViewFlagsType::kThreadedDisplay)))
+  {
     rv = RebuildView(aViewFlags);
+  }
+
   nsMsgDBView::SetViewFlags(aViewFlags);
   return rv;
 }
 
 
 nsresult
 nsMsgXFVirtualFolderDBView::GetMessageEnumerator(nsISimpleEnumerator **enumerator)
 {