Bug 1614846 - Remove nsIArray use in nsIMsgAccountManager.getServersForIdentity(). r=mkmelin

This commit is contained in:
Ben Campbell 2020-04-02 13:40:06 +03:00
Родитель 143b1e4232
Коммит 7dbc33f903
6 изменённых файлов: 76 добавлений и 102 удалений

Просмотреть файл

@ -345,47 +345,38 @@ function fillIdentityListPopup() {
);
var selected = false;
for (var i = 0; i < identities.length; i++) {
var identity = identities[i];
for (let identity of identities) {
EnigmailLog.DEBUG("id.valid=" + identity.valid + "\n");
if (!identity.valid || !identity.email) {
continue;
}
var serverSupports, inServer;
// Gecko >= 20
serverSupports = MailServices.accounts.getServersForIdentity(identity);
if (serverSupports.length > 0) {
inServer = serverSupports.queryElementAt(0, Ci.nsIMsgIncomingServer);
let servers = MailServices.accounts.getServersForIdentity(identity);
if (servers.length == 0) {
continue;
}
let accountName = " - " + servers[0].prettyName;
EnigmailLog.DEBUG("enigmailKeygen.js: accountName=" + accountName + "\n");
EnigmailLog.DEBUG("enigmailKeygen.js: email=" + identity.email + "\n");
let item = document.createXULElement("menuitem");
// item.setAttribute('label', identity.identityName);
item.setAttribute("label", identity.identityName + accountName);
item.setAttribute("class", "identity-popup-item");
item.setAttribute("accountname", accountName);
item.setAttribute("id", identity.key);
item.setAttribute("email", identity.email);
gUserIdentityListPopup.appendChild(item);
if (!selected) {
gUserIdentityList.selectedItem = item;
}
if (inServer) {
var accountName = " - " + inServer.prettyName;
EnigmailLog.DEBUG(
"enigmailKeygen.js: accountName=" + accountName + "\n"
);
EnigmailLog.DEBUG("enigmailKeygen.js: email=" + identity.email + "\n");
var item = document.createXULElement("menuitem");
// item.setAttribute('label', identity.identityName);
item.setAttribute("label", identity.identityName + accountName);
item.setAttribute("class", "identity-popup-item");
item.setAttribute("accountname", accountName);
item.setAttribute("id", identity.key);
item.setAttribute("email", identity.email);
gUserIdentityListPopup.appendChild(item);
if (!selected) {
gUserIdentityList.selectedItem = item;
}
if (identity.key == defIdentity.key) {
gUserIdentityList.selectedItem = item;
selected = true;
}
if (identity.key == defIdentity.key) {
gUserIdentityList.selectedItem = item;
selected = true;
}
}
} catch (ex) {

Просмотреть файл

@ -159,7 +159,7 @@ interface nsIMsgAccountManager : nsISupports {
* this identity
* returns an array of nsIMsgIncomingServer
*/
nsIArray getServersForIdentity(in nsIMsgIdentity identity);
Array<nsIMsgIncomingServer> getServersForIdentity(in nsIMsgIdentity identity);
/* there is a special server "Local Folders" that is guaranteed to exist.
* this will allow you to get */

Просмотреть файл

@ -1917,22 +1917,19 @@ nsMsgAccountManager::GetIdentitiesForServer(
}
NS_IMETHODIMP
nsMsgAccountManager::GetServersForIdentity(nsIMsgIdentity *aIdentity,
nsIArray **_retval) {
nsMsgAccountManager::GetServersForIdentity(
nsIMsgIdentity *aIdentity,
nsTArray<RefPtr<nsIMsgIncomingServer>> &servers) {
NS_ENSURE_ARG_POINTER(aIdentity);
servers.Clear();
nsresult rv;
rv = LoadAccounts();
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIMutableArray> servers(
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
for (uint32_t i = 0; i < m_accounts.Length(); ++i) {
for (auto account : m_accounts) {
nsCOMPtr<nsIArray> identities;
if (NS_FAILED(m_accounts[i]->GetIdentities(getter_AddRefs(identities))))
continue;
if (NS_FAILED(account->GetIdentities(getter_AddRefs(identities)))) continue;
uint32_t idCount = 0;
if (NS_FAILED(identities->GetLength(&idCount))) continue;
@ -1949,16 +1946,15 @@ nsMsgAccountManager::GetServersForIdentity(nsIMsgIdentity *aIdentity,
if (NS_SUCCEEDED(rv) && identityKey.Equals(thisIdentityKey)) {
nsCOMPtr<nsIMsgIncomingServer> thisServer;
rv = m_accounts[i]->GetIncomingServer(getter_AddRefs(thisServer));
rv = account->GetIncomingServer(getter_AddRefs(thisServer));
if (thisServer && NS_SUCCEEDED(rv)) {
servers->AppendElement(thisServer);
servers.AppendElement(thisServer);
break;
}
}
}
}
}
servers.forget(_retval);
return NS_OK;
}

Просмотреть файл

@ -9,10 +9,6 @@ var { MailServices } = ChromeUtils.import(
"resource:///modules/MailServices.jsm"
);
const { fixIterator } = ChromeUtils.import(
"resource:///modules/iteratorUtils.jsm"
);
add_task(async function() {
let mgr = MailServices.accounts;
@ -59,4 +55,10 @@ add_task(async function() {
Assert.equal(mgr.getIdentitiesForServer(acc1.incomingServer).length, 2);
Assert.equal(mgr.getIdentitiesForServer(acc2.incomingServer).length, 2);
Assert.equal(mgr.getIdentitiesForServer(mgr.localFoldersServer).length, 0);
// id1 and id2 are on separate accounts (and servers)
Assert.equal(mgr.getServersForIdentity(id1).length, 1);
Assert.equal(mgr.getServersForIdentity(id2).length, 1);
// id3 is shared
Assert.equal(mgr.getServersForIdentity(id3).length, 2);
});

Просмотреть файл

@ -296,33 +296,34 @@ nsresult nsMsgIdentity::getFolderPref(const char *prefname, nsCString &retval,
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIArray> servers;
rv = accountManager->GetServersForIdentity(this, getter_AddRefs(servers));
nsTArray<RefPtr<nsIMsgIncomingServer>> servers;
rv = accountManager->GetServersForIdentity(this, servers);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIMsgIncomingServer> server(do_QueryElementAt(servers, 0, &rv));
if (NS_SUCCEEDED(rv)) {
bool defaultToServer;
server->GetDefaultCopiesAndFoldersPrefsToServer(&defaultToServer);
// if we should default to special folders on the server,
// use the local folders server
if (!defaultToServer) {
rv = accountManager->GetLocalFoldersServer(getter_AddRefs(server));
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIMsgFolder> rootFolder;
// this will get the deferred to server's root folder, if "server"
// is deferred, e.g., using the pop3 global inbox.
rv = server->GetRootMsgFolder(getter_AddRefs(rootFolder));
NS_ENSURE_SUCCESS(rv, rv);
if (rootFolder) {
rv = rootFolder->GetURI(retval);
NS_ENSURE_SUCCESS(rv, rv);
retval.Append('/');
retval.Append(folderName);
return setFolderPref(prefname, retval, folderflag);
}
if (servers.IsEmpty()) {
// if there are no servers for this identity, return generic failure.
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIMsgIncomingServer> server(servers[0]);
bool defaultToServer;
server->GetDefaultCopiesAndFoldersPrefsToServer(&defaultToServer);
// if we should default to special folders on the server,
// use the local folders server
if (!defaultToServer) {
rv = accountManager->GetLocalFoldersServer(getter_AddRefs(server));
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIMsgFolder> rootFolder;
// this will get the deferred to server's root folder, if "server"
// is deferred, e.g., using the pop3 global inbox.
rv = server->GetRootMsgFolder(getter_AddRefs(rootFolder));
NS_ENSURE_SUCCESS(rv, rv);
if (rootFolder) {
rv = rootFolder->GetURI(retval);
NS_ENSURE_SUCCESS(rv, rv);
retval.Append('/');
retval.Append(folderName);
return setFolderPref(prefname, retval, folderflag);
}
// if there are no servers for this identity, return generic failure.
return NS_ERROR_FAILURE;
}
@ -342,17 +343,12 @@ nsresult nsMsgIdentity::setFolderPref(const char *prefname,
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIArray> servers;
rv = accountManager->GetServersForIdentity(this, getter_AddRefs(servers));
nsTArray<RefPtr<nsIMsgIncomingServer>> servers;
rv = accountManager->GetServersForIdentity(this, servers);
NS_ENSURE_SUCCESS(rv, rv);
uint32_t cnt = 0;
servers->GetLength(&cnt);
if (cnt > 0) {
nsCOMPtr<nsIMsgIncomingServer> server(do_QueryElementAt(servers, 0, &rv));
if (NS_SUCCEEDED(rv))
server
->ClearTemporaryReturnReceiptsFilter(); // okay to fail; no need to
// check for return code
if (!servers.IsEmpty()) {
servers[0]->ClearTemporaryReturnReceiptsFilter();
// okay to fail; no need to check for return code
}
}

Просмотреть файл

@ -361,34 +361,23 @@ nsresult LocateMessageFolder(nsIMsgIdentity *userIdentity,
return server->GetMsgFolderFromURI(folder, nsDependentCString(aFolderURI),
msgFolder);
} else {
uint32_t cnt = 0;
uint32_t i;
if (!userIdentity) return NS_ERROR_INVALID_ARG;
// get the account manager
nsCOMPtr<nsIMsgAccountManager> accountManager =
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv, rv);
// If any folder will do, go look for one.
nsCOMPtr<nsIArray> retval;
accountManager->GetServersForIdentity(userIdentity, getter_AddRefs(retval));
if (!retval) return NS_ERROR_FAILURE;
nsTArray<RefPtr<nsIMsgIncomingServer>> servers;
rv = accountManager->GetServersForIdentity(userIdentity, servers);
NS_ENSURE_SUCCESS(rv, rv);
// Ok, we have to look through the servers and try to find the server that
// has a valid folder of the type that interests us...
rv = retval->GetLength(&cnt);
if (NS_FAILED(rv)) return rv;
for (i = 0; i < cnt; i++) {
for (auto inServer : servers) {
// Now that we have the server...we need to get the named message folder
nsCOMPtr<nsIMsgIncomingServer> inServer;
inServer = do_QueryElementAt(retval, i, &rv);
if (NS_FAILED(rv) || (!inServer)) continue;
//
// If aFolderURI is passed in, then the user has chosen a specific
// mail folder to save the message, but if it is null, just find the
// first one and make that work. The folder is specified as a URI, like