From e2b7471fd9d9df8ac0beca459510c4f4b2435e2b Mon Sep 17 00:00:00 2001 From: aceman Date: Tue, 3 Dec 2019 16:04:45 +0200 Subject: [PATCH] Bug 1598865 - do not use new hidden/system files detected in mail account local storage as mail folders. r=mkmelin --- mailnews/imap/src/nsImapMailFolder.cpp | 25 ++++++++++----------- mailnews/local/src/nsMsgBrkMBoxStore.cpp | 8 ++++--- mailnews/local/src/nsMsgLocalStoreUtils.cpp | 10 ++++++++- mailnews/local/src/nsMsgLocalStoreUtils.h | 2 +- mailnews/local/src/nsMsgMaildirStore.cpp | 2 +- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index 731de2bafb..6697f114d2 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -383,31 +383,28 @@ nsresult nsImapMailFolder::AddSubfolderWithPath(nsAString &name, nsresult nsImapMailFolder::CreateSubFolders(nsIFile *path) { nsresult rv = NS_OK; - nsAutoString currentFolderNameStr; // online name - nsAutoString currentFolderDBNameStr; // possibly munged name - nsCOMPtr child; nsCOMPtr server; rv = GetServer(getter_AddRefs(server)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr children; - rv = path->GetDirectoryEntries(getter_AddRefs(children)); - bool more = false; - if (children) children->HasMoreElements(&more); + nsCOMPtr directoryEnumerator; + rv = path->GetDirectoryEntries(getter_AddRefs(directoryEnumerator)); + NS_ENSURE_SUCCESS(rv, rv); - while (more) { + bool hasMore = false; + while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) && + hasMore) { nsCOMPtr currentFolderPath; - rv = children->GetNextFile(getter_AddRefs(currentFolderPath)); - if (NS_FAILED(rv) || !currentFolderPath) break; - rv = children->HasMoreElements(&more); - if (NS_FAILED(rv)) return rv; + rv = directoryEnumerator->GetNextFile(getter_AddRefs(currentFolderPath)); + if (NS_FAILED(rv) || !currentFolderPath) continue; + nsAutoString currentFolderNameStr; // online name + nsAutoString currentFolderDBNameStr; // possibly munged name 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 cacheElement; nsCOMPtr curFolder = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); @@ -421,6 +418,7 @@ nsresult nsImapMailFolder::CreateSubFolders(nsIFile *path) { nsAutoString utf7LeafName = currentFolderNameStr; if (curFolder) { + nsCOMPtr cacheElement; rv = GetFolderCacheElemFromFile(dbFile, getter_AddRefs(cacheElement)); if (NS_SUCCEEDED(rv) && cacheElement) { nsCString onlineFullUtf7Name; @@ -463,6 +461,7 @@ nsresult nsImapMailFolder::CreateSubFolders(nsIFile *path) { msfFilePath->SetLeafName(currentFolderDBNameStr); } // use the utf7 name as the uri for the folder. + nsCOMPtr child; AddSubfolderWithPath(utf7LeafName, msfFilePath, getter_AddRefs(child)); if (child) { // use the unicode name as the "pretty" name. Set it so it won't be diff --git a/mailnews/local/src/nsMsgBrkMBoxStore.cpp b/mailnews/local/src/nsMsgBrkMBoxStore.cpp index f97915c76c..54218f1864 100644 --- a/mailnews/local/src/nsMsgBrkMBoxStore.cpp +++ b/mailnews/local/src/nsMsgBrkMBoxStore.cpp @@ -947,8 +947,10 @@ nsresult nsMsgBrkMBoxStore::AddSubFolders(nsIMsgFolder *parent, while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) && hasMore) { nsCOMPtr currentFile; - directoryEnumerator->GetNextFile(getter_AddRefs(currentFile)); - if (currentFile) currentDirEntries.AppendObject(currentFile); + rv = directoryEnumerator->GetNextFile(getter_AddRefs(currentFile)); + if (NS_SUCCEEDED(rv) && currentFile) { + currentDirEntries.AppendObject(currentFile); + } } // add the folders @@ -960,7 +962,7 @@ nsresult nsMsgBrkMBoxStore::AddSubFolders(nsIMsgFolder *parent, currentFile->GetLeafName(leafName); // here we should handle the case where the current file is a .sbd directory // w/o a matching folder file, or a directory w/o the name .sbd - if (nsShouldIgnoreFile(leafName)) continue; + if (nsShouldIgnoreFile(leafName, currentFile)) continue; nsCOMPtr child; rv = parent->AddSubfolder(leafName, getter_AddRefs(child)); diff --git a/mailnews/local/src/nsMsgLocalStoreUtils.cpp b/mailnews/local/src/nsMsgLocalStoreUtils.cpp index 3b622b5a81..224a255a6b 100644 --- a/mailnews/local/src/nsMsgLocalStoreUtils.cpp +++ b/mailnews/local/src/nsMsgLocalStoreUtils.cpp @@ -21,7 +21,7 @@ nsresult nsMsgLocalStoreUtils::AddDirectorySeparator(nsIFile *path) { return path->SetLeafName(leafName); } -bool nsMsgLocalStoreUtils::nsShouldIgnoreFile(nsAString &name) { +bool nsMsgLocalStoreUtils::nsShouldIgnoreFile(nsAString &name, nsIFile *path) { if (name.IsEmpty()) return true; char16_t firstChar = name.First(); @@ -54,6 +54,14 @@ bool nsMsgLocalStoreUtils::nsShouldIgnoreFile(nsAString &name) { StringBeginsWith(name, NS_LITERAL_STRING("feeditems_error"))) return true; + // Ignore hidden and other special system files. + bool specialFile = false; + path->IsHidden(&specialFile); + if (specialFile) return true; + specialFile = false; + path->IsSpecial(&specialFile); + if (specialFile) return true; + // The .mozmsgs dir is for spotlight support return (StringEndsWith(name, NS_LITERAL_STRING(".mozmsgs")) || StringEndsWith(name, NS_LITERAL_STRING(FOLDER_SUFFIX)) || diff --git a/mailnews/local/src/nsMsgLocalStoreUtils.h b/mailnews/local/src/nsMsgLocalStoreUtils.h index df273b9996..61659510e6 100644 --- a/mailnews/local/src/nsMsgLocalStoreUtils.h +++ b/mailnews/local/src/nsMsgLocalStoreUtils.h @@ -26,7 +26,7 @@ class nsMsgLocalStoreUtils { nsMsgLocalStoreUtils(); static nsresult AddDirectorySeparator(nsIFile *path); - static bool nsShouldIgnoreFile(nsAString &name); + static bool nsShouldIgnoreFile(nsAString &name, nsIFile *path); static void ChangeKeywordsHelper(nsIMsgDBHdr *message, uint64_t desiredOffset, nsLineBuffer *lineBuffer, nsTArray &keywordArray, bool aAdd, diff --git a/mailnews/local/src/nsMsgMaildirStore.cpp b/mailnews/local/src/nsMsgMaildirStore.cpp index 4e5b32f489..cc44cbc4dd 100644 --- a/mailnews/local/src/nsMsgMaildirStore.cpp +++ b/mailnews/local/src/nsMsgMaildirStore.cpp @@ -94,7 +94,7 @@ nsresult nsMsgMaildirStore::AddSubFolders(nsIMsgFolder *parent, nsIFile *path, currentFile->IsDirectory(&isDirectory); // Make sure this really is a mail folder dir (i.e., a directory that // contains cur and tmp sub-dirs, and not a .sbd or .mozmsgs dir). - if (isDirectory && !nsShouldIgnoreFile(leafName)) + if (isDirectory && !nsShouldIgnoreFile(leafName, currentFile)) currentDirEntries.AppendObject(currentFile); } }