diff --git a/mailnews/base/util/nsMsgMailNewsUrl.cpp b/mailnews/base/util/nsMsgMailNewsUrl.cpp index 670bbd7270a2..531e4727bbbf 100644 --- a/mailnews/base/util/nsMsgMailNewsUrl.cpp +++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp @@ -151,10 +151,11 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetServer(nsIMsgIncomingServer ** aIncomingServe nsXPIDLCString userName; nsresult rv = GetHost(getter_Copies(host)); - GetUsername(getter_Copies(userName)); - if ((const char *) userName) - nsUnescape(NS_CONST_CAST(char*,(const char*)userName)); + /* GetUsername() returns an unescaped string. + * do not unescape it again. + */ + GetUsername(getter_Copies(userName)); rv = GetScheme(getter_Copies(scheme)); if (NS_SUCCEEDED(rv)) @@ -392,6 +393,7 @@ NS_IMETHODIMP nsMsgMailNewsUrl::SetPreHost(const char * aPreHost) NS_IMETHODIMP nsMsgMailNewsUrl::GetUsername(char * *aUsername) { + /* note: this will return an unescaped string */ return m_baseURL->GetUsername(aUsername); } diff --git a/mailnews/local/src/nsPop3Protocol.cpp b/mailnews/local/src/nsPop3Protocol.cpp index aa108c3b03d5..a5320a3d864a 100644 --- a/mailnews/local/src/nsPop3Protocol.cpp +++ b/mailnews/local/src/nsPop3Protocol.cpp @@ -496,6 +496,8 @@ void nsPop3Protocol::UpdateProgressPercent (PRUint32 totalDone, PRUint32 total) mProgressEventSink->OnProgress(this, m_channelContext, (PRInt32) totalDone, (PRInt32) total); } +// note: SetUsername() expects an unescaped string +// do not pass in an escaped string void nsPop3Protocol::SetUsername(const char* name) { NS_ASSERTION(name, "no name specified!"); diff --git a/mailnews/local/src/nsPop3Service.cpp b/mailnews/local/src/nsPop3Service.cpp index 41f242e052ff..3d1bf53b218c 100644 --- a/mailnews/local/src/nsPop3Service.cpp +++ b/mailnews/local/src/nsPop3Service.cpp @@ -104,6 +104,8 @@ NS_IMETHODIMP nsPop3Service::CheckForNewMail(nsIMsgWindow* aMsgWindow, if (NS_SUCCEEDED(rv) && popServer) { // now construct a pop3 url... + // we need to escape the username because it may contain + // characters like / % or @ char * urlSpec = PR_smprintf("pop3://%s@%s:%d?check", (const char *)escapedUsername, (const char *)popHost, &popPort); rv = BuildPop3Url(urlSpec, inbox, popServer, aUrlListener, getter_AddRefs(url), aMsgWindow, popPort); PR_FREEIF(urlSpec); @@ -159,6 +161,8 @@ nsresult nsPop3Service::GetNewMail(nsIMsgWindow *aMsgWindow, nsIUrlListener * aU if (NS_SUCCEEDED(rv) && popServer ) { // now construct a pop3 url... + // we need to escape the username because it may contain + // characters like / % or @ char * urlSpec = PR_smprintf("pop3://%s@%s:%d", (const char *)escapedUsername, (const char *)popHost, popPort); if (aInbox) @@ -213,8 +217,12 @@ nsresult nsPop3Service::BuildPop3Url(char * urlSpec, pop3Url->SetPop3Sink(pop3Sink); + // escape the username before we call SetUsername(). we do this because GetUsername() + // will unescape the username nsCOMPtr pop3Uri(do_QueryInterface(pop3Url)); - pop3Uri->SetUsername(userName); + nsXPIDLCString escapedUsername; + *((char **)getter_Copies(escapedUsername)) = nsEscape((const char *)userName, url_XAlphas); + pop3Uri->SetUsername((const char *)escapedUsername); if (aUrlListener) { @@ -254,6 +262,8 @@ nsresult nsPop3Service::RunPopUrl(nsIMsgIncomingServer * aServer, nsIURI * aUrlT nsXPIDLCString userName; // load up required server information + // we store the username unescaped in the server + // so there is no need to unescape it rv = aServer->GetUsername(getter_Copies(userName)); // find out if the server is busy or not...if the server is busy, we are @@ -272,6 +282,7 @@ nsresult nsPop3Service::RunPopUrl(nsIMsgIncomingServer * aServer, nsIURI * aUrlT delete protocol; return rv; } + // the protocol stores the unescaped username, so there is no need to escape it. protocol->SetUsername(userName); rv = protocol->LoadUrl(aUrlToRun); } @@ -330,6 +341,8 @@ NS_IMETHODIMP nsPop3Service::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI server->GetPort(&port); if (port == -1) port = POP3_PORT; + // we need to escape the username because it may contain + // characters like / % or @ nsXPIDLCString escapedUsername; *((char **)getter_Copies(escapedUsername)) = nsEscape(username, url_XAlphas); @@ -354,7 +367,9 @@ NS_IMETHODIMP nsPop3Service::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI do_QueryInterface(*_retval, &rv); if (NS_SUCCEEDED(rv)) { - mailnewsurl->SetUsername((const char*) username); + // escape the username before we call SetUsername(). we do this because GetUsername() + // will unescape the username + mailnewsurl->SetUsername((const char*) escapedUsername); } nsCOMPtr popurl = do_QueryInterface(mailnewsurl, &rv); if (NS_SUCCEEDED(rv)) @@ -391,6 +406,8 @@ NS_IMETHODIMP nsPop3Service::NewChannel(nsIURI *aURI, nsIChannel **_retval) nsCOMPtr url = do_QueryInterface(aURI, &rv); if (NS_SUCCEEDED(rv) && url) { + // GetUsername() returns an unescaped username, and the protocol + // stores the username unescaped, so there is no need to escape or unescape anything url->GetUsername(getter_Copies(username)); protocol->SetUsername((const char *)username); }