Bug 1612239 - Remove nsIArray usage from nsIMsgFolder.getFoldersWithFlags(). r=mkmelin
This commit is contained in:
Родитель
e8cc4c6395
Коммит
adf336206c
|
@ -1311,10 +1311,7 @@ var gFolderTreeView = {
|
|||
aFolderFlag
|
||||
);
|
||||
if (foldersWithFlag.length > 0) {
|
||||
for (let folderWithFlag of fixIterator(
|
||||
foldersWithFlag,
|
||||
Ci.nsIMsgFolder
|
||||
)) {
|
||||
for (let folderWithFlag of foldersWithFlag) {
|
||||
folders.push(folderWithFlag);
|
||||
// Add sub-folders of Sent and Archive to the result.
|
||||
if (
|
||||
|
|
|
@ -323,8 +323,7 @@ IMIncomingServer.prototype = {
|
|||
descendants: [],
|
||||
getFlag: () => false,
|
||||
getFolderWithFlags: aFlags => null,
|
||||
getFoldersWithFlags: aFlags =>
|
||||
Cc["@mozilla.org/array;1"].createInstance(Ci.nsIArray),
|
||||
getFoldersWithFlags: aFlags => [],
|
||||
get subFolders() {
|
||||
return EmptyEnumerator;
|
||||
},
|
||||
|
|
|
@ -432,16 +432,7 @@ interface nsIMsgFolder : nsISupports {
|
|||
* @return An array of folders that have the specified flags set.
|
||||
* The array may have zero elements.
|
||||
*/
|
||||
nsIArray getFoldersWithFlags(in unsigned long flags);
|
||||
|
||||
/**
|
||||
* Lists the folders that have the specified flag set.
|
||||
*
|
||||
* @param flags The flag(s) to check for.
|
||||
* @param folders The array in which to append the found folder(s).
|
||||
*/
|
||||
void listFoldersWithFlags(in unsigned long flags,
|
||||
in nsIMutableArray folders);
|
||||
Array<nsIMsgFolder> getFoldersWithFlags(in unsigned long flags);
|
||||
|
||||
/**
|
||||
* Check if this folder (or one of its ancestors) is special.
|
||||
|
|
|
@ -2733,17 +2733,13 @@ NS_IMETHODIMP nsMsgAccountManager::SaveVirtualFolders() {
|
|||
nsCOMPtr<nsIMsgFolder> rootFolder;
|
||||
server->GetRootFolder(getter_AddRefs(rootFolder));
|
||||
if (rootFolder) {
|
||||
nsCOMPtr<nsIArray> virtualFolders;
|
||||
nsresult rv = rootFolder->GetFoldersWithFlags(
|
||||
nsMsgFolderFlags::Virtual, getter_AddRefs(virtualFolders));
|
||||
nsTArray<RefPtr<nsIMsgFolder>> virtualFolders;
|
||||
nsresult rv = rootFolder->GetFoldersWithFlags(nsMsgFolderFlags::Virtual,
|
||||
virtualFolders);
|
||||
if (NS_FAILED(rv)) {
|
||||
continue;
|
||||
}
|
||||
uint32_t vfCount;
|
||||
virtualFolders->GetLength(&vfCount);
|
||||
for (uint32_t folderIndex = 0; folderIndex < vfCount; folderIndex++) {
|
||||
nsCOMPtr<nsIMsgFolder> msgFolder(
|
||||
do_QueryElementAt(virtualFolders, folderIndex));
|
||||
for (auto msgFolder : virtualFolders) {
|
||||
nsCOMPtr<nsIMsgDatabase> db;
|
||||
nsCOMPtr<nsIDBFolderInfo> dbFolderInfo;
|
||||
rv = msgFolder->GetDBFolderInfoAndDB(
|
||||
|
|
|
@ -4027,32 +4027,24 @@ NS_IMETHODIMP nsMsgDBFolder::GetFolderWithFlags(uint32_t aFlags,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::GetFoldersWithFlags(uint32_t aFlags,
|
||||
nsIArray **aResult) {
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMutableArray> array(do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
ListFoldersWithFlags(aFlags, array);
|
||||
array.forget(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::ListFoldersWithFlags(uint32_t aFlags,
|
||||
nsIMutableArray *aFolders) {
|
||||
NS_ENSURE_ARG_POINTER(aFolders);
|
||||
if ((mFlags & aFlags) == aFlags)
|
||||
aFolders->AppendElement(static_cast<nsIMsgFolder *>(this));
|
||||
NS_IMETHODIMP nsMsgDBFolder::GetFoldersWithFlags(
|
||||
uint32_t aFlags, nsTArray<RefPtr<nsIMsgFolder>> &aResult) {
|
||||
aResult.Clear();
|
||||
|
||||
// Ensure initialisation of mSubFolders.
|
||||
nsCOMPtr<nsISimpleEnumerator> dummy;
|
||||
GetSubFolders(getter_AddRefs(dummy)); // initialize mSubFolders
|
||||
GetSubFolders(getter_AddRefs(dummy));
|
||||
|
||||
int32_t count = mSubFolders.Count();
|
||||
for (int32_t i = 0; i < count; ++i)
|
||||
mSubFolders[i]->ListFoldersWithFlags(aFlags, aFolders);
|
||||
if ((mFlags & aFlags) == aFlags) {
|
||||
aResult.AppendElement(this);
|
||||
}
|
||||
|
||||
// Recurse down through children.
|
||||
for (auto child : mSubFolders) {
|
||||
nsTArray<RefPtr<nsIMsgFolder>> subMatches;
|
||||
child->GetFoldersWithFlags(aFlags, subMatches);
|
||||
aResult.AppendElements(subMatches);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -1371,62 +1371,56 @@ NS_IMETHODIMP nsImapIncomingServer::DiscoveryDone() {
|
|||
// Verify there is only one trash folder. Another might be present if
|
||||
// the trash name has been changed. Or we might be a gmail server and
|
||||
// want to switch to gmail's trash folder.
|
||||
nsCOMPtr<nsIArray> trashFolders;
|
||||
nsTArray<RefPtr<nsIMsgFolder>> trashFolders;
|
||||
rv = rootMsgFolder->GetFoldersWithFlags(nsMsgFolderFlags::Trash,
|
||||
getter_AddRefs(trashFolders));
|
||||
trashFolders);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && trashFolders) {
|
||||
uint32_t numFolders;
|
||||
trashFolders->GetLength(&numFolders);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsAutoString trashName;
|
||||
if (NS_SUCCEEDED(GetTrashFolderName(trashName))) {
|
||||
for (uint32_t i = 0; i < numFolders; i++) {
|
||||
nsCOMPtr<nsIMsgFolder> trashFolder(
|
||||
do_QueryElementAt(trashFolders, i));
|
||||
if (trashFolder) {
|
||||
// If we're a gmail server, we clear the trash flags from folder(s)
|
||||
// without the kImapXListTrash flag. For normal servers, we clear
|
||||
// the trash folder flag if the folder name doesn't match the
|
||||
// pref trash folder name.
|
||||
nsAutoString retval;
|
||||
rv = GetUnicharValue(PREF_TRASH_FOLDER_PATH, retval);
|
||||
if (isGMailServer && (NS_FAILED(rv) || retval.IsEmpty())) {
|
||||
nsCOMPtr<nsIMsgImapMailFolder> imapFolder(
|
||||
do_QueryInterface(trashFolder));
|
||||
int32_t boxFlags;
|
||||
imapFolder->GetBoxFlags(&boxFlags);
|
||||
if (boxFlags & kImapXListTrash) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// Store the trash folder path. We maintain the full path in the
|
||||
// trash_folder_name preference since the full path is stored
|
||||
// there when selecting a trash folder in the Account Manager.
|
||||
nsAutoCString trashURL;
|
||||
trashFolder->GetFolderURL(trashURL);
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewURI(getter_AddRefs(uri), trashURL);
|
||||
nsAutoCString trashPath;
|
||||
uri->GetPathQueryRef(trashPath);
|
||||
nsAutoCString unescapedName;
|
||||
MsgUnescapeString(Substring(trashPath, 1), // Skip leading slash.
|
||||
nsINetUtil::ESCAPE_URL_PATH, unescapedName);
|
||||
nsAutoString nameUnicode;
|
||||
if (NS_FAILED(CopyMUTF7toUTF16(unescapedName, nameUnicode)) ||
|
||||
trashName.Equals(nameUnicode)) {
|
||||
continue;
|
||||
}
|
||||
if (numFolders == 1) {
|
||||
// We got here because the preferred trash folder does not
|
||||
// exist, but a folder got discovered to be the trash folder.
|
||||
SetUnicharValue(PREF_TRASH_FOLDER_PATH, nameUnicode);
|
||||
continue;
|
||||
}
|
||||
for (auto trashFolder : trashFolders) {
|
||||
// If we're a gmail server, we clear the trash flags from folder(s)
|
||||
// without the kImapXListTrash flag. For normal servers, we clear
|
||||
// the trash folder flag if the folder name doesn't match the
|
||||
// pref trash folder name.
|
||||
nsAutoString retval;
|
||||
rv = GetUnicharValue(PREF_TRASH_FOLDER_PATH, retval);
|
||||
if (isGMailServer && (NS_FAILED(rv) || retval.IsEmpty())) {
|
||||
nsCOMPtr<nsIMsgImapMailFolder> imapFolder(
|
||||
do_QueryInterface(trashFolder));
|
||||
int32_t boxFlags;
|
||||
imapFolder->GetBoxFlags(&boxFlags);
|
||||
if (boxFlags & kImapXListTrash) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// Store the trash folder path. We maintain the full path in the
|
||||
// trash_folder_name preference since the full path is stored
|
||||
// there when selecting a trash folder in the Account Manager.
|
||||
nsAutoCString trashURL;
|
||||
trashFolder->GetFolderURL(trashURL);
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewURI(getter_AddRefs(uri), trashURL);
|
||||
nsAutoCString trashPath;
|
||||
uri->GetPathQueryRef(trashPath);
|
||||
nsAutoCString unescapedName;
|
||||
MsgUnescapeString(Substring(trashPath, 1), // Skip leading slash.
|
||||
nsINetUtil::ESCAPE_URL_PATH, unescapedName);
|
||||
nsAutoString nameUnicode;
|
||||
if (NS_FAILED(CopyMUTF7toUTF16(unescapedName, nameUnicode)) ||
|
||||
trashName.Equals(nameUnicode)) {
|
||||
continue;
|
||||
}
|
||||
if (trashFolders.Length() == 1) {
|
||||
// We got here because the preferred trash folder does not
|
||||
// exist, but a folder got discovered to be the trash folder.
|
||||
SetUnicharValue(PREF_TRASH_FOLDER_PATH, nameUnicode);
|
||||
continue;
|
||||
}
|
||||
// We clear the trash folder flag if the trash folder path doesn't
|
||||
// match mail.server.serverX.trash_folder_name.
|
||||
trashFolder->ClearFlag(nsMsgFolderFlags::Trash);
|
||||
}
|
||||
// We clear the trash folder flag if the trash folder path doesn't
|
||||
// match mail.server.serverX.trash_folder_name.
|
||||
trashFolder->ClearFlag(nsMsgFolderFlags::Trash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче