summaryrefslogtreecommitdiffstats
path: root/mailnews
diff options
context:
space:
mode:
Diffstat (limited to 'mailnews')
-rw-r--r--mailnews/base/public/nsIMsgPluggableStore.idl4
-rw-r--r--mailnews/base/util/nsMsgDBFolder.cpp26
-rw-r--r--mailnews/imap/src/nsImapMailFolder.cpp54
-rw-r--r--mailnews/local/src/nsLocalMailFolder.cpp39
-rw-r--r--mailnews/local/src/nsLocalMailFolder.h1
-rw-r--r--mailnews/local/src/nsMsgBrkMBoxStore.cpp32
-rw-r--r--mailnews/local/src/nsMsgMaildirStore.cpp23
-rw-r--r--mailnews/news/src/nsNewsFolder.cpp37
8 files changed, 77 insertions, 139 deletions
diff --git a/mailnews/base/public/nsIMsgPluggableStore.idl b/mailnews/base/public/nsIMsgPluggableStore.idl
index 18415d801..12713b236 100644
--- a/mailnews/base/public/nsIMsgPluggableStore.idl
+++ b/mailnews/base/public/nsIMsgPluggableStore.idl
@@ -51,8 +51,8 @@ interface nsIMsgPluggableStore : nsISupports {
nsIMsgFolder createFolder(in nsIMsgFolder aParent, in AString aFolderName);
/**
- * Delete the passed in folder. This is a real delete, not a move
- * to the trash folder.
+ * Delete storage for a folder and its subfolders, if any.
+ * This is a real delete, not a move to the trash folder.
*
* @param aFolder folder to delete
*/
diff --git a/mailnews/base/util/nsMsgDBFolder.cpp b/mailnews/base/util/nsMsgDBFolder.cpp
index 81790c69a..c6356f83d 100644
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -3559,7 +3559,31 @@ NS_IMETHODIMP nsMsgDBFolder::GetShowDeletedMessages(bool *showDeletedMessages)
NS_IMETHODIMP nsMsgDBFolder::Delete()
{
- return NS_OK;
+ ForceDBClosed();
+
+ // Delete the .msf file.
+ // NOTE: this doesn't remove .msf files in subfolders, but
+ // both nsMsgBrkMBoxStore::DeleteFolder() and
+ // nsMsgMaildirStore::DeleteFolder() will remove those .msf files
+ // as a side-effect of deleting the .sbd directory.
+ nsCOMPtr<nsIFile> summaryFile;
+ nsresult rv = GetSummaryFile(getter_AddRefs(summaryFile));
+ NS_ENSURE_SUCCESS(rv, rv);
+ bool exists = false;
+ summaryFile->Exists(&exists);
+ if (exists) {
+ rv = summaryFile->Remove(false);
+ NS_ENSURE_SUCCESS(rv, rv);
+ }
+
+ // Ask the msgStore to delete the actual storage (mbox, maildir or whatever
+ // else may be supported in future).
+ nsCOMPtr<nsIMsgPluggableStore> msgStore;
+ rv = GetMsgStore(getter_AddRefs(msgStore));
+ NS_ENSURE_SUCCESS(rv, rv);
+ rv = msgStore->DeleteFolder(this);
+
+ return rv;
}
NS_IMETHODIMP nsMsgDBFolder::DeleteSubFolders(nsIArray *folders,
diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp
index df222cb85..4fade9d3f 100644
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -1468,7 +1468,6 @@ NS_IMETHODIMP nsImapMailFolder::EmptyTrash(nsIMsgWindow *aMsgWindow, nsIUrlListe
} // if we fetched an imap server
} // if emptying trash on exit which is done through the account manager.
- nsCOMPtr<nsIMsgDatabase> trashDB;
if (WeAreOffline())
{
nsCOMPtr <nsIMsgDatabase> trashDB;
@@ -1485,12 +1484,7 @@ NS_IMETHODIMP nsImapMailFolder::EmptyTrash(nsIMsgWindow *aMsgWindow, nsIUrlListe
}
return rv;
}
- nsCOMPtr <nsIDBFolderInfo> transferInfo;
- rv = trashFolder->GetDBTransferInfo(getter_AddRefs(transferInfo));
- rv = trashFolder->Delete(); // delete summary spec
- trashFolder->SetDBTransferInfo(transferInfo);
- trashFolder->SetSizeOnDisk(0);
nsCOMPtr<nsIImapService> imapService = do_GetService(NS_IMAPSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
@@ -1536,7 +1530,17 @@ NS_IMETHODIMP nsImapMailFolder::EmptyTrash(nsIMsgWindow *aMsgWindow, nsIUrlListe
}
}
- // The trash folder has effectively been deleted
+ nsCOMPtr <nsIDBFolderInfo> transferInfo;
+ rv = trashFolder->GetDBTransferInfo(getter_AddRefs(transferInfo));
+ NS_ENSURE_SUCCESS(rv, rv);
+ // Bulk-delete all the messages by deleting the msf file and storage.
+ // This is a little kludgy.
+ rv = trashFolder->Delete();
+ NS_ENSURE_SUCCESS(rv, rv);
+ trashFolder->SetDBTransferInfo(transferInfo);
+ trashFolder->SetSizeOnDisk(0);
+
+ // The trash folder has effectively been deleted.
nsCOMPtr<nsIMsgFolderNotificationService> notifier(do_GetService(NS_MSGNOTIFICATIONSERVICE_CONTRACTID));
if (notifier)
notifier->NotifyFolderDeleted(trashFolder);
@@ -1548,41 +1552,9 @@ NS_IMETHODIMP nsImapMailFolder::EmptyTrash(nsIMsgWindow *aMsgWindow, nsIUrlListe
NS_IMETHODIMP nsImapMailFolder::Delete()
{
- nsresult rv;
- if (!mDatabase)
- {
- // Check if anyone has this db open. If so, do a force closed.
- nsCOMPtr<nsIMsgDBService> msgDBService = do_GetService(NS_MSGDB_SERVICE_CONTRACTID, &rv);
- NS_ENSURE_SUCCESS(rv, rv);
- msgDBService->CachedDBForFolder(this, getter_AddRefs(mDatabase));
- }
- if (mDatabase)
- {
- mDatabase->ForceClosed();
- mDatabase = nullptr;
- }
+ nsresult rv = nsMsgDBFolder::Delete();
- nsCOMPtr<nsIFile> path;
- rv = GetFilePath(getter_AddRefs(path));
- if (NS_SUCCEEDED(rv))
- {
- nsCOMPtr<nsIFile> summaryLocation;
- rv = GetSummaryFileLocation(path, getter_AddRefs(summaryLocation));
- if (NS_SUCCEEDED(rv))
- {
- bool exists = false;
- rv = summaryLocation->Exists(&exists);
- if (NS_SUCCEEDED(rv) && exists)
- {
- rv = summaryLocation->Remove(false);
- if (NS_FAILED(rv))
- NS_WARNING("failed to remove imap summary file");
- }
- }
- }
- if (mPath)
- mPath->Remove(false);
- // should notify nsIMsgFolderListeners about the folder getting deleted...
+ // Should notify nsIMsgFolderListeners about the folder getting deleted?
return rv;
}
diff --git a/mailnews/local/src/nsLocalMailFolder.cpp b/mailnews/local/src/nsLocalMailFolder.cpp
index 00244ca87..78991ebfd 100644
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -653,8 +653,6 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EmptyTrash(nsIMsgWindow *msgWindow,
if (NS_SUCCEEDED(rv))
{
uint32_t flags;
- nsCString trashUri;
- trashFolder->GetURI(trashUri);
trashFolder->GetFlags(&flags);
int32_t totalMessages = 0;
rv = trashFolder->GetTotalMessages(true, &totalMessages);
@@ -750,43 +748,6 @@ nsresult nsMsgLocalMailFolder::IsChildOfTrash(bool *result)
return rv;
}
-NS_IMETHODIMP nsMsgLocalMailFolder::Delete()
-{
- nsresult rv;
- nsCOMPtr<nsIMsgDBService> msgDBService = do_GetService(NS_MSGDB_SERVICE_CONTRACTID, &rv);
- NS_ENSURE_SUCCESS(rv, rv);
- msgDBService->CachedDBForFolder(this, getter_AddRefs(mDatabase));
- if (mDatabase)
- {
- mDatabase->ForceClosed();
- mDatabase = nullptr;
- }
-
- nsCOMPtr<nsIMsgIncomingServer> server;
- rv = GetServer(getter_AddRefs(server));
- NS_ENSURE_SUCCESS(rv, rv);
-
- nsCOMPtr<nsIMsgPluggableStore> msgStore;
-
- rv = server->GetMsgStore(getter_AddRefs(msgStore));
- NS_ENSURE_SUCCESS(rv, rv);
-
- nsCOMPtr <nsIFile> summaryFile;
- rv = GetSummaryFile(getter_AddRefs(summaryFile));
- NS_ENSURE_SUCCESS(rv, rv);
-
- //Clean up .sbd folder if it exists.
- // Remove summary file.
- rv = summaryFile->Remove(false);
- NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Could not delete msg summary file");
-
- rv = msgStore->DeleteFolder(this);
- if (rv == NS_ERROR_FILE_NOT_FOUND ||
- rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
- rv = NS_OK; // virtual folders do not have a msgStore file
- return rv;
-}
-
NS_IMETHODIMP nsMsgLocalMailFolder::DeleteSubFolders(nsIArray *folders, nsIMsgWindow *msgWindow)
{
nsresult rv;
diff --git a/mailnews/local/src/nsLocalMailFolder.h b/mailnews/local/src/nsLocalMailFolder.h
index b2503a157..1ed964b16 100644
--- a/mailnews/local/src/nsLocalMailFolder.h
+++ b/mailnews/local/src/nsLocalMailFolder.h
@@ -120,7 +120,6 @@ public:
NS_IMETHOD Compact(nsIUrlListener *aListener, nsIMsgWindow *aMsgWindow) override;
NS_IMETHOD CompactAll(nsIUrlListener *aListener, nsIMsgWindow *aMsgWindow, bool aCompactOfflineAlso) override;
NS_IMETHOD EmptyTrash(nsIMsgWindow *msgWindow, nsIUrlListener *aListener) override;
- NS_IMETHOD Delete () override;
NS_IMETHOD DeleteSubFolders(nsIArray *folders, nsIMsgWindow *msgWindow) override;
NS_IMETHOD CreateStorageIfMissing(nsIUrlListener* urlListener) override;
NS_IMETHOD Rename (const nsAString& aNewName, nsIMsgWindow *msgWindow) override;
diff --git a/mailnews/local/src/nsMsgBrkMBoxStore.cpp b/mailnews/local/src/nsMsgBrkMBoxStore.cpp
index 31836dd3c..1ab464385 100644
--- a/mailnews/local/src/nsMsgBrkMBoxStore.cpp
+++ b/mailnews/local/src/nsMsgBrkMBoxStore.cpp
@@ -300,26 +300,30 @@ NS_IMETHODIMP nsMsgBrkMBoxStore::SetSummaryFileValid(nsIMsgFolder *aFolder,
NS_IMETHODIMP nsMsgBrkMBoxStore::DeleteFolder(nsIMsgFolder *aFolder)
{
NS_ENSURE_ARG_POINTER(aFolder);
- //Delete mailbox
+ bool exists;
+
+ // Delete mbox file.
nsCOMPtr<nsIFile> pathFile;
nsresult rv = aFolder->GetFilePath(getter_AddRefs(pathFile));
NS_ENSURE_SUCCESS(rv, rv);
- pathFile->Remove(false);
+ exists = false;
+ pathFile->Exists(&exists);
+ if (exists) {
+ rv = pathFile->Remove(false);
+ NS_ENSURE_SUCCESS(rv, rv);
+ }
- bool isDirectory = false;
- pathFile->IsDirectory(&isDirectory);
- if (!isDirectory)
- {
- nsAutoString leafName;
- pathFile->GetLeafName(leafName);
- leafName.AppendLiteral(FOLDER_SUFFIX);
- pathFile->SetLeafName(leafName);
+ // Delete any subfolders (.sbd-suffixed directories).
+ AddDirectorySeparator(pathFile);
+ exists = false;
+ pathFile->Exists(&exists);
+ if (exists) {
+ rv = pathFile->Remove(true);
+ NS_ENSURE_SUCCESS(rv, rv);
}
- isDirectory = false;
- pathFile->IsDirectory(&isDirectory);
- //If this is a directory, then remove it.
- return isDirectory ? pathFile->Remove(true) : NS_OK;
+
+ return NS_OK;
}
NS_IMETHODIMP nsMsgBrkMBoxStore::RenameFolder(nsIMsgFolder *aFolder,
diff --git a/mailnews/local/src/nsMsgMaildirStore.cpp b/mailnews/local/src/nsMsgMaildirStore.cpp
index 7a4633367..993abbad5 100644
--- a/mailnews/local/src/nsMsgMaildirStore.cpp
+++ b/mailnews/local/src/nsMsgMaildirStore.cpp
@@ -323,19 +323,30 @@ NS_IMETHODIMP nsMsgMaildirStore::SetSummaryFileValid(nsIMsgFolder *aFolder,
NS_IMETHODIMP nsMsgMaildirStore::DeleteFolder(nsIMsgFolder *aFolder)
{
NS_ENSURE_ARG_POINTER(aFolder);
+ bool exists;
- // Delete Maildir structure
+ // Delete the Maildir itself.
nsCOMPtr<nsIFile> pathFile;
nsresult rv = aFolder->GetFilePath(getter_AddRefs(pathFile));
NS_ENSURE_SUCCESS(rv, rv);
- rv = pathFile->Remove(true); // recursive
+ exists = false;
+ pathFile->Exists(&exists);
+ if (exists) {
+ rv = pathFile->Remove(true);
+ NS_ENSURE_SUCCESS(rv, rv);
+ }
+
+ // Delete any subfolders (.sbd-suffixed directories).
AddDirectorySeparator(pathFile);
- bool exists;
+ exists = false;
pathFile->Exists(&exists);
- if (exists)
- pathFile->Remove(true);
- return rv;
+ if (exists) {
+ rv = pathFile->Remove(true);
+ NS_ENSURE_SUCCESS(rv, rv);
+ }
+
+ return NS_OK;
}
NS_IMETHODIMP nsMsgMaildirStore::RenameFolder(nsIMsgFolder *aFolder,
diff --git a/mailnews/news/src/nsNewsFolder.cpp b/mailnews/news/src/nsNewsFolder.cpp
index 3af5ae43f..33faa4269 100644
--- a/mailnews/news/src/nsNewsFolder.cpp
+++ b/mailnews/news/src/nsNewsFolder.cpp
@@ -495,41 +495,8 @@ NS_IMETHODIMP nsMsgNewsFolder::CreateSubfolder(const nsAString& newsgroupName,
NS_IMETHODIMP nsMsgNewsFolder::Delete()
{
- nsresult rv = GetDatabase();
-
- if(NS_SUCCEEDED(rv))
- {
- mDatabase->ForceClosed();
- mDatabase = nullptr;
- }
-
- nsCOMPtr<nsIFile> folderPath;
- rv = GetFilePath(getter_AddRefs(folderPath));
-
- if (NS_SUCCEEDED(rv))
- {
- nsCOMPtr<nsIFile> summaryPath;
- rv = GetSummaryFileLocation(folderPath, getter_AddRefs(summaryPath));
- if (NS_SUCCEEDED(rv))
- {
- bool exists = false;
- rv = folderPath->Exists(&exists);
-
- if (NS_SUCCEEDED(rv) && exists)
- rv = folderPath->Remove(false);
-
- if (NS_FAILED(rv))
- NS_WARNING("Failed to remove News Folder");
-
- rv = summaryPath->Exists(&exists);
-
- if (NS_SUCCEEDED(rv) && exists)
- rv = summaryPath->Remove(false);
-
- if (NS_FAILED(rv))
- NS_WARNING("Failed to remove News Folder Summary File");
- }
- }
+ nsresult rv = nsMsgDBFolder::Delete();
+ NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr <nsINntpIncomingServer> nntpServer;
rv = GetNntpServer(getter_AddRefs(nntpServer));