mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 04:15:43 +00:00
fix for #34996. make sure pop works with usernames like
foo%bar, foo@bar, foo:bar, and foo/bar r=alecf
This commit is contained in:
parent
86e0e4dfef
commit
21066d7dbd
@ -151,10 +151,11 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetServer(nsIMsgIncomingServer ** aIncomingServe
|
|||||||
nsXPIDLCString userName;
|
nsXPIDLCString userName;
|
||||||
|
|
||||||
nsresult rv = GetHost(getter_Copies(host));
|
nsresult rv = GetHost(getter_Copies(host));
|
||||||
GetUsername(getter_Copies(userName));
|
|
||||||
|
|
||||||
if ((const char *) userName)
|
/* GetUsername() returns an unescaped string.
|
||||||
nsUnescape(NS_CONST_CAST(char*,(const char*)userName));
|
* do not unescape it again.
|
||||||
|
*/
|
||||||
|
GetUsername(getter_Copies(userName));
|
||||||
|
|
||||||
rv = GetScheme(getter_Copies(scheme));
|
rv = GetScheme(getter_Copies(scheme));
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv))
|
||||||
@ -392,6 +393,7 @@ NS_IMETHODIMP nsMsgMailNewsUrl::SetPreHost(const char * aPreHost)
|
|||||||
|
|
||||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetUsername(char * *aUsername)
|
NS_IMETHODIMP nsMsgMailNewsUrl::GetUsername(char * *aUsername)
|
||||||
{
|
{
|
||||||
|
/* note: this will return an unescaped string */
|
||||||
return m_baseURL->GetUsername(aUsername);
|
return m_baseURL->GetUsername(aUsername);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,6 +496,8 @@ void nsPop3Protocol::UpdateProgressPercent (PRUint32 totalDone, PRUint32 total)
|
|||||||
mProgressEventSink->OnProgress(this, m_channelContext, (PRInt32) totalDone, (PRInt32) 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)
|
void nsPop3Protocol::SetUsername(const char* name)
|
||||||
{
|
{
|
||||||
NS_ASSERTION(name, "no name specified!");
|
NS_ASSERTION(name, "no name specified!");
|
||||||
|
@ -104,6 +104,8 @@ NS_IMETHODIMP nsPop3Service::CheckForNewMail(nsIMsgWindow* aMsgWindow,
|
|||||||
if (NS_SUCCEEDED(rv) && popServer)
|
if (NS_SUCCEEDED(rv) && popServer)
|
||||||
{
|
{
|
||||||
// now construct a pop3 url...
|
// 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);
|
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);
|
rv = BuildPop3Url(urlSpec, inbox, popServer, aUrlListener, getter_AddRefs(url), aMsgWindow, popPort);
|
||||||
PR_FREEIF(urlSpec);
|
PR_FREEIF(urlSpec);
|
||||||
@ -159,6 +161,8 @@ nsresult nsPop3Service::GetNewMail(nsIMsgWindow *aMsgWindow, nsIUrlListener * aU
|
|||||||
if (NS_SUCCEEDED(rv) && popServer )
|
if (NS_SUCCEEDED(rv) && popServer )
|
||||||
{
|
{
|
||||||
// now construct a pop3 url...
|
// 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);
|
char * urlSpec = PR_smprintf("pop3://%s@%s:%d", (const char *)escapedUsername, (const char *)popHost, popPort);
|
||||||
|
|
||||||
if (aInbox)
|
if (aInbox)
|
||||||
@ -213,8 +217,12 @@ nsresult nsPop3Service::BuildPop3Url(char * urlSpec,
|
|||||||
|
|
||||||
pop3Url->SetPop3Sink(pop3Sink);
|
pop3Url->SetPop3Sink(pop3Sink);
|
||||||
|
|
||||||
|
// escape the username before we call SetUsername(). we do this because GetUsername()
|
||||||
|
// will unescape the username
|
||||||
nsCOMPtr<nsIURI> pop3Uri(do_QueryInterface(pop3Url));
|
nsCOMPtr<nsIURI> 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)
|
if (aUrlListener)
|
||||||
{
|
{
|
||||||
@ -254,6 +262,8 @@ nsresult nsPop3Service::RunPopUrl(nsIMsgIncomingServer * aServer, nsIURI * aUrlT
|
|||||||
nsXPIDLCString userName;
|
nsXPIDLCString userName;
|
||||||
|
|
||||||
// load up required server information
|
// 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));
|
rv = aServer->GetUsername(getter_Copies(userName));
|
||||||
|
|
||||||
// find out if the server is busy or not...if the server is busy, we are
|
// 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;
|
delete protocol;
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
// the protocol stores the unescaped username, so there is no need to escape it.
|
||||||
protocol->SetUsername(userName);
|
protocol->SetUsername(userName);
|
||||||
rv = protocol->LoadUrl(aUrlToRun);
|
rv = protocol->LoadUrl(aUrlToRun);
|
||||||
}
|
}
|
||||||
@ -330,6 +341,8 @@ NS_IMETHODIMP nsPop3Service::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI
|
|||||||
server->GetPort(&port);
|
server->GetPort(&port);
|
||||||
if (port == -1) port = POP3_PORT;
|
if (port == -1) port = POP3_PORT;
|
||||||
|
|
||||||
|
// we need to escape the username because it may contain
|
||||||
|
// characters like / % or @
|
||||||
nsXPIDLCString escapedUsername;
|
nsXPIDLCString escapedUsername;
|
||||||
*((char **)getter_Copies(escapedUsername)) =
|
*((char **)getter_Copies(escapedUsername)) =
|
||||||
nsEscape(username, url_XAlphas);
|
nsEscape(username, url_XAlphas);
|
||||||
@ -354,7 +367,9 @@ NS_IMETHODIMP nsPop3Service::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI
|
|||||||
do_QueryInterface(*_retval, &rv);
|
do_QueryInterface(*_retval, &rv);
|
||||||
if (NS_SUCCEEDED(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<nsIPop3URL> popurl = do_QueryInterface(mailnewsurl, &rv);
|
nsCOMPtr<nsIPop3URL> popurl = do_QueryInterface(mailnewsurl, &rv);
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv))
|
||||||
@ -391,6 +406,8 @@ NS_IMETHODIMP nsPop3Service::NewChannel(nsIURI *aURI, nsIChannel **_retval)
|
|||||||
nsCOMPtr<nsIMsgMailNewsUrl> url = do_QueryInterface(aURI, &rv);
|
nsCOMPtr<nsIMsgMailNewsUrl> url = do_QueryInterface(aURI, &rv);
|
||||||
if (NS_SUCCEEDED(rv) && url)
|
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));
|
url->GetUsername(getter_Copies(username));
|
||||||
protocol->SetUsername((const char *)username);
|
protocol->SetUsername((const char *)username);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user