Bug 1770342 - Remove the aRealFlag argument from nsIMsgAccountManager.findServerByURI. r=mkmelin draft
authorPing Chen <remotenonsense@gmail.com>
Sat, 21 May 2022 14:07:56 +0900
changeset 116728 1718a7205416ce74b5bbb9dcc44c117c30fc3caa
parent 116727 d50715ea3d66ebc6140c3ce81022a415ea991d3b
child 116729 db396449da7bfad364e5643c0b7c298f7051b3f6
push id15950
push userremotenonsense@gmail.com
push dateSat, 21 May 2022 05:09:00 +0000
treeherdertry-comm-central@db396449da7b [default view] [failures only]
reviewersmkmelin
bugs1770342
Bug 1770342 - Remove the aRealFlag argument from nsIMsgAccountManager.findServerByURI. r=mkmelin
mailnews/base/public/nsIMsgAccountManager.idl
mailnews/base/src/nsMsgAccountManager.cpp
mailnews/base/src/nsMsgAccountManager.h
mailnews/base/src/nsMsgDBFolder.cpp
mailnews/base/src/nsMsgMailNewsUrl.cpp
mailnews/imap/src/ImapChannel.jsm
mailnews/imap/src/nsImapService.cpp
mailnews/local/src/Pop3Channel.jsm
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/local/src/nsLocalUtils.cpp
mailnews/news/src/nsNntpService.cpp
--- a/mailnews/base/public/nsIMsgAccountManager.idl
+++ b/mailnews/base/public/nsIMsgAccountManager.idl
@@ -122,21 +122,18 @@ interface nsIMsgAccountManager : nsISupp
   nsIMsgIncomingServer findServer(in ACString userName,
                                   in ACString hostname,
                                   in ACString type,
                                   [optional] in long port);
 
   /*
    * search for the server with the given uri
    * an analog to FindServer()
-   * The boolean flag selects whether we compare input against the
-   * 'realhostname' and 'realuserName' pref settings.
    */
-  nsIMsgIncomingServer
-      findServerByURI(in nsIURI aURI, in boolean aRealFlag);
+  nsIMsgIncomingServer findServerByURI(in nsIURI aURI);
 
   /**
    * find the index of this server in the (ordered) list of accounts
    */
   long FindServerIndex(in nsIMsgIncomingServer server);
 
   /**
    * Finds an account for the given incoming server.
--- a/mailnews/base/src/nsMsgAccountManager.cpp
+++ b/mailnews/base/src/nsMsgAccountManager.cpp
@@ -1722,17 +1722,17 @@ NS_IMETHODIMP nsMsgAccountManager::Notif
     nsIIncomingServerListener* listener = m_incomingServerListeners[i];
     listener->OnServerChanged(server);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMsgAccountManager::FindServerByURI(nsIURI* aURI, bool aRealFlag,
+nsMsgAccountManager::FindServerByURI(nsIURI* aURI,
                                      nsIMsgIncomingServer** aResult) {
   NS_ENSURE_ARG_POINTER(aURI);
 
   nsresult rv = LoadAccounts();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Get username and hostname and port so we can get the server
   nsAutoCString username;
@@ -1767,27 +1767,23 @@ nsMsgAccountManager::FindServerByURI(nsI
   int32_t port = 0;
   // check the port of the scheme is not 'none' or blank
   if (!(type.EqualsLiteral("none") || type.IsEmpty())) {
     rv = aURI->GetPort(&port);
     // Set the port to zero if we got a -1 (use default)
     if (NS_SUCCEEDED(rv) && (port == -1)) port = 0;
   }
 
-  return findServerInternal(username, hostname, type, port, aRealFlag, aResult);
+  return findServerInternal(username, hostname, type, port, aResult);
 }
 
 nsresult nsMsgAccountManager::findServerInternal(
     const nsACString& username, const nsACString& hostname,
-    const nsACString& type, int32_t port, bool aRealFlag,
-    nsIMsgIncomingServer** aResult) {
-  // If 'aRealFlag' is set then we want to scan all existing accounts
-  // to make sure there's no duplicate including those whose host and/or
-  // user names have been changed.
-  if (!aRealFlag && (m_lastFindServerUserName.Equals(username)) &&
+    const nsACString& type, int32_t port, nsIMsgIncomingServer** aResult) {
+  if ((m_lastFindServerUserName.Equals(username)) &&
       (m_lastFindServerHostName.Equals(hostname)) &&
       (m_lastFindServerType.Equals(type)) && (m_lastFindServerPort == port) &&
       m_lastFindServerResult) {
     NS_ADDREF(*aResult = m_lastFindServerResult);
     return NS_OK;
   }
 
   for (auto iter = m_incomingServers.Iter(); !iter.Done(); iter.Next()) {
@@ -1821,33 +1817,32 @@ nsresult nsMsgAccountManager::findServer
     // treat "" as a wild card, so if the caller passed in "" for the desired
     // attribute treat it as a match
     if ((type.IsEmpty() || thisType.Equals(type)) &&
         (hostname.IsEmpty() ||
          thisHostname.Equals(hostname, nsCaseInsensitiveCStringComparator)) &&
         (!(port != 0) || (port == thisPort)) &&
         (username.IsEmpty() || thisUsername.Equals(username))) {
       // stop on first find; cache for next time
-      if (!aRealFlag)
-        SetLastServerFound(server, hostname, username, port, type);
+      SetLastServerFound(server, hostname, username, port, type);
 
       NS_ADDREF(*aResult = server);  // Was populated from member variable.
       return NS_OK;
     }
   }
 
   return NS_ERROR_UNEXPECTED;
 }
 
 NS_IMETHODIMP
 nsMsgAccountManager::FindServer(const nsACString& username,
                                 const nsACString& hostname,
                                 const nsACString& type, int32_t port,
                                 nsIMsgIncomingServer** aResult) {
-  return findServerInternal(username, hostname, type, port, false, aResult);
+  return findServerInternal(username, hostname, type, port, aResult);
 }
 
 void nsMsgAccountManager::findAccountByServerKey(const nsCString& aKey,
                                                  nsIMsgAccount** aResult) {
   *aResult = nullptr;
 
   for (uint32_t i = 0; i < m_accounts.Length(); ++i) {
     nsCOMPtr<nsIMsgIncomingServer> server;
--- a/mailnews/base/src/nsMsgAccountManager.h
+++ b/mailnews/base/src/nsMsgAccountManager.h
@@ -170,17 +170,17 @@ class nsMsgAccountManager : public nsIMs
   //
   // server enumerators
   // ("element" is always a server)
   //
 
   nsresult findServerInternal(const nsACString& username,
                               const nsACString& hostname,
                               const nsACString& type, int32_t port,
-                              bool aRealFlag, nsIMsgIncomingServer** aResult);
+                              nsIMsgIncomingServer** aResult);
 
   // handle virtual folders
   static nsresult GetVirtualFoldersFile(nsCOMPtr<nsIFile>& file);
   static nsresult WriteLineToOutputStream(const char* prefix, const char* line,
                                           nsIOutputStream* outputStream);
   void ParseAndVerifyVirtualFolderScope(nsCString& buffer);
   nsresult AddVFListenersForVF(nsIMsgFolder* virtualFolder,
                                const nsCString& srchFolderUris,
--- a/mailnews/base/src/nsMsgDBFolder.cpp
+++ b/mailnews/base/src/nsMsgDBFolder.cpp
@@ -2903,17 +2903,17 @@ nsresult nsMsgDBFolder::parseURI(bool ne
       GetIncomingServerType(serverType);
       if (serverType.IsEmpty()) {
         NS_WARNING("can't determine folder's server type");
         return NS_ERROR_FAILURE;
       }
 
       rv = NS_MutateURI(url).SetScheme(serverType).Finalize(url);
       NS_ENSURE_SUCCESS(rv, rv);
-      rv = accountManager->FindServerByURI(url, false, getter_AddRefs(server));
+      rv = accountManager->FindServerByURI(url, getter_AddRefs(server));
       NS_ENSURE_SUCCESS(rv, rv);
     }
     mServer = do_GetWeakReference(server);
   } /* !mServer */
 
   // now try to find the local path for this folder
   if (server) {
     nsAutoCString newPath;
--- a/mailnews/base/src/nsMsgMailNewsUrl.cpp
+++ b/mailnews/base/src/nsMsgMailNewsUrl.cpp
@@ -281,25 +281,25 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetServe
     if (scheme.EqualsLiteral("news")) scheme.AssignLiteral("nntp");
     rv = NS_MutateURI(url).SetScheme(scheme).Finalize(url);
     NS_ENSURE_SUCCESS(rv, rv);
     nsCOMPtr<nsIMsgAccountManager> accountManager =
         do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIMsgIncomingServer> server;
-    rv = accountManager->FindServerByURI(url, false, aIncomingServer);
+    rv = accountManager->FindServerByURI(url, aIncomingServer);
     if (!*aIncomingServer && scheme.EqualsLiteral("imap")) {
       // look for any imap server with this host name so clicking on
       // other users folder urls will work. We could override this method
       // for imap urls, or we could make caching of servers work and
       // just set the server in the imap code for this case.
       rv = NS_MutateURI(url).SetUserPass(EmptyCString()).Finalize(url);
       NS_ENSURE_SUCCESS(rv, rv);
-      rv = accountManager->FindServerByURI(url, false, aIncomingServer);
+      rv = accountManager->FindServerByURI(url, aIncomingServer);
     }
   }
 
   return rv;
 }
 
 NS_IMETHODIMP nsMsgMailNewsUrl::GetMsgWindow(nsIMsgWindow** aMsgWindow) {
   NS_ENSURE_ARG_POINTER(aMsgWindow);
--- a/mailnews/imap/src/ImapChannel.jsm
+++ b/mailnews/imap/src/ImapChannel.jsm
@@ -27,17 +27,17 @@ class ImapChannel {
   });
 
   /**
    * @param {nsIURI} uri - The uri to construct the channel from.
    * @param {nsILoadInfo} loadInfo - The loadInfo associated with the channel.
    */
   constructor(uri, loadInfo) {
     this._server = MailServices.accounts
-      .findServerByURI(uri, false)
+      .findServerByURI(uri)
       .QueryInterface(Ci.nsIImapIncomingServer);
 
     // nsIChannel attributes.
     this.originalURI = uri;
     this.URI = uri;
     this.loadInfo = loadInfo;
     this.contentLength = 0;
   }
--- a/mailnews/imap/src/nsImapService.cpp
+++ b/mailnews/imap/src/nsImapService.cpp
@@ -2324,34 +2324,34 @@ nsresult nsImapService::GetServerFromUrl
     rv = mailnewsUrl->GetFileName(folderName);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsCOMPtr<nsIMsgAccountManager> accountManager =
       do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = accountManager->FindServerByURI(mailnewsUrl, false, aServer);
+  rv = accountManager->FindServerByURI(mailnewsUrl, aServer);
 
   // look for server with any user name, in case we're trying to subscribe
   // to a folder with some one else's user name like the following
   // "IMAP://userSharingFolder@server1/SharedFolderName"
   if (NS_FAILED(rv) || !aServer) {
     nsAutoCString turl;
     rv = mailnewsUrl->GetSpec(turl);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIURL> url;
     rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID)
              .SetSpec(turl)
              .SetUserPass(EmptyCString())
              .Finalize(url);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    rv = accountManager->FindServerByURI(url, false, aServer);
+    rv = accountManager->FindServerByURI(url, aServer);
     if (*aServer) aImapUrl->SetExternalLinkUrl(true);
   }
 
   // if we can't extract the imap server from this url then give up!!!
   NS_ENSURE_TRUE(*aServer, NS_ERROR_FAILURE);
   return rv;
 }
 
--- a/mailnews/local/src/Pop3Channel.jsm
+++ b/mailnews/local/src/Pop3Channel.jsm
@@ -28,17 +28,17 @@ class Pop3Channel {
   });
 
   /**
    * @param {nsIURI} uri - The uri to construct the channel from.
    * @param {nsILoadInfo} loadInfo - The loadInfo associated with the channel.
    */
   constructor(uri, loadInfo) {
     this._server = MailServices.accounts
-      .findServerByURI(uri, false)
+      .findServerByURI(uri)
       .QueryInterface(Ci.nsIPop3IncomingServer);
 
     // nsIChannel attributes.
     this.originalURI = uri;
     this.URI = uri;
     this.loadInfo = loadInfo;
     this.contentLength = 0;
   }
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -2778,32 +2778,31 @@ nsMsgLocalMailFolder::GetIncomingServerT
     nsCOMPtr<nsIMsgAccountManager> accountManager =
         do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
     if (NS_FAILED(rv)) return rv;
 
     nsCOMPtr<nsIMsgIncomingServer> server;
     // try "none" first
     rv = NS_MutateURI(url).SetScheme("none"_ns).Finalize(url);
     NS_ENSURE_SUCCESS(rv, rv);
-    rv = accountManager->FindServerByURI(url, false, getter_AddRefs(server));
+    rv = accountManager->FindServerByURI(url, getter_AddRefs(server));
     if (NS_SUCCEEDED(rv) && server)
       mType.AssignLiteral("none");
     else {
       // next try "pop3"
       rv = NS_MutateURI(url).SetScheme("pop3"_ns).Finalize(url);
       NS_ENSURE_SUCCESS(rv, rv);
-      rv = accountManager->FindServerByURI(url, false, getter_AddRefs(server));
+      rv = accountManager->FindServerByURI(url, getter_AddRefs(server));
       if (NS_SUCCEEDED(rv) && server)
         mType.AssignLiteral("pop3");
       else {
         // next try "rss"
         rv = NS_MutateURI(url).SetScheme("rss"_ns).Finalize(url);
         NS_ENSURE_SUCCESS(rv, rv);
-        rv =
-            accountManager->FindServerByURI(url, false, getter_AddRefs(server));
+        rv = accountManager->FindServerByURI(url, getter_AddRefs(server));
         if (NS_SUCCEEDED(rv) && server)
           mType.AssignLiteral("rss");
         else {
         }
       }
     }
   }
   aServerType = mType;
--- a/mailnews/local/src/nsLocalUtils.cpp
+++ b/mailnews/local/src/nsLocalUtils.cpp
@@ -38,45 +38,45 @@ static nsresult nsGetMailboxServer(const
   if (NS_FAILED(rv)) return rv;
 
   // find all local mail "no servers" matching the given hostname
   nsCOMPtr<nsIMsgIncomingServer> none_server;
   rv = NS_MutateURI(url).SetScheme("none"_ns).Finalize(url);
   NS_ENSURE_SUCCESS(rv, rv);
   // No unescaping of username or hostname done here.
   // The unescaping is done inside of FindServerByURI
-  rv = accountManager->FindServerByURI(url, false, getter_AddRefs(none_server));
+  rv = accountManager->FindServerByURI(url, getter_AddRefs(none_server));
   if (NS_SUCCEEDED(rv)) {
     none_server.forget(aResult);
     return rv;
   }
 
   // if that fails, look for the rss hosts matching the given hostname
   nsCOMPtr<nsIMsgIncomingServer> rss_server;
   rv = NS_MutateURI(url).SetScheme("rss"_ns).Finalize(url);
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = accountManager->FindServerByURI(url, false, getter_AddRefs(rss_server));
+  rv = accountManager->FindServerByURI(url, getter_AddRefs(rss_server));
   if (NS_SUCCEEDED(rv)) {
     rss_server.forget(aResult);
     return rv;
   }
 
   // if that fails, look for the pop hosts matching the given hostname
   nsCOMPtr<nsIMsgIncomingServer> server;
   if (NS_FAILED(rv)) {
     rv = NS_MutateURI(url).SetScheme("pop3"_ns).Finalize(url);
     NS_ENSURE_SUCCESS(rv, rv);
-    rv = accountManager->FindServerByURI(url, false, getter_AddRefs(server));
+    rv = accountManager->FindServerByURI(url, getter_AddRefs(server));
 
     // if we can't find a pop server, maybe it's a local message
     // in an imap hierarchy. look for an imap server.
     if (NS_FAILED(rv)) {
       rv = NS_MutateURI(url).SetScheme("imap"_ns).Finalize(url);
       NS_ENSURE_SUCCESS(rv, rv);
-      rv = accountManager->FindServerByURI(url, false, getter_AddRefs(server));
+      rv = accountManager->FindServerByURI(url, getter_AddRefs(server));
     }
   }
   if (NS_SUCCEEDED(rv)) {
     server.forget(aResult);
     return rv;
   }
 
   // If you fail after looking at all "pop3", "none" servers, you fail.
--- a/mailnews/news/src/nsNntpService.cpp
+++ b/mailnews/news/src/nsNntpService.cpp
@@ -524,17 +524,17 @@ nsresult nsNntpService::GetFolderFromUri
   rv = uri->GetPathQueryRef(path);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIMsgAccountManager> accountManager =
       do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIMsgIncomingServer> server;
-  rv = accountManager->FindServerByURI(uri, false, getter_AddRefs(server));
+  rv = accountManager->FindServerByURI(uri, getter_AddRefs(server));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIMsgFolder> rootFolder;
   rv = server->GetRootFolder(getter_AddRefs(rootFolder));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // check if path is "/"
   // if so, use the root folder