diff --git a/mozilla/mailnews/base/public/nsIFolder.idl b/mozilla/mailnews/base/public/nsIFolder.idl index f0247e0a8ad..1389111b1ff 100644 --- a/mozilla/mailnews/base/public/nsIFolder.idl +++ b/mozilla/mailnews/base/public/nsIFolder.idl @@ -23,6 +23,8 @@ #include "nsICollection.idl" #include "nsIFolderListener.idl" +interface nsISupportsArray; + [scriptable, uuid(75621650-0fce-11d3-8b49-006008948010)] interface nsIFolder : nsICollection { @@ -66,7 +68,8 @@ interface nsIFolder : nsICollection { // void NotifyFolderLoaded(); // void NotifyDeleteOrMoveMessagesCompleted(in nsIFolder folder); - + // lists all descendents, not just first level children + void ListDescendents(in nsISupportsArray descendents); void Shutdown(in boolean shutdownChildren); }; diff --git a/mozilla/mailnews/base/public/nsIMessenger.idl b/mozilla/mailnews/base/public/nsIMessenger.idl index 1d1e9fc9781..a138e63f003 100644 --- a/mozilla/mailnews/base/public/nsIMessenger.idl +++ b/mozilla/mailnews/base/public/nsIMessenger.idl @@ -70,7 +70,8 @@ interface nsIMessenger : nsISupports { void RenameFolder(in nsIRDFCompositeDataSource db, in nsIRDFResource folder, in wstring name); void CompactFolder(in nsIRDFCompositeDataSource db, - in nsIRDFResource folder); + in nsIRDFResource folder, + in boolean forAll); void EmptyTrash(in nsIRDFCompositeDataSource db, in nsIRDFResource folder); diff --git a/mozilla/mailnews/base/public/nsIMsgFolder.idl b/mozilla/mailnews/base/public/nsIMsgFolder.idl index d16a7160e58..f4d3ede8a30 100644 --- a/mozilla/mailnews/base/public/nsIMsgFolder.idl +++ b/mozilla/mailnews/base/public/nsIMsgFolder.idl @@ -126,6 +126,8 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne */ readonly attribute boolean canRename; + readonly attribute boolean canCompact; + /** * the phantom server folder */ @@ -151,6 +153,7 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne void createStorageIfMissing(in nsIUrlListener urlListener); void compact(in nsIUrlListener aListener); + void compactAll(in nsIUrlListener aListener); void emptyTrash(in nsIMsgWindow aMsgWindow, in nsIUrlListener aListener); /** @@ -331,6 +334,8 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne */ attribute nsIFileSpec path; + readonly attribute string baseMessageURI; + const nsMsgDispositionState nsMsgDispositionState_Replied = 0; const nsMsgDispositionState nsMsgDispositionState_Forwarded = 1; void addMessageDispositionState(in nsIMessage aMessage, in nsMsgDispositionState aDispositionFlag); diff --git a/mozilla/mailnews/base/public/nsIMsgFolderCompactor.idl b/mozilla/mailnews/base/public/nsIMsgFolderCompactor.idl index 8dd92809dc2..3537007e5ba 100644 --- a/mozilla/mailnews/base/public/nsIMsgFolderCompactor.idl +++ b/mozilla/mailnews/base/public/nsIMsgFolderCompactor.idl @@ -35,6 +35,7 @@ interface nsIMsgFolderCompactor : nsISupports { void Init(in nsIMsgFolder folder, in string baseMsgUri, in nsIMsgDatabase db, in nsIFileSpec pathSpec); + void InitCompactAll(in nsIMsgFolder folder); // we probably want to add the ability to set an enumerator to determine which // messages to copy over in the compaction process. void StartCompacting(); diff --git a/mozilla/mailnews/base/resources/content/folderPane.xul b/mozilla/mailnews/base/resources/content/folderPane.xul index 2362aad805a..8f0955e9e28 100644 --- a/mozilla/mailnews/base/resources/content/folderPane.xul +++ b/mozilla/mailnews/base/resources/content/folderPane.xul @@ -54,6 +54,7 @@ NewMessages="rdf:http://home.netscape.com/NC-rdf#NewMessages" SubfoldersHaveUnreadMessages="rdf:http://home.netscape.com/NC-rdf#SubfoldersHaveUnreadMessages" CanRename="rdf:http://home.netscape.com/NC-rdf#CanRename" + CanCompact="rdf:http://home.netscape.com/NC-rdf#CanCompact" CanCreateSubfolders="rdf:http://home.netscape.com/NC-rdf#CanCreateSubfolders" CanSubscribe="rdf:http://home.netscape.com/NC-rdf#CanSubscribe" CanFileMessages="rdf:http://home.netscape.com/NC-rdf#CanFileMessages" @@ -74,6 +75,7 @@ HasUnreadMessages="rdf:http://home.netscape.com/NC-rdf#HasUnreadMessages" SubfoldersHaveUnreadMessages="rdf:http://home.netscape.com/NC-rdf#SubfoldersHaveUnreadMessages" CanRename="rdf:http://home.netscape.com/NC-rdf#CanRename" + CanCompact="rdf:http://home.netscape.com/NC-rdf#CanCompact" CanCreateSubfolders="rdf:http://home.netscape.com/NC-rdf#CanCreateSubfolders" CanSubscribe="rdf:http://home.netscape.com/NC-rdf#CanSubscribe" CanFileMessages="rdf:http://home.netscape.com/NC-rdf#CanFileMessages" diff --git a/mozilla/mailnews/base/resources/content/mail3PaneWindowCommands.js b/mozilla/mailnews/base/resources/content/mail3PaneWindowCommands.js index cae5b9668d9..f20296708b5 100644 --- a/mozilla/mailnews/base/resources/content/mail3PaneWindowCommands.js +++ b/mozilla/mailnews/base/resources/content/mail3PaneWindowCommands.js @@ -490,7 +490,7 @@ var DefaultController = MsgEmptyTrash(); return; case "cmd_compactFolder": - MsgCompactFolder(); + MsgCompactFolder(true); return; } }, diff --git a/mozilla/mailnews/base/resources/content/mailContextMenus.js b/mozilla/mailnews/base/resources/content/mailContextMenus.js index 0f8727bddc9..f184853b818 100644 --- a/mozilla/mailnews/base/resources/content/mailContextMenus.js +++ b/mozilla/mailnews/base/resources/content/mailContextMenus.js @@ -191,6 +191,7 @@ function fillFolderPaneContextMenu() SetupRenameMenuItem(targetFolder, numSelected, isServer, serverType, specialFolder); SetupRemoveMenuItem(targetFolder, numSelected, isServer, serverType, specialFolder); + SetupCompactMenuItem(targetFolder, numSelected, isServer, serverType); ShowMenuItem("folderPaneContext-emptyTrash", (numSelected <= 1) && (specialFolder == 'Trash')); EnableMenuItem("folderPaneContext-emptyTrash", true); @@ -252,6 +253,18 @@ function SetupRemoveMenuItem(targetFolder, numSelected, isServer, serverType, sp } } +function SetupCompactMenuItem(targetFolder, numSelected) +{ + var canCompact = (targetFolder.getAttribute('CanCompact') == "true"); + ShowMenuItem("folderPaneContext-compact", (numSelected <=1) && canCompact); + EnableMenuItem("folderPaneContext-compact", true ); + + if(canCompact) + { + SetMenuItemValue("folderPaneContext-compact", Bundle.GetStringFromName("compactFolder")); + } +} + function SetupNewMenuItem(targetFolder, numSelected, isServer, serverType, specialFolder) { var canCreateNew = targetFolder.getAttribute('CanCreateSubfolders') == 'true'; diff --git a/mozilla/mailnews/base/resources/content/mailWindowOverlay.js b/mozilla/mailnews/base/resources/content/mailWindowOverlay.js index e415c61e7c2..d95aa918d48 100644 --- a/mozilla/mailnews/base/resources/content/mailWindowOverlay.js +++ b/mozilla/mailnews/base/resources/content/mailWindowOverlay.js @@ -940,7 +940,18 @@ function IsEmptyTrashEnabled() function IsCompactFolderEnabled() { - return IsMailFolderSelected(); + var folderTree = GetFolderTree(); + var selectedFolders = folderTree.selectedItems; + var numFolders = selectedFolders.length; + + if (numFolders <= 0 ) + return false; + + var folder = selectedFolders[0]; + if (!folder) + return false; + + return (folder.getAttribute('CanCompact') == "true"); } var gDeleteButton = null; diff --git a/mozilla/mailnews/base/resources/content/mailWindowOverlay.xul b/mozilla/mailnews/base/resources/content/mailWindowOverlay.xul index 4de46bcd2bf..9058c8faaed 100644 --- a/mozilla/mailnews/base/resources/content/mailWindowOverlay.xul +++ b/mozilla/mailnews/base/resources/content/mailWindowOverlay.xul @@ -122,7 +122,7 @@ Rights Reserved. - + @@ -387,6 +387,10 @@ Rights Reserved. value="&folderContextRename.label;" accesskey="&folderContextRename.accesskey;" oncommand="MsgRenameFolder();"/> + //for one folder only - + - + diff --git a/mozilla/mailnews/base/resources/content/widgetglue.js b/mozilla/mailnews/base/resources/content/widgetglue.js index af3dffa271c..92a21def2b4 100644 --- a/mozilla/mailnews/base/resources/content/widgetglue.js +++ b/mozilla/mailnews/base/resources/content/widgetglue.js @@ -168,7 +168,7 @@ function MsgEmptyTrash() } } -function MsgCompactFolder() +function MsgCompactFolder(isAll) { //get the selected elements var tree = GetFolderTree(); @@ -209,7 +209,7 @@ function MsgCompactFolder() dump("folder = " + folder.localName + "\n"); try { - messenger.CompactFolder(tree.database, folder.resource); + messenger.CompactFolder(tree.database, folder.resource, isAll); } catch(e) { diff --git a/mozilla/mailnews/base/resources/locale/en-US/messenger.dtd b/mozilla/mailnews/base/resources/locale/en-US/messenger.dtd index 07f8842072e..5e67b742db3 100644 --- a/mozilla/mailnews/base/resources/locale/en-US/messenger.dtd +++ b/mozilla/mailnews/base/resources/locale/en-US/messenger.dtd @@ -58,7 +58,7 @@ Rights Reserved. - + @@ -428,6 +428,8 @@ Rights Reserved. + + diff --git a/mozilla/mailnews/base/resources/locale/en-US/messenger.properties b/mozilla/mailnews/base/resources/locale/en-US/messenger.properties index 7d41dce6faf..6be14141b8a 100644 --- a/mozilla/mailnews/base/resources/locale/en-US/messenger.properties +++ b/mozilla/mailnews/base/resources/locale/en-US/messenger.properties @@ -25,6 +25,7 @@ renameAccount=Rename Account... renameNewsAccount=Rename News Account... renameFolder=Rename Folder... +compactFolder=Compact This Folder removeAccount=Delete Account... removeNewsAccount=Delete News Account... removeFolder=Delete Folder... diff --git a/mozilla/mailnews/base/src/nsMessenger.cpp b/mozilla/mailnews/base/src/nsMessenger.cpp index c47c67577a2..fbc4af66677 100644 --- a/mozilla/mailnews/base/src/nsMessenger.cpp +++ b/mozilla/mailnews/base/src/nsMessenger.cpp @@ -1164,7 +1164,7 @@ nsMessenger::RenameFolder(nsIRDFCompositeDataSource* db, NS_IMETHODIMP nsMessenger::CompactFolder(nsIRDFCompositeDataSource* db, - nsIRDFResource* folderResource) + nsIRDFResource* folderResource, PRBool forAll) { nsresult rv = NS_ERROR_NULL_POINTER; @@ -1174,7 +1174,7 @@ nsMessenger::CompactFolder(nsIRDFCompositeDataSource* db, rv = NS_NewISupportsArray(getter_AddRefs(folderArray)); if (NS_FAILED(rv)) return rv; folderArray->AppendElement(folderResource); - rv = DoCommand(db, NC_RDF_COMPACT, folderArray, nsnull); + rv = DoCommand(db, forAll ? NC_RDF_COMPACTALL : NC_RDF_COMPACT, folderArray, nsnull); if (NS_SUCCEEDED(rv) && mTxnMgr) mTxnMgr->Clear(); return rv; diff --git a/mozilla/mailnews/base/src/nsMsgFolderCompactor.cpp b/mozilla/mailnews/base/src/nsMsgFolderCompactor.cpp index 15243fba25a..1a1b4328949 100644 --- a/mozilla/mailnews/base/src/nsMsgFolderCompactor.cpp +++ b/mozilla/mailnews/base/src/nsMsgFolderCompactor.cpp @@ -54,6 +54,8 @@ nsFolderCompactState::nsFolderCompactState() m_curIndex = -1; m_status = NS_OK; m_messageService = nsnull; + m_compactAll = PR_FALSE; + m_folderIndex =0; } nsFolderCompactState::~nsFolderCompactState() @@ -128,6 +130,85 @@ nsFolderCompactState::InitDB(nsIMsgDatabase *db) return rv; } +NS_IMETHODIMP nsFolderCompactState::InitCompactAll(nsIMsgFolder *folder) +{ + nsresult rv = NS_OK; + nsCOMPtr rootFolder; + nsCOMPtr allDescendents; + folder->GetRootFolder(getter_AddRefs(rootFolder)); + NS_NewISupportsArray(getter_AddRefs(allDescendents)); + rootFolder->ListDescendents(allDescendents); + PRUint32 cnt =0; + rv = allDescendents->Count(&cnt); + NS_ENSURE_SUCCESS(rv,rv); + + NS_NewISupportsArray(getter_AddRefs(m_folderArray)); + PRUint32 expungedBytes=0; + for (PRUint32 i=0; i< cnt;i++) + { + nsCOMPtr supports = getter_AddRefs(allDescendents->ElementAt(i)); + nsCOMPtr folder = do_QueryInterface(supports, &rv); + NS_ENSURE_SUCCESS(rv,rv); + + expungedBytes=0; + if (folder) + rv = folder->GetExpungedBytes(&expungedBytes); + + NS_ENSURE_SUCCESS(rv,rv); + + if (expungedBytes > 0) + rv = m_folderArray->AppendElement(supports); + + NS_ENSURE_SUCCESS(rv,rv); + } + + rv = m_folderArray->Count(&cnt); + NS_ENSURE_SUCCESS(rv,rv); + if ( cnt == 0) + return rv; //no folders to compact + else + m_compactAll = PR_TRUE; + + m_folderIndex = 0; + nsCOMPtr supports = getter_AddRefs(m_folderArray->ElementAt(m_folderIndex)); + nsCOMPtr firstFolder = do_QueryInterface(supports, &rv); + + if (NS_SUCCEEDED(rv) && firstFolder) + CompactHelper(firstFolder); //start with first folder from here. + + return rv; +} + +nsresult +nsFolderCompactState::CompactHelper(nsIMsgFolder *folder) +{ + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr db; + nsCOMPtr folderInfo; + nsCOMPtr mailDBFactory; + nsresult folderOpen = NS_OK; + nsCOMPtr pathSpec; + char *baseMessageURI; + + rv = folder->GetMsgDatabase(nsnull, getter_AddRefs(db)); + NS_ENSURE_SUCCESS(rv,rv); + + rv = folder->GetPath(getter_AddRefs(pathSpec)); + NS_ENSURE_SUCCESS(rv,rv); + + rv = folder->GetBaseMessageURI(&baseMessageURI); + NS_ENSURE_SUCCESS(rv,rv); + + rv = Init(folder, baseMessageURI, db, pathSpec); + if (NS_SUCCEEDED(rv)) + rv = StartCompacting(); + + if (baseMessageURI) + nsCRT::free(baseMessageURI); + + return rv; +} + nsresult nsFolderCompactState::Init(nsIMsgFolder *folder, const char *baseMsgUri, nsIMsgDatabase *db, nsIFileSpec *pathSpec) @@ -197,10 +278,8 @@ nsFolderCompactState::FinishCompact() nsCOMPtr parentFolder; nsCOMPtr folderInfo; nsFileSpec fileSpec; - PRUint32 flags; // get leaf name and database name of the folder - m_folder->GetFlags(&flags); rv = m_folder->GetPath(getter_AddRefs(pathSpec)); pathSpec->GetFileSpec(&fileSpec); @@ -229,7 +308,6 @@ nsFolderCompactState::FinishCompact() // close down database of the original folder and remove the folder node // and all it's message node from the tree m_folder->ForceDBClosed(); - // remove the old folder and database fileSpec.Delete(PR_FALSE); summarySpec.Delete(PR_FALSE); @@ -238,6 +316,22 @@ nsFolderCompactState::FinishCompact() m_fileSpec.Rename((const char*) idlName); newSummarySpec.Rename(dbName); + if (m_compactAll) + { + m_folderIndex++; + PRUint32 cnt=0; + rv = m_folderArray->Count(&cnt); + NS_ENSURE_SUCCESS(rv,rv); + if (m_folderIndex == cnt) + return rv; + + nsCOMPtr supports = getter_AddRefs(m_folderArray->ElementAt(m_folderIndex)); + nsCOMPtr folder = do_QueryInterface(supports, &rv); + + if (NS_SUCCEEDED(rv) && folder) + CompactHelper(folder); + } + return rv; } diff --git a/mozilla/mailnews/base/src/nsMsgFolderCompactor.h b/mozilla/mailnews/base/src/nsMsgFolderCompactor.h index 965c537cc15..7366ffe86e5 100644 --- a/mozilla/mailnews/base/src/nsMsgFolderCompactor.h +++ b/mozilla/mailnews/base/src/nsMsgFolderCompactor.h @@ -45,6 +45,7 @@ public: // nsIFileSpec *pathSpec); // virtual nsresult FinishCompact(); virtual nsresult InitDB(nsIMsgDatabase *db); + nsresult CompactHelper(nsIMsgFolder *folder); nsresult GetMessage(nsIMessage **message); nsresult BuildMessageURI(const char *baseURI, PRUint32 key, nsCString& uri); @@ -62,6 +63,10 @@ public: nsresult m_status; // the status of the copying operation nsIMsgMessageService* m_messageService; // message service for copying // message + nsCOMPtr m_folderArray; // to store all the folders in case of compact all + PRUint32 m_folderIndex; // tells which folder to compact in case of compact all + PRBool m_compactAll; //flag for compact all + }; class nsOfflineStoreCompactState : public nsFolderCompactState diff --git a/mozilla/mailnews/base/src/nsMsgFolderDataSource.cpp b/mozilla/mailnews/base/src/nsMsgFolderDataSource.cpp index 5b56f255188..7b564b6b435 100644 --- a/mozilla/mailnews/base/src/nsMsgFolderDataSource.cpp +++ b/mozilla/mailnews/base/src/nsMsgFolderDataSource.cpp @@ -67,6 +67,7 @@ nsIRDFResource* nsMsgFolderDataSource::kNC_CanSubscribe = nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_CanFileMessages = nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_CanCreateSubfolders = nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_CanRename = nsnull; +nsIRDFResource* nsMsgFolderDataSource::kNC_CanCompact = nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_TotalMessages= nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_TotalUnreadMessages= nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_Charset = nsnull; @@ -87,6 +88,7 @@ nsIRDFResource* nsMsgFolderDataSource::kNC_CopyFolder= nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_MoveFolder= nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_MarkAllMessagesRead= nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_Compact= nsnull; +nsIRDFResource* nsMsgFolderDataSource::kNC_CompactAll= nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_Rename= nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_EmptyTrash= nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_DownloadFlagged= nsnull; @@ -120,6 +122,7 @@ nsMsgFolderDataSource::nsMsgFolderDataSource() rdf->GetResource(NC_RDF_CANFILEMESSAGES, &kNC_CanFileMessages); rdf->GetResource(NC_RDF_CANCREATESUBFOLDERS, &kNC_CanCreateSubfolders); rdf->GetResource(NC_RDF_CANRENAME, &kNC_CanRename); + rdf->GetResource(NC_RDF_CANCOMPACT, &kNC_CanCompact); rdf->GetResource(NC_RDF_TOTALMESSAGES, &kNC_TotalMessages); rdf->GetResource(NC_RDF_TOTALUNREADMESSAGES, &kNC_TotalUnreadMessages); rdf->GetResource(NC_RDF_CHARSET, &kNC_Charset); @@ -140,6 +143,7 @@ nsMsgFolderDataSource::nsMsgFolderDataSource() rdf->GetResource(NC_RDF_MARKALLMESSAGESREAD, &kNC_MarkAllMessagesRead); rdf->GetResource(NC_RDF_COMPACT, &kNC_Compact); + rdf->GetResource(NC_RDF_COMPACTALL, &kNC_CompactAll); rdf->GetResource(NC_RDF_RENAME, &kNC_Rename); rdf->GetResource(NC_RDF_EMPTYTRASH, &kNC_EmptyTrash); rdf->GetResource(NC_RDF_DOWNLOADFLAGGED, &kNC_DownloadFlagged); @@ -176,6 +180,7 @@ nsMsgFolderDataSource::~nsMsgFolderDataSource (void) NS_RELEASE2(kNC_CanFileMessages, refcnt); NS_RELEASE2(kNC_CanCreateSubfolders, refcnt); NS_RELEASE2(kNC_CanRename, refcnt); + NS_RELEASE2(kNC_CanCompact, refcnt); NS_RELEASE2(kNC_TotalMessages, refcnt); NS_RELEASE2(kNC_TotalUnreadMessages, refcnt); NS_RELEASE2(kNC_Charset, refcnt); @@ -195,6 +200,7 @@ nsMsgFolderDataSource::~nsMsgFolderDataSource (void) NS_RELEASE2(kNC_MoveFolder, refcnt); NS_RELEASE2(kNC_MarkAllMessagesRead, refcnt); NS_RELEASE2(kNC_Compact, refcnt); + NS_RELEASE2(kNC_CompactAll, refcnt); NS_RELEASE2(kNC_Rename, refcnt); NS_RELEASE2(kNC_EmptyTrash, refcnt); NS_RELEASE2(kNC_DownloadFlagged, refcnt); @@ -392,6 +398,7 @@ NS_IMETHODIMP nsMsgFolderDataSource::GetTargets(nsIRDFResource* source, (kNC_CanFileMessages == property) || (kNC_CanCreateSubfolders == property) || (kNC_CanRename == property) || + (kNC_CanCompact == property) || (kNC_ServerType == property) || (kNC_NoSelect == property) ) { @@ -477,6 +484,7 @@ nsMsgFolderDataSource::HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, aArc == kNC_CanFileMessages || aArc == kNC_CanCreateSubfolders || aArc == kNC_CanRename || + aArc == kNC_CanCompact || aArc == kNC_TotalMessages || aArc == kNC_TotalUnreadMessages || aArc == kNC_Charset || @@ -533,6 +541,7 @@ nsMsgFolderDataSource::getFolderArcLabelsOut(nsISupportsArray **arcs) (*arcs)->AppendElement(kNC_CanFileMessages); (*arcs)->AppendElement(kNC_CanCreateSubfolders); (*arcs)->AppendElement(kNC_CanRename); + (*arcs)->AppendElement(kNC_CanCompact); (*arcs)->AppendElement(kNC_TotalMessages); (*arcs)->AppendElement(kNC_TotalUnreadMessages); (*arcs)->AppendElement(kNC_Charset); @@ -572,6 +581,7 @@ nsMsgFolderDataSource::GetAllCommands(nsIRDFResource* source, cmds->AppendElement(kNC_MoveFolder); cmds->AppendElement(kNC_MarkAllMessagesRead); cmds->AppendElement(kNC_Compact); + cmds->AppendElement(kNC_CompactAll); cmds->AppendElement(kNC_Rename); cmds->AppendElement(kNC_EmptyTrash); cmds->AppendElement(kNC_DownloadFlagged); @@ -617,6 +627,7 @@ nsMsgFolderDataSource::IsCommandEnabled(nsISupportsArray/**/* aS (aCommand == kNC_GetNewMessages) || (aCommand == kNC_MarkAllMessagesRead) || (aCommand == kNC_Compact) || + (aCommand == kNC_CompactAll) || (aCommand == kNC_Rename) || (aCommand == kNC_EmptyTrash) || (aCommand == kNC_DownloadFlagged) )) @@ -690,6 +701,10 @@ nsMsgFolderDataSource::DoCommand(nsISupportsArray/**/* aSources, { rv = folder->Compact(nsnull); } + else if ((aCommand == kNC_CompactAll)) + { + rv = folder->CompactAll(nsnull); + } else if ((aCommand == kNC_EmptyTrash)) { rv = folder->EmptyTrash(mWindow, nsnull); @@ -908,6 +923,8 @@ nsresult nsMsgFolderDataSource::createFolderNode(nsIMsgFolder* folder, rv = createFolderCanCreateSubfoldersNode(folder, target); else if ((kNC_CanRename == property)) rv = createFolderCanRenameNode(folder, target); + else if ((kNC_CanCompact == property)) + rv = createFolderCanCompactNode(folder, target); else if ((kNC_TotalMessages == property)) rv = createTotalMessagesNode(folder, target); else if ((kNC_TotalUnreadMessages == property)) @@ -1192,6 +1209,25 @@ nsMsgFolderDataSource::createFolderCanRenameNode(nsIMsgFolder* folder, return NS_OK; } +nsresult +nsMsgFolderDataSource::createFolderCanCompactNode(nsIMsgFolder* folder, + nsIRDFNode **target) +{ + nsresult rv; + PRBool canCompact; + rv = folder->GetCanCompact(&canCompact); + if (NS_FAILED(rv)) return rv; + + *target = nsnull; + + if (canCompact) + *target = kTrueLiteral; + else + *target = kFalseLiteral; + NS_IF_ADDREF(*target); + return NS_OK; +} + nsresult nsMsgFolderDataSource::createTotalMessagesNode(nsIMsgFolder *folder, @@ -1724,6 +1760,7 @@ nsresult nsMsgFolderDataSource::DoFolderHasAssertion(nsIMsgFolder *folder, (kNC_CanFileMessages == property) || (kNC_CanCreateSubfolders == property) || (kNC_CanRename == property) || + (kNC_CanCompact == property) || (kNC_TotalMessages == property) || (kNC_TotalUnreadMessages == property) || (kNC_Charset == property) || diff --git a/mozilla/mailnews/base/src/nsMsgFolderDataSource.h b/mozilla/mailnews/base/src/nsMsgFolderDataSource.h index 26bc131f961..f94549cc7ae 100644 --- a/mozilla/mailnews/base/src/nsMsgFolderDataSource.h +++ b/mozilla/mailnews/base/src/nsMsgFolderDataSource.h @@ -128,6 +128,8 @@ protected: nsIRDFNode **target); nsresult createFolderCanRenameNode(nsIMsgFolder *folder, nsIRDFNode **target); + nsresult createFolderCanCompactNode(nsIMsgFolder *folder, + nsIRDFNode **target); nsresult createTotalMessagesNode(nsIMsgFolder *folder, nsIRDFNode **target); nsresult createUnreadMessagesNode(nsIMsgFolder *folder, nsIRDFNode **target); nsresult createCharsetNode(nsIMsgFolder *folder, nsIRDFNode **target); @@ -196,6 +198,7 @@ protected: static nsIRDFResource* kNC_CanFileMessages; static nsIRDFResource* kNC_CanCreateSubfolders; static nsIRDFResource* kNC_CanRename; + static nsIRDFResource* kNC_CanCompact; static nsIRDFResource* kNC_TotalMessages; static nsIRDFResource* kNC_TotalUnreadMessages; static nsIRDFResource* kNC_Charset; @@ -216,6 +219,7 @@ protected: static nsIRDFResource* kNC_MoveFolder; static nsIRDFResource* kNC_MarkAllMessagesRead; static nsIRDFResource* kNC_Compact; + static nsIRDFResource* kNC_CompactAll; static nsIRDFResource* kNC_Rename; static nsIRDFResource* kNC_EmptyTrash; static nsIRDFResource* kNC_DownloadFlagged; diff --git a/mozilla/mailnews/base/src/nsMsgRDFUtils.h b/mozilla/mailnews/base/src/nsMsgRDFUtils.h index efe584bd8fd..63e51669bda 100644 --- a/mozilla/mailnews/base/src/nsMsgRDFUtils.h +++ b/mozilla/mailnews/base/src/nsMsgRDFUtils.h @@ -71,6 +71,7 @@ typedef struct _nsMsgRDFNotification { #define NC_RDF_CANFILEMESSAGES NC_NAMESPACE_URI "CanFileMessages" #define NC_RDF_CANCREATESUBFOLDERS NC_NAMESPACE_URI "CanCreateSubfolders" #define NC_RDF_CANRENAME NC_NAMESPACE_URI "CanRename" +#define NC_RDF_CANCOMPACT NC_NAMESPACE_URI "CanCompact" #define NC_RDF_TOTALMESSAGES NC_NAMESPACE_URI "TotalMessages" #define NC_RDF_TOTALUNREADMESSAGES NC_NAMESPACE_URI "TotalUnreadMessages" #define NC_RDF_CHARSET NC_NAMESPACE_URI "Charset" @@ -107,6 +108,7 @@ typedef struct _nsMsgRDFNotification { #define NC_RDF_MARKALLMESSAGESREAD NC_NAMESPACE_URI "MarkAllMessagesRead" #define NC_RDF_MARKTHREADREAD NC_NAMESPACE_URI "MarkThreadRead" #define NC_RDF_COMPACT NC_NAMESPACE_URI "Compact" +#define NC_RDF_COMPACTALL NC_NAMESPACE_URI "CompactAll" #define NC_RDF_RENAME NC_NAMESPACE_URI "Rename" #define NC_RDF_EMPTYTRASH NC_NAMESPACE_URI "EmptyTrash" #define NC_RDF_DOWNLOADFLAGGED NC_NAMESPACE_URI "DownloadFlaggedMessages" diff --git a/mozilla/mailnews/base/util/nsMsgFolder.cpp b/mozilla/mailnews/base/util/nsMsgFolder.cpp index e138956e900..b19a0768105 100644 --- a/mozilla/mailnews/base/util/nsMsgFolder.cpp +++ b/mozilla/mailnews/base/util/nsMsgFolder.cpp @@ -807,6 +807,17 @@ nsMsgFolder::GetCanRename(PRBool *aResult) return NS_OK; } +NS_IMETHODIMP +nsMsgFolder::GetCanCompact(PRBool *aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + PRBool isServer = PR_FALSE; + nsresult rv = GetIsServer(&isServer); + NS_ENSURE_SUCCESS(rv,rv); + *aResult = !isServer; //servers cannot be compacted --> 4.x + return NS_OK; +} NS_IMETHODIMP nsMsgFolder::GetPrettyName(PRUnichar ** name) @@ -1178,6 +1189,12 @@ NS_IMETHODIMP nsMsgFolder::Compact(nsIUrlListener *aListener) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP nsMsgFolder::CompactAll(nsIUrlListener *aListener) +{ + NS_ASSERTION(PR_FALSE, "should be overridden by child class"); + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsMsgFolder::EmptyTrash(nsIMsgWindow *msgWindow, nsIUrlListener *aListener) { return NS_ERROR_NOT_IMPLEMENTED; @@ -2489,4 +2506,41 @@ NS_IMETHODIMP nsMsgFolder::GetMessageHeader(nsMsgKey msgKey, nsIMsgDBHdr **aMsgH return rv; } +// this gets the deep sub-folders too, e.g., the children of the children +NS_IMETHODIMP nsMsgFolder::ListDescendents(nsISupportsArray *descendents) +{ + NS_ENSURE_ARG(descendents); + PRUint32 cnt; + nsresult rv = mSubFolders->Count(&cnt); + NS_ENSURE_SUCCESS(rv,rv); + for (PRUint32 index = 0; index < cnt; index++) + { + nsresult rv; + nsCOMPtr supports = getter_AddRefs(mSubFolders->ElementAt(index)); + nsCOMPtr child(do_QueryInterface(supports, &rv)); + + if (NS_SUCCEEDED(rv)) + { + rv = descendents->AppendElement(supports); + if(NS_SUCCEEDED(rv)) + { + rv = child->ListDescendents(descendents); // recurse + } + } + } + return rv; +} + +NS_IMETHODIMP nsMsgFolder::GetBaseMessageURI(char **baseMessageURI) +{ + NS_ENSURE_ARG_POINTER(baseMessageURI); + + if (mBaseMessageURI) + { + *baseMessageURI = nsCRT::strdup(mBaseMessageURI); + return NS_OK; + } + else + return NS_ERROR_FAILURE; +} diff --git a/mozilla/mailnews/base/util/nsMsgFolder.h b/mozilla/mailnews/base/util/nsMsgFolder.h index 637fbe8e2cd..441a4ffbcd4 100644 --- a/mozilla/mailnews/base/util/nsMsgFolder.h +++ b/mozilla/mailnews/base/util/nsMsgFolder.h @@ -89,6 +89,7 @@ hasMessages); NS_IMETHOD GetCanFileMessages(PRBool *aCanFileMessages); NS_IMETHOD GetCanCreateSubfolders(PRBool *aCanCreateSubfolders); NS_IMETHOD GetCanRename(PRBool *aCanRename); + NS_IMETHOD GetCanCompact(PRBool *aCanCompact); NS_IMETHOD GetFilterList(nsIMsgFilterList **aFilterList); NS_IMETHOD ForceDBClosed(void); NS_IMETHOD Delete(void); @@ -99,6 +100,7 @@ hasMessages); NS_IMETHOD CreateSubfolder(const PRUnichar *folderName, nsIMsgWindow *msgWindow); NS_IMETHOD AddSubfolder(nsAutoString *folderName, nsIMsgFolder **newFolder); NS_IMETHOD Compact(nsIUrlListener *aListener); + NS_IMETHOD CompactAll(nsIUrlListener *aListener); NS_IMETHOD EmptyTrash(nsIMsgWindow *msgWindow, nsIUrlListener *aListener); NS_IMETHOD Rename(const PRUnichar *name, nsIMsgWindow *msgWindow); NS_IMETHOD Adopt(nsIMsgFolder *srcFolder, PRUint32 *outPos); @@ -166,6 +168,7 @@ hasMessages); NS_IMETHOD GetPath(nsIFileSpec * *aPath); NS_IMETHOD SetPath(nsIFileSpec * aPath); + NS_IMETHOD GetBaseMessageURI (char ** baseMessageURI); NS_IMETHOD MarkMessagesRead(nsISupportsArray *messages, PRBool markRead); NS_IMETHOD AddMessageDispositionState(nsIMessage *aMessage, nsMsgDispositionState aDispositionFlag); NS_IMETHOD MarkAllMessagesRead(void); diff --git a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp index 02db955069c..68c131dacef 100644 --- a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp @@ -1013,6 +1013,11 @@ NS_IMETHODIMP nsImapMailFolder::Compact(nsIUrlListener *aListener) return rv; } +NS_IMETHODIMP nsImapMailFolder::CompactAll(nsIUrlListener *aListener) +{ +return Compact(aListener); //for now +} + NS_IMETHODIMP nsImapMailFolder::EmptyTrash(nsIMsgWindow *msgWindow, nsIUrlListener *aListener) { diff --git a/mozilla/mailnews/imap/src/nsImapMailFolder.h b/mozilla/mailnews/imap/src/nsImapMailFolder.h index 5a3b809c667..016910306be 100644 --- a/mozilla/mailnews/imap/src/nsImapMailFolder.h +++ b/mozilla/mailnews/imap/src/nsImapMailFolder.h @@ -126,6 +126,7 @@ public: NS_IMETHODIMP CreateStorageIfMissing(nsIUrlListener* urlListener); NS_IMETHOD Compact(nsIUrlListener *aListener); + NS_IMETHOD CompactAll(nsIUrlListener *aListener); NS_IMETHOD EmptyTrash(nsIMsgWindow *msgWindow, nsIUrlListener *aListener); NS_IMETHOD Delete (); NS_IMETHOD Rename (const PRUnichar *newName, nsIMsgWindow *msgWindow); diff --git a/mozilla/mailnews/local/src/nsLocalMailFolder.cpp b/mozilla/mailnews/local/src/nsLocalMailFolder.cpp index 230af1d0a5f..08cfaf9c2b9 100644 --- a/mozilla/mailnews/local/src/nsLocalMailFolder.cpp +++ b/mozilla/mailnews/local/src/nsLocalMailFolder.cpp @@ -843,6 +843,17 @@ nsMsgLocalMailFolder::CreateSubfolder(const PRUnichar *folderName, nsIMsgWindow return rv; } +NS_IMETHODIMP nsMsgLocalMailFolder::CompactAll(nsIUrlListener *aListener) +{ + nsresult rv; + nsCOMPtr folderCompactor = do_CreateInstance(NS_MSGLOCALFOLDERCOMPACTOR_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv) && folderCompactor) + { + rv=folderCompactor->InitCompactAll(this); // start with each folder compaction from there + } + return rv; +} + // **** jefft -- needs to provide nsIMsgWindow for the compact status // update; come back later NS_IMETHODIMP nsMsgLocalMailFolder::Compact(nsIUrlListener *aListener) diff --git a/mozilla/mailnews/local/src/nsLocalMailFolder.h b/mozilla/mailnews/local/src/nsLocalMailFolder.h index a225eba2d47..1e7a49cb043 100644 --- a/mozilla/mailnews/local/src/nsLocalMailFolder.h +++ b/mozilla/mailnews/local/src/nsLocalMailFolder.h @@ -106,6 +106,7 @@ public: NS_IMETHOD AddSubfolder(nsAutoString *folderName, nsIMsgFolder** newFolder); NS_IMETHOD Compact(nsIUrlListener *aListener); + NS_IMETHOD CompactAll(nsIUrlListener *aListener); NS_IMETHOD EmptyTrash(nsIMsgWindow *msgWindow, nsIUrlListener *aListener); NS_IMETHOD Delete (); NS_IMETHOD DeleteSubFolders(nsISupportsArray *folders, nsIMsgWindow *msgWindow); diff --git a/mozilla/mailnews/news/src/nsNewsFolder.cpp b/mozilla/mailnews/news/src/nsNewsFolder.cpp index af861686e1d..633eb175a97 100644 --- a/mozilla/mailnews/news/src/nsNewsFolder.cpp +++ b/mozilla/mailnews/news/src/nsNewsFolder.cpp @@ -453,6 +453,15 @@ nsMsgNewsFolder::GetCanRename(PRBool *aResult) return NS_OK; } +NS_IMETHODIMP +nsMsgNewsFolder::GetCanCompact(PRBool *aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + *aResult = PR_FALSE; + // you can't compact a news server or a news group + return NS_OK; +} + NS_IMETHODIMP nsMsgNewsFolder::GetMessages(nsIMsgWindow *aMsgWindow, nsISimpleEnumerator* *result) { diff --git a/mozilla/mailnews/news/src/nsNewsFolder.h b/mozilla/mailnews/news/src/nsNewsFolder.h index a4a4298bd51..6b89a74373c 100644 --- a/mozilla/mailnews/news/src/nsNewsFolder.h +++ b/mozilla/mailnews/news/src/nsNewsFolder.h @@ -92,6 +92,7 @@ public: NS_IMETHOD GetCanFileMessages(PRBool *aResult); NS_IMETHOD GetCanCreateSubfolders(PRBool *aResult); NS_IMETHOD GetCanRename(PRBool *aResult); + NS_IMETHOD GetCanCompact(PRBool *aResult); NS_IMETHOD OnReadChanged(nsIDBChangeListener * aInstigator); NS_IMETHOD Compact(nsIUrlListener *aListener);