diff --git a/mailnews/imap/src/nsImapService.cpp b/mailnews/imap/src/nsImapService.cpp index 881e72184bff..d78778076ceb 100644 --- a/mailnews/imap/src/nsImapService.cpp +++ b/mailnews/imap/src/nsImapService.cpp @@ -32,6 +32,7 @@ static NS_DEFINE_CID(kCImapHostSessionList, NS_IIMAPHOSTSESSIONLIST_CID); static NS_DEFINE_CID(kImapProtocolCID, NS_IMAPPROTOCOL_CID); +static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID); nsImapService::nsImapService() { @@ -65,4 +66,56 @@ NS_IMETHODIMP nsImapService::CreateImapConnection(PLEventQueue *aEventQueue, nsI } return rv; -} \ No newline at end of file +} + +NS_IMETHODIMP nsImapService::SelectFolder(PLEventQueue * aClientEventQueue, nsIImapMailfolder * aImapMailfolder, + nsIUrlListener * aUrlListener, nsIURL ** aURL) +{ + + // create a protocol instance to handle the request. + // NOTE: once we start working with multiple connections, this step will be much more complicated...but for now + // just create a connection and process the request. + + nsIImapProtocol * protocolInstance = nsnull; + nsresult rv = CreateImapConnection(aClientEventQueue, &protocolInstance); + nsIImapUrl * imapUrl = nsnull; + + if (NS_SUCCEEDED(rv) && protocolInstance) + { + // now we need to create an imap url to load into the connection. The url needs to represent a select folder action. + rv = nsComponentManager::CreateInstance(kImapUrlCID, nsnull, + nsIImapUrl::GetIID(), (void **) + &imapUrl); + } + if (NS_SUCCEEDED(rv) && imapUrl) + { + rv = imapUrl->SetImapAction(nsIImapUrl::nsImapSelectFolder); + rv = imapUrl->SetImapMailfolder(aImapMailfolder); + // hmmm this is cludgy...we need to get the incoming server, get the host and port, and generate an imap url spec + // based on that information then tell the imap parser to parse that spec...*yuck*. I have to think of a better way + // for automatically generating the spec based on the incoming server data... + nsIMsgIncomingServer * server = nsnull; + rv = imapUrl->GetServer(&server); + if (NS_SUCCEEDED(rv) && server) + { + char * hostName = nsnull; + rv = server->GetHostName(&hostName); + if (NS_SUCCEEDED(rv) && hostName) + { + char * urlSpec = PR_smprintf("imap://%s", hostName); + rv = imapUrl->SetSpec(urlSpec); + PR_Free(hostName); + PR_FREEIF(urlSpec); + } // if we got a host name + } // if we have a incoming server + + imapUrl->RegisterListener(aUrlListener); // register listener if there is one. + protocolInstance->LoadUrl(imapUrl, nsnull); + if (aURL) + *aURL = imapUrl; + else + NS_RELEASE(imapUrl); // release our ref count from the create instance call... + } // if we have a url to run.... + + return rv; +} diff --git a/mailnews/imap/src/nsImapService.h b/mailnews/imap/src/nsImapService.h index c7a897380b0d..7cd869b82f9e 100644 --- a/mailnews/imap/src/nsImapService.h +++ b/mailnews/imap/src/nsImapService.h @@ -37,7 +37,8 @@ public: //////////////////////////////////////////////////////////////////////////////////////// NS_IMETHOD CreateImapConnection (PLEventQueue *aEventQueue, nsIImapProtocol ** aImapConnection); - + + NS_IMETHOD SelectFolder(PLEventQueue * aClientEventQueue, nsIImapMailfolder *, nsIUrlListener * aUrlListener, nsIURL ** aURL); //////////////////////////////////////////////////////////////////////////////////////// // End support of nsISmtpService interface ////////////////////////////////////////////////////////////////////////////////////////