Bug 1496598 - Port bug 1493226: fix 'don't use do_QueryInterface for compile-time-determinable casts' errors. rs=bustage-fix
authorJorg K <jorgk@jorgk.com>
Fri, 05 Oct 2018 14:22:33 +0200
changeset 33307 f77c18acceafaa7e9fed65ab27e293cf117850a4
parent 33306 8a607b0960af73bb04908e4a035e700654b60bfb
child 33308 93daa9a87d526f51aa749070a5c33e54142ec49a
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersbustage-fix
bugs1496598, 1493226
Bug 1496598 - Port bug 1493226: fix 'don't use do_QueryInterface for compile-time-determinable casts' errors. rs=bustage-fix
mailnews/addrbook/src/nsAbLDAPReplicationData.cpp
mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
mailnews/base/search/src/nsMsgFilter.cpp
mailnews/base/search/src/nsMsgFilterService.cpp
mailnews/base/search/src/nsMsgSearchSession.cpp
mailnews/base/src/nsMessenger.cpp
mailnews/base/src/nsMsgAccountManager.cpp
mailnews/base/src/nsMsgContentPolicy.cpp
mailnews/base/src/nsMsgFolderCache.cpp
mailnews/base/src/nsMsgGroupView.cpp
mailnews/base/src/nsMsgPrintEngine.cpp
mailnews/base/src/nsMsgSearchDBView.cpp
mailnews/base/src/nsMsgWindow.cpp
mailnews/base/util/nsImapMoveCoalescer.cpp
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/base/util/nsMsgIncomingServer.cpp
mailnews/base/util/nsMsgMailNewsUrl.cpp
mailnews/base/util/nsMsgUtils.cpp
mailnews/compose/src/nsMsgAttachmentHandler.cpp
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgSend.cpp
mailnews/compose/src/nsSmtpProtocol.cpp
mailnews/compose/src/nsURLFetcher.cpp
mailnews/db/msgdb/src/nsMsgDatabase.cpp
mailnews/imap/src/nsAutoSyncState.cpp
mailnews/imap/src/nsImapIncomingServer.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/imap/src/nsImapOfflineSync.cpp
mailnews/imap/src/nsImapProtocol.cpp
mailnews/imap/src/nsImapService.cpp
mailnews/import/src/nsImportEncodeScan.cpp
mailnews/import/text/src/nsTextImport.cpp
mailnews/import/vcard/src/nsVCardImport.cpp
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/local/src/nsMailboxUrl.cpp
mailnews/local/src/nsParseMailbox.cpp
mailnews/local/src/nsPop3Protocol.cpp
mailnews/local/src/nsPop3Sink.cpp
mailnews/mapi/mapihook/src/msgMapiImp.cpp
mailnews/mime/emitters/nsMimeBaseEmitter.cpp
mailnews/mime/src/mimedrft.cpp
mailnews/mime/src/mimemrel.cpp
mailnews/mime/src/mimepbuf.cpp
mailnews/news/src/nsNNTPProtocol.cpp
rdf/base/nsInMemoryDataSource.cpp
--- a/mailnews/addrbook/src/nsAbLDAPReplicationData.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPReplicationData.cpp
@@ -380,21 +380,17 @@ nsresult nsAbLDAPProcessReplicationData:
         // And also important in case if replication fails we donot lose user's existing
         // replicated data for both Download all and Changelog.
         nsCOMPtr<nsIFile> clone;
         rv = mReplicationFile->Clone(getter_AddRefs(clone));
         if(NS_FAILED(rv))  {
             Done(false);
             return rv;
         }
-        mBackupReplicationFile = do_QueryInterface(clone, &rv);
-        if(NS_FAILED(rv))  {
-            Done(false);
-            return rv;
-        }
+        mBackupReplicationFile = clone;
         rv = mBackupReplicationFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0777);
         if(NS_FAILED(rv))  {
             Done(false);
             return rv;
         }
         nsAutoString backupFileLeafName;
         rv = mBackupReplicationFile->GetLeafName(backupFileLeafName);
         if(NS_FAILED(rv))  {
--- a/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
+++ b/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
@@ -89,35 +89,34 @@ nsAddbookProtocolHandler::GenerateXMLOut
   nsCOMPtr<nsIStringInputStream> inStr(do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ConvertUTF16toUTF8 utf8String(aOutput.get());
 
   rv = inStr->SetData(utf8String.get(), utf8String.Length());
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIInputStream> stream(do_QueryInterface(inStr));
   if (aLoadInfo) {
     return NS_NewInputStreamChannelInternal(_retval,
                                             aURI,
-                                            stream.forget(),
+                                            inStr.forget(),
                                             NS_LITERAL_CSTRING("text/xml"),
                                             EmptyCString(),
                                             aLoadInfo);
   }
 
   nsCOMPtr<nsIPrincipal> nullPrincipal =
     do_CreateInstance("@mozilla.org/nullprincipal;1", &rv);
   NS_ASSERTION(NS_SUCCEEDED(rv), "CreateInstance of nullprincipalfailed.");
   if (NS_FAILED(rv))
       return rv;
 
   return NS_NewInputStreamChannel(_retval,
                                   aURI,
-                                  stream.forget(),
+                                  inStr.forget(),
                                   nullPrincipal,
                                   nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                                   nsIContentPolicy::TYPE_OTHER,
                                   NS_LITERAL_CSTRING("text/xml"));
 }
 
 NS_IMETHODIMP
 nsAddbookProtocolHandler::NewChannel(nsIURI *aURI, nsIChannel **_retval)
--- a/mailnews/base/search/src/nsMsgFilter.cpp
+++ b/mailnews/base/search/src/nsMsgFilter.cpp
@@ -788,17 +788,16 @@ nsresult nsMsgFilter::ConvertMoveOrCopyT
         rv = accountManager->GetLocalFoldersServer(getter_AddRefs(server));
         if (NS_SUCCEEDED(rv) && server)
           rv = server->GetRootFolder(getter_AddRefs(localMailRoot));
       }
       if (NS_SUCCEEDED(rv) && localMailRoot)
       {
         nsCString localRootURI;
         nsCOMPtr <nsIMsgFolder> destIMsgFolder;
-        nsCOMPtr <nsIMsgFolder> localMailRootMsgFolder = do_QueryInterface(localMailRoot);
         localMailRoot->GetURI(localRootURI);
         nsCString destFolderUri;
         destFolderUri.Assign(localRootURI);
         // need to remove ".sbd" from moveValue, and perhaps escape it.
         int32_t offset = moveValue.Find(FOLDER_SUFFIX8 "/");
         if (offset != -1)
           moveValue.Cut(offset, FOLDER_SUFFIX_LENGTH);
 
@@ -812,17 +811,17 @@ nsresult nsMsgFilter::ConvertMoveOrCopyT
         {
           nsAutoString unicodeStr;
           rv = nsMsgI18NConvertToUnicode(nsMsgI18NFileSystemCharset(),
                                          moveValue, unicodeStr);
           NS_ENSURE_SUCCESS(rv, rv);
           rv = NS_MsgEscapeEncodeURLPath(unicodeStr, moveValue);
         }
         destFolderUri.Append(moveValue);
-        localMailRootMsgFolder->GetChildWithURI (destFolderUri, true, false /*caseInsensitive*/, getter_AddRefs(destIMsgFolder));
+        localMailRoot->GetChildWithURI(destFolderUri, true, false /*caseInsensitive*/, getter_AddRefs(destIMsgFolder));
 
         if (destIMsgFolder)
         {
           destIMsgFolder->GetURI(folderUri);
           filterAction->SetTargetFolderUri(folderUri);
           moveValue.Assign(folderUri);
         }
       }
--- a/mailnews/base/search/src/nsMsgFilterService.cpp
+++ b/mailnews/base/search/src/nsMsgFilterService.cpp
@@ -231,17 +231,17 @@ nsMsgFilterService::GetFilterStringBundl
   return NS_OK;
 }
 
 nsresult
 nsMsgFilterService::ThrowAlertMsg(const char*aMsgName, nsIMsgWindow *aMsgWindow)
 {
   nsString alertString;
   nsresult rv = GetStringFromBundle(aMsgName, alertString);
-  nsCOMPtr<nsIMsgWindow> msgWindow(do_QueryInterface(aMsgWindow));
+  nsCOMPtr<nsIMsgWindow> msgWindow = aMsgWindow;
   if (!msgWindow) {
     nsCOMPtr<nsIMsgMailSession> mailSession ( do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv));
     if (NS_SUCCEEDED(rv))
       rv = mailSession->GetTopmostMsgWindow(getter_AddRefs(msgWindow));
   }
 
   if (NS_SUCCEEDED(rv) && !alertString.IsEmpty() && msgWindow)
   {
--- a/mailnews/base/search/src/nsMsgSearchSession.cpp
+++ b/mailnews/base/search/src/nsMsgSearchSession.cpp
@@ -395,21 +395,20 @@ nsresult nsMsgSearchSession::BeginSearch
 }
 
 nsresult nsMsgSearchSession::DoNextSearch()
 {
   nsMsgSearchScopeTerm *scope = m_scopeList.ElementAt(m_idxRunningScope);
   if (scope->m_attribute == nsMsgSearchScope::onlineMail ||
     (scope->m_attribute == nsMsgSearchScope::news && scope->m_searchServer))
   {
-    nsCOMPtr<nsIMsgSearchAdapter> adapter = do_QueryInterface(scope->m_adapter);
-    if (adapter)
+    if (scope->m_adapter)
     {
       m_runningUrl.Truncate();
-      adapter->GetEncoding(getter_Copies(m_runningUrl));
+      scope->m_adapter->GetEncoding(getter_Copies(m_runningUrl));
     }
     NS_ENSURE_STATE(!m_runningUrl.IsEmpty());
     return GetNextUrl();
   }
   else
   {
     return SearchWOUrls();
   }
--- a/mailnews/base/src/nsMessenger.cpp
+++ b/mailnews/base/src/nsMessenger.cpp
@@ -242,17 +242,17 @@ NS_IMETHODIMP nsMessenger::SetWindow(moz
 
     rv = mailSession->AddFolderListener(this, nsIFolderListener::removed);
     NS_ENSURE_SUCCESS(rv, rv);
 
     NS_ENSURE_TRUE(aWin, NS_ERROR_FAILURE);
     nsCOMPtr<nsPIDOMWindowOuter> win = nsPIDOMWindowOuter::From(aWin);
 
     nsIDocShell *docShell = win->GetDocShell();
-    nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
+    nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(docShell);
     NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
 
     nsCOMPtr<nsIDocShellTreeItem> rootDocShellAsItem;
     docShellAsItem->GetSameTypeRootTreeItem(getter_AddRefs(rootDocShellAsItem));
 
     nsCOMPtr<nsIDocShellTreeItem> childAsItem;
     rv = rootDocShellAsItem->FindChildWithName(NS_LITERAL_STRING("messagepane"), true, false,
                                                nullptr, nullptr, getter_AddRefs(childAsItem));
@@ -1611,17 +1611,17 @@ NS_IMETHODIMP
 nsMessenger::GetLastDisplayedMessageUri(nsACString& aLastDisplayedMessageUri)
 {
   aLastDisplayedMessageUri = mLastDisplayURI;
   return NS_OK;
 }
 
 nsSaveMsgListener::nsSaveMsgListener(nsIFile* aFile, nsMessenger *aMessenger, nsIUrlListener *aListener)
 {
-  m_file = do_QueryInterface(aFile);
+  m_file = aFile;
   m_messenger = aMessenger;
   mListener = aListener;
   mUrlHasStopped = false;
   mRequestHasStopped = false;
 
     // rhp: for charset handling
   m_doCharsetConversion = false;
   m_saveAllAttachmentsState = nullptr;
@@ -2095,36 +2095,34 @@ nsMessenger::GetLastSaveDirectory(nsIFil
   if (NS_SUCCEEDED(rv))
     localFile.forget(aLastSaveDir);
   return rv;
 }
 
 nsresult
 nsMessenger::SetLastSaveDirectory(nsIFile *aLocalFile)
 {
+  NS_ENSURE_ARG_POINTER(aLocalFile);
   nsresult rv;
   nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv,rv);
 
-  nsCOMPtr <nsIFile> file = do_QueryInterface(aLocalFile, &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
-
   // if the file is a directory, just use it for the last dir chosen
   // otherwise, use the parent of the file as the last dir chosen.
   // IsDirectory() will return error on saving a file, as the
   // file doesn't exist yet.
   bool isDirectory;
-  rv = file->IsDirectory(&isDirectory);
+  rv = aLocalFile->IsDirectory(&isDirectory);
   if (NS_SUCCEEDED(rv) && isDirectory) {
     rv = prefBranch->SetComplexValue(MESSENGER_SAVE_DIR_PREF_NAME, NS_GET_IID(nsIFile), aLocalFile);
     NS_ENSURE_SUCCESS(rv,rv);
   }
   else {
     nsCOMPtr <nsIFile> parent;
-    rv = file->GetParent(getter_AddRefs(parent));
+    rv = aLocalFile->GetParent(getter_AddRefs(parent));
     NS_ENSURE_SUCCESS(rv,rv);
 
     rv = prefBranch->SetComplexValue(MESSENGER_SAVE_DIR_PREF_NAME, NS_GET_IID(nsIFile), parent);
     NS_ENSURE_SUCCESS(rv,rv);
   }
   return NS_OK;
 }
 
--- a/mailnews/base/src/nsMsgAccountManager.cpp
+++ b/mailnews/base/src/nsMsgAccountManager.cpp
@@ -1595,106 +1595,101 @@ nsMsgAccountManager::CleanupOnExit()
     if (emptyTrashOnExit || cleanupInboxOnExit)
     {
       nsCOMPtr<nsIMsgFolder> root;
       server->GetRootFolder(getter_AddRefs(root));
       nsCString type;
       server->GetType(type);
       if (root)
       {
-        nsCOMPtr<nsIMsgFolder> folder;
-        folder = do_QueryInterface(root);
-        if (folder)
+        nsString passwd;
+        bool serverRequiresPasswordForAuthentication = true;
+        bool isImap = type.EqualsLiteral("imap");
+        if (isImap)
+        {
+          server->GetServerRequiresPasswordForBiff(&serverRequiresPasswordForAuthentication);
+          server->GetPassword(passwd);
+        }
+        if (!isImap || (isImap && (!serverRequiresPasswordForAuthentication || !passwd.IsEmpty())))
         {
-          nsString passwd;
-          bool serverRequiresPasswordForAuthentication = true;
-          bool isImap = type.EqualsLiteral("imap");
+          nsCOMPtr<nsIUrlListener> urlListener;
+          nsCOMPtr<nsIMsgAccountManager> accountManager =
+                   do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
+          if (NS_FAILED(rv))
+            continue;
+
           if (isImap)
+            urlListener = do_QueryInterface(accountManager, &rv);
+
+          if (isImap && cleanupInboxOnExit)
           {
-            server->GetServerRequiresPasswordForBiff(&serverRequiresPasswordForAuthentication);
-            server->GetPassword(passwd);
-          }
-          if (!isImap || (isImap && (!serverRequiresPasswordForAuthentication || !passwd.IsEmpty())))
-          {
-            nsCOMPtr<nsIUrlListener> urlListener;
-            nsCOMPtr<nsIMsgAccountManager> accountManager =
-                     do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
-            if (NS_FAILED(rv))
-              continue;
-
-            if (isImap)
-              urlListener = do_QueryInterface(accountManager, &rv);
-
-            if (isImap && cleanupInboxOnExit)
+            nsCOMPtr<nsISimpleEnumerator> enumerator;
+            rv = root->GetSubFolders(getter_AddRefs(enumerator));
+            if (NS_SUCCEEDED(rv))
             {
-              nsCOMPtr<nsISimpleEnumerator> enumerator;
-              rv = folder->GetSubFolders(getter_AddRefs(enumerator));
-              if (NS_SUCCEEDED(rv))
+              bool hasMore;
+              while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) &&
+                     hasMore)
               {
-                bool hasMore;
-                while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) &&
-                       hasMore)
+                nsCOMPtr<nsISupports> item;
+                enumerator->GetNext(getter_AddRefs(item));
+
+                nsCOMPtr<nsIMsgFolder> inboxFolder(do_QueryInterface(item));
+                if (!inboxFolder)
+                  continue;
+
+                uint32_t flags;
+                inboxFolder->GetFlags(&flags);
+                if (flags & nsMsgFolderFlags::Inbox)
                 {
-                  nsCOMPtr<nsISupports> item;
-                  enumerator->GetNext(getter_AddRefs(item));
-
-                  nsCOMPtr<nsIMsgFolder> inboxFolder(do_QueryInterface(item));
-                  if (!inboxFolder)
-                    continue;
-
-                  uint32_t flags;
-                  inboxFolder->GetFlags(&flags);
-                  if (flags & nsMsgFolderFlags::Inbox)
-                  {
-                    rv = inboxFolder->Compact(urlListener, nullptr /* msgwindow */);
-                    if (NS_SUCCEEDED(rv))
-                      accountManager->SetFolderDoingCleanupInbox(inboxFolder);
-                    break;
-                  }
+                  rv = inboxFolder->Compact(urlListener, nullptr /* msgwindow */);
+                  if (NS_SUCCEEDED(rv))
+                    accountManager->SetFolderDoingCleanupInbox(inboxFolder);
+                  break;
                 }
               }
             }
-
+          }
+
+          if (emptyTrashOnExit)
+          {
+            rv = root->EmptyTrash(nullptr, urlListener);
+            if (isImap && NS_SUCCEEDED(rv))
+              accountManager->SetFolderDoingEmptyTrash(root);
+          }
+
+          if (isImap && urlListener)
+          {
+            nsCOMPtr<nsIThread> thread(do_GetCurrentThread());
+
+            bool inProgress = false;
+            if (cleanupInboxOnExit)
+            {
+              int32_t loopCount = 0; // used to break out after 5 seconds
+              accountManager->GetCleanupInboxInProgress(&inProgress);
+              while (inProgress && loopCount++ < 5000)
+              {
+                accountManager->GetCleanupInboxInProgress(&inProgress);
+                PR_CEnterMonitor(root);
+                PR_CWait(root, PR_MicrosecondsToInterval(1000UL));
+                PR_CExitMonitor(root);
+                NS_ProcessPendingEvents(thread, PR_MicrosecondsToInterval(1000UL));
+              }
+            }
             if (emptyTrashOnExit)
             {
-              rv = folder->EmptyTrash(nullptr, urlListener);
-              if (isImap && NS_SUCCEEDED(rv))
-                accountManager->SetFolderDoingEmptyTrash(folder);
-            }
-
-            if (isImap && urlListener)
-            {
-              nsCOMPtr<nsIThread> thread(do_GetCurrentThread());
-
-              bool inProgress = false;
-              if (cleanupInboxOnExit)
-              {
-                int32_t loopCount = 0; // used to break out after 5 seconds
-                accountManager->GetCleanupInboxInProgress(&inProgress);
-                while (inProgress && loopCount++ < 5000)
-                {
-                  accountManager->GetCleanupInboxInProgress(&inProgress);
-                  PR_CEnterMonitor(folder);
-                  PR_CWait(folder, PR_MicrosecondsToInterval(1000UL));
-                  PR_CExitMonitor(folder);
-                  NS_ProcessPendingEvents(thread, PR_MicrosecondsToInterval(1000UL));
-                }
-              }
-              if (emptyTrashOnExit)
+              accountManager->GetEmptyTrashInProgress(&inProgress);
+              int32_t loopCount = 0;
+              while (inProgress && loopCount++ < 5000)
               {
                 accountManager->GetEmptyTrashInProgress(&inProgress);
-                int32_t loopCount = 0;
-                while (inProgress && loopCount++ < 5000)
-                {
-                  accountManager->GetEmptyTrashInProgress(&inProgress);
-                  PR_CEnterMonitor(folder);
-                  PR_CWait(folder, PR_MicrosecondsToInterval(1000UL));
-                  PR_CExitMonitor(folder);
-                  NS_ProcessPendingEvents(thread, PR_MicrosecondsToInterval(1000UL));
-                }
+                PR_CEnterMonitor(root);
+                PR_CWait(root, PR_MicrosecondsToInterval(1000UL));
+                PR_CExitMonitor(root);
+                NS_ProcessPendingEvents(thread, PR_MicrosecondsToInterval(1000UL));
               }
             }
           }
         }
       }
     }
   }
 
@@ -2316,31 +2311,29 @@ nsMsgAccountManager::CreateLocalMailAcco
   nsCOMPtr<nsINoIncomingServer> noServer;
   noServer = do_QueryInterface(server, &rv);
   if (NS_FAILED(rv)) return rv;
 
   // create the directory structure for old 4.x "Local Mail"
   // under <profile dir>/Mail/Local Folders or
   // <"mail.directory" pref>/Local Folders
   nsCOMPtr <nsIFile> mailDir;
-  nsCOMPtr <nsIFile> localFile;
   bool dirExists;
 
   // we want <profile>/Mail
   rv = NS_GetSpecialDirectory(NS_APP_MAIL_50_DIR, getter_AddRefs(mailDir));
   if (NS_FAILED(rv)) return rv;
-  localFile = do_QueryInterface(mailDir);
 
   rv = mailDir->Exists(&dirExists);
   if (NS_SUCCEEDED(rv) && !dirExists)
     rv = mailDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
   if (NS_FAILED(rv)) return rv;
 
   // set the default local path for "none"
-  rv = server->SetDefaultLocalPath(localFile);
+  rv = server->SetDefaultLocalPath(mailDir);
   if (NS_FAILED(rv)) return rv;
 
   // Create an account when valid server values are established.
   // This will keep the status of accounts sane by avoiding the addition of incomplete accounts.
   nsCOMPtr<nsIMsgAccount> account;
   rv = CreateAccount(getter_AddRefs(account));
   if (NS_FAILED(rv)) return rv;
 
@@ -2888,25 +2881,25 @@ nsresult VirtualFolderChangeListener::Po
 void VirtualFolderChangeListener::ProcessUpdateEvent(nsIMsgFolder *virtFolder,
                                                      nsIMsgDatabase *virtDB)
 {
   m_batchingEvents = false;
   virtFolder->UpdateSummaryTotals(true); // force update from db.
   virtDB->Commit(nsMsgDBCommitType::kLargeCommit);
 }
 
-nsresult nsMsgAccountManager::GetVirtualFoldersFile(nsCOMPtr<nsIFile>& file)
+nsresult nsMsgAccountManager::GetVirtualFoldersFile(nsCOMPtr<nsIFile>& aFile)
 {
   nsCOMPtr<nsIFile> profileDir;
   nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = profileDir->AppendNative(nsDependentCString("virtualFolders.dat"));
   if (NS_SUCCEEDED(rv))
-    file = do_QueryInterface(profileDir, &rv);
+    aFile = profileDir;
   return rv;
 }
 
 NS_IMETHODIMP nsMsgAccountManager::LoadVirtualFolders()
 {
   nsCOMPtr <nsIFile> file;
   GetVirtualFoldersFile(file);
   if (!file)
--- a/mailnews/base/src/nsMsgContentPolicy.cpp
+++ b/mailnews/base/src/nsMsgContentPolicy.cpp
@@ -781,18 +781,17 @@ void nsMsgContentPolicy::ComposeShouldLo
 
 already_AddRefed<nsIMsgCompose> nsMsgContentPolicy::GetMsgComposeForContext(nsISupports *aRequestingContext)
 {
   nsresult rv;
 
   nsIDocShell *shell = NS_CP_GetDocShellFromContext(aRequestingContext);
   if (!shell)
     return nullptr;
-  nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(do_QueryInterface(shell, &rv));
-  NS_ENSURE_SUCCESS(rv, nullptr);
+  nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(shell);
 
   nsCOMPtr<nsIDocShellTreeItem> rootItem;
   rv = docShellTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(rootItem));
   NS_ENSURE_SUCCESS(rv, nullptr);
 
   nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(rootItem, &rv));
   NS_ENSURE_SUCCESS(rv, nullptr);
 
@@ -838,18 +837,17 @@ nsresult nsMsgContentPolicy::SetDisableI
   NS_ENSURE_SUCCESS(rv, rv);
 
   RefPtr<nsFrameLoader> frameLoader = flOwner->GetFrameLoader();
   NS_ENSURE_TRUE(frameLoader, NS_ERROR_INVALID_POINTER);
 
   nsCOMPtr<nsIDocShell> docShell = frameLoader->GetDocShell(mozilla::IgnoreErrors());
   NS_ENSURE_TRUE(docShell, NS_ERROR_INVALID_POINTER);
 
-  nsCOMPtr<nsIDocShellTreeItem> docshellTreeItem(do_QueryInterface(docShell, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIDocShellTreeItem> docshellTreeItem(docShell);
 
   // what sort of docshell is this?
   int32_t itemType;
   rv = docshellTreeItem->GetItemType(&itemType);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // we're only worried about policy settings in content docshells
   if (itemType != nsIDocShellTreeItem::typeContent) {
@@ -891,18 +889,18 @@ nsresult nsMsgContentPolicy::SetDisableI
 nsresult
 nsMsgContentPolicy::GetRootDocShellForContext(nsISupports *aRequestingContext,
                                               nsIDocShell **aDocShell)
 {
   NS_ENSURE_ARG_POINTER(aRequestingContext);
   nsresult rv;
 
   nsIDocShell *shell = NS_CP_GetDocShellFromContext(aRequestingContext);
-  nsCOMPtr<nsIDocShellTreeItem> docshellTreeItem(do_QueryInterface(shell, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
+  NS_ENSURE_TRUE(shell, NS_ERROR_NULL_POINTER);
+  nsCOMPtr<nsIDocShellTreeItem> docshellTreeItem(shell);
 
   nsCOMPtr<nsIDocShellTreeItem> rootItem;
   rv = docshellTreeItem->GetRootTreeItem(getter_AddRefs(rootItem));
   NS_ENSURE_SUCCESS(rv, rv);
 
   return CallQueryInterface(rootItem, aDocShell);
 }
 
@@ -921,18 +919,17 @@ nsMsgContentPolicy::GetOriginatingURIFor
   NS_ENSURE_ARG_POINTER(aRequestingContext);
   nsresult rv;
 
   nsIDocShell *shell = NS_CP_GetDocShellFromContext(aRequestingContext);
   if (!shell) {
     *aURI = nullptr;
     return NS_OK;
   }
-  nsCOMPtr<nsIDocShellTreeItem> docshellTreeItem(do_QueryInterface(shell, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIDocShellTreeItem> docshellTreeItem(shell);
 
   nsCOMPtr<nsIDocShellTreeItem> rootItem;
   rv = docshellTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(rootItem));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIWebNavigation> webNavigation(do_QueryInterface(rootItem, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/mailnews/base/src/nsMsgFolderCache.cpp
+++ b/mailnews/base/src/nsMsgFolderCache.cpp
@@ -335,17 +335,17 @@ NS_IMETHODIMP nsMsgFolderCache::Commit(b
     GetEnv()->ClearErrors();
   return ret;
 }
 
 nsresult nsMsgFolderCache::AddCacheElement(const nsACString& key, nsIMdbRow *row, nsIMsgFolderCacheElement **result)
 {
   nsMsgFolderCacheElement *cacheElement = new nsMsgFolderCacheElement;
   NS_ENSURE_TRUE(cacheElement, NS_ERROR_OUT_OF_MEMORY);
-  nsCOMPtr<nsIMsgFolderCacheElement> folderCacheEl(do_QueryInterface(cacheElement));
+  nsCOMPtr<nsIMsgFolderCacheElement> folderCacheEl = cacheElement;
 
   cacheElement->SetMDBRow(row);
   cacheElement->SetOwningCache(this);
   nsCString hashStrKey(key);
   // if caller didn't pass in key, try to get it from row.
   if (key.IsEmpty())
     folderCacheEl->GetStringProperty("key", hashStrKey);
   folderCacheEl->SetKey(hashStrKey);
--- a/mailnews/base/src/nsMsgGroupView.cpp
+++ b/mailnews/base/src/nsMsgGroupView.cpp
@@ -329,17 +329,17 @@ nsMsgGroupThread *nsMsgGroupView::AddHdr
       *pNewThread = newThread = true;
     }
   }
 
   // If the thread does not already exist, create one
   if (!foundThread)
   {
     foundThread = CreateGroupThread(m_db);
-    msgThread = do_QueryInterface(foundThread);
+    msgThread = foundThread;
     m_groupsTable.Put(hashKey, msgThread);
     if (GroupViewUsesDummyRow())
     {
       foundThread->m_dummy = true;
       msgFlags |=  MSG_VIEW_FLAG_DUMMY | MSG_VIEW_FLAG_HASCHILDREN;
     }
 
     viewIndexOfThread = GetInsertIndex(msgHdr);
--- a/mailnews/base/src/nsMsgPrintEngine.cpp
+++ b/mailnews/base/src/nsMsgPrintEngine.cpp
@@ -226,18 +226,17 @@ nsMsgPrintEngine::SetWindow(mozIDOMWindo
 
   mWindow = aWin;
 
   NS_ENSURE_TRUE(mWindow, NS_ERROR_FAILURE);
   nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(mWindow);
 
   window->GetDocShell()->SetAppType(nsIDocShell::APP_TYPE_MAIL);
 
-  nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
-    do_QueryInterface(window->GetDocShell());
+  nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =  window->GetDocShell();
   NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDocShellTreeItem> rootAsItem;
   docShellAsItem->GetSameTypeRootTreeItem(getter_AddRefs(rootAsItem));
 
   nsCOMPtr<nsIDocShellTreeItem> childItem;
   rootAsItem->FindChildWithName(NS_LITERAL_STRING("content"), true,
         false, nullptr, nullptr,
@@ -262,19 +261,18 @@ NS_IMETHODIMP nsMsgPrintEngine::SetParen
 NS_IMETHODIMP
 nsMsgPrintEngine::ShowWindow(bool aShow)
 {
   nsresult rv;
 
   NS_ENSURE_TRUE(mWindow, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(mWindow);
-  nsCOMPtr <nsIDocShellTreeItem> treeItem =
-    do_QueryInterface(window->GetDocShell(), &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
+  nsCOMPtr<nsIDocShellTreeItem> treeItem = window->GetDocShell();
+  NS_ENSURE_TRUE(treeItem, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr <nsIDocShellTreeOwner> treeOwner;
   rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
   NS_ENSURE_SUCCESS(rv,rv);
 
   if (treeOwner) {
     // disable (enable) the window
     nsCOMPtr<nsIBaseWindow> baseWindow;
@@ -353,17 +351,17 @@ nsMsgPrintEngine::ShowProgressDialog(boo
   // If we don't get a service, that's ok, then just don't show progress
   if (showProgressDialog) {
     if (!mPrintPromptService)
     {
       mPrintPromptService = do_GetService(kPrintingPromptService);
     }
     if (mPrintPromptService)
     {
-      nsCOMPtr<mozIDOMWindowProxy> domWin(do_QueryInterface(mParentWindow));
+      nsCOMPtr<mozIDOMWindowProxy> domWin = mParentWindow;
       if (!domWin)
       {
         domWin = mWindow;
       }
 
       rv = mPrintPromptService->ShowProgress(domWin, mWebBrowserPrint, mPrintSettings, this, aIsForPrinting,
                                             getter_AddRefs(mPrintProgressListener),
                                             getter_AddRefs(mPrintProgressParams),
--- a/mailnews/base/src/nsMsgSearchDBView.cpp
+++ b/mailnews/base/src/nsMsgSearchDBView.cpp
@@ -442,17 +442,17 @@ nsMsgSearchDBView::AddHdrFromFolder(nsIM
     bool newThread = !thread;
     nsMsgXFViewThread *viewThread;
     if (!thread)
     {
       viewThread = new nsMsgXFViewThread(this, m_nextThreadId++);
       if (!viewThread)
         return NS_ERROR_OUT_OF_MEMORY;
 
-      thread = do_QueryInterface(viewThread);
+      thread = viewThread;
     }
     else
     {
       viewThread = static_cast<nsMsgXFViewThread*>(thread.get());
       thread->GetChildHdrAt(0, getter_AddRefs(threadRoot));
     }
 
     AddMsgToHashTables(msgHdr, thread);
--- a/mailnews/base/src/nsMsgWindow.cpp
+++ b/mailnews/base/src/nsMsgWindow.cpp
@@ -330,17 +330,17 @@ NS_IMETHODIMP nsMsgWindow::SetDomWindow(
   NS_ENSURE_ARG_POINTER(aWindow);
   mDomWindow = do_GetWeakReference(aWindow);
 
   nsCOMPtr<nsPIDOMWindowOuter> win = nsPIDOMWindowOuter::From(aWindow);
   nsIDocShell *docShell = nullptr;
   if (win)
     docShell = win->GetDocShell();
 
-  nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
+  nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(docShell);
 
   if(docShellAsItem)
   {
     nsCOMPtr<nsIDocShellTreeItem> rootAsItem;
     docShellAsItem->GetSameTypeRootTreeItem(getter_AddRefs(rootAsItem));
 
     nsCOMPtr<nsIDocShell> rootAsShell(do_QueryInterface(rootAsItem));
     SetRootDocShell(rootAsShell);
--- a/mailnews/base/util/nsImapMoveCoalescer.cpp
+++ b/mailnews/base/util/nsImapMoveCoalescer.cpp
@@ -116,17 +116,17 @@ nsresult nsImapMoveCoalescer::PlaybackMo
     nsCOMPtr<nsIMsgCopyService> copySvc = do_GetService(NS_MSGCOPYSERVICE_CONTRACTID);
     if (copySvc)
     {
       nsCOMPtr <nsIMsgCopyServiceListener> listener;
       if (m_doNewMailNotification)
       {
         nsMoveCoalescerCopyListener *copyListener = new nsMoveCoalescerCopyListener(this, destFolder);
         if (copyListener)
-          listener = do_QueryInterface(copyListener);
+          listener = copyListener;
       }
       rv = copySvc->CopyMessages(m_sourceFolder, messages, destFolder, true,
                                  listener, m_msgWindow, false /*allowUndo*/);
       if (NS_SUCCEEDED(rv))
         m_outstandingMoves++;
     }
   }
   return rv;
@@ -208,18 +208,17 @@ NS_IMETHODIMP nsMoveCoalescerCopyListene
     {
       uint32_t folderFlags;
       m_destFolder->GetFlags(&folderFlags);
       if (!(folderFlags & (nsMsgFolderFlags::Junk | nsMsgFolderFlags::Trash)))
       {
         nsCOMPtr<nsIImapService> imapService = do_GetService(NS_IMAPSERVICE_CONTRACTID, &rv);
         NS_ENSURE_SUCCESS(rv, rv);
         nsCOMPtr <nsIURI> url;
-        nsCOMPtr <nsIUrlListener> listener = do_QueryInterface(m_coalescer);
-        rv = imapService->SelectFolder(m_destFolder, listener, nullptr, getter_AddRefs(url));
+        rv = imapService->SelectFolder(m_destFolder, m_coalescer, nullptr, getter_AddRefs(url));
       }
     }
     else // give junk filters a chance to run on new msgs in destination local folder
     {
       bool filtersRun;
       m_destFolder->CallFilterPlugins(nullptr, &filtersRun);
     }
   }
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -3058,29 +3058,25 @@ NS_IMETHODIMP nsMsgDBFolder::RemoveFolde
 }
 
 NS_IMETHODIMP nsMsgDBFolder::SetParent(nsIMsgFolder *aParent)
 {
   mParent = do_GetWeakReference(aParent);
   if (aParent)
   {
     nsresult rv;
-    nsCOMPtr<nsIMsgFolder> parentMsgFolder = do_QueryInterface(aParent, &rv);
-    if (NS_SUCCEEDED(rv))
-    {
-      // servers do not have parents, so we must not be a server
-      mIsServer = false;
-      mIsServerIsValid = true;
-
-      // also set the server itself while we're here.
-      nsCOMPtr<nsIMsgIncomingServer> server;
-      rv = parentMsgFolder->GetServer(getter_AddRefs(server));
-      if (NS_SUCCEEDED(rv) && server)
-        mServer = do_GetWeakReference(server);
-    }
+    // servers do not have parents, so we must not be a server
+    mIsServer = false;
+    mIsServerIsValid = true;
+
+    // also set the server itself while we're here.
+    nsCOMPtr<nsIMsgIncomingServer> server;
+    rv = aParent->GetServer(getter_AddRefs(server));
+    if (NS_SUCCEEDED(rv) && server)
+      mServer = do_GetWeakReference(server);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgDBFolder::GetParent(nsIMsgFolder **aParent)
 {
   NS_ENSURE_ARG_POINTER(aParent);
   nsCOMPtr<nsIMsgFolder> parent = do_QueryReferent(mParent);
--- a/mailnews/base/util/nsMsgIncomingServer.cpp
+++ b/mailnews/base/util/nsMsgIncomingServer.cpp
@@ -235,19 +235,17 @@ NS_IMETHODIMP nsMsgIncomingServer::SetPe
 
 NS_IMPL_GETSET(nsMsgIncomingServer, BiffState, uint32_t, m_biffState)
 
 NS_IMETHODIMP nsMsgIncomingServer::WriteToFolderCache(nsIMsgFolderCache *folderCache)
 {
   nsresult rv = NS_OK;
   if (m_rootFolder)
   {
-    nsCOMPtr <nsIMsgFolder> msgFolder = do_QueryInterface(m_rootFolder, &rv);
-    if (NS_SUCCEEDED(rv) && msgFolder)
-      rv = msgFolder->WriteToFolderCache(folderCache, true /* deep */);
+    rv = m_rootFolder->WriteToFolderCache(folderCache, true /* deep */);
   }
   return rv;
 }
 
 NS_IMETHODIMP
 nsMsgIncomingServer::Shutdown()
 {
   nsresult rv = CloseCachedConnections();
--- a/mailnews/base/util/nsMsgMailNewsUrl.cpp
+++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp
@@ -346,17 +346,17 @@ NS_IMETHODIMP nsMsgMailNewsUrl::IsUrlTyp
   *isType = false;
   return NS_OK;
 
 }
 
 NS_IMETHODIMP nsMsgMailNewsUrl::SetSearchSession(nsIMsgSearchSession *aSearchSession)
 {
   if (aSearchSession)
-    m_searchSession = do_QueryInterface(aSearchSession);
+    m_searchSession = aSearchSession;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgMailNewsUrl::GetSearchSession(nsIMsgSearchSession **aSearchSession)
 {
   NS_ENSURE_ARG(aSearchSession);
   NS_IF_ADDREF(*aSearchSession = m_searchSession);
   return NS_OK;
--- a/mailnews/base/util/nsMsgUtils.cpp
+++ b/mailnews/base/util/nsMsgUtils.cpp
@@ -1861,20 +1861,19 @@ MsgStreamMsgHeaders(nsIInputStream *aInp
     msgHeaders.Append(curLine);
     msgHeaders.AppendLiteral("\r\n");
   }
   lineBuffer = nullptr;
   nsCOMPtr<nsIStringInputStream> hdrsStream =
         do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   hdrsStream->SetData(msgHeaders.get(), msgHeaders.Length());
-  nsCOMPtr<nsIInputStream> stream(do_QueryInterface(hdrsStream));
 
   nsCOMPtr<nsIInputStreamPump> pump;
-  rv = NS_NewInputStreamPump(getter_AddRefs(pump), stream.forget());
+  rv = NS_NewInputStreamPump(getter_AddRefs(pump), hdrsStream.forget());
   NS_ENSURE_SUCCESS(rv, rv);
 
   return pump->AsyncRead(aConsumer, nullptr);
 }
 
 class CharsetDetectionObserver : public nsICharsetDetectionObserver
 {
 public:
--- a/mailnews/compose/src/nsMsgAttachmentHandler.cpp
+++ b/mailnews/compose/src/nsMsgAttachmentHandler.cpp
@@ -519,22 +519,20 @@ DONE:
 }
 
 nsresult
 nsMsgAttachmentHandler::PickCharset()
 {
   if (!m_charset.IsEmpty() || !m_type.LowerCaseEqualsLiteral(TEXT_PLAIN))
     return NS_OK;
 
-  nsCOMPtr<nsIFile> tmpFile =
-    do_QueryInterface(mTmpFile);
-  if (!tmpFile)
+  if (!mTmpFile)
     return NS_OK;
 
-  return MsgDetectCharsetFromFile(tmpFile, m_charset);
+  return MsgDetectCharsetFromFile(mTmpFile, m_charset);
 }
 
 static nsresult
 FetcherURLDoneCallback(nsresult aStatus,
                        const nsACString &aContentType,
                        const nsACString &aCharset,
                        int32_t totalSize,
                        const char16_t* aMsg, void *tagData)
@@ -572,17 +570,17 @@ nsMsgAttachmentHandler::SnarfMsgAttachme
   nsresult rv = NS_ERROR_INVALID_ARG;
   nsCOMPtr <nsIMsgMessageService> messageService;
 
   if (m_uri.Find("-message:", /* ignoreCase = */ true) != -1)
   {
     nsCOMPtr <nsIFile> tmpFile;
     rv = nsMsgCreateTempFile("nsmail.tmp", getter_AddRefs(tmpFile));
     NS_ENSURE_SUCCESS(rv, rv);
-    mTmpFile = do_QueryInterface(tmpFile);
+    mTmpFile = tmpFile;
     mDeleteFile = true;
     mCompFields = compFields;
     m_type = MESSAGE_RFC822;
     m_overrideType = MESSAGE_RFC822;
     if (!mTmpFile)
     {
       rv = NS_ERROR_FAILURE;
       goto done;
@@ -636,20 +634,16 @@ nsMsgAttachmentHandler::SnarfMsgAttachme
       if (mimeConverter)
       {
         mimeConverter->SetMimeOutputType(nsMimeOutput::nsMimeMessageDecrypt);
         mimeConverter->SetForwardInline(false);
         mimeConverter->SetIdentity(nullptr);
         mimeConverter->SetOriginalMsgURI(nullptr);
       }
 
-      nsCOMPtr<nsIStreamListener> convertedListener = do_QueryInterface(m_mime_parser, &rv);
-      if (NS_FAILED(rv))
-        goto done;
-
       nsCOMPtr<nsIURI> aURL;
       rv = messageService->GetUrlForUri(uri.get(), getter_AddRefs(aURL), nullptr);
       if (NS_FAILED(rv))
         goto done;
 
 
       nsCOMPtr<nsIPrincipal> nullPrincipal =
         do_CreateInstance("@mozilla.org/nullprincipal;1", &rv);
@@ -667,17 +661,17 @@ nsMsgAttachmentHandler::SnarfMsgAttachme
         goto done;
 
       rv = m_mime_parser->AsyncConvertData("message/rfc822", "message/rfc822",
                                            strListener, m_converter_channel);
       if (NS_FAILED(rv))
         goto done;
 
       nsCOMPtr<nsIURI> dummyNull;
-      rv = messageService->DisplayMessage(uri.get(), convertedListener, nullptr, nullptr, nullptr,
+      rv = messageService->DisplayMessage(uri.get(), m_mime_parser, nullptr, nullptr, nullptr,
                                           getter_AddRefs(dummyNull));
     }
   }
 done:
   if (NS_FAILED(rv))
   {
       if (mOutFile)
       {
@@ -714,17 +708,17 @@ nsMsgAttachmentHandler::SnarfAttachment(
 
   mCompFields = compFields;
 
   // First, get as file spec and create the stream for the
   // temp file where we will save this data
   nsCOMPtr <nsIFile> tmpFile;
   nsresult rv = nsMsgCreateTempFile("nsmail.tmp", getter_AddRefs(tmpFile));
   NS_ENSURE_SUCCESS(rv, rv);
-  mTmpFile = do_QueryInterface(tmpFile);
+  mTmpFile = tmpFile;
   mDeleteFile = true;
 
   rv = MsgNewBufferedFileOutputStream(getter_AddRefs(mOutFile), mTmpFile, -1, 00600);
   if (NS_FAILED(rv) || !mOutFile)
   {
     if (m_mime_delivery_state)
     {
       nsCOMPtr<nsIMsgSendReport> sendReport;
@@ -799,17 +793,17 @@ nsMsgAttachmentHandler::ConvertToZipFile
   nsresult rv = aSourceFile->GetNativeLeafName(zippedName);
   NS_ENSURE_SUCCESS(rv, rv);
   zippedName.AppendLiteral(".zip");
 
   // create a temporary file that we'll work on
   nsCOMPtr <nsIFile> tmpFile;
   rv = nsMsgCreateTempFile(zippedName.get(), getter_AddRefs(tmpFile));
   NS_ENSURE_SUCCESS(rv, rv);
-  mEncodedWorkingFile = do_QueryInterface(tmpFile);
+  mEncodedWorkingFile = tmpFile;
 
   // point our URL at the zipped temp file
   NS_NewFileURI(getter_AddRefs(mURL), mEncodedWorkingFile);
 
   // zip it!
   rv = nsSimpleZipper::Zip(aSourceFile, mEncodedWorkingFile);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -883,17 +877,17 @@ nsMsgAttachmentHandler::ConvertToAppleEn
 
     separator = mime_make_separator("ad");
     if (!separator)
       return NS_ERROR_OUT_OF_MEMORY;
 
     nsCOMPtr <nsIFile> tmpFile;
     nsresult rv = nsMsgCreateTempFile("appledouble", getter_AddRefs(tmpFile));
     if (NS_SUCCEEDED(rv))
-      mEncodedWorkingFile = do_QueryInterface(tmpFile);
+      mEncodedWorkingFile = tmpFile;
     if (!mEncodedWorkingFile)
     {
       PR_FREEIF(separator);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     //
     // RICHIE_MAC - ok, here's the deal, we have a file that we need
@@ -1097,17 +1091,17 @@ nsMsgAttachmentHandler::UrlExit(nsresult
   }
   // this silliness is because Windows nsIFile caches its file size
   // so if an output stream writes to it, it will still return the original
   // cached size.
   if (mTmpFile)
   {
     nsCOMPtr <nsIFile> tmpFile;
     mTmpFile->Clone(getter_AddRefs(tmpFile));
-    mTmpFile = do_QueryInterface(tmpFile);
+    mTmpFile = tmpFile;
   }
   mRequest = nullptr;
 
   // First things first, we are now going to see if this is an HTML
   // Doc and if it is, we need to see if we can determine the charset
   // for this part by sniffing the HTML file.
   // This is needed only when the charset is not set already.
   // (e.g. a charset may be specified in HTTP header)
@@ -1233,17 +1227,17 @@ nsMsgAttachmentHandler::UrlExit(nsresult
           outputStream->Close();
           // this silliness is because Windows nsIFile caches its file size
           // so if an output stream writes to it, it will still return the original
           // cached size.
           if (mTmpFile)
           {
             nsCOMPtr <nsIFile> tmpFile;
             mTmpFile->Clone(getter_AddRefs(tmpFile));
-            mTmpFile = do_QueryInterface(tmpFile);
+            mTmpFile = tmpFile;
           }
 
         }
       }
     }
 
     m_type = m_desiredType;
     m_desiredType.Truncate();
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -222,17 +222,17 @@ GetChildOffset(nsINode *aChild, nsINode 
 
 nsresult
 GetNodeLocation(nsINode *inChild, nsCOMPtr<nsINode> *outParent, int32_t *outOffset)
 {
   NS_ASSERTION((outParent && outOffset), "bad args");
   nsresult result = NS_ERROR_NULL_POINTER;
   if (inChild && outParent && outOffset)
   {
-    nsCOMPtr<nsINode> inChild2 = do_QueryInterface(inChild);
+    nsCOMPtr<nsINode> inChild2 = inChild;
     *outParent = inChild2->GetParentNode();
     if (*outParent)
     {
       result = GetChildOffset(inChild2, *outParent, *outOffset);
     }
   }
 
   return result;
@@ -580,17 +580,17 @@ nsMsgCompose::InsertDivWrappedTextAtSele
   {
     RefPtr<Selection> selection;
     m_editor->GetSelection(getter_AddRefs(selection));
 
     if (selection)
       selection->Collapse(parent, offset + 1);
   }
   if (divElem) {
-    nsCOMPtr<Element> divElem2 = do_QueryInterface(divElem);
+    RefPtr<Element> divElem2 = divElem;
     IgnoredErrorResult rv2;
     divElem2->SetAttribute(NS_LITERAL_STRING("class"), classStr, rv2);
   }
 }
 
 /*
  * The following function replaces <plaintext> tags with <x-plaintext>.
  * <plaintext> is a funny beast: It leads to everything following it
@@ -1011,18 +1011,17 @@ nsMsgCompose::Initialize(nsIMsgComposePa
   aParams->GetIdentity(getter_AddRefs(m_identity));
 
   if (aWindow)
   {
     m_window = aWindow;
     nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(aWindow);
     NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
 
-    nsCOMPtr<nsIDocShellTreeItem> treeItem =
-      do_QueryInterface(window->GetDocShell());
+    nsCOMPtr<nsIDocShellTreeItem> treeItem = window->GetDocShell();
     nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
     rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
     if (NS_FAILED(rv)) return rv;
 
     m_baseWindow = do_QueryInterface(treeOwner);
   }
 
   MSG_ComposeFormat format;
@@ -5628,17 +5627,17 @@ nsMsgCompose::MoveToAboveQuote(void)
   }
 
   nsCOMPtr<nsINode> node;
   nsAutoString attributeName;
   nsAutoString attributeValue;
   nsAutoString tagLocalName;
   attributeName.AssignLiteral("class");
 
-  nsCOMPtr<nsINode> rootElement2 = do_QueryInterface(rootElement);
+  RefPtr<nsINode> rootElement2 = rootElement;
   node = rootElement2->GetFirstChild();
   while (node) {
     nsCOMPtr<Element> element = do_QueryInterface(node);
     if (element) {
       // First check for <blockquote>. This will most likely not trigger
       // since well-behaved quotes are preceded by a cite prefix.
       tagLocalName = node->LocalName();
       if (tagLocalName.EqualsLiteral("blockquote")) {
@@ -5720,17 +5719,17 @@ nsMsgCompose::MoveToEndOfDocument(void)
   int32_t offset;
   RefPtr<Element> rootElement;
   nsCOMPtr<nsINode> lastNode;
   nsresult rv = m_editor->GetRootElement(getter_AddRefs(rootElement));
   if (NS_FAILED(rv) || !rootElement) {
     return rv;
   }
 
-  nsCOMPtr<nsINode> rootElement2 = do_QueryInterface(rootElement);
+  RefPtr<nsINode> rootElement2 = rootElement;
   lastNode = rootElement2->GetLastChild();
   if (!lastNode) {
     return NS_ERROR_NULL_POINTER;
   }
 
   rv = GetChildOffset(lastNode, rootElement2, offset);
   if (NS_FAILED(rv)) {
     return rv;
@@ -5762,17 +5761,17 @@ nsMsgCompose::SetIdentity(nsIMsgIdentity
     return rv;
 
   //First look for the current signature, if we have one
   nsCOMPtr<nsINode> lastNode;
   nsCOMPtr<nsINode> node;
   nsCOMPtr<nsINode> tempNode;
   nsAutoString tagLocalName;
 
-  nsCOMPtr<nsINode> rootElement2 = do_QueryInterface(rootElement);
+  RefPtr<nsINode> rootElement2 = rootElement;
   lastNode = rootElement2->GetLastChild();
   if (lastNode)
   {
     node = lastNode;
     // In html, the signature is inside an element with
     // class="moz-signature"
     bool signatureFound = false;
     nsAutoString attributeName;
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -1992,17 +1992,17 @@ nsMsgComposeAndSend::AddCompFieldLocalAt
           NS_ENSURE_TRUE(ioService, NS_ERROR_UNEXPECTED);
           nsCOMPtr <nsIURI> uri;
           rv = ioService->NewURI(url, nullptr, nullptr, getter_AddRefs(uri));
           NS_ENSURE_SUCCESS(rv, rv);
           nsCOMPtr <nsIFileURL> fileURL = do_QueryInterface(uri);
           NS_ENSURE_SUCCESS(rv, rv);
           nsCOMPtr <nsIFile> fileURLFile;
           fileURL->GetFile(getter_AddRefs(fileURLFile));
-          m_attachments[newLoc]->mTmpFile = do_QueryInterface(fileURLFile);
+          m_attachments[newLoc]->mTmpFile = fileURLFile;
           m_attachments[newLoc]->mDeleteFile = false;
           if (m_attachments[newLoc]->mURL)
           {
             nsAutoString proposedName;
             attachment->GetName(proposedName);
             msg_pick_real_name(m_attachments[newLoc], proposedName.get(), mCompFields->GetCharacterSet());
           }
 
@@ -3352,17 +3352,17 @@ nsMsgComposeAndSend::DeliverFileAsMail()
 
     // Tell the user we are sending the message!
     nsString msg;
     mComposeBundle->GetStringFromName("sendingMessage", msg);
     SetStatusMessage(msg);
     nsCOMPtr<nsIMsgStatusFeedback> msgStatus (do_QueryInterface(mSendProgress));
     // if the sendProgress isn't set, let's use the member variable.
     if (!msgStatus)
-      msgStatus = do_QueryInterface(mStatusFeedback);
+      msgStatus = mStatusFeedback;
 
     nsCOMPtr<nsIURI> runningUrl;
     rv = smtpService->SendMailMessage(mTempFile, buf, mUserIdentity, mCompFields->GetFrom(),
                                       mSmtpPassword, deliveryListener, msgStatus,
                                       callbacks, mCompFields->GetDSN(),
                                       getter_AddRefs(runningUrl),
                                       getter_AddRefs(mRunningRequest));
     // set envid on the returned URL
--- a/mailnews/compose/src/nsSmtpProtocol.cpp
+++ b/mailnews/compose/src/nsSmtpProtocol.cpp
@@ -710,18 +710,17 @@ nsresult nsSmtpProtocol::SendHeloRespons
                           m_responseText.get(), nullptr);
     NS_ASSERTION(NS_SUCCEEDED(rv), "failed to explain SMTP error");
 
     m_urlErrorState = NS_ERROR_BUT_DONT_SHOW_ALERT;
     return NS_ERROR_SMTP_AUTH_FAILURE;
   }
 
   // check if we're just verifying the ability to logon
-  nsCOMPtr<nsISmtpUrl> smtpUrl = do_QueryInterface(m_runningURL, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsISmtpUrl> smtpUrl = m_runningURL;
   bool verifyingLogon = false;
   smtpUrl->GetVerifyLogon(&verifyingLogon);
   if (verifyingLogon)
     return SendQuit();
 
   nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIPrefBranch> prefBranch;
@@ -2183,18 +2182,17 @@ nsresult nsSmtpProtocol::ProcessProtocol
 
   return NS_OK;
 }
 
 nsresult
 nsSmtpProtocol::GetPassword(nsString &aPassword)
 {
     nsresult rv;
-    nsCOMPtr<nsISmtpUrl> smtpUrl = do_QueryInterface(m_runningURL, &rv);
-    NS_ENSURE_SUCCESS(rv,rv);
+    nsCOMPtr<nsISmtpUrl> smtpUrl = m_runningURL;
 
     nsCOMPtr<nsISmtpServer> smtpServer;
     rv = smtpUrl->GetSmtpServer(getter_AddRefs(smtpServer));
     NS_ENSURE_SUCCESS(rv,rv);
 
     rv = smtpServer->GetPassword(aPassword);
     NS_ENSURE_SUCCESS(rv,rv);
 
@@ -2276,18 +2274,17 @@ nsSmtpProtocol::PromptForPassword(nsISmt
   return rv;
 }
 
 nsresult
 nsSmtpProtocol::GetUsernamePassword(nsACString &aUsername,
                                     nsAString &aPassword)
 {
     nsresult rv;
-    nsCOMPtr<nsISmtpUrl> smtpUrl = do_QueryInterface(m_runningURL, &rv);
-    NS_ENSURE_SUCCESS(rv,rv);
+    nsCOMPtr<nsISmtpUrl> smtpUrl = m_runningURL;
 
     nsCOMPtr<nsISmtpServer> smtpServer;
     rv = smtpUrl->GetSmtpServer(getter_AddRefs(smtpServer));
     NS_ENSURE_SUCCESS(rv,rv);
 
     rv = smtpServer->GetPassword(aPassword);
     NS_ENSURE_SUCCESS(rv,rv);
 
--- a/mailnews/compose/src/nsURLFetcher.cpp
+++ b/mailnews/compose/src/nsURLFetcher.cpp
@@ -48,17 +48,17 @@ nsURLFetcher::nsURLFetcher()
   mTotalWritten = 0;
   mBuffer = nullptr;
   mBufferSize = 0;
   mStillRunning = true;
   mCallback = nullptr;
   mOnStopRequestProcessed = false;
   mIsFile=false;
   nsURLFetcherStreamConsumer *consumer = new nsURLFetcherStreamConsumer(this);
-  mConverter = do_QueryInterface(consumer);
+  mConverter = consumer;
 }
 
 nsURLFetcher::~nsURLFetcher()
 {
   mStillRunning = false;
 
   PR_FREEIF(mBuffer);
   // Remove the DocShell as a listener of the old WebProgress...
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -2023,18 +2023,17 @@ nsresult nsMsgDatabase::RemoveHeaderFrom
 {
   if (!msgHdr)
     return NS_ERROR_NULL_POINTER;
   nsresult ret = NS_OK;
   nsCOMPtr <nsIMsgThread> thread ;
   ret = GetThreadContainingMsgHdr(msgHdr, getter_AddRefs(thread));
   if (NS_SUCCEEDED(ret) && thread)
   {
-    nsCOMPtr <nsIDBChangeAnnouncer> announcer = do_QueryInterface(this);
-    ret = thread->RemoveChildHdr(msgHdr, announcer);
+    ret = thread->RemoveChildHdr(msgHdr, this);
   }
   return ret;
 }
 
 NS_IMETHODIMP nsMsgDatabase::RemoveHeaderMdbRow(nsIMsgDBHdr *msg)
 {
   NS_ENSURE_ARG_POINTER(msg);
   nsMsgHdr* msgHdr = static_cast<nsMsgHdr*>(msg);  // closed system, so this is ok
@@ -4557,19 +4556,17 @@ nsresult nsMsgDatabase::ThreadNewHdr(nsM
     newThread = false;
   }
   return result;
 }
 
 nsresult nsMsgDatabase::AddToThread(nsMsgHdr *newHdr, nsIMsgThread *thread, nsIMsgDBHdr *inReplyTo, bool threadInThread)
 {
   // don't worry about real threading yet.
-  nsCOMPtr <nsIDBChangeAnnouncer> announcer = do_QueryInterface(this);
-
-  return thread->AddChild(newHdr, inReplyTo, threadInThread, announcer);
+  return thread->AddChild(newHdr, inReplyTo, threadInThread, this);
 }
 
 nsMsgHdr * nsMsgDatabase::GetMsgHdrForReference(nsCString &reference)
 {
   NS_ASSERTION(false, "not implemented yet.");
   return nullptr;
 }
 
--- a/mailnews/imap/src/nsAutoSyncState.cpp
+++ b/mailnews/imap/src/nsAutoSyncState.cpp
@@ -37,19 +37,18 @@ bool MsgStrategyComparatorAdaptor::Equal
   mDatabase->GetMsgHdrForKey(a, getter_AddRefs(hdrA));
   mDatabase->GetMsgHdrForKey(b, getter_AddRefs(hdrB));
 
   if (hdrA && hdrB)
   {
     nsresult rv = NS_OK;
     nsAutoSyncStrategyDecisionType decision = nsAutoSyncStrategyDecisions::Same;
 
-    nsCOMPtr<nsIMsgFolder> folder = do_QueryInterface(mFolder);
     if (mStrategy)
-      rv = mStrategy->Sort(folder, hdrA, hdrB, &decision);
+      rv = mStrategy->Sort(mFolder, hdrA, hdrB, &decision);
 
     if (NS_SUCCEEDED(rv))
       return (decision == nsAutoSyncStrategyDecisions::Same);
   }
 
   return false;
 }
 
@@ -62,19 +61,18 @@ bool MsgStrategyComparatorAdaptor::LessT
   mDatabase->GetMsgHdrForKey(a, getter_AddRefs(hdrA));
   mDatabase->GetMsgHdrForKey(b, getter_AddRefs(hdrB));
 
   if (hdrA && hdrB)
   {
     nsresult rv = NS_OK;
     nsAutoSyncStrategyDecisionType decision = nsAutoSyncStrategyDecisions::Same;
 
-    nsCOMPtr<nsIMsgFolder> folder = do_QueryInterface(mFolder);
     if (mStrategy)
-      rv = mStrategy->Sort(folder, hdrA, hdrB, &decision);
+      rv = mStrategy->Sort(mFolder, hdrA, hdrB, &decision);
 
     if (NS_SUCCEEDED(rv))
       return (decision == nsAutoSyncStrategyDecisions::Lower);
   }
 
   return false;
 }
 
--- a/mailnews/imap/src/nsImapIncomingServer.cpp
+++ b/mailnews/imap/src/nsImapIncomingServer.cpp
@@ -629,20 +629,17 @@ nsresult nsImapIncomingServer::DoomUrlIf
 
   if (aMailNewsUrl && aImapUrl)
   {
     nsCOMPtr <nsIImapMockChannel> mockChannel;
 
     if (NS_SUCCEEDED(aImapUrl->GetMockChannel(getter_AddRefs(mockChannel))) && mockChannel)
     {
       nsresult requestStatus;
-      nsCOMPtr<nsIRequest> request = do_QueryInterface(mockChannel);
-      if (!request)
-        return NS_ERROR_FAILURE;
-      request->GetStatus(&requestStatus);
+      mockChannel->GetStatus(&requestStatus);
       if (NS_FAILED(requestStatus))
       {
         nsresult res;
         *urlDoomed = true;
         nsImapProtocol::LogImapUrl("dooming url", aImapUrl);
 
         mockChannel->Close(); // try closing it to get channel listener nulled out.
 
@@ -688,24 +685,19 @@ nsImapIncomingServer::ConnectionTimeOut(
   }
 
   PRTime cacheTimeoutLimits = timeoutInMinutes * 60 * PR_USEC_PER_SEC;
   PRTime lastActiveTimeStamp;
   rv = aConnection->GetLastActiveTimeStamp(&lastActiveTimeStamp);
 
   if (PR_Now() - lastActiveTimeStamp >= cacheTimeoutLimits)
   {
-      nsCOMPtr<nsIImapProtocol> aProtocol(do_QueryInterface(aConnection,
-                                                            &rv));
-      if (NS_SUCCEEDED(rv) && aProtocol)
-      {
-        RemoveConnection(aConnection);
-        aProtocol->TellThreadToDie(false);
-        retVal = true;
-      }
+    RemoveConnection(aConnection);
+    aConnection->TellThreadToDie(false);
+    retVal = true;
   }
   return retVal;
 }
 
 nsresult
 nsImapIncomingServer::GetImapConnection(nsIImapUrl * aImapUrl,
                                         nsIImapProtocol ** aImapConnection)
 {
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -425,29 +425,28 @@ nsresult nsImapMailFolder::CreateSubFold
   rv = GetServer(getter_AddRefs(server));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDirectoryEnumerator> children;
   rv = path->GetDirectoryEntries(getter_AddRefs(children));
   bool more = false;
   if (children)
     children->HasMoreElements(&more);
-  nsCOMPtr<nsIFile> dirEntry;
+  nsCOMPtr<nsIFile> currentFolderPath;
 
   while (more)
   {
     nsCOMPtr<nsISupports> supports;
     rv = children->GetNext(getter_AddRefs(supports));
-    dirEntry = do_QueryInterface(supports);
-    if (NS_FAILED(rv) || !dirEntry)
+    currentFolderPath = do_QueryInterface(supports);
+    if (NS_FAILED(rv) || !currentFolderPath)
       break;
     rv = children->HasMoreElements(&more);
     if (NS_FAILED(rv)) return rv;
 
-    nsCOMPtr <nsIFile> currentFolderPath = do_QueryInterface(dirEntry);
     currentFolderPath->GetLeafName(currentFolderNameStr);
     if (nsShouldIgnoreFile(currentFolderNameStr))
       continue;
 
     // OK, here we need to get the online name from the folder cache if we can.
     // If we can, use that to create the sub-folder
     nsCOMPtr <nsIMsgFolderCacheElement> cacheElement;
     nsCOMPtr <nsIFile> curFolder = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
@@ -2936,18 +2935,17 @@ NS_IMETHODIMP nsImapMailFolder::ParseMsg
       headerInfo->GetMsgHdrs(&msgHdrs);
       // create an input stream based on the hdr string.
       nsCOMPtr<nsIStringInputStream> inputStream =
             do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
       NS_ENSURE_SUCCESS(rv, rv);
       inputStream->ShareData(msgHdrs, strlen(msgHdrs));
       GetMessageHeader(msgKey, getter_AddRefs(msgHdr));
       if (msgHdr) {
-        nsCOMPtr<nsIInputStream> stream(do_QueryInterface(inputStream));
-        GetMsgPreviewTextFromStream(msgHdr, stream);
+        GetMsgPreviewTextFromStream(msgHdr, inputStream);
       }
       continue;
     }
     if (mDatabase && NS_SUCCEEDED(mDatabase->ContainsKey(msgKey, &containsKey)) && containsKey)
     {
       NS_ERROR("downloading hdrs for hdr we already have");
       continue;
     }
@@ -3225,17 +3223,17 @@ NS_IMETHODIMP nsImapMailFolder::BeginCop
     if (NS_FAILED(rv))
     {
       nsCString nativePath = m_copyState->m_tmpFile->HumanReadablePath();
       MOZ_LOG(IMAP, mozilla::LogLevel::Info, ("couldn't remove prev temp file %s: %" PRIx32 "\n", nativePath.get(), static_cast<uint32_t>(rv)));
     }
     m_copyState->m_tmpFile = nullptr;
   }
   if (message)
-    m_copyState->m_message = do_QueryInterface(message, &rv);
+    m_copyState->m_message = message;
 
   rv = GetSpecialDirectoryWithFileName(NS_OS_TEMP_DIR,
                                        "nscpmsg.txt",
                                         getter_AddRefs(m_copyState->m_tmpFile));
   if (NS_FAILED(rv))
     MOZ_LOG(IMAP, mozilla::LogLevel::Info, ("couldn't find nscpmsg.txt:%" PRIx32 "\n", static_cast<uint32_t>(rv)));
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -6627,19 +6625,17 @@ nsresult nsImapMailFolder::DisplayStatus
   nsCOMPtr<nsIImapMockChannel> mockChannel;
   aImapUrl->GetMockChannel(getter_AddRefs(mockChannel));
   if (mockChannel)
   {
     nsCOMPtr<nsIProgressEventSink> progressSink;
     mockChannel->GetProgressEventSink(getter_AddRefs(progressSink));
     if (progressSink)
     {
-        nsCOMPtr<nsIRequest> request = do_QueryInterface(mockChannel);
-        if (!request) return NS_ERROR_FAILURE;
-      progressSink->OnStatus(request, nullptr, NS_OK, PromiseFlatString(msg).get());      // XXX i18n message
+      progressSink->OnStatus(mockChannel, nullptr, NS_OK, PromiseFlatString(msg).get());      // XXX i18n message
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsImapMailFolder::ProgressStatusString(nsIImapProtocol* aProtocol,
                                        const char* aMsgName,
@@ -6691,23 +6687,21 @@ nsImapMailFolder::PercentProgress(nsIIma
       nsCOMPtr<nsIImapMockChannel> mockChannel;
       imapUrl->GetMockChannel(getter_AddRefs(mockChannel));
       if (mockChannel)
       {
         nsCOMPtr<nsIProgressEventSink> progressSink;
         mockChannel->GetProgressEventSink(getter_AddRefs(progressSink));
         if (progressSink)
         {
-            nsCOMPtr<nsIRequest> request = do_QueryInterface(mockChannel);
-            if (!request) return NS_ERROR_FAILURE;
-            progressSink->OnProgress(request, nullptr,
+            progressSink->OnProgress(mockChannel, nullptr,
                                      aCurrentProgress,
                                      aMaxProgress);
             if (aMessage)
-              progressSink->OnStatus(request, nullptr, NS_OK, aMessage); // XXX i18n message
+              progressSink->OnStatus(mockChannel, nullptr, NS_OK, aMessage); // XXX i18n message
         }
       }
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -8095,16 +8089,17 @@ nsImapMailFolder::CopyFileMessage(nsIFil
 }
 
 nsresult
 nsImapMailFolder::CopyStreamMessage(nsIMsgDBHdr* message,
                                     nsIMsgFolder* dstFolder, // should be this
                                     nsIMsgWindow *aMsgWindow,
                                     bool isMove)
 {
+  NS_ENSURE_ARG_POINTER(message);
   if (!m_copyState)
     MOZ_LOG(IMAP, mozilla::LogLevel::Info, ("CopyStreamMessage failed with null m_copyState"));
   NS_ENSURE_TRUE(m_copyState, NS_ERROR_NULL_POINTER);
   nsresult rv;
   nsCOMPtr<nsICopyMessageStreamListener> copyStreamListener = do_CreateInstance(NS_COPYMESSAGESTREAMLISTENER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv,rv);
 
   nsCOMPtr<nsICopyMessageListener> copyListener(do_QueryInterface(dstFolder, &rv));
@@ -8114,21 +8109,18 @@ nsImapMailFolder::CopyStreamMessage(nsIM
   if (NS_FAILED(rv))
     MOZ_LOG(IMAP, mozilla::LogLevel::Info, ("CopyStreaMessage failed with null m_copyState->m_srcSupport"));
   if (NS_FAILED(rv)) return rv;
   rv = copyStreamListener->Init(srcFolder, copyListener, nullptr);
   if (NS_FAILED(rv))
     MOZ_LOG(IMAP, mozilla::LogLevel::Info, ("CopyStreaMessage failed in copyStreamListener->Init"));
   if (NS_FAILED(rv)) return rv;
 
-  nsCOMPtr<nsIMsgDBHdr> msgHdr(do_QueryInterface(message, &rv));
-  if (NS_FAILED(rv)) return rv;
-
   nsCString uri;
-  srcFolder->GetUriForMsg(msgHdr, uri);
+  srcFolder->GetUriForMsg(message, uri);
 
   if (!m_copyState->m_msgService)
     rv = GetMessageServiceFromURI(uri, getter_AddRefs(m_copyState->m_msgService));
 
   if (NS_SUCCEEDED(rv) && m_copyState->m_msgService)
   {
     nsCOMPtr<nsIStreamListener> streamListener(do_QueryInterface(copyStreamListener, &rv));
     NS_ENSURE_SUCCESS(rv, rv);
@@ -8269,18 +8261,18 @@ nsImapMailFolder::InitCopyState(nsISuppo
 
   m_copyState->m_isMove = isMove;
   m_copyState->m_newMsgFlags = newMsgFlags;
   m_copyState->m_newMsgKeywords = newMsgKeywords;
   m_copyState->m_allowUndo = allowUndo;
   m_copyState->m_selectedState = selectedState;
   m_copyState->m_msgWindow = msgWindow;
   if (listener)
-    m_copyState->m_listener = do_QueryInterface(listener, &rv);
-  return rv;
+    m_copyState->m_listener = listener;
+  return NS_OK;
 }
 
 nsresult
 nsImapMailFolder::CopyFileToOfflineStore(nsIFile *srcFile, nsMsgKey msgKey)
 {
   nsresult rv = GetDatabase();
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/mailnews/imap/src/nsImapOfflineSync.cpp
+++ b/mailnews/imap/src/nsImapOfflineSync.cpp
@@ -474,17 +474,17 @@ nsImapOfflineSync::ProcessAppendMsgOpera
       // fails to close above.
       mozilla::Unused << NS_WARN_IF(NS_FAILED(tmpFile->Remove(false)));
       break;
     }
 
     nsCOMPtr<nsIFile> cloneTmpFile;
     // clone the tmp file to defeat nsIFile's stat/size caching.
     tmpFile->Clone(getter_AddRefs(cloneTmpFile));
-    m_curTempFile = do_QueryInterface(cloneTmpFile);
+    m_curTempFile = cloneTmpFile;
     nsCOMPtr<nsIMsgCopyService> copyService = do_GetService(NS_MSGCOPYSERVICE_CONTRACTID);
 
     // CopyFileMessage returns error async to this->OnStopCopy
     // if copyService is null, let's crash here and now.
     rv = copyService->CopyFileMessage(cloneTmpFile, destFolder,
                                       nullptr, // nsIMsgDBHdr* msgToReplace
                                       true,    // isDraftOrTemplate
                                       0,       // new msg flags
--- a/mailnews/imap/src/nsImapProtocol.cpp
+++ b/mailnews/imap/src/nsImapProtocol.cpp
@@ -738,19 +738,18 @@ nsresult nsImapProtocol::SetupWithUrl(ns
                          nsIContentPolicy::TYPE_OTHER);
       m_mockChannel = do_QueryInterface(channel);
 
       // Certain imap operations (not initiated by the IO Service via AsyncOpen) can be interrupted by  the stop button on the toolbar.
       // We do this by using the loadgroup of the docshell for the message pane. We really shouldn't be doing this..
       // See the comment in nsMsgMailNewsUrl::GetLoadGroup.
       nsCOMPtr<nsILoadGroup> loadGroup;
       mailnewsUrl->GetLoadGroup(getter_AddRefs(loadGroup)); // get the message pane load group
-      nsCOMPtr<nsIRequest> ourRequest = do_QueryInterface(m_mockChannel);
       if (loadGroup)
-        loadGroup->AddRequest(ourRequest, nullptr /* context isupports */);
+        loadGroup->AddRequest(m_mockChannel, nullptr /* context isupports */);
     }
 
     if (m_mockChannel)
     {
       m_mockChannel->SetImapProtocol(this);
       // if we have a listener from a mock channel, over-ride the consumer that was passed in
       nsCOMPtr<nsIStreamListener> channelListener;
       m_mockChannel->GetChannelListener(getter_AddRefs(channelListener));
@@ -1603,18 +1602,17 @@ bool nsImapProtocol::ProcessCurrentURL()
     if (m_imapAction == nsIImapUrl::nsImapSelectFolder)
     {
       // we need to send a start request so that the doc loader
       // will call HandleContent on the imap service so we
       // can abort this url, and run a new url in a new msg window
       // to run the folder load url and get off this crazy merry-go-round.
       if (m_channelListener)
       {
-        nsCOMPtr<nsIRequest> request = do_QueryInterface(m_mockChannel);
-        m_channelListener->OnStartRequest(request, m_channelContext);
+        m_channelListener->OnStartRequest(m_mockChannel, m_channelContext);
       }
       return false;
     }
   }
 
   if (!m_imapMailFolderSink && m_imapProtocolSink)
   {
     // This occurs when running another URL in the main thread loop
@@ -1639,18 +1637,17 @@ bool nsImapProtocol::ProcessCurrentURL()
     m_imapMailFolderSink->SetUrlState(this, mailnewsurl, true, false,
                                       NS_OK);
 
   // if we are set up as a channel, we should notify our channel listener that we are starting...
   // so pass in ourself as the channel and not the underlying socket or file channel the protocol
   // happens to be using
   if (m_channelListener) // ### not sure we want to do this if rerunning url...
   {
-    nsCOMPtr<nsIRequest> request = do_QueryInterface(m_mockChannel);
-    m_channelListener->OnStartRequest(request, m_channelContext);
+    m_channelListener->OnStartRequest(m_mockChannel, m_channelContext);
   }
   // If we haven't received the greeting yet, we need to make sure we strip
   // it out of the input before we start to do useful things...
   if (!TestFlag(IMAP_RECEIVED_GREETING))
     EstablishServerConnection();
 
   // Step 1: If we have not moved into the authenticated state yet then do so
   // by attempting to logon.
@@ -1676,21 +1673,19 @@ bool nsImapProtocol::ProcessCurrentURL()
              && (m_socketType == nsMsgSocketType::trySTARTTLS
              && (GetServerStateParser().GetCapabilityFlag() & kHasStartTLSCapability)))
             || m_socketType == nsMsgSocketType::alwaysSTARTTLS)
         {
           StartTLS();
           if (GetServerStateParser().LastCommandSuccessful())
           {
             nsCOMPtr<nsISupports> secInfo;
-            nsCOMPtr<nsISocketTransport> strans = do_QueryInterface(m_transport, &rv);
-            if (NS_FAILED(rv))
-              return false;
-
-            rv = strans->GetSecurityInfo(getter_AddRefs(secInfo));
+
+            NS_ENSURE_TRUE(m_transport, false);
+            rv = m_transport->GetSecurityInfo(getter_AddRefs(secInfo));
 
             if (NS_SUCCEEDED(rv) && secInfo)
             {
               nsCOMPtr<nsISSLSocketControl> sslControl = do_QueryInterface(secInfo, &rv);
 
               if (NS_SUCCEEDED(rv) && sslControl)
               {
                 rv = sslControl->StartTLS();
@@ -1794,24 +1789,23 @@ bool nsImapProtocol::ProcessCurrentURL()
   else if (!logonFailed)
       HandleCurrentUrlError();
 
 // if we are set up as a channel, we should notify our channel listener that we are stopping...
 // so pass in ourself as the channel and not the underlying socket or file channel the protocol
 // happens to be using
   if (m_channelListener)
   {
-      nsCOMPtr<nsIRequest> request = do_QueryInterface(m_mockChannel);
-      NS_ASSERTION(request, "no request");
-      if (request) {
+      NS_ASSERTION(m_mockChannel, "no request");
+      if (m_mockChannel) {
         nsresult status;
-        request->GetStatus(&status);
+        m_mockChannel->GetStatus(&status);
         if (!GetServerStateParser().LastCommandSuccessful() && NS_SUCCEEDED(status))
           status = NS_MSG_ERROR_IMAP_COMMAND_FAILED;
-        rv = m_channelListener->OnStopRequest(request, m_channelContext, status);
+        rv = m_channelListener->OnStopRequest(m_mockChannel, m_channelContext, status);
       }
   }
   bool suspendUrl = false;
   m_runningUrl->GetMoreHeadersToDownload(&suspendUrl);
   if (mailnewsurl && m_imapMailFolderSink)
   {
     if (logonFailed)
       rv = NS_ERROR_FAILURE;
@@ -3813,18 +3807,17 @@ nsImapProtocol::PostLineDownLoadEvent(co
     {
       uint32_t count = 0;
       if (m_channelOutputStream)
       {
         nsresult rv = m_channelOutputStream->Write(line, byteCount, &count);
         NS_ASSERTION(count == byteCount, "IMAP channel pipe couldn't buffer entire write");
         if (NS_SUCCEEDED(rv))
         {
-          nsCOMPtr<nsIRequest> request = do_QueryInterface(m_mockChannel);
-          m_channelListener->OnDataAvailable(request, m_channelContext, m_channelInputStream, 0, count);
+          m_channelListener->OnDataAvailable(m_mockChannel, m_channelContext, m_channelInputStream, 0, count);
         }
         // else some sort of explosion?
       }
     }
     if (m_runningUrl)
       m_runningUrl->GetStoreResultsOffline(&echoLineToMessageSink);
 
     m_bytesToChannel += byteCount;
@@ -4758,24 +4751,20 @@ uint32_t nsImapProtocol::CountMessagesIn
 // It would be really nice not to have to use this method nearly as much as we did
 // in 4.5 - we need to think about this some. Some of it may just go away in the new world order
 bool nsImapProtocol::DeathSignalReceived()
 {
   // ignore mock channel status if we've been pseudo interrupted
   // ### need to make sure we clear pseudo interrupted status appropriately.
   if (!GetPseudoInterrupted() && m_mockChannel)
   {
-    nsCOMPtr<nsIRequest> request = do_QueryInterface(m_mockChannel);
-    if (request)
-    {
-      nsresult returnValue;
-      request->GetStatus(&returnValue);
-      if (NS_FAILED(returnValue))
-        return false;
-    }
+    nsresult returnValue;
+    m_mockChannel->GetStatus(&returnValue);
+    if (NS_FAILED(returnValue))
+      return false;
   }
 
   // Check the other way of cancelling.
   ReentrantMonitorAutoEnter threadDeathMon(m_threadDeathMonitor);
   return m_threadShouldDie;
 }
 
 NS_IMETHODIMP nsImapProtocol::ResetToAuthenticatedState()
@@ -9004,20 +8993,19 @@ nsImapCacheStreamListener::OnStartReques
 {
   if (!mChannelToUse)
   {
     NS_ERROR("OnStartRequest called after OnStopRequest");
     return NS_ERROR_NULL_POINTER;
   }
   nsCOMPtr<nsILoadGroup> loadGroup;
   mChannelToUse->GetLoadGroup(getter_AddRefs(loadGroup));
-  nsCOMPtr<nsIRequest> ourRequest = do_QueryInterface(mChannelToUse);
   if (loadGroup)
-    loadGroup->AddRequest(ourRequest, nullptr /* context isupports */);
-  return mListener->OnStartRequest(ourRequest, aCtxt);
+    loadGroup->AddRequest(mChannelToUse, nullptr /* context isupports */);
+  return mListener->OnStartRequest(mChannelToUse, aCtxt);
 }
 
 NS_IMETHODIMP
 nsImapCacheStreamListener::OnStopRequest(nsIRequest *request, nsISupports * aCtxt, nsresult aStatus)
 {
   if (!mListener)
   {
     NS_ERROR("OnStopRequest called twice");
@@ -9350,17 +9338,17 @@ nsImapMockChannel::OnCacheEntryAvailable
       {
         nsCOMPtr<nsIOutputStream> out;
         // This will fail with the cache turned off, so we need to fall through
         // to ReadFromImapConnection instead of aborting with NS_ENSURE_SUCCESS(rv,rv).
         rv = entry->OpenOutputStream(0, -1, getter_AddRefs(out));
         if (NS_SUCCEEDED(rv))
         {
           rv = tee->Init(m_channelListener, out, nullptr);
-          m_channelListener = do_QueryInterface(tee);
+          m_channelListener = tee;
         }
         else
           NS_WARNING("IMAP Protocol failed to open output stream to Necko cache");
       }
     }
     else
     {
       rv = ReadFromMemCache(entry);
--- a/mailnews/imap/src/nsImapService.cpp
+++ b/mailnews/imap/src/nsImapService.cpp
@@ -2199,18 +2199,17 @@ nsresult nsImapService::GetImapConnectio
   }
 
   nsCOMPtr<nsIMsgIncomingServer> aMsgIncomingServer;
   nsCOMPtr<nsIMsgMailNewsUrl> msgUrl = do_QueryInterface(aImapUrl);
   nsresult rv = msgUrl->GetServer(getter_AddRefs(aMsgIncomingServer));
 
   if (aURL)
   {
-    nsCOMPtr<nsIURI> msgUrlUri = do_QueryInterface(msgUrl);
-    msgUrlUri.forget(aURL);
+    msgUrl.forget(aURL);
   }
 
   if (NS_SUCCEEDED(rv) && aMsgIncomingServer)
   {
     nsCOMPtr<nsIImapIncomingServer> aImapServer(do_QueryInterface(aMsgIncomingServer, &rv));
     if (NS_SUCCEEDED(rv) && aImapServer)
       rv = aImapServer->GetImapConnectionAndLoadUrl(aImapUrl, aConsumer);
   }
@@ -2590,26 +2589,25 @@ NS_IMETHODIMP nsImapService::NewURI(cons
     // in this low-level service. Cloning URIs where the folder
     // isn't found is common when folders are renamed or moved.
     // We also ignore return statuses here.
     if (folder)
     {
       nsCOMPtr<nsIImapMessageSink> msgSink = do_QueryInterface(folder);
       (void) aImapUrl->SetImapMessageSink(msgSink);
 
-      nsCOMPtr<nsIMsgFolder> msgFolder = do_QueryInterface(folder);
-      (void) SetImapUrlSink(msgFolder, aImapUrl);
+      (void) SetImapUrlSink(folder, aImapUrl);
 
       nsCString messageIdString;
       aImapUrl->GetListOfMessageIds(messageIdString);
       if (!messageIdString.IsEmpty())
       {
         bool useLocalCache = false;
-        msgFolder->HasMsgOffline(strtoul(messageIdString.get(), nullptr, 10),
-                                 &useLocalCache);
+        folder->HasMsgOffline(strtoul(messageIdString.get(), nullptr, 10),
+                              &useLocalCache);
         mailnewsUrl->SetMsgIsInLocalCache(useLocalCache);
       }
     }
   }
 
   // if we are fetching a part, be sure to enable fetch parts on demand
   bool mimePartSelectorDetected = false;
   aImapUrl->GetMimePartSelectorDetected(&mimePartSelectorDetected);
--- a/mailnews/import/src/nsImportEncodeScan.cpp
+++ b/mailnews/import/src/nsImportEncodeScan.cpp
@@ -68,17 +68,17 @@ nsImportEncodeScan::~nsImportEncodeScan(
 {
 }
 
 bool nsImportEncodeScan::InitEncodeScan(bool appleSingleEncode, nsIFile *fileLoc, const char *pName, uint8_t * pBuf, uint32_t sz)
 {
   CleanUpEncodeScan();
   m_isAppleSingle = appleSingleEncode;
   m_encodeScanState = kBeginAppleSingle;
-  m_pInputFile = do_QueryInterface(fileLoc);
+  m_pInputFile = fileLoc;
   m_useFileName = pName;
   m_pBuf = pBuf;
   m_bufSz = sz;
   if (!m_isAppleSingle)
         {
     if (!m_inputStream)
                 {
                   nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(m_inputStream), m_pInputFile);
--- a/mailnews/import/text/src/nsTextImport.cpp
+++ b/mailnews/import/text/src/nsTextImport.cpp
@@ -260,17 +260,17 @@ NS_IMETHODIMP ImportAddressImpl::FindAdd
 
   if (NS_FAILED(rv)) {
     IMPORT_LOG0("*** Error determining delimitter\n");
     return rv;
   }
   m_haveDelim = true;
   m_delim = m_text.GetDelim();
 
-  m_fileLoc = do_QueryInterface(pLoc);
+  m_fileLoc = pLoc;
 
   /* Build an address book descriptor based on the file passed in! */
   nsCOMPtr<nsIMutableArray> array(do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
   if (NS_FAILED(rv)) {
     IMPORT_LOG0("FAILED to allocate the nsIMutableArray\n");
     return rv;
   }
 
@@ -572,17 +572,17 @@ NS_IMETHODIMP ImportAddressImpl::GetSamp
 
   return NS_OK;
 }
 
 NS_IMETHODIMP ImportAddressImpl::SetSampleLocation(nsIFile *pLocation)
 {
   NS_ENSURE_ARG_POINTER(pLocation);
 
-  m_fileLoc = do_QueryInterface(pLocation);
+  m_fileLoc = pLocation;
   m_haveDelim = false;
   return NS_OK;
 }
 
 void ImportAddressImpl::ClearSampleFile(void)
 {
   m_fileLoc = nullptr;
   m_haveDelim = false;
--- a/mailnews/import/vcard/src/nsVCardImport.cpp
+++ b/mailnews/import/vcard/src/nsVCardImport.cpp
@@ -224,17 +224,17 @@ NS_IMETHODIMP ImportVCardAddressImpl::Fi
   if (NS_FAILED(rv) || !exists)
     return NS_ERROR_FAILURE;
 
   bool isFile = false;
   rv = pLoc->IsFile(&isFile);
   if (NS_FAILED(rv) || !isFile)
     return NS_ERROR_FAILURE;
 
-  m_fileLoc = do_QueryInterface(pLoc);
+  m_fileLoc = pLoc;
 
   /* Build an address book descriptor based on the file passed in! */
   nsCOMPtr<nsIMutableArray> array(do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
   if (NS_FAILED(rv)) {
     IMPORT_LOG0("FAILED to allocate the nsIMutableArray\n");
     return rv;
   }
 
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -1415,17 +1415,17 @@ nsMsgLocalMailFolder::InitCopyState(nsIS
   mCopyState->m_messages = messages;
   mCopyState->m_curCopyIndex = 0;
   mCopyState->m_isMove = isMove;
   mCopyState->m_isFolder = isFolder;
   mCopyState->m_allowUndo = allowUndo;
   mCopyState->m_msgWindow = msgWindow;
   rv = messages->GetLength(&mCopyState->m_totalMsgCount);
   if (listener)
-    mCopyState->m_listener = do_QueryInterface(listener, &rv);
+    mCopyState->m_listener = listener;
   mCopyState->m_copyingMultipleMessages = false;
   mCopyState->m_wholeMsgInStream = false;
 
   // If we have source messages then we need destination messages too.
   if (messages)
     mCopyState->m_destMessages = do_CreateInstance(NS_ARRAY_CONTRACTID);
 
   return rv;
@@ -2814,17 +2814,17 @@ nsresult nsMsgLocalMailFolder::CopyMessa
 {
   if (!mCopyState)
     return NS_ERROR_OUT_OF_MEMORY;
 
   nsresult rv;
   nsCOMPtr<nsIMsgDBHdr> msgHdr(do_QueryInterface(message, &rv));
   NS_ENSURE_SUCCESS(rv, NS_ERROR_NO_INTERFACE);
 
-  mCopyState->m_message = do_QueryInterface(msgHdr, &rv);
+  mCopyState->m_message = msgHdr;
 
   nsCOMPtr<nsIMsgFolder> srcFolder(do_QueryInterface(mCopyState->m_srcSupport, &rv));
   NS_ENSURE_SUCCESS(rv, NS_ERROR_NO_INTERFACE);
   nsCString uri;
   srcFolder->GetUriForMsg(msgHdr, uri);
 
   nsCOMPtr<nsICopyMessageStreamListener> copyStreamListener = do_CreateInstance(NS_COPYMESSAGESTREAMLISTENER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv,rv);
--- a/mailnews/local/src/nsMailboxUrl.cpp
+++ b/mailnews/local/src/nsMailboxUrl.cpp
@@ -400,18 +400,18 @@ nsresult nsMailboxUrl::ParseUrl()
     NS_ENSURE_TRUE(ioService, NS_ERROR_UNEXPECTED);
     nsCOMPtr <nsIURI> uri;
     rv = ioService->NewURI(fileUri, nullptr, nullptr, getter_AddRefs(uri));
     NS_ENSURE_SUCCESS(rv, rv);
     nsCOMPtr <nsIFileURL> fileURL = do_QueryInterface(uri);
     NS_ENSURE_SUCCESS(rv, rv);
     nsCOMPtr <nsIFile> fileURLFile;
     fileURL->GetFile(getter_AddRefs(fileURLFile));
-    m_filePath = do_QueryInterface(fileURLFile, &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
+    NS_ENSURE_TRUE(fileURLFile, NS_ERROR_NULL_POINTER);
+    m_filePath = fileURLFile;
   }
 
   GetPathQueryRef(m_file);
   return NS_OK;
 }
 
 nsresult nsMailboxUrl::SetSpecInternal(const nsACString &aSpec)
 {
--- a/mailnews/local/src/nsParseMailbox.cpp
+++ b/mailnews/local/src/nsParseMailbox.cpp
@@ -1675,47 +1675,46 @@ nsParseNewMailState::nsParseNewMailState
 
 NS_IMPL_ISUPPORTS_INHERITED(nsParseNewMailState, nsMsgMailboxParser, nsIMsgFilterHitNotify)
 
 nsresult
 nsParseNewMailState::Init(nsIMsgFolder *serverFolder, nsIMsgFolder *downloadFolder,
                           nsIMsgWindow *aMsgWindow, nsIMsgDBHdr *aHdr,
                           nsIOutputStream *aOutputStream)
 {
+  NS_ENSURE_ARG_POINTER(serverFolder);
   nsresult rv;
   Clear();
   m_rootFolder = serverFolder;
   m_msgWindow = aMsgWindow;
   m_downloadFolder = downloadFolder;
 
   m_newMsgHdr = aHdr;
   m_outputStream = aOutputStream;
   // the new mail parser isn't going to get the stream input, it seems, so we can't use
   // the OnStartRequest mechanism the mailbox parser uses. So, let's open the db right now.
   nsCOMPtr<nsIMsgDBService> msgDBService = do_GetService(NS_MSGDB_SERVICE_CONTRACTID, &rv);
   if (msgDBService && !m_mailDB)
     rv = msgDBService->OpenFolderDB(downloadFolder, false,
                                     getter_AddRefs(m_mailDB));
   NS_ENSURE_SUCCESS(rv, rv);
-  nsCOMPtr <nsIMsgFolder> rootMsgFolder = do_QueryInterface(serverFolder, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIMsgIncomingServer> server;
-  rv = rootMsgFolder->GetServer(getter_AddRefs(server));
+  rv = serverFolder->GetServer(getter_AddRefs(server));
   if (NS_SUCCEEDED(rv))
   {
     rv = server->GetFilterList(aMsgWindow, getter_AddRefs(m_filterList));
 
     if (m_filterList)
       rv = server->ConfigureTemporaryFilters(m_filterList);
     // check if this server defers to another server, in which case
     // we'll use that server's filters as well.
     nsCOMPtr <nsIMsgFolder> deferredToRootFolder;
     server->GetRootMsgFolder(getter_AddRefs(deferredToRootFolder));
-    if (rootMsgFolder != deferredToRootFolder)
+    if (serverFolder != deferredToRootFolder)
     {
       nsCOMPtr <nsIMsgIncomingServer> deferredToServer;
       deferredToRootFolder->GetServer(getter_AddRefs(deferredToServer));
       if (deferredToServer)
         deferredToServer->GetFilterList(aMsgWindow, getter_AddRefs(m_deferredToServerFilterList));
     }
   }
   m_disableFilters = false;
@@ -1913,21 +1912,20 @@ void nsParseNewMailState::ApplyFilters(b
 {
   m_msgMovedByFilter = m_msgCopiedByFilter = false;
   m_curHdrOffset = msgOffset;
 
   if (!m_disableFilters)
   {
     nsCOMPtr<nsIMsgDBHdr> msgHdr = m_newMsgHdr;
     nsCOMPtr<nsIMsgFolder> downloadFolder = m_downloadFolder;
-    nsCOMPtr <nsIMsgFolder> rootMsgFolder = do_QueryInterface(m_rootFolder);
-    if (rootMsgFolder)
+    if (m_rootFolder)
     {
       if (!downloadFolder)
-        rootMsgFolder->GetFolderWithFlags(nsMsgFolderFlags::Inbox,
+        m_rootFolder->GetFolderWithFlags(nsMsgFolderFlags::Inbox,
                                           getter_AddRefs(downloadFolder));
       if (downloadFolder)
         downloadFolder->GetURI(m_inboxUri);
       char * headers = m_headers.GetBuffer();
       uint32_t headersSize = m_headers.GetBufferPos();
       if (m_filterList)
         (void) m_filterList->
           ApplyFiltersToHdr(nsMsgFilterType::InboxRule, msgHdr, downloadFolder,
--- a/mailnews/local/src/nsPop3Protocol.cpp
+++ b/mailnews/local/src/nsPop3Protocol.cpp
@@ -479,17 +479,17 @@ nsresult nsPop3Protocol::Initialize(nsIU
   m_tlsEnabled = false;
   m_socketType = nsMsgSocketType::trySTARTTLS;
   m_prefAuthMethods = POP3_AUTH_MECH_UNDEFINED;
   m_failedAuthMethods = 0;
   m_password_already_sent = false;
   m_currentAuthMethod = POP3_AUTH_MECH_UNDEFINED;
   m_needToRerunUrl = false;
 
-  m_url = do_QueryInterface(aURL);
+  m_url = aURL;
 
   m_lineStreamBuffer = new nsMsgLineStreamBuffer(OUTPUT_BUFFER_SIZE, true);
 
   nsCOMPtr<nsIStringBundleService> bundleService =
     mozilla::services::GetStringBundleService();
   NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED);
   return bundleService->CreateBundle("chrome://messenger/locale/localMsgs.properties", getter_AddRefs(mLocalBundle));
 }
@@ -695,21 +695,20 @@ void nsPop3Protocol::SetUsername(const c
 {
   NS_ASSERTION(name, "no name specified!");
     if (name)
       m_username = name;
 }
 
 nsresult nsPop3Protocol::RerunUrl()
 {
-  nsCOMPtr<nsIURI> url = do_QueryInterface(m_url);
   ClearFlag(POP3_PASSWORD_FAILED);
   m_pop3Server->SetRunningProtocol(nullptr);
   Cleanup();
-  return LoadUrl(url, nullptr);
+  return LoadUrl(m_url, nullptr);
 }
 
 Pop3StatesEnum nsPop3Protocol::GetNextPasswordObtainState()
 {
   switch (m_pop3ConData->next_state)
   {
   case POP3_OBTAIN_PASSWORD_EARLY:
     return POP3_FINISH_OBTAIN_PASSWORD_EARLY;
--- a/mailnews/local/src/nsPop3Sink.cpp
+++ b/mailnews/local/src/nsPop3Sink.cpp
@@ -475,23 +475,20 @@ nsPop3Sink::IncorporateBegin(const char*
       return rv;
 
     if (!m_tmpDownloadFile)
     {
       //need a unique tmp file to prevent dataloss in multiuser environment
       rv = tmpDownloadFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 00600);
       NS_ENSURE_SUCCESS(rv, rv);
 
-      m_tmpDownloadFile = do_QueryInterface(tmpDownloadFile, &rv);
+      m_tmpDownloadFile = tmpDownloadFile;
     }
-    if (NS_SUCCEEDED(rv))
-    {
-      rv = MsgGetFileStream(m_tmpDownloadFile, getter_AddRefs(m_outFileStream));
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
+    rv = MsgGetFileStream(m_tmpDownloadFile, getter_AddRefs(m_outFileStream));
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   else
   {
     rv = server->GetMsgStore(getter_AddRefs(m_msgStore));
     bool reusable;
     NS_ENSURE_SUCCESS(rv, rv);
     m_msgStore->GetNewMsgOutputStream(m_folder, getter_AddRefs(newHdr),
                                       &reusable, getter_AddRefs(m_outFileStream));
@@ -539,20 +536,19 @@ nsPop3Sink::IncorporateBegin(const char*
     seekableOutStream->Seek(nsISeekableStream::NS_SEEK_END, 0);
 
 #ifdef DEBUG
     // Debugging, see bug 1116055.
     int64_t first_post_seek_pos;
     nsresult rv4 = seekableOutStream->Tell(&first_post_seek_pos);
     if (NS_SUCCEEDED(rv3) && NS_SUCCEEDED(rv4)) {
       if (first_pre_seek_pos != first_post_seek_pos) {
-        nsCOMPtr<nsIMsgFolder> localFolder = do_QueryInterface(m_folder);
         nsString folderName;
-        if (localFolder)
-          localFolder->GetPrettyName(folderName);
+        if (m_folder)
+          m_folder->GetPrettyName(folderName);
         if (!folderName.IsEmpty()) {
           fprintf(stderr,"(seekdebug) Seek was necessary in IncorporateBegin() for folder %s.\n",
                   NS_ConvertUTF16toUTF8(folderName).get());
         } else {
           fprintf(stderr,"(seekdebug) Seek was necessary in IncorporateBegin().\n");
         }
         fprintf(stderr,"(seekdebug) first_pre_seek_pos = 0x%016llx, first_post_seek_pos=0x%016llx\n",
                 (unsigned long long) first_pre_seek_pos, (unsigned long long) first_post_seek_pos);
@@ -709,20 +705,19 @@ nsresult nsPop3Sink::WriteLineToMailbox(
     seekableOutStream->Seek(nsISeekableStream::NS_SEEK_END, 0);
 
     int64_t after_seek_pos;
     nsresult rv3 = seekableOutStream->Tell(&after_seek_pos);
     MOZ_ASSERT(NS_SUCCEEDED(rv3), "seekableOutStream->Tell(&after_seek_pos) failed");
 
     if (NS_SUCCEEDED(rv2) && NS_SUCCEEDED(rv3)) {
       if (before_seek_pos != after_seek_pos) {
-        nsCOMPtr<nsIMsgFolder> localFolder = do_QueryInterface(m_folder);
         nsString folderName;
-        if (localFolder)
-          localFolder->GetPrettyName(folderName);
+        if (m_folder)
+          m_folder->GetPrettyName(folderName);
         // This merits a console message, it's poor man's telemetry.
         MsgLogToConsole4(
           NS_LITERAL_STRING("Unexpected file position change detected") +
           (folderName.IsEmpty() ? EmptyString() : NS_LITERAL_STRING(" in folder ")) +
           (folderName.IsEmpty() ? EmptyString() : folderName) + NS_LITERAL_STRING(". "
           "If you can reliably reproduce this, please report the steps "
           "you used to dev-apps-thunderbird@lists.mozilla.org or to bug 1308335 at bugzilla.mozilla.org. "
           "Resolving this problem will allow speeding up message downloads."),
--- a/mailnews/mapi/mapihook/src/msgMapiImp.cpp
+++ b/mailnews/mapi/mapihook/src/msgMapiImp.cpp
@@ -686,77 +686,73 @@ char *MsgMapiListContext::ConvertBodyToM
   const int kBufLen = 64000; // I guess we only return the first 64K of a message.
 #define EMPTY_MESSAGE_LINE(buf) (buf[0] == '\r' || buf[0] == '\n' || buf[0] == '\0')
 
   nsCOMPtr <nsIMsgFolder> folder;
   hdr->GetFolder(getter_AddRefs(folder));
   if (!folder)
     return nullptr;
 
-  nsCOMPtr <nsIInputStream> inputStream;
   nsCOMPtr <nsIFile> localFile;
   folder->GetFilePath(getter_AddRefs(localFile));
 
   nsresult rv;
   nsCOMPtr<nsIFileInputStream> fileStream = do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, nullptr);
 
   rv = fileStream->Init(localFile,  PR_RDONLY, 0664, false);  //just have to read the messages
-  inputStream = do_QueryInterface(fileStream);
+  NS_ENSURE_SUCCESS(rv, nullptr);
+
+  nsCOMPtr <nsILineInputStream> fileLineStream = do_QueryInterface(fileStream);
+  if (!fileLineStream)
+    return nullptr;
 
-  if (inputStream)
+  // ### really want to skip past headers...
+  uint64_t messageOffset;
+  uint32_t lineCount;
+  hdr->GetMessageOffset(&messageOffset);
+  hdr->GetLineCount(&lineCount);
+  nsCOMPtr <nsISeekableStream> seekableStream = do_QueryInterface(fileStream);
+  seekableStream->Seek(PR_SEEK_SET, messageOffset);
+  bool hasMore = true;
+  nsAutoCString curLine;
+
+  while (hasMore) // advance past message headers
   {
-    nsCOMPtr <nsILineInputStream> fileLineStream = do_QueryInterface(inputStream);
-    if (!fileLineStream)
-      return nullptr;
-    // ### really want to skip past headers...
-    uint64_t messageOffset;
-    uint32_t lineCount;
-    hdr->GetMessageOffset(&messageOffset);
-    hdr->GetLineCount(&lineCount);
-    nsCOMPtr <nsISeekableStream> seekableStream = do_QueryInterface(inputStream);
-    seekableStream->Seek(PR_SEEK_SET, messageOffset);
-    bool hasMore = true;
-    nsAutoCString curLine;
-    nsresult rv = NS_OK;
-    while (hasMore) // advance past message headers
+    nsresult rv = fileLineStream->ReadLine(curLine, &hasMore);
+    if (NS_FAILED(rv) || EMPTY_MESSAGE_LINE(curLine))
+      break;
+  }
+  uint32_t msgSize;
+  hdr->GetMessageSize(&msgSize);
+  if (msgSize > kBufLen)
+    msgSize = kBufLen - 1;
+  // this is too big, since it includes the msg hdr size...oh well
+  char *body = (char*) CoTaskMemAlloc (msgSize + 1);
+
+  if (!body)
+    return nullptr;
+  int32_t bytesCopied = 0;
+  for (hasMore = TRUE; lineCount > 0 && hasMore && NS_SUCCEEDED(rv); lineCount--)
+  {
+    rv = fileLineStream->ReadLine(curLine, &hasMore);
+    if (NS_FAILED(rv))
+      break;
+    curLine.Append(CRLF);
+    // make sure we have room left
+    if (bytesCopied + curLine.Length() < msgSize)
     {
-      nsresult rv = fileLineStream->ReadLine(curLine, &hasMore);
-      if (NS_FAILED(rv) || EMPTY_MESSAGE_LINE(curLine))
-        break;
+      strcpy(body + bytesCopied, curLine.get());
+      bytesCopied += curLine.Length();
     }
-    uint32_t msgSize;
-    hdr->GetMessageSize(&msgSize);
-    if (msgSize > kBufLen)
-      msgSize = kBufLen - 1;
-    // this is too big, since it includes the msg hdr size...oh well
-    char *body = (char*) CoTaskMemAlloc (msgSize + 1);
-
-    if (!body)
-      return nullptr;
-    int32_t bytesCopied = 0;
-    for (hasMore = TRUE; lineCount > 0 && hasMore && NS_SUCCEEDED(rv); lineCount--)
-    {
-      rv = fileLineStream->ReadLine(curLine, &hasMore);
-      if (NS_FAILED(rv))
-        break;
-      curLine.Append(CRLF);
-      // make sure we have room left
-      if (bytesCopied + curLine.Length() < msgSize)
-      {
-        strcpy(body + bytesCopied, curLine.get());
-        bytesCopied += curLine.Length();
-      }
-    }
-    MOZ_LOG(MAPI, mozilla::LogLevel::Debug, ("ConvertBodyToMapiFormat size=%x allocated size %x body = %100.100s\n",
-        bytesCopied, msgSize + 1, (char *) body) );
-    body[bytesCopied] = '\0';   // rhp - fix last line garbage...
-    return body;
   }
-  return nullptr;
+  MOZ_LOG(MAPI, mozilla::LogLevel::Debug, ("ConvertBodyToMapiFormat size=%x allocated size %x body = %100.100s\n",
+      bytesCopied, msgSize + 1, (char *) body) );
+  body[bytesCopied] = '\0';   // rhp - fix last line garbage...
+  return body;
 }
 
 
 //*****************************************************************************
 // MSGMAPI API implementation
 
 
 
--- a/mailnews/mime/emitters/nsMimeBaseEmitter.cpp
+++ b/mailnews/mime/emitters/nsMimeBaseEmitter.cpp
@@ -1027,18 +1027,17 @@ nsMimeBaseEmitter::Complete()
 
   if (mOutListener)
   {
     uint64_t bytesInStream = 0;
     mozilla::DebugOnly<nsresult> rv2 = mInputStream->Available(&bytesInStream);
     NS_ASSERTION(NS_SUCCEEDED(rv2), "Available failed");
     if (bytesInStream)
     {
-      nsCOMPtr<nsIRequest> request = do_QueryInterface(mChannel);
-      mOutListener->OnDataAvailable(request, mURL, mInputStream, 0, std::min(bytesInStream, uint64_t(PR_UINT32_MAX)));
+      mOutListener->OnDataAvailable(mChannel, mURL, mInputStream, 0, std::min(bytesInStream, uint64_t(PR_UINT32_MAX)));
     }
   }
 
   return NS_OK;
 }
 
 //
 // This needs to do the right thing with the stored information. It only
--- a/mailnews/mime/src/mimedrft.cpp
+++ b/mailnews/mime/src/mimedrft.cpp
@@ -1504,17 +1504,17 @@ mime_parse_stream_complete(nsMIMESession
 
       char *body = nullptr;
 
       if (!bodyAsAttachment && mdd->messageBody->m_tmpFile)
       {
         int64_t fileSize;
         nsCOMPtr<nsIFile> tempFileCopy;
         mdd->messageBody->m_tmpFile->Clone(getter_AddRefs(tempFileCopy));
-        mdd->messageBody->m_tmpFile = do_QueryInterface(tempFileCopy);
+        mdd->messageBody->m_tmpFile = tempFileCopy;
         tempFileCopy = nullptr;
         mdd->messageBody->m_tmpFile->GetFileSize(&fileSize);
         uint32_t bodyLen = 0;
 
         // The stream interface can only read up to 4GB (32bit uint).
         // It is highly unlikely to encounter a body lager than that limit,
         // so we just skip it instead of reading it in chunks.
         if (fileSize < UINT32_MAX)
@@ -2058,17 +2058,17 @@ mime_decompose_file_init_fn(void *stream
       if (NS_SUCCEEDED(rv))
         nsMimeNewURI(getter_AddRefs(newAttachment->m_origUrl),
                      fileURL.get(), nullptr);
   }
 
   if (!tmpFile)
     return MIME_OUT_OF_MEMORY;
 
-  mdd->tmpFile = do_QueryInterface(tmpFile);
+  mdd->tmpFile = tmpFile;
 
   newAttachment->m_tmpFile = mdd->tmpFile;
 
   rv = MsgNewBufferedFileOutputStream(getter_AddRefs(mdd->tmpFileStream), tmpFile,PR_WRONLY | PR_CREATE_FILE, 00600);
   if (NS_FAILED(rv))
     return MIME_UNABLE_TO_OPEN_TMP_FILE;
 
   // For now, we are always going to decode all of the attachments
--- a/mailnews/mime/src/mimemrel.cpp
+++ b/mailnews/mime/src/mimemrel.cpp
@@ -667,17 +667,17 @@ MimeMultipartRelated_parse_child_line (M
   nsresult rv;
   /* Ok, if at this point we still don't have either kind of buffer, try and
      make a file buffer. */
   if (!relobj->head_buffer && !relobj->file_buffer)
   {
     nsCOMPtr <nsIFile> file;
     rv = nsMsgCreateTempFile("nsma", getter_AddRefs(file));
     NS_ENSURE_SUCCESS(rv, -1);
-    relobj->file_buffer = do_QueryInterface(file);
+    relobj->file_buffer = file;
 
     rv = MsgNewBufferedFileOutputStream(getter_AddRefs(relobj->output_file_stream), relobj->file_buffer, PR_WRONLY | PR_CREATE_FILE, 00600);
     NS_ENSURE_SUCCESS(rv, -1);
   }
 
   PR_ASSERT(relobj->head_buffer || relobj->output_file_stream);
 
 
@@ -694,17 +694,17 @@ MimeMultipartRelated_parse_child_line (M
        to it. */
     if (!relobj->output_file_stream)
     {
       if (!relobj->file_buffer)
       {
         nsCOMPtr <nsIFile> file;
         rv = nsMsgCreateTempFile("nsma", getter_AddRefs(file));
         NS_ENSURE_SUCCESS(rv, -1);
-        relobj->file_buffer = do_QueryInterface(file);
+        relobj->file_buffer = file;
       }
 
       nsresult rv = MsgNewBufferedFileOutputStream(getter_AddRefs(relobj->output_file_stream), relobj->file_buffer, PR_WRONLY | PR_CREATE_FILE, 00600);
       NS_ENSURE_SUCCESS(rv, -1);
 
       if (relobj->head_buffer && relobj->head_buffer_fp)
       {
         uint32_t bytesWritten;
--- a/mailnews/mime/src/mimepbuf.cpp
+++ b/mailnews/mime/src/mimepbuf.cpp
@@ -165,17 +165,17 @@ MimePartBufferWrite (MimePartBufferData 
 
   /* Ok, if at this point we still don't have either kind of buffer, try and
     make a file buffer. */
   if (!data->part_buffer && !data->file_buffer)
   {
     nsCOMPtr <nsIFile> tmpFile;
     nsresult rv = nsMsgCreateTempFile("nsma", getter_AddRefs(tmpFile));
     NS_ENSURE_SUCCESS(rv, MIME_UNABLE_TO_OPEN_TMP_FILE);
-    data->file_buffer = do_QueryInterface(tmpFile);
+    data->file_buffer = tmpFile;
 
     rv = MsgNewBufferedFileOutputStream(getter_AddRefs(data->output_file_stream), data->file_buffer, PR_WRONLY | PR_CREATE_FILE, 00600);
     NS_ENSURE_SUCCESS(rv, MIME_UNABLE_TO_OPEN_TMP_FILE);
   }
 
   NS_ASSERTION(data->part_buffer || data->output_file_stream, "no part_buffer or file_stream");
 
   /* If this buf will fit in the memory buffer, put it there.
@@ -196,17 +196,17 @@ MimePartBufferWrite (MimePartBufferData 
     if (!data->output_file_stream)
     {
       nsresult rv;
       if (!data->file_buffer)
       {
         nsCOMPtr <nsIFile> tmpFile;
         rv = nsMsgCreateTempFile("nsma", getter_AddRefs(tmpFile));
         NS_ENSURE_SUCCESS(rv, MIME_UNABLE_TO_OPEN_TMP_FILE);
-        data->file_buffer = do_QueryInterface(tmpFile);
+        data->file_buffer = tmpFile;
 
       }
 
       rv = MsgNewBufferedFileOutputStream(getter_AddRefs(data->output_file_stream), data->file_buffer, PR_WRONLY | PR_CREATE_FILE, 00600);
       NS_ENSURE_SUCCESS(rv, MIME_UNABLE_TO_OPEN_TMP_FILE);
 
       if (data->part_buffer && data->part_buffer_fp)
       {
--- a/mailnews/news/src/nsNNTPProtocol.cpp
+++ b/mailnews/news/src/nsNNTPProtocol.cpp
@@ -541,40 +541,38 @@ nsresult nsNntpCacheStreamListener::Init
   mRunningUrl = aRunningUrl;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNntpCacheStreamListener::OnStartRequest(nsIRequest *request, nsISupports * aCtxt)
 {
   nsCOMPtr <nsILoadGroup> loadGroup;
-  nsCOMPtr <nsIRequest> ourRequest = do_QueryInterface(mChannelToUse);
 
   NS_ASSERTION(mChannelToUse, "null channel in OnStartRequest");
   if (mChannelToUse)
     mChannelToUse->GetLoadGroup(getter_AddRefs(loadGroup));
   if (loadGroup)
-    loadGroup->AddRequest(ourRequest, nullptr /* context isupports */);
-  return (mListener) ? mListener->OnStartRequest(ourRequest, aCtxt) : NS_OK;
+    loadGroup->AddRequest(mChannelToUse, nullptr /* context isupports */);
+  return (mListener) ? mListener->OnStartRequest(mChannelToUse, aCtxt) : NS_OK;
 }
 
 NS_IMETHODIMP
 nsNntpCacheStreamListener::OnStopRequest(nsIRequest *request, nsISupports * aCtxt, nsresult aStatus)
 {
-  nsCOMPtr <nsIRequest> ourRequest = do_QueryInterface(mChannelToUse);
   nsresult rv = NS_OK;
   NS_ASSERTION(mListener, "this assertion is for Bug 531794 comment 7");
   if (mListener)
-    mListener->OnStopRequest(ourRequest, aCtxt, aStatus);
+    mListener->OnStopRequest(mChannelToUse, aCtxt, aStatus);
   nsCOMPtr <nsILoadGroup> loadGroup;
   NS_ASSERTION(mChannelToUse, "null channel in OnStopRequest");
   if (mChannelToUse)
     mChannelToUse->GetLoadGroup(getter_AddRefs(loadGroup));
   if (loadGroup)
-    loadGroup->RemoveRequest(ourRequest, nullptr, aStatus);
+    loadGroup->RemoveRequest(mChannelToUse, nullptr, aStatus);
 
   // clear out mem cache entry so we're not holding onto it.
   if (mRunningUrl)
     mRunningUrl->SetMemCacheEntry(nullptr);
 
   mListener = nullptr;
   nsCOMPtr <nsINNTPProtocol> nntpProtocol = do_QueryInterface(mChannelToUse);
   if (nntpProtocol) {
@@ -584,18 +582,17 @@ nsNntpCacheStreamListener::OnStopRequest
   mChannelToUse = nullptr;
   return rv;
 }
 
 NS_IMETHODIMP
 nsNntpCacheStreamListener::OnDataAvailable(nsIRequest *request, nsISupports * aCtxt, nsIInputStream * aInStream, uint64_t aSourceOffset, uint32_t aCount)
 {
     NS_ENSURE_STATE(mListener);
-    nsCOMPtr <nsIRequest> ourRequest = do_QueryInterface(mChannelToUse);
-    return mListener->OnDataAvailable(ourRequest, aCtxt, aInStream, aSourceOffset, aCount);
+    return mListener->OnDataAvailable(mChannelToUse, aCtxt, aInStream, aSourceOffset, aCount);
 }
 
 NS_IMETHODIMP nsNNTPProtocol::GetOriginalURI(nsIURI* *aURI)
 {
     // News does not seem to have the notion of an original URI (See Bug #193317)
     NS_IF_ADDREF(*aURI = m_url);
     return NS_OK;
 }
@@ -779,18 +776,18 @@ nsNNTPProtocol::OnCacheEntryAvailable(ns
       nsCOMPtr<nsIStreamListenerTee> tee = do_CreateInstance(NS_STREAMLISTENERTEE_CONTRACTID, &rv);
       NS_ENSURE_SUCCESS(rv, rv);
 
       nsCOMPtr<nsIOutputStream> outStream;
       rv = entry->OpenOutputStream(0, -1, getter_AddRefs(outStream));
       NS_ENSURE_SUCCESS(rv, rv);
 
       rv = tee->Init(m_channelListener, outStream, nullptr);
-      m_channelListener = do_QueryInterface(tee);
       NS_ENSURE_SUCCESS(rv, rv);
+      m_channelListener = tee;
     }
     else
     {
       rv = ReadFromMemCache(entry);
       if (NS_SUCCEEDED(rv)) {
         entry->MarkValid();
         return NS_OK; // kick out if reading from the cache succeeded...
       }
--- a/rdf/base/nsInMemoryDataSource.cpp
+++ b/rdf/base/nsInMemoryDataSource.cpp
@@ -1846,23 +1846,17 @@ InMemoryDataSource::VisitAllSubjects(rdf
 {
     // Lock datasource against writes
     ++mReadCount;
 
     // Enumerate all of our entries.
     nsresult rv = NS_OK;
     for (auto iter = mForwardArcs.Iter(); !iter.Done(); iter.Next()) {
         auto entry = static_cast<Entry*>(iter.Get());
-        nsresult rv2;
-        nsCOMPtr<nsIRDFNode> subject = do_QueryInterface(entry->mNode, &rv2);
-        if (NS_FAILED(rv2)) {
-            NS_WARNING("QI to nsIRDFNode failed");
-            continue;
-        }
-        rv = aVisitor->Visit(subject, nullptr, nullptr, true);
+        rv = aVisitor->Visit(entry->mNode, nullptr, nullptr, true);
         if (NS_FAILED(rv) || rv == NS_RDF_STOP_VISIT) {
             break;
         }
     }
 
     // Unlock datasource
     --mReadCount;
 
@@ -1875,49 +1869,44 @@ InMemoryDataSource::VisitAllTriples(rdfI
     // Lock datasource against writes
     ++mReadCount;
 
     // Enumerate all of our entries.
     nsresult rv = NS_OK;
     for (auto iter = mForwardArcs.Iter(); !iter.Done(); iter.Next()) {
         auto entry = static_cast<Entry*>(iter.Get());
 
-        nsresult rv2;
-        nsCOMPtr<nsIRDFNode> subject = do_QueryInterface(entry->mNode, &rv2);
-        if (NS_FAILED(rv2)) {
-            NS_WARNING("QI to nsIRDFNode failed");
-
-        } else if (entry->mAssertions->mHashEntry) {
+        if (entry->mAssertions->mHashEntry) {
             for (auto iter = entry->mAssertions->u.hash.mPropertyHash->Iter();
                  !iter.Done();
                  iter.Next()) {
                 auto entry = static_cast<Entry*>(iter.Get());
                 Assertion* assertion = entry->mAssertions;
                 while (assertion) {
                     NS_ASSERTION(!assertion->mHashEntry, "shouldn't have to hashes");
-                    rv = aVisitor->Visit(subject, assertion->u.as.mProperty,
-                                                  assertion->u.as.mTarget,
-                                                  assertion->u.as.mTruthValue);
+                    rv = aVisitor->Visit(entry->mNode, assertion->u.as.mProperty,
+                                                       assertion->u.as.mTarget,
+                                                       assertion->u.as.mTruthValue);
                     if (NS_FAILED(rv)) {
                         goto end;
                     }
                     if (rv == NS_RDF_STOP_VISIT) {
                         goto inner_end;
                     }
                     assertion = assertion->mNext;
                 }
             }
 
         } else {
             Assertion* assertion = entry->mAssertions;
             while (assertion) {
                 NS_ASSERTION(!assertion->mHashEntry, "shouldn't have to hashes");
-                rv = aVisitor->Visit(subject, assertion->u.as.mProperty,
-                                              assertion->u.as.mTarget,
-                                              assertion->u.as.mTruthValue);
+                rv = aVisitor->Visit(entry->mNode, assertion->u.as.mProperty,
+                                                   assertion->u.as.mTarget,
+                                                   assertion->u.as.mTruthValue);
                 if (NS_FAILED(rv) || rv == NS_RDF_STOP_VISIT) {
                     goto end;
                 }
                 assertion = assertion->mNext;
             }
         }
 
       inner_end: