Bug 789679 - allow mail folders larger than 4GB in HasSpaceAvailable() based on a pref. r=rkent
authoraceman <acelists@atlas.sk>
Mon, 01 Aug 2016 22:16:30 +0200
changeset 26504 75ff4740fc0f1b558871c7f20a0b804b4e1ff2ea
parent 26503 f48a5c3d3e8424a6cd6c0d7e8ff7a5519804d7bc
child 26505 264ccac9eb403db7b4aeb55d92aa3929c7c51f47
push id353
push userclokep@gmail.com
push dateMon, 23 Jan 2017 21:39:40 +0000
reviewersrkent
bugs789679
Bug 789679 - allow mail folders larger than 4GB in HasSpaceAvailable() based on a pref. r=rkent
mailnews/local/src/nsMsgBrkMBoxStore.cpp
mailnews/local/test/unit/test_over4GBMailboxes.js
mailnews/mailnews.js
--- a/mailnews/local/src/nsMsgBrkMBoxStore.cpp
+++ b/mailnews/local/src/nsMsgBrkMBoxStore.cpp
@@ -29,16 +29,17 @@
 #include "nsMailHeaders.h"
 #include "nsReadLine.h"
 #include "nsParseMailbox.h"
 #include "nsIMailboxService.h"
 #include "nsMsgLocalCID.h"
 #include "nsIMsgFolderCompactor.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
+#include "mozilla/Preferences.h"
 #include "prprf.h"
 #include <cstdlib> // for std::abs(int/long)
 #include <cmath> // for std::abs(float/double)
 
 nsMsgBrkMBoxStore::nsMsgBrkMBoxStore()
 {
 }
 
@@ -167,24 +168,28 @@ NS_IMETHODIMP nsMsgBrkMBoxStore::HasSpac
 {
   NS_ENSURE_ARG_POINTER(aResult);
   NS_ENSURE_ARG_POINTER(aFolder);
 
   nsCOMPtr<nsIFile> pathFile;
   nsresult rv = aFolder->GetFilePath(getter_AddRefs(pathFile));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  // Allow the mbox to only reach 0xFFC00000 = 4 GiB - 4 MiB for now.
-  // This limit can be increased after bug 789679 is fixed.
-  int64_t fileSize;
-  rv = pathFile->GetFileSize(&fileSize);
-  NS_ENSURE_SUCCESS(rv, rv);
-  *aResult = ((fileSize + aSpaceRequested) < 0xFFC00000LL);
-  if (!*aResult)
-    return NS_ERROR_FILE_TOO_BIG;
+  bool allow4GBfolders = mozilla::Preferences::GetBool("mailnews.allowMboxOver4GB", true);
+
+  if (!allow4GBfolders) {
+    // Allow the mbox to only reach 0xFFC00000 = 4 GiB - 4 MiB.
+    int64_t fileSize;
+    rv = pathFile->GetFileSize(&fileSize);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    *aResult = ((fileSize + aSpaceRequested) < 0xFFC00000LL);
+    if (!*aResult)
+      return NS_ERROR_FILE_TOO_BIG;
+  }
 
   *aResult = DiskSpaceAvailableInStore(pathFile, aSpaceRequested);
   if (!*aResult)
     return NS_ERROR_FILE_DISK_FULL;
 
   return NS_OK;
 }
 
--- a/mailnews/local/test/unit/test_over4GBMailboxes.js
+++ b/mailnews/local/test/unit/test_over4GBMailboxes.js
@@ -22,16 +22,18 @@ load("../../../resources/asyncTestUtils.
 load("../../../resources/alertTestUtils.js");
 load("../../../resources/messageGenerator.js");
 load("../../../resources/POP3pump.js");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 Services.prefs.setCharPref("mail.serverDefaultStoreContractID",
                            "@mozilla.org/msgstore/berkeleystore;1");
 
+Services.prefs.setBoolPref("mailnews.allowMboxOver4GB", false);
+
 // If we're running out of memory parsing the folder, lowering the
 // block size might help, though it will slow the test down and consume
 // more disk space.
 var kSparseBlockSize = 102400000;
 var kSizeLimit = 0x100000000; // 4GiB
 var kNearLimit = kSizeLimit - 0x1000000; // -16MiB
 
 var gGotAlert = false;
@@ -264,17 +266,17 @@ function growOver4GiB()
   // that it's out of date.
   gInbox.msgDatabase.ForceClosed();
   gInbox.msgDatabase = null;
   try {
     gInbox.getDatabaseWithReparse(ParseListener_growOver4GiB, gDummyMsgWindow);
   } catch (ex) {
     do_check_eq(ex.result, Cr.NS_ERROR_NOT_INITIALIZED);
   }
-  // Execution continues in copyOver4GiB() when done.
+  // Execution continues in copyIntoOver4GiB() when done.
 }
 
 /**
  * Bug 598104
  * Check that copy operation does not allow to grow a local folder above 4 GiB.
  */
 function copyIntoOver4GiB()
 {
@@ -497,11 +499,12 @@ var CompactListener_compactUnder4GiB =
 };
 
 function endTest()
 {
   MailServices.mailSession.RemoveFolderListener(FListener);
   // Free up disk space - if you want to look at the file after running
   // this test, comment out this line.
   gInbox.filePath.remove(false);
+  Services.prefs.clearUserPref("mailnews.allowMboxOver4GB");
 
   do_test_finished();
 }
--- a/mailnews/mailnews.js
+++ b/mailnews/mailnews.js
@@ -82,16 +82,19 @@ pref("mailnews.headers.showSender", fals
 // be greater than one hour so daylight savings time changes don't affect us.
 // We will still always regenerate .msf files if the file size changes.
 pref("mail.db_timestamp_leeway", 4000);
 // How long should we leave idle db's open, in milliseconds.
 pref("mail.db.idle_limit", 300000);
 // How many db's should we leave open? LRU db's will be closed first
 pref("mail.db.max_open", 30);
 
+// Should we allow folders over 4GB in size?
+pref("mailnews.allowMboxOver4GB", true);
+
 pref("mail.imap.chunk_size",                65536);
 pref("mail.imap.min_chunk_size_threshold",  98304);
 pref("mail.imap.chunk_fast",                2);
 pref("mail.imap.chunk_ideal",               4);
 pref("mail.imap.chunk_add",                 8192);
 pref("mail.imap.hide_other_users",          false);
 pref("mail.imap.hide_unused_namespaces",    true);
 pref("mail.imap.auto_unsubscribe_from_noselect_folders",    true);