Bug 1134944 - Move getSummaryFile to folder so that maildir can be selected in imap mail setup, r=jcranmer, a=rkent
authorR Kent James <kent@caspia.com>
Thu, 05 Mar 2015 16:12:35 -0800
changeset 25777 90580bc940ab6f738a1e51158c027cc12a2fdefd
parent 25776 136e574bccc5b726f6b5787697e34f2854e50a95
child 25778 68905e000342adadc1edea8aac6d5ee6253c7e74
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjcranmer, rkent
bugs1134944
Bug 1134944 - Move getSummaryFile to folder so that maildir can be selected in imap mail setup, r=jcranmer, a=rkent
mailnews/base/public/nsIMsgFolder.idl
mailnews/base/public/nsIMsgPluggableStore.idl
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/base/util/nsMsgDBFolder.h
mailnews/db/msgdb/src/nsMsgDatabase.cpp
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/local/src/nsMsgBrkMBoxStore.cpp
mailnews/local/src/nsMsgMaildirStore.cpp
mailnews/local/test/unit/test_streamHeaders.js
--- a/mailnews/base/public/nsIMsgFolder.idl
+++ b/mailnews/base/public/nsIMsgFolder.idl
@@ -25,17 +25,17 @@ interface nsIArray;
 interface nsIMutableArray;
 interface nsIMsgPluggableStore;
 
 typedef long nsMsgBiffState;
 
 // enumerated type for determining if a message has been replied to, forwarded, etc.
 typedef long nsMsgDispositionState;
 
-[scriptable, uuid(d277b1d2-e820-42f9-8706-914df7d429b3)]
+[scriptable, uuid(E065F5CC-A358-4258-96EB-99F944162D32)]
 interface nsIMsgFolder : nsISupports {
 
   const nsMsgBiffState nsMsgBiffState_NewMail = 0; // User has new mail waiting.
   const nsMsgBiffState nsMsgBiffState_NoMail =  1; // No new mail is waiting.
   const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is new mail.
 
   /// Returns an enumerator containing the messages within the current database.
   readonly attribute nsISimpleEnumerator messages;
@@ -450,16 +450,19 @@ interface nsIMsgFolder : nsISupports {
    */
   attribute boolean gettingNewMessages;
 
   /**
    * local path of this folder
    */
   attribute nsIFile filePath;
 
+  /// an nsIFile corresponding to the .msf file.
+  readonly attribute nsIFile summaryFile;
+
   readonly attribute ACString baseMessageURI;
   ACString generateMessageURI(in nsMsgKey msgKey);
 
   const nsMsgDispositionState nsMsgDispositionState_None = -1;
   const nsMsgDispositionState nsMsgDispositionState_Replied = 0;
   const nsMsgDispositionState nsMsgDispositionState_Forwarded = 1;
   void addMessageDispositionState(in nsIMsgDBHdr aMessage,
                                   in nsMsgDispositionState aDispositionFlag);
--- a/mailnews/base/public/nsIMsgPluggableStore.idl
+++ b/mailnews/base/public/nsIMsgPluggableStore.idl
@@ -12,17 +12,17 @@ interface nsIMsgDBHdr;
 interface nsIMsgWindow;
 interface nsIOutputStream;
 interface nsIInputStream;
 interface nsIArray;
 interface nsIUrlListener;
 interface nsIMsgDatabase;
 interface nsITransaction;
 
-[scriptable, uuid(2a861ed8-b4c2-4443-8c20-5e8a217a6310)]
+[scriptable, uuid(F732CE58-E540-4dc4-B803-9456056EBEFC)]
 
 /**
  * Pluggable message store interface. Each incoming server can have a different
  * message store.
  * All methods are synchronous unless otherwise specified.
  */
 interface nsIMsgPluggableStore : nsISupports {
   /**
@@ -46,25 +46,16 @@ interface nsIMsgPluggableStore : nsISupp
    * @param aFolderName leaf name of folder.
    * @return newly created folder.
    * @exception NS_MSG_FOLDER_EXISTS If the child exists.
    * @exception NS_MSG_CANT_CREATE_FOLDER for other errors.
    */
   nsIMsgFolder createFolder(in nsIMsgFolder aParent, in AString aFolderName);
 
   /**
-   * Get an nsIFile corresponding to the .msf file. This allows stores
-   * to put the .msf files where they want.
-   *
-   * @param aFolder folder we want summary file for
-   * @return summary file
-   */
-  nsIFile getSummaryFile(in nsIMsgFolder aFolder);
-
-  /**
    * Delete the passed in folder. This is a real delete, not a move
    * to the trash folder.
    *
    * @param aFolder folder to delete
    */
   void deleteFolder(in nsIMsgFolder aFolder);
 
   /**
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -738,24 +738,16 @@ NS_IMETHODIMP nsMsgDBFolder::GetMsgStore
 {
   NS_ENSURE_ARG_POINTER(aStore);
   nsCOMPtr<nsIMsgIncomingServer> server;
   nsresult rv = GetServer(getter_AddRefs(server));
   NS_ENSURE_SUCCESS(rv, NS_MSG_INVALID_OR_MISSING_SERVER);
   return server->GetMsgStore(aStore);
 }
 
-nsresult nsMsgDBFolder::GetSummaryFile(nsIFile** aSummaryFile)
-{
-  nsCOMPtr<nsIMsgPluggableStore> msgStore;
-  nsresult rv = GetMsgStore(getter_AddRefs(msgStore));
-  NS_ENSURE_SUCCESS(rv, rv);
-  return msgStore->GetSummaryFile(this, aSummaryFile);
-}
-
 bool nsMsgDBFolder::VerifyOfflineMessage(nsIMsgDBHdr *msgHdr, nsIInputStream *fileStream)
 {
   nsCOMPtr <nsISeekableStream> seekableStream = do_QueryInterface(fileStream);
   if (seekableStream)
   {
     uint64_t offset;
     msgHdr->GetMessageOffset(&offset);
     nsresult rv = seekableStream->Seek(nsISeekableStream::NS_SEEK_CUR, offset);
@@ -4701,16 +4693,43 @@ nsMsgDBFolder::GetFilePath(nsIFile * *aF
   NS_ENSURE_SUCCESS(rv, rv);
   if (!mPath)
     parseURI(true);
   rv = file->InitWithFile(mPath);
   file.swap(*aFile);
   return NS_OK;
 }
 
+NS_IMETHODIMP nsMsgDBFolder::GetSummaryFile(nsIFile **aSummaryFile)
+{
+  NS_ENSURE_ARG_POINTER(aSummaryFile);
+
+  nsresult rv;
+  nsCOMPtr <nsIFile> newSummaryLocation =
+    do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIFile> pathFile;
+  rv = GetFilePath(getter_AddRefs(pathFile));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  newSummaryLocation->InitWithFile(pathFile);
+
+  nsString fileName;
+  rv = newSummaryLocation->GetLeafName(fileName);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  fileName.Append(NS_LITERAL_STRING(SUMMARY_SUFFIX));
+  rv = newSummaryLocation->SetLeafName(fileName);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  newSummaryLocation.forget(aSummaryFile);
+  return NS_OK;
+}
+
 NS_IMETHODIMP
 nsMsgDBFolder::MarkMessagesRead(nsIArray *messages, bool markRead)
 {
   uint32_t count;
   nsresult rv;
 
   rv = messages->GetLength(&count);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/mailnews/base/util/nsMsgDBFolder.h
+++ b/mailnews/base/util/nsMsgDBFolder.h
@@ -121,18 +121,16 @@ protected:
   nsresult GetFolderCacheKey(nsIFile **aFile, bool createDBIfMissing = false);
   nsresult GetFolderCacheElemFromFile(nsIFile *file, nsIMsgFolderCacheElement **cacheElement);
   nsresult AddDirectorySeparator(nsIFile *path);
   nsresult CheckIfFolderExists(const nsAString& newFolderName, nsIMsgFolder *parentFolder, nsIMsgWindow *msgWindow);
   bool     ConfirmAutoFolderRename(nsIMsgWindow *aMsgWindow,
                                    const nsString& aOldName,
                                    const nsString& aNewName);
 
-  nsresult GetSummaryFile(nsIFile** aSummaryFile);
-
   // Returns true if: a) there is no need to prompt or b) the user is already
   // logged in or c) the user logged in successfully.
   static bool PromptForMasterPasswordIfNecessary();
 
   // offline support methods.
   nsresult StartNewOfflineMessage();
   nsresult WriteStartOfNewLocalMessage();
   nsresult EndNewOfflineMessage();
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -92,25 +92,22 @@ nsMsgDBService::~nsMsgDBService()
 #endif
 }
 
 NS_IMETHODIMP nsMsgDBService::OpenFolderDB(nsIMsgFolder *aFolder,
                                            bool aLeaveInvalidDB,
                                            nsIMsgDatabase **_retval)
 {
   NS_ENSURE_ARG(aFolder);
-  nsCOMPtr<nsIMsgPluggableStore> msgStore;
   nsCOMPtr<nsIMsgIncomingServer> incomingServer;
-  nsCOMPtr <nsIFile> summaryFilePath;
-
   nsresult rv = aFolder->GetServer(getter_AddRefs(incomingServer));
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = aFolder->GetMsgStore(getter_AddRefs(msgStore));
-  NS_ENSURE_SUCCESS(rv, rv);
-  rv = msgStore->GetSummaryFile(aFolder, getter_AddRefs(summaryFilePath));
+
+  nsCOMPtr<nsIFile> summaryFilePath;
+  rv = aFolder->GetSummaryFile(getter_AddRefs(summaryFilePath));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsMsgDatabase *cacheDB = FindInCache(summaryFilePath);
   if (cacheDB)
   {
     // this db could have ended up in the folder cache w/o an m_folder pointer via
     // OpenMailDBFromFile. If so, take this chance to fix the folder.
     if (!cacheDB->m_folder)
@@ -162,22 +159,18 @@ NS_IMETHODIMP nsMsgDBService::OpenFolder
 }
 
 NS_IMETHODIMP nsMsgDBService::AsyncOpenFolderDB(nsIMsgFolder *aFolder,
                                                 bool aLeaveInvalidDB,
                                                 nsIMsgDatabase **_retval)
 {
   NS_ENSURE_ARG(aFolder);
 
-  nsCOMPtr<nsIMsgPluggableStore> msgStore;
-  nsresult rv = aFolder->GetMsgStore(getter_AddRefs(msgStore));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   nsCOMPtr <nsIFile> summaryFilePath;
-  rv = msgStore->GetSummaryFile(aFolder, getter_AddRefs(summaryFilePath));
+  nsresult rv = aFolder->GetSummaryFile(getter_AddRefs(summaryFilePath));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsMsgDatabase *cacheDB = FindInCache(summaryFilePath);
   if (cacheDB)
   {
     // this db could have ended up in the folder cache w/o an m_folder pointer via
     // OpenMailDBFromFile. If so, take this chance to fix the folder.
     if (!cacheDB->m_folder)
@@ -376,21 +369,18 @@ NS_IMETHODIMP nsMsgDBService::CreateNewD
                                           nsIMsgDatabase **_retval)
 {
   NS_ENSURE_ARG(aFolder);
   
   nsCOMPtr <nsIMsgIncomingServer> incomingServer;
   nsresult rv = aFolder->GetServer(getter_AddRefs(incomingServer));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIMsgPluggableStore> msgStore;
-  rv = aFolder->GetMsgStore(getter_AddRefs(msgStore));
-  NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIFile> summaryFilePath;
-  rv = msgStore->GetSummaryFile(aFolder, getter_AddRefs(summaryFilePath));
+  rv = aFolder->GetSummaryFile(getter_AddRefs(summaryFilePath));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCString localStoreType;
   incomingServer->GetLocalStoreType(localStoreType);
   nsAutoCString dbContractID(NS_MSGDB_CONTRACTID);
   dbContractID.Append(localStoreType.get());
   
   nsCOMPtr <nsIMsgDatabase> msgDB = do_CreateInstance(dbContractID.get(), &rv);
@@ -442,22 +432,18 @@ NS_IMETHODIMP nsMsgDBService::Unregister
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP nsMsgDBService::CachedDBForFolder(nsIMsgFolder *aFolder, nsIMsgDatabase **aRetDB)
 {
   NS_ENSURE_ARG_POINTER(aFolder);
   NS_ENSURE_ARG_POINTER(aRetDB);
 
-  nsCOMPtr<nsIMsgPluggableStore> msgStore;
-  nsresult rv = aFolder->GetMsgStore(getter_AddRefs(msgStore));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   nsCOMPtr<nsIFile> summaryFilePath;
-  rv = msgStore->GetSummaryFile(aFolder, getter_AddRefs(summaryFilePath));
+  nsresult rv = aFolder->GetSummaryFile(getter_AddRefs(summaryFilePath));
   NS_ENSURE_SUCCESS(rv, rv);
 
   *aRetDB = FindInCache(summaryFilePath);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgDBService::ForceFolderDBClosed(nsIMsgFolder *aFolder)
 {
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -764,17 +764,17 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Dele
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIMsgPluggableStore> msgStore;
 
   rv = server->GetMsgStore(getter_AddRefs(msgStore));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr <nsIFile> summaryFile;
-  rv = msgStore->GetSummaryFile(this, getter_AddRefs(summaryFile));
+  rv = GetSummaryFile(getter_AddRefs(summaryFile));
   NS_ENSURE_SUCCESS(rv, rv);
 
   //Clean up .sbd folder if it exists.
   // Remove summary file.
   summaryFile->Remove(false);
 
   return msgStore->DeleteFolder(this);
 }
--- a/mailnews/local/src/nsMsgBrkMBoxStore.cpp
+++ b/mailnews/local/src/nsMsgBrkMBoxStore.cpp
@@ -134,41 +134,16 @@ NS_IMETHODIMP nsMsgBrkMBoxStore::CreateF
       path->Remove(false);
       rv = NS_MSG_CANT_CREATE_FOLDER;
     }
   }
   child.forget(aResult);
   return rv;
 }
 
-NS_IMETHODIMP nsMsgBrkMBoxStore::GetSummaryFile(nsIMsgFolder *aFolder,
-                                                nsIFile **aSummaryFile)
-{
-  NS_ENSURE_ARG_POINTER(aFolder);
-  NS_ENSURE_ARG_POINTER(aSummaryFile);
-
-  nsresult rv;
-  nsCOMPtr<nsIFile> newSummaryLocation;
-  rv = aFolder->GetFilePath(getter_AddRefs(newSummaryLocation));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsString fileName;
-
-  rv = newSummaryLocation->GetLeafName(fileName);
-  if (NS_FAILED(rv))
-    return rv;
-
-  fileName.Append(NS_LITERAL_STRING(SUMMARY_SUFFIX));
-  rv = newSummaryLocation->SetLeafName(fileName);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  newSummaryLocation.forget(aSummaryFile);
-  return NS_OK;
-}
-
 // Get the current attributes of the mbox file, corrected for caching
 void nsMsgBrkMBoxStore::GetMailboxModProperties(nsIMsgFolder *aFolder,
                                                 int64_t *aSize, uint32_t *aDate)
 {
   // We'll simply return 0 on errors.
   *aDate = 0;
   *aSize = 0;
   nsCOMPtr<nsIFile> pathFile;
@@ -358,17 +333,17 @@ NS_IMETHODIMP nsMsgBrkMBoxStore::RenameF
   nsCOMPtr<nsIMsgFolder> parentFolder;
   rv = aFolder->GetParent(getter_AddRefs(parentFolder));
   if (!parentFolder)
     return NS_ERROR_NULL_POINTER;
 
   nsCOMPtr<nsISupports> parentSupport = do_QueryInterface(parentFolder);
 
   nsCOMPtr<nsIFile> oldSummaryFile;
-  rv = GetSummaryFile(aFolder, getter_AddRefs(oldSummaryFile));
+  rv = aFolder->GetSummaryFile(getter_AddRefs(oldSummaryFile));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIFile> dirFile;
   oldPathFile->Clone(getter_AddRefs(dirFile));
 
   if (numChildren > 0)
   {
     rv = CreateDirectoryForFolder(dirFile);
--- a/mailnews/local/src/nsMsgMaildirStore.cpp
+++ b/mailnews/local/src/nsMsgMaildirStore.cpp
@@ -319,45 +319,16 @@ NS_IMETHODIMP nsMsgMaildirStore::SetSumm
 {
   NS_ENSURE_ARG_POINTER(aFolder);
   NS_ENSURE_ARG_POINTER(aDB);
   nsCOMPtr<nsIDBFolderInfo> dbFolderInfo;
   aDB->GetDBFolderInfo(getter_AddRefs(dbFolderInfo));
   return dbFolderInfo->SetBooleanProperty("maildirValid", aValid);
 }
 
-NS_IMETHODIMP nsMsgMaildirStore::GetSummaryFile(nsIMsgFolder *aFolder,
-                                                nsIFile **aSummaryFile)
-{
-  NS_ENSURE_ARG_POINTER(aFolder);
-  NS_ENSURE_ARG_POINTER(aSummaryFile);
-
-  nsresult rv;
-  nsCOMPtr <nsIFile> newSummaryLocation =
-    do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIFile> pathFile;
-  rv = aFolder->GetFilePath(getter_AddRefs(pathFile));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  newSummaryLocation->InitWithFile(pathFile);
-  nsString fileName;
-
-  rv = newSummaryLocation->GetLeafName(fileName);
-  if (NS_FAILED(rv))
-    return rv;
-  fileName.Append(NS_LITERAL_STRING(SUMMARY_SUFFIX));
-  rv = newSummaryLocation->SetLeafName(fileName);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  NS_IF_ADDREF(*aSummaryFile = newSummaryLocation);
-  return NS_OK;
-}
-
 NS_IMETHODIMP nsMsgMaildirStore::DeleteFolder(nsIMsgFolder *aFolder)
 {
   NS_ENSURE_ARG_POINTER(aFolder);
 
   // Delete Maildir structure
   nsCOMPtr<nsIFile> pathFile;
   nsresult rv = aFolder->GetFilePath(getter_AddRefs(pathFile));
   NS_ENSURE_SUCCESS(rv, rv);
@@ -393,17 +364,17 @@ NS_IMETHODIMP nsMsgMaildirStore::RenameF
     NS_ENSURE_SUCCESS(rv, rv);
     rv = sbdPathFile->InitWithFile(oldPathFile);
     NS_ENSURE_SUCCESS(rv, rv);
     GetDirectoryForFolder(sbdPathFile);
   }
 
   // old summary
   nsCOMPtr<nsIFile> oldSummaryFile;
-  rv = GetSummaryFile(aFolder, getter_AddRefs(oldSummaryFile));
+  rv = aFolder->GetSummaryFile(getter_AddRefs(oldSummaryFile));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Validate new name
   nsAutoString safeName(aNewName);
   NS_MsgHashIfNecessary(safeName);
 
   aFolder->ForceDBClosed();
 
--- a/mailnews/local/test/unit/test_streamHeaders.js
+++ b/mailnews/local/test/unit/test_streamHeaders.js
@@ -66,17 +66,17 @@ function goodStreaming()
 
 // crash from bug 752768
 function badStreaming()
 {
   // try to stream the headers of the last message
   let folder = gHdr.folder;
   let uri = folder.getUriForMsg(gHdr);
 
-  let dbFile = folder.msgStore.getSummaryFile(folder);
+  let dbFile = folder.summaryFile;
   // force invalid database
   folder.msgDatabase.ForceClosed();
   dbFile.remove(false);
   folder.msgDatabase = null;
 
   let messageService = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger)
                                                      .messageServiceFromURI(uri);
   let haveError = false;