Bug 1557829 - Follow-up: Fix Linux/Mac specific code. rs=bustage-fix
authorJorg K <jorgk@jorgk.com>
Wed, 12 Jun 2019 01:05:06 +0200
changeset 35833 18519908af98b0500d7e21b9e3394eb54143de5c
parent 35832 be5c06a3f4d225c6147368b89f3baa05ccc3dfc7
child 35834 0f52c1933b47e5e15cc6e12d4962a90a0513d515
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersbustage-fix
bugs1557829
Bug 1557829 - Follow-up: Fix Linux/Mac specific code. rs=bustage-fix
mailnews/base/src/nsMessengerOSXIntegration.mm
mailnews/local/src/nsMovemailService.cpp
mailnews/local/src/nsMovemailService.h
--- a/mailnews/base/src/nsMessengerOSXIntegration.mm
+++ b/mailnews/base/src/nsMessengerOSXIntegration.mm
@@ -289,41 +289,40 @@ void nsMessengerOSXIntegration::FillTool
       numNewMsgsText.AppendInt(aNewCount);
       nsString finalText;
       nsCString uri;
       aFolder->GetURI(uri);
 
       if (numNotDisplayed > 0) {
         nsAutoString numNotDisplayedText;
         numNotDisplayedText.AppendInt(numNotDisplayed);
-        const char16_t *formatStrings[3] = {numNewMsgsText.get(), authors.get(),
-                                            numNotDisplayedText.get()};
-        bundle->FormatStringFromName("macBiffNotification_messages_extra", formatStrings, 3,
+        AutoTArray<nsString, 3> formatStrings = {numNewMsgsText, authors, numNotDisplayedText};
+        bundle->FormatStringFromName("macBiffNotification_messages_extra", formatStrings,
                                      finalText);
       } else {
-        const char16_t *formatStrings[2] = {numNewMsgsText.get(), authors.get()};
+        AutoTArray<nsString, 2> formatStrings = {numNewMsgsText, authors};
 
         if (aNewCount == 1) {
-          bundle->FormatStringFromName("macBiffNotification_message", formatStrings, 2, finalText);
+          bundle->FormatStringFromName("macBiffNotification_message", formatStrings, finalText);
           // Since there is only 1 message, use the most recent mail's URI instead of the folder's
           nsCOMPtr<nsIMsgDatabase> db;
           rv = aFolder->GetMsgDatabase(getter_AddRefs(db));
           if (NS_SUCCEEDED(rv) && db) {
             uint32_t numNewKeys;
             uint32_t *newMessageKeys;
             rv = db->GetNewList(&numNewKeys, &newMessageKeys);
             if (NS_SUCCEEDED(rv)) {
               nsCOMPtr<nsIMsgDBHdr> hdr;
               rv = db->GetMsgHdrForKey(newMessageKeys[numNewKeys - 1], getter_AddRefs(hdr));
               if (NS_SUCCEEDED(rv) && hdr) aFolder->GetUriForMsg(hdr, uri);
             }
             free(newMessageKeys);
           }
         } else
-          bundle->FormatStringFromName("macBiffNotification_messages", formatStrings, 2, finalText);
+          bundle->FormatStringFromName("macBiffNotification_messages", formatStrings, finalText);
       }
       ShowAlertMessage(accountName, finalText, uri);
     }  // if we got a bundle
   }    // if we got a folder
 }
 
 nsresult nsMessengerOSXIntegration::ShowAlertMessage(const nsAString &aAlertTitle,
                                                      const nsAString &aAlertText,
--- a/mailnews/local/src/nsMovemailService.cpp
+++ b/mailnews/local/src/nsMovemailService.cpp
@@ -97,68 +97,67 @@ nsMovemailService::CheckForNewMail(nsIUr
                                    nsIMsgFolder *inbox,
                                    nsIMovemailIncomingServer *movemailServer,
                                    nsIURI **aURL) {
   nsresult rv = NS_OK;
   LOG(("nsMovemailService::CheckForNewMail\n"));
   return rv;
 }
 
-void nsMovemailService::Error(const char *errorCode,
-                              nsTArray<nsString> &params, ) {
+void nsMovemailService::Error(const char *errorCode, const char16_t *param) {
   if (!mMsgWindow) return;
 
   nsCOMPtr<nsIPrompt> dialog;
   nsresult rv = mMsgWindow->GetPromptDialog(getter_AddRefs(dialog));
   if (NS_FAILED(rv)) return;
 
   nsCOMPtr<nsIStringBundleService> bundleService =
       mozilla::services::GetStringBundleService();
   if (!bundleService) return;
   nsCOMPtr<nsIStringBundle> bundle;
   rv = bundleService->CreateBundle(
       "chrome://messenger/locale/localMsgs.properties", getter_AddRefs(bundle));
   if (NS_FAILED(rv)) return;
 
   nsString errStr;
   // Format the error string if necessary
-  if (params)
+  if (param) {
+    AutoTArray<nsString, 1> params = {nsDependentString(param)};
     bundle->FormatStringFromName(errorCode, params, errStr);
-  else
+  } else {
     bundle->GetStringFromName(errorCode, errStr);
+  }
 
   if (!errStr.IsEmpty()) {
     dialog->Alert(nullptr, errStr.get());
   }
 }
 
 SpoolLock::SpoolLock(nsACString *aSpoolName, int aSeconds,
                      nsMovemailService &aMovemail,
                      nsIMsgIncomingServer *aServer)
     : mLocked(false),
       mSpoolName(*aSpoolName),
       mOwningService(&aMovemail),
       mServer(aServer) {
   if (!ObtainSpoolLock(aSeconds)) {
     NS_ConvertUTF8toUTF16 lockFile(mSpoolName);
     lockFile.AppendLiteral(LOCK_SUFFIX);
-    AutoTArray<nsString, 1> params = {lockFile};
-    mOwningService->Error("movemailCantCreateLock", params);
+    mOwningService->Error("movemailCantCreateLock", lockFile.get());
     return;
   }
   mServer->SetServerBusy(true);
   mLocked = true;
 }
 
 SpoolLock::~SpoolLock() {
   if (mLocked && !YieldSpoolLock()) {
     NS_ConvertUTF8toUTF16 lockFile(mSpoolName);
     lockFile.AppendLiteral(LOCK_SUFFIX);
-    AutoTArray<nsString, 1> params = {lockFile};
-    mOwningService->Error("movemailCantDeleteLock", params);
+    mOwningService->Error("movemailCantDeleteLock", lockFile.get());
   }
   mServer->SetServerBusy(false);
 }
 
 bool SpoolLock::isLocked() { return mLocked; }
 
 bool SpoolLock::ObtainSpoolLock(
     unsigned int aSeconds /* number of seconds to retry */) {
@@ -378,31 +377,28 @@ nsresult nsMovemailService::GetNewMail(
   NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && in_server,
                  NS_MSG_INVALID_OR_MISSING_SERVER);
 
   // Attempt to locate the mail spool file
   nsAutoCString spoolPath;
   rv = in_server->GetCharValue("spoolDir", spoolPath);
   if (NS_FAILED(rv) || spoolPath.IsEmpty()) rv = LocateSpoolFile(spoolPath);
   if (NS_FAILED(rv) || spoolPath.IsEmpty()) {
-    Error("movemailSpoolFileNotFound", nullptr, 0);
+    Error("movemailSpoolFileNotFound");
     return NS_ERROR_FAILURE;
   }
 
-  NS_ConvertUTF8toUTF16 wideSpoolPath(spoolPath);
-  const char16_t *spoolPathString[] = {wideSpoolPath.get()};
-
   // Create an input stream for the spool file
   nsCOMPtr<nsIFile> spoolFile;
   rv = NS_NewNativeLocalFile(spoolPath, true, getter_AddRefs(spoolFile));
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIInputStream> spoolInputStream;
   rv = NS_NewLocalFileInputStream(getter_AddRefs(spoolInputStream), spoolFile);
   if (NS_FAILED(rv)) {
-    Error("movemailCantOpenSpoolFile", spoolPathString, 1);
+    Error("movemailCantOpenSpoolFile", NS_ConvertUTF8toUTF16(spoolPath).get());
     return rv;
   }
 
   // Get a line input interface for the spool file
   nsCOMPtr<nsILineInputStream> lineInputStream =
       do_QueryInterface(spoolInputStream, &rv);
   NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && lineInputStream, rv);
 
@@ -461,17 +457,17 @@ nsresult nsMovemailService::GetNewMail(
       rv = newMailParser->Init(serverFolder, inbox, nullptr, newHdr,
                                outputStream);
       NS_ENSURE_SUCCESS(rv, rv);
     }
     if (!outputStream) {
       // If we do not have outputStream here, something bad happened.
       // We probably didn't find the proper message start delimiter "From "
       // and are now reading in the middle of a message. Bail out.
-      Error("movemailCantParseSpool", spoolPathString, 1);
+      Error("movemailCantParseSpool", NS_ConvertUTF8toUTF16(spoolPath).get());
       return NS_ERROR_UNEXPECTED;
     }
 
     newMailParser->HandleLine(buffer.BeginWriting(), buffer.Length());
     rv = outputStream->Write(buffer.get(), buffer.Length(), &bytesWritten);
     NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && (bytesWritten == buffer.Length()),
                    NS_ERROR_FAILURE);
 
@@ -496,17 +492,18 @@ nsresult nsMovemailService::GetNewMail(
     newMailParser->OnStopRequest(nullptr, NS_OK);
     rv = msgStore->FinishNewMessage(outputStream, newHdr);
     NS_ENSURE_SUCCESS(rv, rv);
     outputStream->Close();
   }
   // Truncate the spool file as we parsed it successfully.
   rv = spoolFile->SetFileSize(0);
   if (NS_FAILED(rv)) {
-    Error("movemailCantTruncateSpoolFile", spoolPathString, 1);
+    Error("movemailCantTruncateSpoolFile",
+          NS_ConvertUTF8toUTF16(spoolPath).get());
   }
 
   LOG(("GetNewMail returning rv=%" PRIx32, static_cast<uint32_t>(rv)));
   return rv;
 }
 
 NS_IMETHODIMP
 nsMovemailService::SetDefaultLocalPath(nsIFile *aPath) {
--- a/mailnews/local/src/nsMovemailService.h
+++ b/mailnews/local/src/nsMovemailService.h
@@ -16,16 +16,16 @@
 class nsMovemailService : public nsIMsgProtocolInfo, public nsIMovemailService {
  public:
   nsMovemailService();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIMOVEMAILSERVICE
   NS_DECL_NSIMSGPROTOCOLINFO
 
-  void Error(const char* errorCode, nsTArray<nsString>& params);
+  void Error(const char* errorCode, const char16_t* param = nullptr);
 
  private:
   virtual ~nsMovemailService();
   nsCOMPtr<nsIMsgWindow> mMsgWindow;
 };
 
 #endif /* nsMovemailService_h___ */