Bug 1492889 - Allow extensions to reactivate accounts without restart. r=aceman,jorgk a=jorgk
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Mon, 15 Oct 2018 21:58:29 +0100
changeset 33061 1af8d4fa7627
parent 33060 9ce6347cab62
child 33062 74c68eb741b5
push id386
push userclokep@gmail.com
push dateTue, 23 Oct 2018 00:48:12 +0000
reviewersaceman, jorgk, jorgk
bugs1492889
Bug 1492889 - Allow extensions to reactivate accounts without restart. r=aceman,jorgk a=jorgk
db/mork/src/morkConfig.cpp
mailnews/base/public/nsIMsgAccountManager.idl
mailnews/base/src/nsMsgAccountManager.cpp
mailnews/news/test/unit/test_nntpPassword2.js
--- a/db/mork/src/morkConfig.cpp
+++ b/db/mork/src/morkConfig.cpp
@@ -14,20 +14,17 @@
 #ifndef _MORKCONFIG_
 #include "morkConfig.h"
 #endif
 
 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
 
 void mork_assertion_signal(const char* inMessage)
 {
-#if defined(MORK_WIN) || defined(MORK_MAC)
-  // asm { int 3 }
   NS_ERROR(inMessage);
-#endif /*MORK_WIN*/
 }
 
 #ifdef MORK_PROVIDE_STDLIB
 
 MORK_LIB_IMPL(mork_i4)
 mork_memcmp(const void* inOne, const void* inTwo, mork_size inSize)
 {
   const mork_u1* t = (const mork_u1*) inTwo;
--- a/mailnews/base/public/nsIMsgAccountManager.idl
+++ b/mailnews/base/public/nsIMsgAccountManager.idl
@@ -165,16 +165,25 @@ interface nsIMsgAccountManager : nsISupp
   void createLocalMailAccount();
 
   /* load accounts kicks off the creation of all accounts. You do not need
    * to call this and all accounts should be loaded lazily if you use any
    * of the above.
    */
   void LoadAccounts();
 
+  /**
+   * When the server for an account could not be loaded, typically because the
+   * extension providing it could not be loaded, it is deactivated for a period
+   * of time as documented in nsIMsgAccount.idl. The server is normally only
+   * rechecked at startup but this function can be used to recheck all servers
+   * at any time to avoid having to restart to reactivate an account.
+   */
+  void ReactivateAccounts();
+
   void setSpecialFolders();
 
   void loadVirtualFolders();
 
   /* unload accounts frees all the account manager data structures */
   void UnloadAccounts();
 
   void WriteToFolderCache(in nsIMsgFolderCache folderCache);
--- a/mailnews/base/src/nsMsgAccountManager.cpp
+++ b/mailnews/base/src/nsMsgAccountManager.cpp
@@ -1397,16 +1397,32 @@ nsMsgAccountManager::LoadAccounts()
         if (account)
           account->SetIncomingServer(server);
       }
     }
   }
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsMsgAccountManager::ReactivateAccounts()
+{
+  for (nsIMsgAccount* account : m_accounts) {
+    // This will error out if the account already has its server, or
+    // if this isn't the account that the extension is trying to reactivate.
+    if (NS_SUCCEEDED(account->CreateServer())) {
+      nsCOMPtr<nsIMsgIncomingServer> server;
+      account->GetIncomingServer(getter_AddRefs(server));
+      // This triggers all of the notifications required by the UI.
+      account->SetIncomingServer(server);
+    }
+  }
+  return NS_OK;
+}
+
 // this routine goes through all the identities and makes sure
 // that the special folders for each identity have the
 // correct special folder flags set, e.g, the Sent folder has
 // the sent flag set.
 //
 // it also goes through all the spam settings for each account
 // and makes sure the folder flags are set there, too
 NS_IMETHODIMP
--- a/mailnews/news/test/unit/test_nntpPassword2.js
+++ b/mailnews/news/test/unit/test_nntpPassword2.js
@@ -33,25 +33,21 @@ add_task(async function () {
   Services.prefs.setCharPref("mail.accountmanager.localfoldersserver",
                              "server1");
   Services.prefs.setCharPref("mail.accountmanager.defaultaccount",
                              "account2");
   Services.prefs.setCharPref("mail.identity.id1.fullName", "testnntp");
   Services.prefs.setCharPref("mail.identity.id1.useremail",
                              "testnntp@localhost");
   Services.prefs.setBoolPref("mail.identity.id1.valid", true);
-  Services.prefs.setCharPref("mail.server.server1.directory-rel",
-                             "[ProfD]Mail/Local Folders");
   Services.prefs.setCharPref("mail.server.server1.hostname",
                              "Local Folders");
   Services.prefs.setCharPref("mail.server.server1.name", "Local Folders");
   Services.prefs.setCharPref("mail.server.server1.type", "none");
   Services.prefs.setCharPref("mail.server.server1.userName", "nobody");
-  Services.prefs.setCharPref("mail.server.server2.directory-rel",
-                             "[ProfD]News/invalid");
   Services.prefs.setCharPref("mail.server.server2.hostname", "invalid");
   Services.prefs.setCharPref("mail.server.server2.name",
                              "testnntp on localhost");
   Services.prefs.setIntPref("mail.server.server2.port", server.port);
   Services.prefs.setCharPref("mail.server.server2.realhostname",
                              "localhost");
   Services.prefs.setCharPref("mail.server.server2.type", "nntp");