Bug 312593 - Allow unicode in passwords. r=neil,standard8,jorgk
authorDavid Bienvenu <mozilla@davidbienvenu.org>
Thu, 12 Jul 2012 16:52:00 +0200
changeset 29036 23725f858c42de69a528dc63ecd089b23fc5dd12
parent 29035 d2b98c955e08bcd938971ab2950ebef8307df156
child 29037 61251d6ba888a140ce843319b86a8050164cb9ed
push id2068
push userclokep@gmail.com
push dateMon, 13 Nov 2017 19:02:14 +0000
treeherdercomm-beta@9c7e7ce8672b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil, standard8, jorgk
bugs312593
Bug 312593 - Allow unicode in passwords. r=neil,standard8,jorgk
mailnews/base/public/nsIMsgIncomingServer.idl
mailnews/base/src/nsMsgAccountManager.cpp
mailnews/base/util/nsMsgIncomingServer.cpp
mailnews/base/util/nsMsgIncomingServer.h
mailnews/base/util/nsMsgProtocol.cpp
mailnews/base/util/nsMsgProtocol.h
mailnews/compose/public/nsIMsgComposeParams.idl
mailnews/compose/public/nsIMsgSend.idl
mailnews/compose/public/nsISmtpServer.idl
mailnews/compose/public/nsISmtpService.idl
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgCompose.h
mailnews/compose/src/nsMsgComposeParams.cpp
mailnews/compose/src/nsMsgComposeParams.h
mailnews/compose/src/nsMsgSend.cpp
mailnews/compose/src/nsMsgSend.h
mailnews/compose/src/nsSmtpProtocol.cpp
mailnews/compose/src/nsSmtpProtocol.h
mailnews/compose/src/nsSmtpServer.cpp
mailnews/compose/src/nsSmtpServer.h
mailnews/compose/src/nsSmtpService.cpp
mailnews/extensions/mdn/src/nsMsgMdnGenerator.cpp
mailnews/imap/public/nsIIMAPHostSessionList.h
mailnews/imap/public/nsIImapIncomingServer.idl
mailnews/imap/public/nsIImapProtocol.idl
mailnews/imap/public/nsIImapServerSink.idl
mailnews/imap/src/nsIMAPHostSessionList.cpp
mailnews/imap/src/nsIMAPHostSessionList.h
mailnews/imap/src/nsImapIncomingServer.cpp
mailnews/imap/src/nsImapProtocol.cpp
mailnews/imap/src/nsImapProtocol.h
mailnews/imap/src/nsSyncRunnableHelpers.cpp
mailnews/local/src/nsPop3Protocol.cpp
mailnews/local/src/nsPop3Protocol.h
mailnews/local/test/unit/test_pop3PasswordFailure.js
mailnews/mapi/mapihook/src/msgMapiHook.cpp
--- a/mailnews/base/public/nsIMsgIncomingServer.idl
+++ b/mailnews/base/public/nsIMsgIncomingServer.idl
@@ -97,18 +97,18 @@ interface nsIMsgIncomingServer : nsISupp
    * message folders associated with this server.
    */
   readonly attribute ACString localDatabaseType;
 
   // Perform specific tasks (reset flags, remove files, etc) for account user/server name changes.
   void onUserOrHostNameChanged(in ACString oldName, in ACString newName,
                                in bool hostnameChanged);
 
-  /* cleartext version of the password */
-  attribute ACString password;
+  /// cleartext utf16 version of the password
+  attribute AString password;
 
   /**
    * Attempts to get the password first from the password manager, if that
    * fails it will attempt to get it from the user if aMsgWindow is supplied.
    *
    * @param aPromptString  The text of the prompt if the user is prompted for
    *                       password.
    * @param aPromptTitle   The title of the prompt if the user is prompted.
@@ -116,17 +116,17 @@ interface nsIMsgIncomingServer : nsISupp
    * @return               The obtained password. Could be an empty password.
    *
    * @exception NS_ERROR_FAILURE  The password could not be obtained.
    *
    * @note NS_MSG_PASSWORD_PROMPT_CANCELLED is a success code that is returned
    *       if the prompt was presented to the user but the user cancelled the
    *       prompt.
    */
-  ACString getPasswordWithUI(in AString aPromptString, in AString aPromptTitle,
+  AString getPasswordWithUI(in AString aPromptString, in AString aPromptTitle,
                              in nsIMsgWindow aMsgWindow);
 
   /* forget the password in memory and in single signon database */
   void forgetPassword();
 
   /* forget the password in memory which is cached for the session */
   void forgetSessionPassword();
 
--- a/mailnews/base/src/nsMsgAccountManager.cpp
+++ b/mailnews/base/src/nsMsgAccountManager.cpp
@@ -1599,17 +1599,17 @@ nsMsgAccountManager::CleanupOnExit()
       nsCString type;
       server->GetType(type);
       if (root)
       {
         nsCOMPtr<nsIMsgFolder> folder;
         folder = do_QueryInterface(root);
         if (folder)
         {
-          nsCString passwd;
+          nsString passwd;
           bool serverRequiresPasswordForAuthentication = true;
           bool isImap = type.EqualsLiteral("imap");
           if (isImap)
           {
             server->GetServerRequiresPasswordForBiff(&serverRequiresPasswordForAuthentication);
             server->GetPassword(passwd);
           }
           if (!isImap || (isImap && (!serverRequiresPasswordForAuthentication || !passwd.IsEmpty())))
--- a/mailnews/base/util/nsMsgIncomingServer.cpp
+++ b/mailnews/base/util/nsMsgIncomingServer.cpp
@@ -641,23 +641,23 @@ NS_IMETHODIMP
 nsMsgIncomingServer::ToString(nsAString& aResult)
 {
   aResult.AssignLiteral("[nsIMsgIncomingServer: ");
   aResult.Append(NS_ConvertASCIItoUTF16(m_serverKey));
   aResult.AppendLiteral("]");
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgIncomingServer::SetPassword(const nsACString& aPassword)
+NS_IMETHODIMP nsMsgIncomingServer::SetPassword(const nsAString& aPassword)
 {
   m_password = aPassword;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgIncomingServer::GetPassword(nsACString& aPassword)
+NS_IMETHODIMP nsMsgIncomingServer::GetPassword(nsAString& aPassword)
 {
   aPassword = m_password;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgIncomingServer::GetServerRequiresPasswordForBiff(bool *aServerRequiresPasswordForBiff)
 {
   NS_ENSURE_ARG_POINTER(aServerRequiresPasswordForBiff);
@@ -716,30 +716,30 @@ nsresult nsMsgIncomingServer::GetPasswor
       NS_ENSURE_SUCCESS(rv, rv);
 
       if (username.Equals(serverUsername))
       {
         nsString password;
         rv = logins[i]->GetPassword(password);
         NS_ENSURE_SUCCESS(rv, rv);
 
-        m_password = NS_LossyConvertUTF16toASCII(password);
+        m_password = password;
         break;
       }
     }
     NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(numLogins, logins);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgIncomingServer::GetPasswordWithUI(const nsAString& aPromptMessage, const
                                        nsAString& aPromptTitle,
                                        nsIMsgWindow* aMsgWindow,
-                                       nsACString& aPassword)
+                                       nsAString& aPassword)
 {
   nsresult rv = NS_OK;
 
   if (m_password.IsEmpty())
   {
     // let's see if we have the password in the password manager and
     // can avoid this prompting thing. This makes it easier to get embedders
     // to get up and running w/o a password prompting UI.
@@ -784,37 +784,37 @@ nsMsgIncomingServer::GetPasswordWithUI(c
 
       serverUri.Append(temp);
 
       // we pass in the previously used password, if any, into PromptPassword
       // so that it will appear as ******. This means we can't use an nsString
       // and getter_Copies.
       char16_t *uniPassword = nullptr;
       if (!aPassword.IsEmpty())
-        uniPassword = ToNewUnicode(NS_ConvertASCIItoUTF16(aPassword));
+        uniPassword = ToNewUnicode(aPassword);
 
       bool okayValue = true;
       rv = dialog->PromptPassword(PromiseFlatString(aPromptTitle).get(),
                                   PromiseFlatString(aPromptMessage).get(),
                                   NS_ConvertASCIItoUTF16(serverUri).get(),
                                   nsIAuthPrompt::SAVE_PASSWORD_PERMANENTLY,
                                   &uniPassword, &okayValue);
-      nsAutoString uniPasswordAdopted;
-      uniPasswordAdopted.Adopt(uniPassword);
       NS_ENSURE_SUCCESS(rv, rv);
 
       if (!okayValue) // if the user pressed cancel, just return an empty string;
       {
         aPassword.Truncate();
         return NS_MSG_PASSWORD_PROMPT_CANCELLED;
       }
 
       // we got a password back...so remember it
-      rv = SetPassword(NS_LossyConvertUTF16toASCII(uniPasswordAdopted));
+      rv = SetPassword(nsDependentString(uniPassword));
       NS_ENSURE_SUCCESS(rv, rv);
+
+      PR_FREEIF(uniPassword);
     } // if we got a prompt dialog
     else
       return NS_ERROR_FAILURE;
   } // if the password is empty
   return GetPassword(aPassword);
 }
 
 NS_IMETHODIMP
@@ -863,17 +863,17 @@ nsMsgIncomingServer::ForgetPassword()
     {
       // If this fails, just continue, we'll still want to remove the password
       // from our local cache.
       loginMgr->RemoveLogin(logins[i]);
     }
   }
   NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, logins);
 
-  return SetPassword(EmptyCString());
+  return SetPassword(EmptyString());
 }
 
 NS_IMETHODIMP
 nsMsgIncomingServer::ForgetSessionPassword()
 {
   m_password.Truncate();
   return NS_OK;
 }
--- a/mailnews/base/util/nsMsgIncomingServer.h
+++ b/mailnews/base/util/nsMsgIncomingServer.h
@@ -86,17 +86,17 @@ protected:
 
 private:
   uint32_t m_biffState;
   bool m_serverBusy;
   nsCOMPtr <nsISpamSettings> mSpamSettings;
   nsCOMPtr<nsIMsgFilterPlugin> mFilterPlugin;  // XXX should be a list
 
 protected:
-  nsCString m_password;
+  nsString m_password;
   bool m_canHaveFilters;
   bool m_displayStartupPage;
   bool mPerformingBiff;
 };
 
 #undef  IMETHOD_VISIBILITY
 #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
 
--- a/mailnews/base/util/nsMsgProtocol.cpp
+++ b/mailnews/base/util/nsMsgProtocol.cpp
@@ -936,27 +936,27 @@ nsresult nsMsgProtocol::DoGSSAPIStep2(ns
     }
 
 #ifdef DEBUG_BenB
     printf(NS_SUCCEEDED(rv) ? "GSSAPI step 2 succeeded\n" : "GSSAPI step 2 failed\n");
 #endif
     return rv;
 }
 
-nsresult nsMsgProtocol::DoNtlmStep1(const char *username, const char *password, nsCString &response)
+nsresult nsMsgProtocol::DoNtlmStep1(const nsACString &username, const nsAString &password, nsCString &response)
 {
     nsresult rv;
 
     m_authModule = do_CreateInstance(NS_AUTH_MODULE_CONTRACTID_PREFIX "ntlm", &rv);
     // if this fails, then it means that we cannot do NTLM auth.
     if (NS_FAILED(rv) || !m_authModule)
         return rv;
 
     m_authModule->Init(nullptr, 0, nullptr, NS_ConvertUTF8toUTF16(username).get(),
-                       NS_ConvertUTF8toUTF16(password).get());
+                       nsPromiseFlatString(password).get());
 
     void *outBuf;
     uint32_t outBufLen;
     rv = m_authModule->GetNextToken((void *)nullptr, 0, &outBuf, &outBufLen);
     if (NS_SUCCEEDED(rv) && outBuf)
     {
         char *base64Str = PL_Base64Encode((char *)outBuf, outBufLen, nullptr);
         if (base64Str)
--- a/mailnews/base/util/nsMsgProtocol.h
+++ b/mailnews/base/util/nsMsgProtocol.h
@@ -111,17 +111,17 @@ protected:
   // stream, etc).
     // aSuppressLogging is a hint that sensitive data is being sent and should not be logged
   virtual nsresult SendData(const char * dataBuffer, bool aSuppressLogging = false);
 
   virtual nsresult PostMessage(nsIURI* url, nsIFile* aPostFile);
 
   virtual nsresult InitFromURI(nsIURI *aUrl);
 
-  nsresult DoNtlmStep1(const char *username, const char *password, nsCString &response);
+  nsresult DoNtlmStep1(const nsACString &username, const nsAString &password, nsCString &response);
   nsresult DoNtlmStep2(nsCString &commandResponse, nsCString &response);
 
   nsresult DoGSSAPIStep1(const char *service, const char *username, nsCString &response);
   nsresult DoGSSAPIStep2(nsCString &commandResponse, nsCString &response);
   // Ouput stream for writing commands to the socket
   nsCOMPtr<nsIOutputStream>   m_outputStream;   // this will be obtained from the transport interface
   nsCOMPtr<nsIInputStream>    m_inputStream;
 
@@ -152,17 +152,17 @@ protected:
   nsCOMPtr<nsIProgressEventSink> mProgressEventSink;
   nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
   nsCOMPtr<nsISupports>       mOwner;
   nsCString                   mContentType;
   nsCString                   mCharset;
   int64_t                     mContentLength;
   nsCOMPtr<nsILoadInfo>       m_loadInfo;
 
-  nsCString m_lastPasswordSent; // used to prefill the password prompt
+  nsString m_lastPasswordSent; // used to prefill the password prompt
 
   // private helper routine used by subclasses to quickly get a reference to the correct prompt dialog
   // for a mailnews url.
   nsresult GetPromptDialogFromUrl(nsIMsgMailNewsUrl * aMsgUrl, nsIPrompt ** aPromptDialog);
 
   // if a url isn't going to result in any content then we want to suppress calls to
   // OnStartRequest, OnDataAvailable and OnStopRequest
   bool mSuppressListenerNotifications;
--- a/mailnews/compose/public/nsIMsgComposeParams.idl
+++ b/mailnews/compose/public/nsIMsgComposeParams.idl
@@ -69,18 +69,18 @@ interface nsIMsgComposeParams : nsISuppo
   attribute MSG_ComposeType       type;
   attribute MSG_ComposeFormat     format;
   attribute string                originalMsgURI;
   attribute nsIMsgIdentity        identity;
 
   attribute nsIMsgCompFields      composeFields;
   attribute boolean               bodyIsLink;
 
-  attribute nsIMsgSendListener	  sendListener;
-  attribute string                smtpPassword;
+  attribute nsIMsgSendListener    sendListener;
+  attribute AString               smtpPassword;
   attribute nsIMsgDBHdr           origMsgHdr;
 
   /**
    * HTML-formatted content to quote in the body of the message.
    * Set this to get different content than what would normally
    * appear in the body, e.g. the original message body in a reply.
    */
   attribute AUTF8String           htmlToQuote;
--- a/mailnews/compose/public/nsIMsgSend.idl
+++ b/mailnews/compose/public/nsIMsgSend.idl
@@ -214,17 +214,17 @@ interface nsIMsgSend : nsISupports
                               in nsIMsgDBHdr aMsgToReplace,
                               in string aBodyType,
                               in ACString aBody,
                               in nsIArray aAttachments,
                               in nsIArray aPreloadedAttachments,
                               in mozIDOMWindowProxy aParentWindow,
                               in nsIMsgProgress aProgress,
                               in nsIMsgSendListener aListener,
-                              in string aPassword,
+                              in AString aPassword,
                               in AUTF8String aOriginalMsgURI,
                               in MSG_ComposeType aType);
 
   /**
    * Creates a file containing an rfc822 message, using the passed information.
    * aListener's OnStopSending method will get called with the file the message
    * was stored in. OnStopSending may be called sync or async, depending on
    * content, so you need to handle both cases.
@@ -288,17 +288,17 @@ interface nsIMsgSend : nsISupports
                        in nsIMsgCompFields     aFields,
                        in nsIFile              aSendIFile,
                        in boolean              aDeleteSendFileOnCompletion,
                        in boolean              aDigest_p,
                        in nsMsgDeliverMode     aMode,
                        in nsIMsgDBHdr          aMsgToReplace,
                        in nsIMsgSendListener   aListener,
                        in nsIMsgStatusFeedback aStatusFeedback,
-                       in string               aPassword
+                       in wstring              aPassword
                        ); 
 
     /* Abort current send/save operation */
     void abort();
 
     /**
      * Report a send failure.
      *
--- a/mailnews/compose/public/nsISmtpServer.idl
+++ b/mailnews/compose/public/nsISmtpServer.idl
@@ -38,17 +38,17 @@ interface nsISmtpServer : nsISupports {
 
   /**
    * The password to access the server with (if required).
    *
    * @note this is stored within the server instance but not within preferences.
    * It can be specified/saved here to avoid prompting the user constantly for
    * the sending password.
    */
-  attribute ACString password;
+  attribute AString password;
 
   /// Returns a displayname of the format hostname:port or just hostname
   readonly attribute string displayname;
 
   /**
    * Authentication mechanism.
    *
    * @see nsMsgAuthMethod (in MailNewsTypes2.idl)
@@ -84,17 +84,17 @@ interface nsISmtpServer : nsISupports {
    * @param promptString  The string to prompt the user with when asking for
    *                      the password.
    * @param promptTitle   The title of the prompt.
    * @param netPrompt     An nsIAuthPrompt instance to use for the password
    *                      prompt.
    * @return              The password to use (may be null if no password was
    *                      obtained).
    */  
-  ACString getPasswordWithUI(in wstring promptString, in wstring promptTitle,
+  AString getPasswordWithUI(in wstring promptString, in wstring promptTitle,
                            in nsIAuthPrompt netPrompt);
 
   /**
    * Gets a username and password for this server, using a UI prompt if
    * necessary.
    *
    * @param promptString  The string to prompt the user with when asking for
    *                      the password.
@@ -103,17 +103,17 @@ interface nsISmtpServer : nsISupports {
    *                      prompt.
    * @param userid        The username to use (may be null if no password was
    *                      obtained).
    * @param password      The password to use (may be empty if no password was
    *                      obtained).
    */  
   void getUsernamePasswordWithUI(in wstring promptString, in wstring promptTitle,
                                  in nsIAuthPrompt netPrompt, out ACString userid,
-                                 out ACString password);
+                                 out AString password);
 
   /**
    * Calling this will *remove* the saved password for this server from the
    * password manager and from the stored value.
    */
   void forgetPassword();
 
     /**
--- a/mailnews/compose/public/nsISmtpService.idl
+++ b/mailnews/compose/public/nsISmtpService.idl
@@ -49,17 +49,17 @@ interface nsISmtpService : nsISupports {
    *                                netlib service manager to interrupt the url
    *                                you are given back. This parameter may be
    *                                null.
    * @param aRequest                Provides a handle to the running request.
    *                                This parameter may be null.
    */
   void sendMailMessage(in nsIFile aFilePath, in string aRecipients, 
                        in nsIMsgIdentity aSenderIdentity,
-                       in string aPassword,
+                       in AString aPassword,
                        in nsIUrlListener aUrlListener, 
                        in nsIMsgStatusFeedback aStatusListener, 
                        in nsIInterfaceRequestor aNotificationCallbacks,
                        in boolean aRequestDSN,
                        out nsIURI aURL,
                        out nsIRequest aRequest);
 
   /**
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -1089,18 +1089,18 @@ nsMsgCompose::Initialize(nsIMsgComposePa
     }
   }
 
   nsCOMPtr<nsIMsgSendListener> externalSendListener;
   aParams->GetSendListener(getter_AddRefs(externalSendListener));
   if(externalSendListener)
     AddMsgSendListener( externalSendListener );
 
-  nsCString smtpPassword;
-  aParams->GetSmtpPassword(getter_Copies(smtpPassword));
+  nsString smtpPassword;
+  aParams->GetSmtpPassword(smtpPassword);
   mSmtpPassword = smtpPassword;
 
   aParams->GetHtmlToQuote(mHtmlToQuote);
 
   if (aDocShell)
   {
     mDocShell = aDocShell;
     // register the compose object with the compose service
@@ -1265,17 +1265,17 @@ nsMsgCompose::SendMsgToServer(MSG_Delive
                     nullptr,
                     m_composeHTML ? TEXT_HTML : TEXT_PLAIN,
                     bodyString,
                     nullptr,
                     nullptr,
                     m_window,
                     mProgress,
                     sendListener,
-                    mSmtpPassword.get(),
+                    mSmtpPassword,
                     mOriginalMsgURI,
                     mType);
     }
     else
         rv = NS_ERROR_FAILURE;
   }
   else
     rv = NS_ERROR_NOT_INITIALIZED;
--- a/mailnews/compose/src/nsMsgCompose.h
+++ b/mailnews/compose/src/nsMsgCompose.h
@@ -127,17 +127,17 @@ protected:
   bool                                      mQuotingToFollow;   // Quoting indicator
   MSG_ComposeType                           mType;              // Message type
   bool                                      mCharsetOverride;
   bool                                      mAnswerDefaultCharset;
   bool                                      mDeleteDraft;
   nsMsgDispositionState                     mDraftDisposition;
   nsCOMPtr <nsIMsgDBHdr>                    mOrigMsgHdr;
 
-  nsCString                                 mSmtpPassword;
+  nsString                                  mSmtpPassword;
   nsCString                                 mHtmlToQuote;
 
   nsTObserverArray<nsCOMPtr<nsIMsgComposeStateListener> > mStateListeners;
   nsTObserverArray<nsCOMPtr<nsIMsgSendListener> > mExternalSendListeners;
 
   bool                                      mInsertingQuotedContent;
   MSG_DeliverMode                           mDeliverMode;  // nsIMsgCompDeliverMode long.
 
--- a/mailnews/compose/src/nsMsgComposeParams.cpp
+++ b/mailnews/compose/src/nsMsgComposeParams.cpp
@@ -148,21 +148,19 @@ NS_IMETHODIMP nsMsgComposeParams::GetSen
 }
 NS_IMETHODIMP nsMsgComposeParams::SetSendListener(nsIMsgSendListener * aSendListener)
 {
   mSendListener = aSendListener;
   return NS_OK;
 }
 
 /* attribute string smtpPassword; */
-NS_IMETHODIMP nsMsgComposeParams::GetSmtpPassword(char * *aSmtpPassword)
+NS_IMETHODIMP nsMsgComposeParams::GetSmtpPassword(nsAString &aSmtpPassword)
 {
-  NS_ENSURE_ARG_POINTER(aSmtpPassword);
-
-  *aSmtpPassword = ToNewCString(mSMTPPassword);
+  aSmtpPassword = mSMTPPassword;
   return NS_OK;
 }
-NS_IMETHODIMP nsMsgComposeParams::SetSmtpPassword(const char * aSmtpPassword)
+NS_IMETHODIMP nsMsgComposeParams::SetSmtpPassword(const nsAString &aSmtpPassword)
 {
   mSMTPPassword = aSmtpPassword;
   return NS_OK;
 }
 
--- a/mailnews/compose/src/nsMsgComposeParams.h
+++ b/mailnews/compose/src/nsMsgComposeParams.h
@@ -19,12 +19,12 @@ private:
   virtual ~nsMsgComposeParams();
   MSG_ComposeType               mType;
   MSG_ComposeFormat             mFormat;
   nsCString                     mOriginalMsgUri;
   nsCOMPtr<nsIMsgIdentity>      mIdentity;
   nsCOMPtr<nsIMsgCompFields>    mComposeFields;
   bool                          mBodyIsLink;
   nsCOMPtr<nsIMsgSendListener>  mSendListener;
-  nsCString                     mSMTPPassword;
+  nsString                     mSMTPPassword;
   nsCOMPtr<nsIMsgDBHdr>         mOrigMsgHdr;
   nsCString                     mHtmlToQuote;
 };
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -3030,17 +3030,17 @@ nsMsgComposeAndSend::Init(
               bool digest_p,
               bool dont_deliver_p,
               nsMsgDeliverMode mode,
               nsIMsgDBHdr *msgToReplace,
               const char *attachment1_type,
               const nsACString &attachment1_body,
               nsIArray *attachments,
               nsIArray *preloaded_attachments,
-              const char *password,
+              const nsAString &password,
               const nsACString &aOriginalMsgURI,
               MSG_ComposeType aType)
 {
   nsresult      rv = NS_OK;
 
   //Let make sure we retreive the correct number of related parts. It may have changed since last time
   GetMultipartRelatedCount(true);
 
@@ -3422,17 +3422,17 @@ nsMsgComposeAndSend::DeliverFileAsMail()
     SetStatusMessage(msg);
     nsCOMPtr<nsIMsgStatusFeedback> msgStatus (do_QueryInterface(mSendProgress));
     // if the sendProgress isn't set, let's use the member variable.
     if (!msgStatus)
       msgStatus = do_QueryInterface(mStatusFeedback);
 
     nsCOMPtr<nsIURI> runningUrl;
     rv = smtpService->SendMailMessage(mTempFile, buf, mUserIdentity,
-                                      mSmtpPassword.get(), deliveryListener, msgStatus,
+                                      mSmtpPassword, deliveryListener, msgStatus,
                                       callbacks, mCompFields->GetDSN(),
                                       getter_AddRefs(runningUrl),
                                       getter_AddRefs(mRunningRequest));
     // set envid on the returned URL
     if (NS_SUCCEEDED(rv))
     {
       nsCOMPtr<nsISmtpUrl> smtpUrl(do_QueryInterface(runningUrl, &rv));
       if (NS_SUCCEEDED(rv))
@@ -4140,17 +4140,17 @@ nsMsgComposeAndSend::CreateAndSendMessag
               nsIMsgDBHdr                       *msgToReplace,
               const char                        *attachment1_type,
               const nsACString                  &attachment1_body,
               nsIArray *attachments,
               nsIArray *preloaded_attachments,
               mozIDOMWindowProxy                *parentWindow,
               nsIMsgProgress                    *progress,
               nsIMsgSendListener                *aListener,
-              const char                        *password,
+              const nsAString                   &password,
               const nsACString                  &aOriginalMsgURI,
               MSG_ComposeType                   aType
               )
 {
   nsresult      rv;
   /* First thing to do is to reset the send errors report */
   mSendReport->Reset();
   mSendReport->SetDeliveryMode(mode);
@@ -4200,17 +4200,17 @@ nsMsgComposeAndSend::CreateRFC822Message
   mListener = aListener;
   mEmbeddedObjectList = aEmbeddedObjects;
 
   rv = Init(aUserIdentity, nullptr, (nsMsgCompFields *)aFields, nullptr,
             false, true, mode, nullptr,
             aMsgType,
             aMsgBody,
             nullptr, aAttachments,
-            nullptr, EmptyCString(), nsIMsgCompType::New);
+            EmptyString(), EmptyCString(), nsIMsgCompType::New);
 
   if (NS_FAILED(rv) && mSendReport)
     mSendReport->SetError(nsIMsgSendReport::process_Current, rv, false);
 
   return rv;
 }
 
 nsresult
@@ -4220,17 +4220,17 @@ nsMsgComposeAndSend::SendMessageFile(
               nsIMsgCompFields                  *fields,
               nsIFile                           *sendIFile,
               bool                              deleteSendFileOnCompletion,
               bool                              digest_p,
               nsMsgDeliverMode                  mode,
               nsIMsgDBHdr                       *msgToReplace,
               nsIMsgSendListener                *aListener,
               nsIMsgStatusFeedback              *aStatusFeedback,
-              const char                        *password
+              const char16_t                    *password
               )
 {
   NS_ENSURE_ARG_POINTER(fields);
   NS_ENSURE_ARG_POINTER(sendIFile);
 
   nsresult      rv;
 
   /* First thing to do is to reset the send errors report */
@@ -4254,17 +4254,18 @@ nsMsgComposeAndSend::SendMessageFile(
   // Should we delete the temp file when done?
   if (!deleteSendFileOnCompletion)
     mReturnFile = sendIFile;
 
   rv = Init(aUserIndentity, aAccountKey, (nsMsgCompFields *)fields, sendIFile,
             digest_p, false, mode, msgToReplace,
             nullptr, EmptyCString(),
             nullptr, nullptr,
-            password, EmptyCString(), nsIMsgCompType::New);
+            password ? nsDependentString(password) : EmptyString(),
+            EmptyCString(), nsIMsgCompType::New);
 
   if (NS_SUCCEEDED(rv))
     rv = DeliverMessage();
 
   if (NS_FAILED(rv) && mSendReport)
     mSendReport->SetError(nsIMsgSendReport::process_Current, rv, false);
 
   return rv;
--- a/mailnews/compose/src/nsMsgSend.h
+++ b/mailnews/compose/src/nsMsgSend.h
@@ -225,17 +225,17 @@ public:
                    bool             digest_p,
                    bool             dont_deliver_p,
                    nsMsgDeliverMode mode,
                    nsIMsgDBHdr      *msgToReplace,
                    const char       *attachment1_type,
                    const nsACString &attachment1_body,
                    nsIArray   *attachments,
                    nsIArray     *preloaded_attachments,
-                   const char       *password,
+                   const nsAString &password,
                    const nsACString &aOriginalMsgURI,
                    MSG_ComposeType  aType);
 
   //
   // Setup the composition fields
   //
   nsresult    InitCompositionFields(nsMsgCompFields *fields,
                                     const nsACString &aOriginalMsgURI,
@@ -390,17 +390,17 @@ protected:
   nsresult AddDefaultCustomHeaders();
 
   // add Mail-Followup-To and Mail-Reply-To header
   nsresult AddMailFollowupToHeader();
   nsresult AddMailReplyToHeader();
   nsresult AddXForwardedMessageIdHeader();
 
   nsCOMPtr<nsIMsgSendReport>  mSendReport;
-  nsCString                   mSmtpPassword;            // store the smtp Password use during a send
+  nsString                    mSmtpPassword;            // store the smtp Password use during a send
 };
 
 //
 // These C routines should only be used by the nsMsgSendPart class.
 //
 extern nsresult mime_write_message_body(nsIMsgSend *state, const char *buf, uint32_t size);
 extern char   *mime_get_stream_write_buffer(void);
 extern nsresult mime_encoder_output_fn (const char *buf, int32_t size, void *closure);
--- a/mailnews/compose/src/nsSmtpProtocol.cpp
+++ b/mailnews/compose/src/nsSmtpProtocol.cpp
@@ -1431,17 +1431,17 @@ void nsSmtpProtocol::AuthLoginStep0Respo
 
 nsresult nsSmtpProtocol::AuthLoginStep1()
 {
   char buffer[512]; // TODO nsAutoCString
   nsresult rv;
   nsresult status = NS_OK;
   nsCString username;
   char *base64Str = nullptr;
-  nsAutoCString password;
+  nsAutoString password;
   nsCOMPtr<nsISmtpServer> smtpServer;
   rv = m_runningURL->GetSmtpServer(getter_AddRefs(smtpServer));
   if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
 
   rv = smtpServer->GetUsername(username);
   if (username.IsEmpty())
   {
     rv = GetUsernamePassword(username, password);
@@ -1458,43 +1458,44 @@ nsresult nsSmtpProtocol::AuthLoginStep1(
 
   GetPassword(password);
   if (password.IsEmpty())
   {
     MOZ_LOG(SMTPLogModule, mozilla::LogLevel::Error, ("SMTP: password undefined"));
     m_urlErrorState = NS_ERROR_SMTP_PASSWORD_UNDEFINED;
     return NS_ERROR_SMTP_PASSWORD_UNDEFINED;
   }
+  NS_ConvertUTF16toUTF8 uniPassword(password);
 
   if (m_currentAuthMethod == SMTP_AUTH_CRAM_MD5_ENABLED)
   {
     MOZ_LOG(SMTPLogModule, mozilla::LogLevel::Error, ("CRAM auth, step 1"));
     PR_snprintf(buffer, sizeof(buffer), "AUTH CRAM-MD5" CRLF);
   }
   else if (m_currentAuthMethod == SMTP_AUTH_NTLM_ENABLED ||
            m_currentAuthMethod == SMTP_AUTH_MSN_ENABLED)
   {
     MOZ_LOG(SMTPLogModule, mozilla::LogLevel::Debug, ("NTLM/MSN auth, step 1"));
     nsAutoCString response;
-    rv = DoNtlmStep1(username.get(), password.get(), response);
+    rv = DoNtlmStep1(username, password, response);
     PR_snprintf(buffer, sizeof(buffer), TestFlag(SMTP_AUTH_NTLM_ENABLED) ?
                                         "AUTH NTLM %.256s" CRLF :
                                         "%.256s" CRLF, response.get());
   }
   else if (m_currentAuthMethod == SMTP_AUTH_PLAIN_ENABLED)
   {
     MOZ_LOG(SMTPLogModule, mozilla::LogLevel::Debug, ("PLAIN auth"));
     char plain_string[512];
     int len = 1; /* first <NUL> char */
 
     memset(plain_string, 0, 512);
     PR_snprintf(&plain_string[1], 510, "%s", username.get());
     len += username.Length();
     len++; /* second <NUL> char */
-    PR_snprintf(&plain_string[len], 511-len, "%s", password.get());
+    PR_snprintf(&plain_string[len], 511-len, "%s", uniPassword.get());
     len += password.Length();
 
     base64Str = PL_Base64Encode(plain_string, len, nullptr);
     PR_snprintf(buffer, sizeof(buffer), "AUTH PLAIN %.256s" CRLF, base64Str);
   }
   else if (m_currentAuthMethod == SMTP_AUTH_LOGIN_ENABLED)
   {
     MOZ_LOG(SMTPLogModule, mozilla::LogLevel::Debug, ("LOGIN auth"));
@@ -1518,24 +1519,25 @@ nsresult nsSmtpProtocol::AuthLoginStep2(
 {
   /* use cached smtp password first
   * if not then use cached pop password
   * if pop password undefined
   * sync with smtp password
   */
   nsresult status = NS_OK;
   nsresult rv;
-  nsAutoCString password;
+  nsAutoString uniPassword;
 
-  GetPassword(password);
-  if (password.IsEmpty())
+  GetPassword(uniPassword);
+  if (uniPassword.IsEmpty())
   {
     m_urlErrorState = NS_ERROR_SMTP_PASSWORD_UNDEFINED;
     return NS_ERROR_SMTP_PASSWORD_UNDEFINED;
   }
+  NS_ConvertUTF16toUTF8 password(uniPassword);
   MOZ_LOG(SMTPLogModule, mozilla::LogLevel::Debug, ("SMTP AuthLoginStep2"));
 
   if (!password.IsEmpty())
   {
     char buffer[512];
     if (m_currentAuthMethod == SMTP_AUTH_CRAM_MD5_ENABLED)
     {
       MOZ_LOG(SMTPLogModule, mozilla::LogLevel::Debug, ("CRAM auth, step 2"));
@@ -2143,17 +2145,17 @@ nsresult nsSmtpProtocol::ProcessProtocol
       }
     }
   } /* while(!SMTP_PAUSE_FOR_READ) */
 
   return NS_OK;
 }
 
 nsresult
-nsSmtpProtocol::GetPassword(nsCString &aPassword)
+nsSmtpProtocol::GetPassword(nsString &aPassword)
 {
     nsresult rv;
     nsCOMPtr<nsISmtpUrl> smtpUrl = do_QueryInterface(m_runningURL, &rv);
     NS_ENSURE_SUCCESS(rv,rv);
 
     nsCOMPtr<nsISmtpServer> smtpServer;
     rv = smtpUrl->GetSmtpServer(getter_AddRefs(smtpServer));
     NS_ENSURE_SUCCESS(rv,rv);
@@ -2196,17 +2198,18 @@ nsSmtpProtocol::GetPassword(nsCString &a
     return rv;
 }
 
 /**
  * formatStrings is an array for the prompts, item 0 is the hostname, item 1
  * is the username.
  */
 nsresult
-nsSmtpProtocol::PromptForPassword(nsISmtpServer *aSmtpServer, nsISmtpUrl *aSmtpUrl, const char16_t **formatStrings, nsACString &aPassword)
+nsSmtpProtocol::PromptForPassword(nsISmtpServer *aSmtpServer, nsISmtpUrl *aSmtpUrl,
+                                  const char16_t **formatStrings, nsAString &aPassword)
 {
   nsCOMPtr<nsIStringBundleService> stringService =
     mozilla::services::GetStringBundleService();
   NS_ENSURE_TRUE(stringService, NS_ERROR_UNEXPECTED);
 
   nsCOMPtr<nsIStringBundle> composeStringBundle;
   nsresult rv = stringService->CreateBundle("chrome://messenger/locale/messengercompose/composeMsgs.properties", getter_AddRefs(composeStringBundle));
   NS_ENSURE_SUCCESS(rv,rv);
@@ -2235,17 +2238,17 @@ nsSmtpProtocol::PromptForPassword(nsISmt
   rv = aSmtpServer->GetPasswordWithUI(passwordPromptString.get(), passwordTitle.get(),
     netPrompt, aPassword);
   NS_ENSURE_SUCCESS(rv,rv);
   return rv;
 }
 
 nsresult
 nsSmtpProtocol::GetUsernamePassword(nsACString &aUsername,
-                                    nsACString &aPassword)
+                                    nsAString &aPassword)
 {
     nsresult rv;
     nsCOMPtr<nsISmtpUrl> smtpUrl = do_QueryInterface(m_runningURL, &rv);
     NS_ENSURE_SUCCESS(rv,rv);
 
     nsCOMPtr<nsISmtpServer> smtpServer;
     rv = smtpUrl->GetSmtpServer(getter_AddRefs(smtpServer));
     NS_ENSURE_SUCCESS(rv,rv);
--- a/mailnews/compose/src/nsSmtpProtocol.h
+++ b/mailnews/compose/src/nsSmtpProtocol.h
@@ -200,21 +200,21 @@ private:
 
     ////////////////////////////////////////////////////////////////////////////////////////
     // End of Protocol Methods
     ////////////////////////////////////////////////////////////////////////////////////////
 
     void SendMessageInFile();
 
     void AppendHelloArgument(nsACString& aResult);
-    nsresult GetPassword(nsCString &aPassword);
-    nsresult GetUsernamePassword(nsACString &aUsername, nsACString &aPassword);
+    nsresult GetPassword(nsString &aPassword);
+    nsresult GetUsernamePassword(nsACString &aUsername, nsAString &aPassword);
     nsresult PromptForPassword(nsISmtpServer *aSmtpServer, nsISmtpUrl *aSmtpUrl,
                                const char16_t **formatStrings,
-                               nsACString &aPassword);
+                               nsAString &aPassword);
 
     void    InitPrefAuthMethods(int32_t authMethodPrefValue);
     nsresult ChooseAuthMethod();
     void    MarkAuthMethodAsFailed(int32_t failedAuthMethod);
     void    ResetAuthMethods();
 
     virtual const char* GetType() override {return "smtp";}
 
--- a/mailnews/compose/src/nsSmtpServer.cpp
+++ b/mailnews/compose/src/nsSmtpServer.cpp
@@ -249,17 +249,17 @@ nsSmtpServer::SetUsername(const nsACStri
 
   // If the pref value is already empty, ClearUserPref will return
   // NS_ERROR_UNEXPECTED, so don't check the rv here.
   mPrefBranch->ClearUserPref("username");
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsSmtpServer::GetPassword(nsACString& aPassword)
+nsSmtpServer::GetPassword(nsAString& aPassword)
 {
     if (m_password.IsEmpty() && !m_logonFailed)
     {
       // try to avoid prompting the user for another password. If the user has set
       // the appropriate pref, we'll use the password from an incoming server, if
       // the user has already logged onto that server.
 
       // if this is set, we'll only use this, and not the other prefs
@@ -355,17 +355,17 @@ nsSmtpServer::VerifyLogon(nsIUrlListener
   nsresult rv;
   nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
   return smtpService->VerifyLogon(this, aUrlListener, aMsgWindow, aURL);
 }
 
 
 NS_IMETHODIMP
-nsSmtpServer::SetPassword(const nsACString& aPassword)
+nsSmtpServer::SetPassword(const nsAString& aPassword)
 {
   m_password = aPassword;
   return NS_OK;
 }
 
 nsresult
 nsSmtpServer::GetPasswordWithoutUI()
 {
@@ -401,30 +401,30 @@ nsSmtpServer::GetPasswordWithoutUI()
       NS_ENSURE_SUCCESS(rv, rv);
 
       if (username.Equals(serverUsername))
       {
         nsString password;
         rv = logins[i]->GetPassword(password);
         NS_ENSURE_SUCCESS(rv, rv);
 
-        LossyCopyUTF16toASCII(password, m_password);
+        m_password = password;
         break;
       }
     }
   }
   NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(numLogins, logins);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSmtpServer::GetPasswordWithUI(const char16_t *aPromptMessage,
                                 const char16_t *aPromptTitle,
                                 nsIAuthPrompt* aDialog,
-                                nsACString &aPassword)
+                                nsAString &aPassword)
 {
   if (!m_password.IsEmpty())
     return GetPassword(aPassword);
 
   // We need to get a password, but see if we can get it from the password
   // manager without requiring a prompt.
   nsresult rv = GetPasswordWithoutUI();
   if (rv == NS_ERROR_ABORT)
@@ -439,46 +439,41 @@ nsSmtpServer::GetPasswordWithUI(const ch
   }
 
   NS_ENSURE_ARG_POINTER(aDialog);
 
   // PromptPassword needs the username as well.
   nsCString serverUri(GetServerURIInternal(true));
 
   bool okayValue = true;
-  nsString uniPassword;
 
   rv = aDialog->PromptPassword(aPromptTitle, aPromptMessage,
                                NS_ConvertASCIItoUTF16(serverUri).get(),
                                nsIAuthPrompt::SAVE_PASSWORD_PERMANENTLY,
-                               getter_Copies(uniPassword), &okayValue);
+                               getter_Copies(aPassword), &okayValue);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // If the user pressed cancel, just return an empty string.
   if (!okayValue)
   {
     aPassword.Truncate();
     return NS_MSG_PASSWORD_PROMPT_CANCELLED;
   }
-
-  NS_LossyConvertUTF16toASCII password(uniPassword);
-
-  rv = SetPassword(password);
+  rv = SetPassword(aPassword);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  aPassword = password;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSmtpServer::GetUsernamePasswordWithUI(const char16_t * aPromptMessage, const
                                 char16_t *aPromptTitle,
                                 nsIAuthPrompt* aDialog,
                                 nsACString &aUsername,
-                                nsACString &aPassword)
+                                nsAString &aPassword)
 {
   nsresult rv;
   if (!m_password.IsEmpty())
   {
     rv = GetUsername(aUsername);
     NS_ENSURE_SUCCESS(rv, rv);
 
     return GetPassword(aPassword);
@@ -486,24 +481,23 @@ nsSmtpServer::GetUsernamePasswordWithUI(
 
   NS_ENSURE_ARG_POINTER(aDialog);
 
   nsCString serverUri;
   rv = GetServerURI(serverUri);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsString uniUsername;
-  nsString uniPassword;
   bool okayValue = true;
 
   rv = aDialog->PromptUsernameAndPassword(aPromptTitle, aPromptMessage,
                                           NS_ConvertASCIItoUTF16(serverUri).get(),
                                           nsIAuthPrompt::SAVE_PASSWORD_PERMANENTLY,
                                           getter_Copies(uniUsername),
-                                          getter_Copies(uniPassword),
+                                          getter_Copies(aPassword),
                                           &okayValue);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // If the user pressed cancel, just return emtpy strings.
   if (!okayValue)
   {
     aUsername.Truncate();
     aPassword.Truncate();
@@ -511,23 +505,20 @@ nsSmtpServer::GetUsernamePasswordWithUI(
   }
 
   // We got a username and password back...so remember them.
   NS_LossyConvertUTF16toASCII username(uniUsername);
 
   rv = SetUsername(username);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  NS_LossyConvertUTF16toASCII password(uniPassword);
-
-  rv = SetPassword(password);
+  rv = SetPassword(aPassword);
   NS_ENSURE_SUCCESS(rv, rv);
 
   aUsername = username;
-  aPassword = password;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSmtpServer::ForgetPassword()
 {
   nsresult rv;
   nsCOMPtr<nsILoginManager> loginMgr =
@@ -572,17 +563,17 @@ nsSmtpServer::ForgetPassword()
     {
       // If this fails, just continue, we'll still want to remove the password
       // from our local cache.
       loginMgr->RemoveLogin(logins[i]);
     }
   }
   NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, logins);
 
-  rv = SetPassword(EmptyCString());
+  rv = SetPassword(EmptyString());
   m_logonFailed = true;
   return rv;
 }
 
 NS_IMETHODIMP
 nsSmtpServer::GetServerURI(nsACString &aResult)
 {
   aResult = GetServerURIInternal(true);
--- a/mailnews/compose/src/nsSmtpServer.h
+++ b/mailnews/compose/src/nsSmtpServer.h
@@ -28,13 +28,13 @@ private:
     nsCOMPtr<nsIPrefBranch> mDefPrefBranch;
 
     nsresult getPrefs();
     void getIntPrefWithDefault(const char *prefName, int32_t *val,
                                int32_t defval);
     nsresult GetPasswordWithoutUI();
     nsCString GetServerURIInternal(const bool aIncludeUsername);
 
-    nsCString m_password;
+    nsString m_password;
     bool m_logonFailed;
 };
 
 #endif
--- a/mailnews/compose/src/nsSmtpService.cpp
+++ b/mailnews/compose/src/nsSmtpService.cpp
@@ -75,34 +75,34 @@ nsSmtpService::~nsSmtpService()
 }
 
 NS_IMPL_ISUPPORTS(nsSmtpService, nsISmtpService, nsIProtocolHandler)
 
 
 NS_IMETHODIMP nsSmtpService::SendMailMessage(nsIFile * aFilePath,
                                         const char * aRecipients,
                                         nsIMsgIdentity * aSenderIdentity,
-                                        const char * aPassword,
+                                        const nsAString & aPassword,
                                         nsIUrlListener * aUrlListener,
                                         nsIMsgStatusFeedback *aStatusFeedback,
                                         nsIInterfaceRequestor* aNotificationCallbacks,
                                         bool aRequestDSN,
                                         nsIURI ** aURL,
                                         nsIRequest ** aRequest)
 {
   nsIURI * urlToRun = nullptr;
   nsresult rv = NS_OK;
 
   nsCOMPtr<nsISmtpServer> smtpServer;
   rv = GetServerByIdentity(aSenderIdentity, getter_AddRefs(smtpServer));
 
   if (NS_SUCCEEDED(rv) && smtpServer)
   {
-    if (aPassword && *aPassword)
-      smtpServer->SetPassword(nsDependentCString(aPassword));
+    if (!aPassword.IsEmpty())
+      smtpServer->SetPassword(aPassword);
 
     // this ref counts urlToRun
     rv = NS_MsgBuildSmtpUrl(aFilePath, smtpServer, aRecipients, aSenderIdentity,
                             aUrlListener, aStatusFeedback,
                             aNotificationCallbacks, &urlToRun, aRequestDSN);
     if (NS_SUCCEEDED(rv) && urlToRun)	
       rv = NS_MsgLoadSmtpUrl(urlToRun, nullptr, aRequest);
 
--- a/mailnews/extensions/mdn/src/nsMsgMdnGenerator.cpp
+++ b/mailnews/extensions/mdn/src/nsMsgMdnGenerator.cpp
@@ -850,17 +850,17 @@ nsresult nsMsgMdnGenerator::SendMdnMsg()
 {
     DEBUG_MDN("nsMsgMdnGenerator::SendMdnMsg");
     nsresult rv;
     nsCOMPtr<nsISmtpService> smtpService = do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv,rv);
 
     nsCOMPtr<nsIRequest> aRequest;
     smtpService->SendMailMessage(m_file, m_dntRrt.get(), m_identity,
-                                     nullptr, this, nullptr, nullptr, false, nullptr,
+                                     EmptyString(), this, nullptr, nullptr, false, nullptr,
                                      getter_AddRefs(aRequest));
 
     return NS_OK;
 }
 
 nsresult nsMsgMdnGenerator::WriteString( const char *str )
 {
   NS_ENSURE_ARG (str);
--- a/mailnews/imap/public/nsIIMAPHostSessionList.h
+++ b/mailnews/imap/public/nsIIMAPHostSessionList.h
@@ -31,17 +31,17 @@ public:
   NS_IMETHOD  GetHostHasAdminURL(const char *serverKey, bool &result) = 0;
   NS_IMETHOD  SetHostHasAdminURL(const char *serverKey, bool hasAdminUrl) = 0;
   // Subscription
   NS_IMETHOD  GetHostIsUsingSubscription(const char *serverKey, bool &result) = 0;
   NS_IMETHOD  SetHostIsUsingSubscription(const char *serverKey, bool usingSubscription) = 0;
 
   // Passwords
   NS_IMETHOD  GetPasswordForHost(const char *serverKey, nsString &result) = 0;
-  NS_IMETHOD  SetPasswordForHost(const char *serverKey, const char *password) = 0;
+  NS_IMETHOD  SetPasswordForHost(const char *serverKey, const nsAString &password) = 0;
   NS_IMETHOD  GetPasswordVerifiedOnline(const char *serverKey, bool &result) = 0;
   NS_IMETHOD  SetPasswordVerifiedOnline(const char *serverKey) = 0;
 
   // OnlineDir
   NS_IMETHOD GetOnlineDirForHost(const char *serverKey,
                                  nsString &result) = 0;
   NS_IMETHOD SetOnlineDirForHost(const char *serverKey,
                                  const char *onlineDir) = 0;
--- a/mailnews/imap/public/nsIImapIncomingServer.idl
+++ b/mailnews/imap/public/nsIImapIncomingServer.idl
@@ -92,14 +92,14 @@ interface nsIImapIncomingServer : nsISup
    * server object.
    * @param aWindow  msgWindow to associate the password prompt with
    * @return Password string.
    * @exception NS_ERROR_FAILURE  The password could not be obtained.
    * @note NS_MSG_PASSWORD_PROMPT_CANCELLED is a success code that is returned
    *       if the prompt was presented to the user but the user cancelled the
    *       prompt.
    */
-  ACString PromptPassword(in nsIMsgWindow aWindow);
+  AString PromptPassword(in nsIMsgWindow aWindow);
   attribute boolean doingLsub;
 
   ACString getUriWithNamespacePrefixIfNecessary(in long namespaceType, in ACString originalUri);
   attribute boolean shuttingDown;
 };
--- a/mailnews/imap/public/nsIImapProtocol.idl
+++ b/mailnews/imap/public/nsIImapProtocol.idl
@@ -60,12 +60,10 @@ interface nsIImapProtocol : nsISupports 
 
   // Get last active time stamp
   void GetLastActiveTimeStamp(out PRTime aTimeStamp);
 
   void pseudoInterruptMsgLoad(in nsIMsgFolder imapFolder, in nsIMsgWindow aMsgWindow, out boolean interrupted);
   void GetSelectedMailboxName(out string folderName);
   // Reset folder connection to authenticated state
   void ResetToAuthenticatedState();
-
-  void OverrideConnectionInfo(in wstring pHost, in unsigned short pPort, in string pCookieData);
 };
 
--- a/mailnews/imap/public/nsIImapServerSink.idl
+++ b/mailnews/imap/public/nsIImapServerSink.idl
@@ -126,17 +126,17 @@ interface nsIImapServerSink : nsISupport
    *
    * @param aProtocol imap protocol object requesting the password.
    * @param aNewPasswordRequested Forces password prompt immediately
    * @param aPassword returns the password, unless we had to prompt or use the,
    *                  login manager and there was already a prompt up.
    */
   void asyncGetPassword(in nsIImapProtocol aProtocol,
                         in boolean aNewPasswordRequested,
-                        out ACString aPassword);
+                        out AString aPassword);
 
   attribute boolean userAuthenticated;
   void setMailServerUrls(in ACString manageMailAccount, in ACString manageLists, in ACString manageFilters);
 
   /** Used by the imap thread when upgrading from the socketType
    * trySTARTTLS.
    * @param aSucceeded whether STARTTLS succeeded. If it did, the server
    * will set the socket type to alwaysSTARTTLS, otherwise plain.
@@ -150,17 +150,17 @@ interface nsIImapServerSink : nsISupport
   string cramMD5Hash(in string decodedChallenge, in string key);
   /// String to send to the imap server as the login user name.
   readonly attribute ACString loginUsername;
   /// String to send to the imap server as the user name.
   readonly attribute ACString originalUsername;
   /// Internal pref key, unique over all servers
   readonly attribute ACString serverKey;
   /// password for server login
-  readonly attribute ACString serverPassword;
+  readonly attribute AString serverPassword;
   /// remove a connection to the server
   void removeServerConnection(in nsIImapProtocol aProtocol);
   /// is the imap server shutting down?
   readonly attribute boolean serverShuttingDown;
   /// reset the connection for a particular folder
   void resetServerConnection(in ACString aFolderName);
   /// tell the server if listing using lsub command
   void setServerDoingLsub(in boolean aDoingLsub);
--- a/mailnews/imap/src/nsIMAPHostSessionList.cpp
+++ b/mailnews/imap/src/nsIMAPHostSessionList.cpp
@@ -18,17 +18,16 @@
 
 nsIMAPHostInfo::nsIMAPHostInfo(const char *serverKey,
                                nsIImapIncomingServer *server)
 {
   fServerKey = serverKey;
   NS_ASSERTION(server, "*** Fatal null imap incoming server...\n");
   server->GetServerDirectory(fOnlineDir);
   fNextHost = NULL;
-  fCachedPassword = NULL;
   fCapabilityFlags = kCapabilityUndefined;
   fHierarchyDelimiters = NULL;
 #ifdef DEBUG_bienvenu1
   fHaveWeEverDiscoveredFolders = true; // try this, see what bad happens - we'll need to
   // figure out a way to make new accounts have it be false
 #else
   fHaveWeEverDiscoveredFolders = false; // try this, see what bad happens
 #endif
@@ -46,17 +45,16 @@ nsIMAPHostInfo::nsIMAPHostInfo(const cha
   fHaveAdminURL = false;
   fNamespacesOverridable = true;
   server->GetOverrideNamespaces(&fNamespacesOverridable);
   fTempNamespaceList = nsIMAPNamespaceList::CreatensIMAPNamespaceList();
 }
 
 nsIMAPHostInfo::~nsIMAPHostInfo()
 {
-  PR_Free(fCachedPassword);
   PR_Free(fHierarchyDelimiters);
   delete fNamespaceList;
   delete fTempNamespaceList;
   delete fShellCache;
 }
 
 NS_IMPL_ISUPPORTS(nsIMAPHostSessionList,
                               nsIImapHostSessionList,
@@ -150,31 +148,27 @@ nsIMAPHostSessionList::AddHostToList(con
   return (newHost == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
 }
 
 NS_IMETHODIMP nsIMAPHostSessionList::GetPasswordForHost(const char *serverKey, nsString &result)
 {
   PR_EnterMonitor(gCachedHostInfoMonitor);
   nsIMAPHostInfo *host = FindHost(serverKey);
   if (host)
-    CopyASCIItoUTF16(nsDependentCString(host->fCachedPassword), result);
+    result = host->fCachedPassword;
   PR_ExitMonitor(gCachedHostInfoMonitor);
   return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
 }
 
-NS_IMETHODIMP nsIMAPHostSessionList::SetPasswordForHost(const char *serverKey, const char *password)
+NS_IMETHODIMP nsIMAPHostSessionList::SetPasswordForHost(const char *serverKey, const nsAString &password)
 {
   PR_EnterMonitor(gCachedHostInfoMonitor);
   nsIMAPHostInfo *host = FindHost(serverKey);
   if (host)
-  {
-    PR_FREEIF(host->fCachedPassword);
-    if (password)
-      host->fCachedPassword = NS_strdup(password);
-  }
+    host->fCachedPassword = password;
   PR_ExitMonitor(gCachedHostInfoMonitor);
   return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
 }
 
 NS_IMETHODIMP nsIMAPHostSessionList::SetPasswordVerifiedOnline(const char *serverKey)
 {
   PR_EnterMonitor(gCachedHostInfoMonitor);
   nsIMAPHostInfo *host = FindHost(serverKey);
--- a/mailnews/imap/src/nsIMAPHostSessionList.h
+++ b/mailnews/imap/src/nsIMAPHostSessionList.h
@@ -20,17 +20,17 @@ class nsIMAPHostInfo
 {
 public:
   friend class nsIMAPHostSessionList;
 
   nsIMAPHostInfo(const char *serverKey, nsIImapIncomingServer *server);
   ~nsIMAPHostInfo();
 protected:
   nsCString fServerKey;
-  char *fCachedPassword;
+  nsString fCachedPassword;
   nsCString fOnlineDir;
   nsIMAPHostInfo *fNextHost;
   eIMAPCapabilityFlags fCapabilityFlags;
   char *fHierarchyDelimiters;// string of top-level hierarchy delimiters
   bool fHaveWeEverDiscoveredFolders;
   char *fCanonicalOnlineSubDir;
   nsIMAPNamespaceList *fNamespaceList, *fTempNamespaceList;
   bool fNamespacesOverridable;
@@ -63,17 +63,17 @@ public:
   NS_IMETHOD GetHostHasAdminURL(const char *serverKey, bool &result) override;
   NS_IMETHOD SetHostHasAdminURL(const char *serverKey, bool hasAdminUrl) override;
   // Subscription
   NS_IMETHOD GetHostIsUsingSubscription(const char *serverKey, bool &result) override;
   NS_IMETHOD SetHostIsUsingSubscription(const char *serverKey, bool usingSubscription) override;
 
   // Passwords
   NS_IMETHOD GetPasswordForHost(const char *serverKey, nsString &result) override;
-  NS_IMETHOD SetPasswordForHost(const char *serverKey, const char *password) override;
+  NS_IMETHOD SetPasswordForHost(const char *serverKey, const nsAString &password) override;
   NS_IMETHOD GetPasswordVerifiedOnline(const char *serverKey, bool &result) override;
   NS_IMETHOD SetPasswordVerifiedOnline(const char *serverKey) override;
 
   // OnlineDir
   NS_IMETHOD GetOnlineDirForHost(const char *serverKey,
                                  nsString &result) override;
   NS_IMETHOD SetOnlineDirForHost(const char *serverKey,
                                  const char *onlineDir) override;
--- a/mailnews/imap/src/nsImapIncomingServer.cpp
+++ b/mailnews/imap/src/nsImapIncomingServer.cpp
@@ -952,17 +952,17 @@ NS_IMETHODIMP nsImapIncomingServer::Rese
 
   PR_CExitMonitor(this);
   return rv;
 }
 
 NS_IMETHODIMP
 nsImapIncomingServer::PerformExpand(nsIMsgWindow *aMsgWindow)
 {
-  nsCString password;
+  nsString password;
   nsresult rv;
   rv = GetPassword(password);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (password.IsEmpty())
     return NS_OK;
 
   rv = ResetFoldersToUnverified(nullptr);
@@ -2145,17 +2145,17 @@ NS_IMETHODIMP nsImapIncomingServer::Forg
 {
   return nsMsgIncomingServer::ForgetPassword();
 }
 
 
 NS_IMETHODIMP
 nsImapIncomingServer::AsyncGetPassword(nsIImapProtocol *aProtocol,
                                        bool aNewPasswordRequested,
-                                       nsACString &aPassword)
+                                       nsAString &aPassword)
 {
   if (m_password.IsEmpty())
   {
     // We're now going to need to do something that will end up with us either
     // poking login manager or prompting the user. We need to ensure we only
     // do one prompt at a time (and login manager could cause a master password
     // prompt), so we need to use the async prompter.
     nsresult rv;
@@ -2171,17 +2171,17 @@ nsImapIncomingServer::AsyncGetPassword(n
   }
   if (!m_password.IsEmpty())
     aPassword = m_password;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsImapIncomingServer::PromptPassword(nsIMsgWindow *aMsgWindow,
-                                     nsACString &aPassword)
+                                     nsAString &aPassword)
 {
   nsString passwordTitle;
   GetImapStringByName("imapEnterPasswordPromptTitle", passwordTitle);
   NS_ENSURE_STATE(m_stringBundle);
 
   nsAutoCString userName;
   GetRealUsername(userName);
 
@@ -3337,17 +3337,17 @@ nsImapIncomingServer::GetOriginalUsernam
 
 NS_IMETHODIMP
 nsImapIncomingServer::GetServerKey(nsACString &aServerKey)
 {
   return GetKey(aServerKey);
 }
 
 NS_IMETHODIMP
-nsImapIncomingServer::GetServerPassword(nsACString &aPassword)
+nsImapIncomingServer::GetServerPassword(nsAString &aPassword)
 {
   return GetPassword(aPassword);
 }
 
 NS_IMETHODIMP
 nsImapIncomingServer::RemoveServerConnection(nsIImapProtocol* aProtocol)
 {
   return RemoveConnection(aProtocol);
--- a/mailnews/imap/src/nsImapProtocol.cpp
+++ b/mailnews/imap/src/nsImapProtocol.cpp
@@ -476,17 +476,16 @@ nsImapProtocol::nsImapProtocol() : nsMsg
   m_fetchBodyListIsNew = false;
   m_flagChangeCount = 0;
   m_lastCheckTime = PR_Now();
 
   m_checkForNewMailDownloadsHeaders = true;  // this should be on by default
   m_hierarchyNameState = kNoOperationInProgress;
   m_discoveryStatus = eContinue;
 
-  m_overRideUrlConnectionInfo = false;
   // m_dataOutputBuf is used by Send Data
   m_dataOutputBuf = (char *) PR_CALLOC(sizeof(char) * OUTPUT_BUFFER_SIZE);
   m_allocatedSize = OUTPUT_BUFFER_SIZE;
 
   // used to buffer incoming data by ReadNextLine
   m_inputStreamBuffer = new nsMsgLineStreamBuffer(OUTPUT_BUFFER_SIZE, true /* allocate new lines */, false /* leave CRLFs on the returned string */);
   m_currentBiffState = nsIMsgFolder::nsMsgBiffState_Unknown;
   m_progressStringName.Truncate();
@@ -889,44 +888,31 @@ nsresult nsImapProtocol::SetupWithUrlCal
     connectionType = "ssl";
   else if (m_socketType == nsMsgSocketType::alwaysSTARTTLS)
     connectionType = "starttls";
   // This can go away once we think everyone is migrated
   // away from the trySTARTTLS socket type.
   else if (m_socketType == nsMsgSocketType::trySTARTTLS)
     connectionType = "starttls";
 
-  const nsACString *socketHost;
-  uint16_t socketPort;
-
-  if (m_overRideUrlConnectionInfo)
-  {
-    socketHost = &m_logonHost;
-    socketPort = m_logonPort;
-  }
-  else
-  {
-    socketHost = &m_realHostName;
-    int32_t port = -1;
-    nsCOMPtr<nsIURI> uri = do_QueryInterface(m_runningUrl, &rv);
-    if (NS_FAILED(rv))
-      return rv;
-    uri->GetPort(&port);
-    socketPort = port;
-  }
+  int32_t port = -1;
+  nsCOMPtr<nsIURI> uri = do_QueryInterface(m_runningUrl, &rv);
+  if (NS_FAILED(rv))
+    return rv;
+  uri->GetPort(&port);
 
   rv = socketService->CreateTransport(&connectionType, connectionType != nullptr,
-                                      *socketHost, socketPort, aProxyInfo,
+                                      m_realHostName, port, aProxyInfo,
                                       getter_AddRefs(m_transport));
   if (NS_FAILED(rv) && m_socketType == nsMsgSocketType::trySTARTTLS)
   {
     connectionType = nullptr;
     m_socketType = nsMsgSocketType::plain;
     rv = socketService->CreateTransport(&connectionType, connectionType != nullptr,
-                                        *socketHost, socketPort, aProxyInfo,
+                                        m_realHostName, port, aProxyInfo,
                                         getter_AddRefs(m_transport));
   }
 
   // remember so we can know whether we can issue a start tls or not...
   m_connectionType = connectionType;
   if (m_transport && m_mockChannel)
   {
     uint8_t qos;
@@ -5753,24 +5739,24 @@ void nsImapProtocol::MarkAuthMethodAsFai
  */
 void nsImapProtocol::ResetAuthMethods()
 {
   MOZ_LOG(IMAP, LogLevel::Debug, ("resetting (failed) auth methods"));
   m_currentAuthMethod = kCapabilityUndefined;
   m_failedAuthMethods = 0;
 }
 
-nsresult nsImapProtocol::AuthLogin(const char *userName, const nsCString &password, eIMAPCapabilityFlag flag)
+nsresult nsImapProtocol::AuthLogin(const char *userName, const nsString &aPassword, eIMAPCapabilityFlag flag)
 {
   ProgressEventFunctionUsingName("imapStatusSendingAuthLogin");
   IncrementCommandTagNumber();
 
   char * currentCommand=nullptr;
   nsresult rv;
-
+  NS_ConvertUTF16toUTF8 password(aPassword);
   MOZ_LOG(IMAP, LogLevel::Debug, ("IMAP: trying auth method 0x%" PRIx64, m_currentAuthMethod));
 
   if (flag & kHasAuthExternalCapability)
   {
       char *base64UserName = PL_Base64Encode(userName, strlen(userName), nullptr);
       nsAutoCString command (GetServerCommandTag());
       command.Append(" authenticate EXTERNAL " );
       command.Append(base64UserName);
@@ -5878,17 +5864,17 @@ nsresult nsImapProtocol::AuthLogin(const
     nsAutoCString command (GetServerCommandTag());
     command.Append((flag & kHasAuthNTLMCapability) ? " authenticate NTLM" CRLF
                                                    : " authenticate MSN" CRLF);
     rv = SendData(command.get());
     ParseIMAPandCheckForNewMail("AUTH NTLM"); // this just waits for ntlm step 1
     if (GetServerStateParser().LastCommandSuccessful())
     {
       nsAutoCString cmd;
-      rv = DoNtlmStep1(userName, password.get(), cmd);
+      rv = DoNtlmStep1(nsDependentCString(userName), aPassword, cmd);
       NS_ENSURE_SUCCESS(rv, rv);
       cmd += CRLF;
       rv = SendData(cmd.get());
       NS_ENSURE_SUCCESS(rv, rv);
       ParseIMAPandCheckForNewMail(command.get());
       if (GetServerStateParser().LastCommandSuccessful())
       {
         nsCString challengeStr(GetServerStateParser().fAuthChallenge);
@@ -5968,17 +5954,19 @@ nsresult nsImapProtocol::AuthLogin(const
     command.Append(" login \"");
     EscapeUserNamePasswordString(userName, &escapedUserName);
     command.Append(escapedUserName);
     command.Append("\" \"");
 
     // if the password contains a \, login will fail
     // turn foo\bar into foo\\bar
     nsAutoCString correctedPassword;
-    EscapeUserNamePasswordString(password.get(), &correctedPassword);
+    // We're assuming old style login doesn't want UTF-8
+    EscapeUserNamePasswordString(NS_LossyConvertUTF16toASCII(aPassword).get(),
+                                 &correctedPassword);
     command.Append(correctedPassword);
     command.Append("\"" CRLF);
     rv = SendData(command.get(), true /* suppress logging */);
     NS_ENSURE_SUCCESS(rv, rv);
     ParseIMAPandCheckForNewMail();
   }
   else if (flag & kHasXOAuth2Capability)
   {
@@ -6016,17 +6004,17 @@ nsresult nsImapProtocol::AuthLogin(const
   {
     MOZ_LOG(IMAP, LogLevel::Error, ("flags param has no auth scheme selected"));
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
   PR_Free(currentCommand);
   NS_ENSURE_SUCCESS(rv, rv);
   return GetServerStateParser().LastCommandSuccessful() ?
-        NS_OK : NS_ERROR_FAILURE;
+           NS_OK : NS_ERROR_FAILURE;
 }
 
 void nsImapProtocol::OnLSubFolders()
 {
   // **** use to find out whether Drafts, Sent, & Templates folder
   // exists or not even the user didn't subscribe to it
   char *mailboxName = OnCreateServerSourceFolderPathString();
   if (mailboxName)
@@ -8455,44 +8443,36 @@ nsresult nsImapProtocol::GetMsgWindow(ns
 }
 
 /**
  * Get password from RAM, disk (password manager) or user (dialog)
  * @return NS_MSG_PASSWORD_PROMPT_CANCELLED
  *    (which is NS_SUCCEEDED!) when user cancelled
  *    NS_FAILED(rv) for other errors
  */
-nsresult nsImapProtocol::GetPassword(nsCString &password,
+nsresult nsImapProtocol::GetPassword(nsString &password,
                                      bool newPasswordRequested)
 {
   // we are in the imap thread so *NEVER* try to extract the password with UI
-  // if logon redirection has changed the password, use the cookie as the password
-  if (m_overRideUrlConnectionInfo)
-  {
-    password.Assign(m_logonCookie);
-    return NS_OK;
-  }
-
   NS_ENSURE_TRUE(m_imapServerSink, NS_ERROR_NULL_POINTER);
   NS_ENSURE_TRUE(m_server, NS_ERROR_NULL_POINTER);
   nsresult rv;
 
   // Get the password already stored in mem
   rv = m_imapServerSink->GetServerPassword(password);
   if (NS_FAILED(rv) || password.IsEmpty())
   {
     AutoProxyReleaseMsgWindow msgWindow;
     GetMsgWindow(getter_AddRefs(msgWindow));
     NS_ENSURE_TRUE(msgWindow, NS_ERROR_NOT_AVAILABLE); // biff case
 
     // Get the password from pw manager (harddisk) or user (dialog)
-    nsAutoCString pwd; // GetPasswordWithUI truncates the password on Cancel
-    rv = m_imapServerSink->AsyncGetPassword(this,
-                                                     newPasswordRequested,
-                                                     password);
+    nsAutoString pwd; // GetPasswordWithUI truncates the password on Cancel
+    rv = m_imapServerSink->AsyncGetPassword(this, newPasswordRequested,
+                                            password);
     if (password.IsEmpty())
     {
       PRIntervalTime sleepTime = kImapSleepTime;
       m_passwordStatus = NS_OK;
       ReentrantMonitorAutoEnter mon(m_passwordReadyMonitor);
       while (m_password.IsEmpty() && !NS_FAILED(m_passwordStatus) &&
              m_passwordStatus != NS_MSG_PASSWORD_PROMPT_CANCELLED &&
              !DeathSignalReceived())
@@ -8512,17 +8492,17 @@ nsImapProtocol::OnPromptStart(bool *aRes
 {
   nsresult rv;
   nsCOMPtr<nsIImapIncomingServer> imapServer = do_QueryReferent(m_server, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIMsgWindow> msgWindow;
 
   *aResult = false;
   GetMsgWindow(getter_AddRefs(msgWindow));
-  nsCString password = m_lastPasswordSent;
+  nsString password = m_lastPasswordSent;
   rv = imapServer->PromptPassword(msgWindow, password);
   m_password = password;
   m_passwordStatus = rv;
   if (!m_password.IsEmpty())
     *aResult = true;
 
   // Notify the imap thread that we have a password.
   ReentrantMonitorAutoEnter passwordMon(m_passwordReadyMonitor);
@@ -8554,17 +8534,17 @@ nsImapProtocol::OnPromptCanceled()
 }
 
 bool nsImapProtocol::TryToLogon()
 {
   MOZ_LOG(IMAP, LogLevel::Debug, ("try to log in"));
   NS_ENSURE_TRUE(m_imapServerSink, false);
   bool loginSucceeded = false;
   bool skipLoop = false;
-  nsAutoCString password;
+  nsAutoString password;
   nsAutoCString userName;
 
   nsresult rv = ChooseAuthMethod();
   if (NS_FAILED(rv)) // all methods failed
   {
     // are there any matching login schemes at all?
     if (!(GetServerStateParser().GetCapabilityFlag() & m_prefAuthMethods))
     {
@@ -8708,17 +8688,17 @@ bool nsImapProtocol::TryToLogon()
                                                     &buttonPressed);
           if (NS_FAILED(rv))
             break;
           if (buttonPressed == 2) // 'New password' button
           {
             MOZ_LOG(IMAP, LogLevel::Warning, ("new password button pressed."));
             // Forget the current password
             password.Truncate();
-            m_hostSessionList->SetPasswordForHost(GetImapServerKey(), nullptr);
+            m_hostSessionList->SetPasswordForHost(GetImapServerKey(), EmptyString());
             m_imapServerSink->ForgetPassword();
             m_password.Truncate();
             MOZ_LOG(IMAP, LogLevel::Warning, ("password resetted (nulled)"));
             newPasswordRequested = true;
             // Will call GetPassword() in beginning of next loop
 
             // Try all possible auth methods again with the new password.
             ResetAuthMethods();
@@ -8741,17 +8721,17 @@ bool nsImapProtocol::TryToLogon()
         } // all methods failed
       } // login failed
   } // while
 
   if (loginSucceeded)
   {
     MOZ_LOG(IMAP, LogLevel::Debug, ("login succeeded"));
     bool passwordAlreadyVerified;
-    m_hostSessionList->SetPasswordForHost(GetImapServerKey(), password.get());
+    m_hostSessionList->SetPasswordForHost(GetImapServerKey(), password);
     rv = m_hostSessionList->GetPasswordVerifiedOnline(GetImapServerKey(), passwordAlreadyVerified);
     if (NS_SUCCEEDED(rv) && !passwordAlreadyVerified)
       m_hostSessionList->SetPasswordVerifiedOnline(GetImapServerKey());
     bool imapPasswordIsNew = !passwordAlreadyVerified;
     if (imapPasswordIsNew)
     {
       if (m_currentBiffState == nsIMsgFolder::nsMsgBiffState_Unknown)
       {
@@ -8827,25 +8807,16 @@ bool
 nsImapProtocol::GetShowDeletedMessages()
 {
     bool rv = false;
     if (m_hostSessionList)
         m_hostSessionList->GetShowDeletedMessagesForHost(GetImapServerKey(), rv);
     return rv;
 }
 
-NS_IMETHODIMP nsImapProtocol::OverrideConnectionInfo(const char16_t *pHost, uint16_t pPort, const char *pCookieData)
-{
-  m_logonHost = NS_LossyConvertUTF16toASCII(pHost);
-  m_logonPort = pPort;
-  m_logonCookie = pCookieData;
-  m_overRideUrlConnectionInfo = true;
-  return NS_OK;
-}
-
 bool nsImapProtocol::CheckNeeded()
 {
   if (m_flagChangeCount >= kFlagChangesBeforeCheck)
     return true;
 
   int32_t deltaInSeconds;
 
   PRTime2Seconds(PR_Now() - m_lastCheckTime, &deltaInSeconds);
--- a/mailnews/imap/src/nsImapProtocol.h
+++ b/mailnews/imap/src/nsImapProtocol.h
@@ -364,17 +364,17 @@ private:
   mozilla::ReentrantMonitor m_threadDeathMonitor;
   mozilla::ReentrantMonitor m_waitForBodyIdsMonitor;
   mozilla::ReentrantMonitor m_fetchBodyListMonitor;
   mozilla::ReentrantMonitor m_passwordReadyMonitor;
   mozilla::Mutex mLock;
   // If we get an async password prompt, this is where the UI thread
   // stores the password, before notifying the imap thread of the password
   // via the m_passwordReadyMonitor.
-  nsCString m_password;
+  nsString m_password;
   // Set to the result of nsImapServer::PromptPassword
   nsresult    m_passwordStatus;
 
   bool         m_imapThreadIsRunning;
   void ImapThreadMainLoop(void);
   nsresult    m_connectionStatus;
   nsCString   m_connectionType;
 
@@ -473,33 +473,33 @@ private:
   char m_currentServerCommandTag[11];
   uint32_t m_currentServerCommandTagNumber;
   void IncrementCommandTagNumber();
   const char *GetServerCommandTag();
 
   void StartTLS();
 
   // login related methods.
-  nsresult GetPassword(nsCString &password, bool aNewPasswordRequested);
+  nsresult GetPassword(nsString &password, bool aNewPasswordRequested);
   void InitPrefAuthMethods(int32_t authMethodPrefValue,
                            nsIMsgIncomingServer *aServer);
   nsresult ChooseAuthMethod();
   void MarkAuthMethodAsFailed(eIMAPCapabilityFlags failedAuthMethod);
   void ResetAuthMethods();
 
   // All of these methods actually issue protocol
   void Capability(); // query host for capabilities.
   void ID(); // send RFC 2971 app info to server
   void EnableCondStore(); 
   void StartCompressDeflate();
   nsresult BeginCompressing();
   void Language(); // set the language on the server if it supports it
   void Namespace();
   void InsecureLogin(const char *userName, const nsCString &password);
-  nsresult AuthLogin(const char *userName, const nsCString &password, eIMAPCapabilityFlag flag);
+  nsresult AuthLogin(const char *userName, const nsString &password, eIMAPCapabilityFlag flag);
   void ProcessAuthenticatedStateURL();
   void ProcessAfterAuthenticated();
   void ProcessSelectedStateURL();
   bool TryToLogon();
 
   // Process Authenticated State Url used to be one giant if statement. I've broken out a set of actions
   // based on the imap action passed into the url. The following functions are imap protocol handlers for
   // each action. They are called by ProcessAuthenticatedStateUrl.
@@ -628,23 +628,16 @@ private:
   // mapping between special xlist mailboxes and the corresponding folder flags
   nsDataHashtable<nsCStringHashKey, int32_t> m_specialXListMailboxes;
 
 
   nsIImapHostSessionList * m_hostSessionList;
 
   bool m_fromHeaderSeen;
 
-  // these settings allow clients to override various pieces of the connection info from the url
-  bool m_overRideUrlConnectionInfo;
-
-  nsCString m_logonHost;
-  nsCString m_logonCookie;
-  int16_t m_logonPort;
-  
   nsString mAcceptLanguages;
   
   // progress stuff
   void SetProgressString(uint32_t aStringIndex);
   
   nsCString     m_progressStringName;
   uint32_t      m_stringIndex;
   int32_t       m_progressCurrentNumber[IMAP_NUMBER_OF_PROGRESS_STRINGS];
--- a/mailnews/imap/src/nsSyncRunnableHelpers.cpp
+++ b/mailnews/imap/src/nsSyncRunnableHelpers.cpp
@@ -435,28 +435,28 @@ NS_SYNCRUNNABLEMETHOD1(ImapServerSink, S
 NS_SYNCRUNNABLEMETHOD2(ImapServerSink, RetryUrl, nsIImapUrl *, nsIImapMockChannel *)
 NS_SYNCRUNNABLEMETHOD0(ImapServerSink, AbortQueuedUrls)
 NS_SYNCRUNNABLEMETHOD2(ImapServerSink, GetImapStringByName, const char*, nsAString &)
 NS_SYNCRUNNABLEMETHOD2(ImapServerSink, PromptLoginFailed, nsIMsgWindow *, int32_t *)
 NS_SYNCRUNNABLEMETHOD2(ImapServerSink, FEAlert, const nsAString &, nsIMsgMailNewsUrl *)
 NS_SYNCRUNNABLEMETHOD2(ImapServerSink, FEAlertWithName, const char*, nsIMsgMailNewsUrl *)
 NS_SYNCRUNNABLEMETHOD2(ImapServerSink, FEAlertFromServer, const nsACString &, nsIMsgMailNewsUrl *)
 NS_SYNCRUNNABLEMETHOD0(ImapServerSink, CommitNamespaces)
-NS_SYNCRUNNABLEMETHOD3(ImapServerSink, AsyncGetPassword, nsIImapProtocol *, bool, nsACString &)
+NS_SYNCRUNNABLEMETHOD3(ImapServerSink, AsyncGetPassword, nsIImapProtocol *, bool, nsAString &)
 NS_SYNCRUNNABLEATTRIBUTE(ImapServerSink, UserAuthenticated, bool)
 NS_SYNCRUNNABLEMETHOD3(ImapServerSink, SetMailServerUrls, const nsACString &, const nsACString &, const nsACString &)
 NS_SYNCRUNNABLEMETHOD1(ImapServerSink, GetArbitraryHeaders, nsACString &)
 NS_SYNCRUNNABLEMETHOD0(ImapServerSink, ForgetPassword)
 NS_SYNCRUNNABLEMETHOD1(ImapServerSink, GetShowAttachmentsInline, bool *)
 NS_SYNCRUNNABLEMETHOD3(ImapServerSink, CramMD5Hash, const char *, const char *, char **)
 NS_SYNCRUNNABLEMETHOD1(ImapServerSink, GetLoginUsername, nsACString &)
 NS_SYNCRUNNABLEMETHOD1(ImapServerSink, UpdateTrySTARTTLSPref, bool)
 NS_SYNCRUNNABLEMETHOD1(ImapServerSink, GetOriginalUsername, nsACString &)
 NS_SYNCRUNNABLEMETHOD1(ImapServerSink, GetServerKey, nsACString &)
-NS_SYNCRUNNABLEMETHOD1(ImapServerSink, GetServerPassword, nsACString &)
+NS_SYNCRUNNABLEMETHOD1(ImapServerSink, GetServerPassword, nsAString &)
 NS_SYNCRUNNABLEMETHOD1(ImapServerSink, RemoveServerConnection, nsIImapProtocol *)
 NS_SYNCRUNNABLEMETHOD1(ImapServerSink, GetServerShuttingDown, bool *)
 NS_SYNCRUNNABLEMETHOD1(ImapServerSink, ResetServerConnection, const nsACString &)
 NS_SYNCRUNNABLEMETHOD1(ImapServerSink, SetServerDoingLsub, bool)
 NS_SYNCRUNNABLEMETHOD1(ImapServerSink, SetServerForceSelect, const nsACString &)
 
 
 namespace mozilla {
--- a/mailnews/local/src/nsPop3Protocol.cpp
+++ b/mailnews/local/src/nsPop3Protocol.cpp
@@ -770,17 +770,17 @@ NS_IMETHODIMP nsPop3Protocol::OnPromptSt
   MOZ_LOG(POP3LOGMODULE, LogLevel::Debug, (POP3LOG("OnPromptStart()")));
 
   *aResult = false;
 
   nsresult rv;
   nsCOMPtr<nsIMsgIncomingServer> server = do_QueryInterface(m_pop3Server, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsAutoCString passwordResult;
+  nsAutoString passwordResult;
 
   // pass the failed password into the password prompt so that
   // it will be pre-filled, in case it failed because of a
   // server problem and not because it was wrong.
   if (!m_lastPasswordSent.IsEmpty())
     passwordResult = m_lastPasswordSent;
 
   // Set up some items that we're going to need for the prompting.
@@ -2139,17 +2139,17 @@ int32_t nsPop3Protocol::SendUsername()
       m_pop3ConData->next_state = POP3_ERROR_DONE;
       return Error("pop3PasswordUndefined");
     }
     // </copied>
 
     nsAutoCString cmd;
 
     if (m_currentAuthMethod == POP3_HAS_AUTH_NTLM)
-        (void) DoNtlmStep1(m_username.get(), m_passwordResult.get(), cmd);
+        (void) DoNtlmStep1(m_username, m_passwordResult, cmd);
     else if (m_currentAuthMethod == POP3_HAS_AUTH_CRAM_MD5)
         cmd = "AUTH CRAM-MD5";
     else if (m_currentAuthMethod == POP3_HAS_AUTH_PLAIN)
         cmd = "AUTH PLAIN";
     else if (m_currentAuthMethod == POP3_HAS_AUTH_LOGIN)
     {
         char *base64Str = PL_Base64Encode(m_username.get(), m_username.Length(), nullptr);
         cmd = base64Str;
@@ -2207,17 +2207,18 @@ int32_t nsPop3Protocol::SendPassword()
     char buffer[512]; // TODO nsAutoCString
     unsigned char digest[DIGEST_LENGTH];
 
     char *decodedChallenge = PL_Base64Decode(m_commandResponse.get(),
     m_commandResponse.Length(), nullptr);
 
     if (decodedChallenge)
       rv = MSGCramMD5(decodedChallenge, strlen(decodedChallenge),
-                      m_passwordResult.get(), m_passwordResult.Length(), digest);
+                      NS_ConvertUTF16toUTF8(m_passwordResult).get(),
+                      m_passwordResult.Length(), digest);
     else
       rv = NS_ERROR_NULL_POINTER;
 
     if (NS_SUCCEEDED(rv))
     {
       nsAutoCString encodedDigest;
       char hexVal[8];
 
@@ -2239,17 +2240,18 @@ int32_t nsPop3Protocol::SendPassword()
   }
   else if (m_currentAuthMethod == POP3_HAS_AUTH_APOP)
   {
     MOZ_LOG(POP3LOGMODULE, LogLevel::Debug, (POP3LOG("APOP login")));
     char buffer[512];
     unsigned char digest[DIGEST_LENGTH];
 
     rv = MSGApopMD5(m_ApopTimestamp.get(), m_ApopTimestamp.Length(),
-                    m_passwordResult.get(), m_passwordResult.Length(), digest);
+                    NS_ConvertUTF16toUTF8(m_passwordResult).get(),  // Or ASCII?
+                    m_passwordResult.Length(), digest);
 
     if (NS_SUCCEEDED(rv))
     {
       nsAutoCString encodedDigest;
       char hexVal[8];
 
       for (uint32_t j=0; j<16; j++)
       {
@@ -2285,37 +2287,38 @@ int32_t nsPop3Protocol::SendPassword()
     }
 
     char plain_string[512]; // TODO nsCString
     int len = 1; /* first <NUL> char */
     memset(plain_string, 0, 512);
     PR_snprintf(&plain_string[1], 510, "%s", m_username.get());
     len += m_username.Length();
     len++; /* second <NUL> char */
-    PR_snprintf(&plain_string[len], 511-len, "%s", m_passwordResult.get());
-    len += m_passwordResult.Length();
+    NS_ConvertUTF16toUTF8 uniPassword(m_passwordResult);
+    PR_snprintf(&plain_string[len], 511-len, "%s", uniPassword.get());
+    len += uniPassword.Length();
 
     char *base64Str = PL_Base64Encode(plain_string, len, nullptr);
     cmd = base64Str;
     PR_Free(base64Str);
   }
   else if (m_currentAuthMethod == POP3_HAS_AUTH_LOGIN)
   {
     MOZ_LOG(POP3LOGMODULE, LogLevel::Debug, (POP3LOG("LOGIN password")));
-    char * base64Str =
-        PL_Base64Encode(m_passwordResult.get(), m_passwordResult.Length(),
-                        nullptr);
+    NS_LossyConvertUTF16toASCII asciiPassword(m_passwordResult);
+    char * base64Str = PL_Base64Encode(asciiPassword.get(),
+                                       asciiPassword.Length(), nullptr);
     cmd = base64Str;
     PR_Free(base64Str);
   }
   else if (m_currentAuthMethod == POP3_HAS_AUTH_USER)
   {
     MOZ_LOG(POP3LOGMODULE, LogLevel::Debug, (POP3LOG("PASS password")));
     cmd = "PASS ";
-    cmd += m_passwordResult;
+    cmd += NS_LossyConvertUTF16toASCII(m_passwordResult);
   }
   else
   {
     MOZ_LOG(POP3LOGMODULE, LogLevel::Error,
             (POP3LOG("In nsPop3Protocol::SendPassword(), m_currentAuthMethod is %X, "
                      "but that is unexpected"), m_currentAuthMethod));
     return Error("pop3AuthInternalError");
   }
--- a/mailnews/local/src/nsPop3Protocol.h
+++ b/mailnews/local/src/nsPop3Protocol.h
@@ -290,17 +290,17 @@ private:
   nsCOMPtr<nsIStringBundle> mLocalBundle;
 
   nsCString m_username;
   nsCString m_senderInfo;
   nsCString m_commandResponse;
   nsCString m_GSSAPICache;
 
   // Used for asynchronous password prompts to store the password temporarily.
-  nsCString m_passwordResult;
+  nsString m_passwordResult;
 
   // progress state information
   void UpdateProgressPercent(int64_t totalDone, int64_t total);
   void UpdateStatus(const char *aStatusName);
   void UpdateStatusWithString(const char16_t *aString);
   nsresult FormatCounterString(const nsString &stringName,
                                uint32_t count1,
                                uint32_t count2,
--- a/mailnews/local/test/unit/test_pop3PasswordFailure.js
+++ b/mailnews/local/test/unit/test_pop3PasswordFailure.js
@@ -8,18 +8,21 @@
  *   - Re-initiate connection, this time select enter new password, check that
  *     we get a new password prompt and can enter the password.
  */
 
 Components.utils.import("resource:///modules/mailServices.js");
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
+load("../../../resources/logHelper.js");
 load("../../../resources/alertTestUtils.js");
 load("../../../resources/passwordStorage.js");
+load("../../../resources/mailTestUtils.js");
+load("../../../resources/asyncTestUtils.js");
 
 var test = null;
 var server;
 var daemon;
 var incomingServer;
 var attempt = 0;
 
 var kUserName = "testpop3";
@@ -88,68 +91,91 @@ var urlListener =
       var transaction = server.playTransaction();
 
       // On the last attempt, we should have successfully got one mail.
       do_check_eq(localAccountUtils.inboxFolder.getTotalMessages(false),
                   attempt == 4 ? 1 : 0);
 
       // If we've just cancelled, expect binding aborted rather than success.
       do_check_eq(result, attempt == 2 ? Cr.NS_BINDING_ABORTED : 0);
+      async_driver();
     }
     catch (e) {
       // If we have an error, clean up nicely before we throw it.
       server.stop();
 
       var thread = gThreadManager.currentThread;
       while (thread.hasPendingEvents())
         thread.processNextEvent(true);
 
       do_throw(e);
     }
   }
 };
 
+// Definition of tests
+var tests = [
+  getMail1,
+  getMail2,
+  end_test
+]
+
 function actually_run_test() {
   daemon.setMessages(["message1.eml"]);
+  async_run_tests(tests);
+}
 
+function* getMail1()
+{
   dump("\nGet Mail 1\n");
 
   // Now get mail
   getPopMail();
+  yield false;
 
   dump("\nGot Mail 1\n");
 
   do_check_eq(attempt, 2);
 
-  // Check that we haven't forgetton the login even though we've retried and
+  // Check that we haven't forgotten the login even though we've retried and
   // canceled.
   let count = {};
   let logins = Services.logins.findLogins(count, "mailbox://localhost", null,
                                           "mailbox://localhost");
 
   do_check_eq(count.value, 1);
   do_check_eq(logins[0].username, kUserName);
   do_check_eq(logins[0].password, kInvalidPassword);
 
   server.resetTest();
+  yield true;
+}
 
+function* getMail2()
+{
   dump("\nGet Mail 2\n");
 
   // Now get the mail
   getPopMail();
-
+  yield false;
   dump("\nGot Mail 2\n");
 
   // Now check the new one has been saved.
-  logins = Services.logins.findLogins(count, "mailbox://localhost", null,
-                                      "mailbox://localhost");
+  let count = {};
+  let logins = Services.logins.findLogins(count, "mailbox://localhost", null,
+                                          "mailbox://localhost");
 
   do_check_eq(count.value, 1);
   do_check_eq(logins[0].username, kUserName);
   do_check_eq(logins[0].password, kValidPassword);
+  yield true;
+}
+
+function* end_test()
+{
   do_test_finished();
 }
 
 add_task(function *() {
   // Disable new mail notifications
   Services.prefs.setBoolPref("mail.biff.play_sound", false);
   Services.prefs.setBoolPref("mail.biff.show_alert", false);
   Services.prefs.setBoolPref("mail.biff.show_tray_icon", false);
--- a/mailnews/mapi/mapihook/src/msgMapiHook.cpp
+++ b/mailnews/mapi/mapihook/src/msgMapiHook.cpp
@@ -280,19 +280,16 @@ nsresult nsMapiHook::BlindSendMail (unsi
   if (NS_FAILED(rv)|| (!appService) ) return rv ;
 
   rv = appService->GetHiddenDOMWindow(getter_AddRefs(hiddenWindow));
   if ( NS_FAILED(rv) ) return rv ;
   // smtp password and Logged in used IdKey from MapiConfig (session obj)
   nsMAPIConfiguration * pMapiConfig = nsMAPIConfiguration::GetMAPIConfiguration() ;
   if (!pMapiConfig) return NS_ERROR_FAILURE ;  // get the singelton obj
   char16_t * password = pMapiConfig->GetPassword(aSession) ;
-  // password
-  nsAutoCString smtpPassword;
-  LossyCopyUTF16toASCII(password, smtpPassword);
 
   // Id key
   nsCString MsgIdKey;
   pMapiConfig->GetIdKey(aSession, MsgIdKey);
 
   // get the MsgIdentity for the above key using AccountManager
   nsCOMPtr <nsIMsgAccountManager> accountManager = do_GetService (NS_MSGACCOUNTMANAGER_CONTRACTID) ;
   if (NS_FAILED(rv) || (!accountManager) ) return rv ;
@@ -313,17 +310,17 @@ nsresult nsMapiHook::BlindSendMail (unsi
   // populate the compose params
   bool forcePlainText;
   aCompFields->GetForcePlainText(&forcePlainText);
   pMsgComposeParams->SetType(nsIMsgCompType::New);
   pMsgComposeParams->SetFormat(forcePlainText ? nsIMsgCompFormat::PlainText : nsIMsgCompFormat::HTML);
   pMsgComposeParams->SetIdentity(pMsgId);
   pMsgComposeParams->SetComposeFields(aCompFields);
   pMsgComposeParams->SetSendListener(sendListener) ;
-  pMsgComposeParams->SetSmtpPassword(smtpPassword.get());
+  pMsgComposeParams->SetSmtpPassword(nsDependentString(password));
 
   // create the nsIMsgCompose object to send the object
   nsCOMPtr<nsIMsgCompose> pMsgCompose (do_CreateInstance(NS_MSGCOMPOSE_CONTRACTID, &rv));
   if (NS_FAILED(rv) || (!pMsgCompose) ) return rv ;
 
   /** initialize nsIMsgCompose, Send the message, wait for send completion response **/
 
   rv = pMsgCompose->Initialize(pMsgComposeParams, hiddenWindow, nullptr);