Bug 1399627 - Port bug 1388789 to mailnews: Remove use of nsTextFormatter::vssprintf() - take 2. f=tromey rs=bustage-fix
authorJorg K <jorgk@jorgk.com>
Thu, 21 Sep 2017 01:57:51 +0200
changeset 29762 3357fc96255733910b579b7510309e6f7fcec2c2
parent 29761 5bfcd3d8d9f0f38f2125dd48b3d9372df2c76e52
child 29763 ca69e392180462fef729e36c0cfba35591d405a8
push id378
push userclokep@gmail.com
push dateMon, 13 Nov 2017 18:45:35 +0000
reviewersbustage-fix
bugs1399627, 1388789
Bug 1399627 - Port bug 1388789 to mailnews: Remove use of nsTextFormatter::vssprintf() - take 2. f=tromey rs=bustage-fix
mailnews/compose/src/nsSmtpProtocol.cpp
--- a/mailnews/compose/src/nsSmtpProtocol.cpp
+++ b/mailnews/compose/src/nsSmtpProtocol.cpp
@@ -16,16 +16,17 @@
 #include "nsIPrompt.h"
 #include "nsIAuthPrompt.h"
 #include "nsString.h"
 #include "nsTextFormatter.h"
 #include "nsIMsgIdentity.h"
 #include "nsISmtpServer.h"
 #include "prtime.h"
 #include "mozilla/Logging.h"
+#include "nsPrintfCString.h"
 #include "prerror.h"
 #include "prprf.h"
 #include "prmem.h"
 #include "plbase64.h"
 #include "prnetdb.h"
 #include "prsystem.h"
 #include "nsMsgUtils.h"
 #include "nsIPipe.h"
@@ -66,79 +67,77 @@ using namespace mozilla::mailnews;
  */
 #define OUTPUT_BUFFER_SIZE (4096*2)
 
 ////////////////////////////////////////////////////////////////////////////////////////////
 // TEMPORARY HARD CODED FUNCTIONS
 ///////////////////////////////////////////////////////////////////////////////////////////
 
 /* based on in NET_ExplainErrorDetails in mkmessag.c */
-nsresult nsExplainErrorDetails(nsISmtpUrl * aSmtpUrl, nsresult aCode, ...)
+nsresult nsExplainErrorDetails(nsISmtpUrl * aSmtpUrl, nsresult aCode,
+                               const char* arg1, const char* arg2)
 {
   NS_ENSURE_ARG(aSmtpUrl);
 
-  va_list args;
-
   nsCOMPtr<nsIPrompt> dialog;
   aSmtpUrl->GetPrompt(getter_AddRefs(dialog));
   NS_ENSURE_TRUE(dialog, NS_ERROR_FAILURE);
 
   nsString msg;
   nsString eMsg;
   nsCOMPtr<nsIStringBundleService> bundleService =
     mozilla::services::GetStringBundleService();
   NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED);
   nsCOMPtr<nsIStringBundle> bundle;
   nsresult rv = bundleService->CreateBundle(
     "chrome://messenger/locale/messengercompose/composeMsgs.properties",
     getter_AddRefs(bundle));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  va_start (args, aCode);
-
   const char* exitString;
 #ifdef __GNUC__
 // Temporary workaroung until bug 783526 is fixed.
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wswitch"
 #endif
   switch (aCode)
   {
     case NS_ERROR_ILLEGAL_LOCALPART:
       bundle->GetStringFromName("errorIllegalLocalPart", eMsg);
-      nsTextFormatter::vssprintf(msg, eMsg.get(), args);
+      nsTextFormatter::ssprintf(msg, eMsg.get(), arg1, arg2);
       break;
     case NS_ERROR_SMTP_SERVER_ERROR:
     case NS_ERROR_TCP_READ_ERROR:
     case NS_ERROR_SMTP_TEMP_SIZE_EXCEEDED:
     case NS_ERROR_SMTP_PERM_SIZE_EXCEEDED_1:
     case NS_ERROR_SMTP_PERM_SIZE_EXCEEDED_2:
     case NS_ERROR_SENDING_FROM_COMMAND:
     case NS_ERROR_SENDING_RCPT_COMMAND:
     case NS_ERROR_SENDING_DATA_COMMAND:
     case NS_ERROR_SENDING_MESSAGE:
     case NS_ERROR_SMTP_GREETING:
       exitString = errorStringNameForErrorCode(aCode);
       bundle->GetStringFromName(exitString, eMsg);
-      nsTextFormatter::vssprintf(msg, eMsg.get(), args);
+      if (aCode == NS_ERROR_SMTP_PERM_SIZE_EXCEEDED_1)
+        nsTextFormatter::ssprintf(msg, eMsg.get(), atoi(arg1), arg2);
+      else
+        nsTextFormatter::ssprintf(msg, eMsg.get(), arg1, arg2);
       break;
     default:
       NS_WARNING("falling to default error code");
       bundle->GetStringFromName("communicationsError", eMsg);
-      nsTextFormatter::ssprintf(msg, eMsg.get(), aCode);
+      nsTextFormatter::ssprintf(msg, eMsg.get(), static_cast<uint32_t>(aCode));
       break;
   }
 #ifdef __GNUC__
 #pragma GCC diagnostic pop
 #endif
 
   rv = dialog->Alert(nullptr, msg.get());
 
-  va_end (args);
-
   return rv;
 }
 
 /* RFC 1891 -- extended smtp value encoding scheme
 
   5. Additional parameters for RCPT and MAIL commands
 
      The extended RCPT and MAIL commands are issued by a client when it wishes to request a DSN from the
@@ -371,17 +370,17 @@ nsresult nsSmtpProtocol::Initialize(nsIU
             // Throw an error, including the broken address
             m_nextState = SMTP_ERROR_DONE;
             ClearFlag(SMTP_PAUSE_FOR_READ);
             // Unfortunately, nsExplainErrorDetails will show the error above
             // the mailnews main window, because we don't necessarily get
             // passed down a compose window - we might be sending in the
             // background!
             rv = nsExplainErrorDetails(m_runningURL,
-                                       NS_ERROR_ILLEGAL_LOCALPART, start);
+                                       NS_ERROR_ILLEGAL_LOCALPART, start, nullptr);
             NS_ASSERTION(NS_SUCCEEDED(rv), "failed to explain illegal localpart");
             m_urlErrorState = NS_ERROR_BUT_DONT_SHOW_ALERT;
             return NS_ERROR_BUT_DONT_SHOW_ALERT;
           }
         }
       }
 
       // final cleanup
@@ -666,17 +665,17 @@ nsresult nsSmtpProtocol::ExtensionLoginR
   nsresult status = NS_OK;
 
   if (m_responseCode != 220)
   {
 #ifdef DEBUG
     nsresult rv =
 #endif
     nsExplainErrorDetails(m_runningURL, NS_ERROR_SMTP_GREETING,
-                          m_responseText.get());
+                          m_responseText.get(), nullptr);
     NS_ASSERTION(NS_SUCCEEDED(rv), "failed to explain SMTP error");
 
     m_urlErrorState = NS_ERROR_BUT_DONT_SHOW_ALERT;
     return NS_ERROR_SMTP_AUTH_FAILURE;
   }
 
   nsAutoCString buffer("EHLO ");
   AppendHelloArgument(buffer);
@@ -698,17 +697,17 @@ nsresult nsSmtpProtocol::SendHeloRespons
   nsresult rv;
 
   if (m_responseCode != 250)
   {
 #ifdef DEBUG
     rv =
 #endif
     nsExplainErrorDetails(m_runningURL, NS_ERROR_SMTP_SERVER_ERROR,
-                          m_responseText.get());
+                          m_responseText.get(), nullptr);
     NS_ASSERTION(NS_SUCCEEDED(rv), "failed to explain SMTP error");
 
     m_urlErrorState = NS_ERROR_BUT_DONT_SHOW_ALERT;
     return NS_ERROR_SMTP_AUTH_FAILURE;
   }
 
   // check if we're just verifying the ability to logon
   nsCOMPtr<nsISmtpUrl> smtpUrl = do_QueryInterface(m_runningURL, &rv);
@@ -839,17 +838,17 @@ nsresult nsSmtpProtocol::SendEhloRespons
          * 501 "Syntax error in EHLOs parameters or arguments"
          */
         else
         {
 #ifdef DEBUG
             nsresult rv =
 #endif
             nsExplainErrorDetails(m_runningURL, NS_ERROR_SMTP_SERVER_ERROR,
-                                  m_responseText.get());
+                                  m_responseText.get(), nullptr);
             NS_ASSERTION(NS_SUCCEEDED(rv), "failed to explain SMTP error");
 
             m_urlErrorState = NS_ERROR_BUT_DONT_SHOW_ALERT;
             return NS_ERROR_SMTP_AUTH_FAILURE;
         }
     }
 
     int32_t responseLength = m_responseText.Length();
@@ -923,17 +922,18 @@ nsresult nsSmtpProtocol::SendEhloRespons
 
     if (TestFlag(SMTP_EHLO_SIZE_ENABLED) &&
        m_sizelimit > 0 && (int32_t)m_totalMessageSize > m_sizelimit)
     {
 #ifdef DEBUG
         nsresult rv =
 #endif
         nsExplainErrorDetails(m_runningURL,
-                              NS_ERROR_SMTP_PERM_SIZE_EXCEEDED_1, m_sizelimit);
+                              NS_ERROR_SMTP_PERM_SIZE_EXCEEDED_1,
+                              nsPrintfCString("%" PRId32, m_sizelimit).get(), nullptr);
         NS_ASSERTION(NS_SUCCEEDED(rv), "failed to explain SMTP error");
 
         m_urlErrorState = NS_ERROR_BUT_DONT_SHOW_ALERT;
         return(NS_ERROR_SENDING_FROM_COMMAND);
     }
 
     m_nextState = SMTP_AUTH_PROCESS_STATE;
     return status;
@@ -1667,17 +1667,17 @@ nsresult nsSmtpProtocol::SendMailRespons
     nsresult errorcode;
     if (TestFlag(SMTP_EHLO_SIZE_ENABLED))
       errorcode = (m_responseCode == 452) ? NS_ERROR_SMTP_TEMP_SIZE_EXCEEDED :
                   (m_responseCode == 552) ? NS_ERROR_SMTP_PERM_SIZE_EXCEEDED_2 :
                   NS_ERROR_SENDING_FROM_COMMAND;
     else
       errorcode = NS_ERROR_SENDING_FROM_COMMAND;
 
-    rv = nsExplainErrorDetails(m_runningURL, errorcode, m_responseText.get());
+    rv = nsExplainErrorDetails(m_runningURL, errorcode, m_responseText.get(), nullptr);
     NS_ASSERTION(NS_SUCCEEDED(rv), "failed to explain SMTP error");
 
     m_urlErrorState = NS_ERROR_BUT_DONT_SHOW_ALERT;
     return(NS_ERROR_SENDING_FROM_COMMAND);
   }
 
   /* Send the RCPT TO: command */
   bool requestDSN = false;
@@ -1768,19 +1768,19 @@ nsresult nsSmtpProtocol::SendRecipientRe
     if (TestFlag(SMTP_EHLO_SIZE_ENABLED))
       errorcode = (m_responseCode == 452) ? NS_ERROR_SMTP_TEMP_SIZE_EXCEEDED :
                   (m_responseCode == 552) ? NS_ERROR_SMTP_PERM_SIZE_EXCEEDED_2 :
                   NS_ERROR_SENDING_RCPT_COMMAND;
     else
       errorcode = NS_ERROR_SENDING_RCPT_COMMAND;
 
     if (errorcode == NS_ERROR_SENDING_RCPT_COMMAND) {
-      rv = nsExplainErrorDetails(
-        m_runningURL, errorcode, NS_ConvertUTF8toUTF16(m_responseText).get(),
-        NS_ConvertUTF8toUTF16(m_addresses[m_addressesLeft - 1]).get());
+      rv = nsExplainErrorDetails(m_runningURL, errorcode,
+                                 m_responseText.get(),
+                                 m_addresses[m_addressesLeft - 1].get());
     } else {
       rv = nsExplainErrorDetails(m_runningURL, errorcode,
                                  m_responseText.get(),
                                  m_addresses[m_addressesLeft - 1].get());
     }
 
     if (!NS_SUCCEEDED(rv))
       NS_ASSERTION(false, "failed to explain SMTP error");
@@ -1828,17 +1828,17 @@ nsresult nsSmtpProtocol::SendData(const 
 nsresult nsSmtpProtocol::SendDataResponse()
 {
   nsresult status = NS_OK;
 
   if (m_responseCode != 354)
   {
     mozilla::DebugOnly<nsresult> rv = nsExplainErrorDetails(m_runningURL,
                                                             NS_ERROR_SENDING_DATA_COMMAND,
-                                                            m_responseText.get());
+                                                            m_responseText.get(), nullptr);
     NS_ASSERTION(NS_SUCCEEDED(rv), "failed to explain SMTP error");
 
     m_urlErrorState = NS_ERROR_BUT_DONT_SHOW_ALERT;
     return(NS_ERROR_SENDING_DATA_COMMAND);
   }
 
   m_nextState = SMTP_SEND_POST_DATA;
   ClearFlag(SMTP_PAUSE_FOR_READ);   /* send data directly */
@@ -1899,17 +1899,17 @@ void nsSmtpProtocol::SendPostData()
 
 
 nsresult nsSmtpProtocol::SendMessageResponse()
 {
   if((m_responseCode/10 != 25))
   {
     mozilla::DebugOnly<nsresult> rv = nsExplainErrorDetails(m_runningURL,
                                                             NS_ERROR_SENDING_MESSAGE,
-                                                            m_responseText.get());
+                                                            m_responseText.get(), nullptr);
     NS_ASSERTION(NS_SUCCEEDED(rv), "failed to explain SMTP error");
 
     m_urlErrorState = NS_ERROR_BUT_DONT_SHOW_ALERT;
     return(NS_ERROR_SENDING_MESSAGE);
   }
 
   UpdateStatus("smtpMailSent");