making selecting message/folder within a folder works; extract imap msg incoming server from url spec

This commit is contained in:
jefft%netscape.com 1999-05-04 18:17:33 +00:00
Родитель 26ee3d2f0f
Коммит 1423ef064d
7 изменённых файлов: 262 добавлений и 145 удалений

Просмотреть файл

@ -477,7 +477,7 @@ NS_IMETHODIMP nsImapMailFolder::GetMessages(nsIEnumerator* *result)
char *folderName = nsnull;
rv = GetName(&folderName);
if (folderName && !PL_strcasecmp(folderName, "INBOX"))
// if (folderName && !PL_strcasecmp(folderName, "INBOX"))
selectFolder = PR_TRUE;
delete [] folderName;
@ -761,7 +761,7 @@ NS_IMETHODIMP nsImapMailFolder::GetUsersName(char** userName)
return rv;
else
*userName = nsnull;
#if 1 // for now
NS_WITH_SERVICE(nsIMsgMailSession, session, kMsgMailSessionCID, &rv);
if (NS_SUCCEEDED(rv) && session)
@ -773,6 +773,32 @@ NS_IMETHODIMP nsImapMailFolder::GetUsersName(char** userName)
rv = server->GetUserName(userName);
NS_IF_RELEASE (server);
}
#else // **** for the future
nsCOMPtr<nsIFolder> aFolder(do_QueryInterface((nsIMsgFolder*) this, &rv));
if (NS_FAILED(rv)) return rv;
char *uri = nsnull;
rv = aFolder->GetURI(&uri);
if (NS_FAILED(rv)) return rv;
nsAutoString aName = uri;
PR_FREEIF(uri);
if (aName.Find(kImapRootURI) != 0)
return NS_ERROR_FAILURE;
aName.Cut(0, PL_strlen(kImapRootURI));
while (aName[0] == '/')
aName.Cut(0, 1);
PRInt32 userEnd = aName.Find('@');
if (userEnd < 1)
return NS_ERROR_NULL_POINTER;
aName.SetLength(userEnd);
char *tmpCString = aName.ToNewCString();
if (tmpCString && *tmpCString)
{
*userName = PL_strdup(tmpCString);
rv = NS_OK;
delete []tmpCString;
}
return rv;
#endif
return rv;
}
@ -787,18 +813,29 @@ NS_IMETHODIMP nsImapMailFolder::GetHostName(char** hostName)
else
*hostName = nsnull;
NS_WITH_SERVICE(nsIMsgMailSession, session, kMsgMailSessionCID, &rv);
if (NS_SUCCEEDED(rv) && session)
nsCOMPtr<nsIFolder> aFolder(do_QueryInterface((nsIMsgFolder*)this, &rv));
if (NS_FAILED(rv)) return rv;
char *uri = nsnull;
rv = aFolder->GetURI(&uri);
if (NS_FAILED(rv)) return rv;
nsAutoString aName = uri;
PR_FREEIF(uri);
if (aName.Find(kImapRootURI) == 0)
aName.Cut(0, PL_strlen(kImapRootURI));
else
return NS_ERROR_FAILURE;
while (aName[0] == '/')
aName.Cut(0, 1);
PRInt32 hostEnd = aName.Find('/');
if (hostEnd > 0) // must have at least one valid charater
aName.SetLength(hostEnd);
char *tmpCString = aName.ToNewCString();
if (tmpCString && *tmpCString)
{
nsIMsgIncomingServer *server = nsnull;
rv = session->GetCurrentServer(&server);
if (NS_SUCCEEDED(rv) && server)
rv = server->GetHostName(hostName);
NS_IF_RELEASE (server);
*hostName = PL_strdup(tmpCString);
rv = NS_OK;
delete [] tmpCString;
}
return rv;
}
@ -858,7 +895,10 @@ NS_IMETHODIMP nsImapMailFolder::PossibleImapMailbox(
if(NS_FAILED(rv))
return rv;
if (!m_haveDiscoverAllFolders)
m_haveDiscoverAllFolders = PR_TRUE;
nsAutoString folderName = aSpec->allocatedPathName;
nsAutoString uri;
uri.Append(kImapRootURI);

Просмотреть файл

@ -144,6 +144,28 @@ nsImapService::CreateImapConnection(PLEventQueue *aEventQueue, nsIImapUrl * aIma
return rv;
}
nsresult
nsImapService::GetFolderName(nsIImapUrl* aImapUrl, nsIMsgFolder* aImapFolder,
nsString2& folderName)
{
nsresult rv;
nsCOMPtr<nsIFolder> aFolder(do_QueryInterface(aImapFolder, &rv));
if (NS_FAILED(rv)) return rv;
char *uri = nsnull;
rv = aFolder->GetURI(&uri);
if (NS_FAILED(rv)) return rv;
char * hostname = nsnull;
rv = aImapFolder->GetHostName(&hostname);
if (NS_FAILED(rv)) return rv;
nsString name;
rv = nsImapURI2FullName(kImapRootURI, hostname, uri, name);
PR_FREEIF(uri);
PR_FREEIF(hostname);
if (NS_SUCCEEDED(rv))
folderName = name;
return rv;
}
NS_IMETHODIMP
nsImapService::SelectFolder(PLEventQueue * aClientEventQueue,
nsIMsgFolder * aImapMailFolder,
@ -163,9 +185,10 @@ nsImapService::SelectFolder(PLEventQueue * aClientEventQueue,
nsIImapProtocol * protocolInstance = nsnull;
nsIImapUrl * imapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsresult rv;
rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl, aImapMailFolder,
protocolInstance, urlSpec);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl,
protocolInstance, urlSpec);
if (NS_SUCCEEDED(rv) && imapUrl)
{
PRBool gotFolder = PR_FALSE;
@ -174,13 +197,12 @@ nsImapService::SelectFolder(PLEventQueue * aClientEventQueue,
if (NS_SUCCEEDED(rv))
{
char *folderName = nsnull;
aImapMailFolder->GetName(&folderName);
gotFolder = folderName && PL_strlen(folderName) > 0;
nsString2 folderName("", eOneByte);
GetFolderName(imapUrl, aImapMailFolder, folderName);
gotFolder = folderName.Length() > 0;
urlSpec.Append("/select>/");
urlSpec.Append(folderName);
urlSpec.Append(folderName.GetBuffer());
rv = imapUrl->SetSpec(urlSpec.GetBuffer());
delete [] folderName;
} // if we got a host name
imapUrl->RegisterListener(aUrlListener); // register listener if there is one.
@ -213,9 +235,13 @@ nsImapService::LiteSelectFolder(PLEventQueue * aClientEventQueue,
nsIImapProtocol * protocolInstance = nsnull;
nsIImapUrl * imapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsString2 urlSpec("", eOneByte);
nsresult rv;
rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl, aImapMailFolder,
protocolInstance, urlSpec);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl, protocolInstance, urlSpec);
if (NS_SUCCEEDED(rv) && imapUrl)
{
@ -227,12 +253,9 @@ nsImapService::LiteSelectFolder(PLEventQueue * aClientEventQueue,
char hierarchySeparator = '/';
urlSpec.Append("/liteselect>");
urlSpec.Append(hierarchySeparator);
// ### FIXME - hardcode selection of the inbox - should get folder
// name from folder
char* folderName = nsnull;
aImapMailFolder->GetName(&folderName);
urlSpec.Append(folderName);
delete [] folderName;
nsString2 folderName("", eOneByte);
GetFolderName(imapUrl, aImapMailFolder, folderName);
urlSpec.Append(folderName.GetBuffer());
rv = imapUrl->SetSpec(urlSpec.GetBuffer());
} // if we got a host name
@ -280,7 +303,7 @@ NS_IMETHODIMP nsImapService::DisplayMessage(const char* aMessageURI, nsISupports
nsCOMPtr<nsIImapMessageSink> imapMessageSink(do_QueryInterface(res, &rv));
if (NS_SUCCEEDED(rv))
{
nsString2 messageIdString(eOneByte);
nsString2 messageIdString("", eOneByte);
messageIdString.Append(msgKey, 10);
rv = FetchMessage(queue, folder, imapMessageSink, aUrlListener,
@ -324,9 +347,12 @@ nsImapService::FetchMessage(PLEventQueue * aClientEventQueue,
nsIImapProtocol * protocolInstance = nsnull;
nsIImapUrl * imapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsString2 urlSpec("",eOneByte);
nsresult rv;
rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl, aImapMailFolder,
protocolInstance, urlSpec);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl, protocolInstance, urlSpec);
if (NS_SUCCEEDED(rv) && imapUrl)
{
@ -342,12 +368,11 @@ nsImapService::FetchMessage(PLEventQueue * aClientEventQueue,
urlSpec.Append(messageIdsAreUID ? uidString : sequenceString);
urlSpec.Append(">");
urlSpec.Append(hierarchySeparator);
char *folderName = nsnull;
aImapMailFolder->GetName(&folderName);
urlSpec.Append(folderName);
nsString2 folderName("", eOneByte);
GetFolderName(imapUrl, aImapMailFolder, folderName);
urlSpec.Append(folderName.GetBuffer());
urlSpec.Append(">");
urlSpec.Append(messageIdentifierList);
delete [] folderName;
rv = imapUrl->SetSpec(urlSpec.GetBuffer());
imapUrl->RegisterListener(aUrlListener); // register listener if there is one.
protocolInstance->LoadUrl(imapUrl, aDisplayConsumer);
@ -360,17 +385,29 @@ nsImapService::FetchMessage(PLEventQueue * aClientEventQueue,
return rv;
}
// utility function to handle basic setup - will probably change when the real connection stuff is done.
nsresult nsImapService::GetImapConnectionAndUrl(PLEventQueue * aClientEventQueue, nsIImapUrl * &imapUrl,
nsIImapProtocol * &protocolInstance, nsString2 &urlSpec)
nsresult nsImapService::GetImapConnectionAndUrl(
PLEventQueue * aClientEventQueue, nsIImapUrl * &imapUrl,
nsIMsgFolder* &aImapMailFolder, nsIImapProtocol * &protocolInstance,
nsString2 &urlSpec)
{
nsresult rv = NS_OK;
char *hostname = nsnull;
char *username = nsnull;
rv = aImapMailFolder->GetHostName(&hostname);
if (NS_FAILED(rv)) return rv;
rv = aImapMailFolder->GetUsersName(&username);
if (NS_FAILED(rv))
{
PR_FREEIF(hostname);
return rv;
}
// 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 = CreateStartOfImapUrl(*imapUrl, urlSpec);
rv = CreateStartOfImapUrl(*imapUrl, urlSpec, hostname, username);
// Create a imap connection to run the url inside of....
rv = CreateImapConnection(aClientEventQueue, imapUrl, &protocolInstance);
@ -378,30 +415,31 @@ nsresult nsImapService::GetImapConnectionAndUrl(PLEventQueue * aClientEventQueue
if (NS_FAILED(rv))
NS_IF_RELEASE(imapUrl); // release the imap url before we return it because the whole command failed...
PR_FREEIF(hostname);
PR_FREEIF(username);
return rv;
}
// these are all the urls we know how to generate. I'm going to make service methods
// for most of these...and use nsString2's to build up the string.
nsresult nsImapService::CreateStartOfImapUrl(nsIImapUrl &imapUrl, nsString2 &urlString)
nsresult nsImapService::CreateStartOfImapUrl(nsIImapUrl &imapUrl, nsString2
&urlString, const char* hostName,
const char* userName)
{
// 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...
nsresult rv = NS_OK;
// *** jefft -- let's only do hostname now. I'll do username later when
// the incoming server works were done. We might also need to pass in the
// port number
urlString = "imap://";
#if 0
uriString.Append(userName);
uriString.Append("@");
#endif
urlString.Append(hostName);
nsIMsgIncomingServer * server = nsnull;
nsresult rv = imapUrl.GetServer(&server); // no need to release server?
if (NS_SUCCEEDED(rv) && server)
{
char * hostName = nsnull;
rv = server->GetHostName(&hostName);
if (NS_SUCCEEDED(rv) && hostName)
{
urlString = "imap://";
urlString.Append(hostName);
PR_Free(hostName);
}
}
imapUrl.SetSpec(urlString.GetBuffer()); // *** jefft - force to parse the
// urlSpec in order to search for
// the correct incoming server
return rv;
}
@ -427,9 +465,11 @@ nsImapService::GetHeaders(PLEventQueue * aClientEventQueue,
nsIImapProtocol * protocolInstance = nsnull;
nsIImapUrl * imapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsString2 urlSpec("", eOneByte);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl, protocolInstance, urlSpec);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl,
aImapMailFolder, protocolInstance,
urlSpec);
if (NS_SUCCEEDED(rv) && imapUrl)
{
@ -444,10 +484,9 @@ nsImapService::GetHeaders(PLEventQueue * aClientEventQueue,
urlSpec.Append(messageIdsAreUID ? uidString : sequenceString);
urlSpec.Append(">");
urlSpec.Append(hierarchySeparator);
char *folderName = nsnull;
aImapMailFolder->GetName(&folderName);
urlSpec.Append(folderName);
delete [] folderName;
nsString2 folderName("", eOneByte);
GetFolderName(imapUrl, aImapMailFolder, folderName);
urlSpec.Append(folderName.GetBuffer());
urlSpec.Append(">");
urlSpec.Append(messageIdentifierList);
rv = imapUrl->SetSpec(urlSpec.GetBuffer());
@ -477,9 +516,11 @@ nsImapService::Noop(PLEventQueue * aClientEventQueue,
nsIImapProtocol * protocolInstance = nsnull;
nsIImapUrl * imapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsString2 urlSpec("", eOneByte);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl, protocolInstance, urlSpec);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl,
aImapMailFolder, protocolInstance,
urlSpec);
if (NS_SUCCEEDED(rv) && imapUrl)
{
@ -492,9 +533,9 @@ nsImapService::Noop(PLEventQueue * aClientEventQueue,
urlSpec.Append("/selectnoop>");
urlSpec.Append(hierarchySeparator);
char *folderName = nsnull;
urlSpec.Append(folderName);
delete [] folderName;
nsString2 folderName("", eOneByte);
GetFolderName(imapUrl, aImapMailFolder, folderName);
urlSpec.Append(folderName.GetBuffer());
rv = imapUrl->SetSpec(urlSpec.GetBuffer());
imapUrl->RegisterListener(aUrlListener); // register listener if there is one.
protocolInstance->LoadUrl(imapUrl, nsnull);
@ -521,9 +562,11 @@ nsImapService::Expunge(PLEventQueue * aClientEventQueue,
nsIImapProtocol * protocolInstance = nsnull;
nsIImapUrl * imapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsString2 urlSpec("",eOneByte);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl, protocolInstance, urlSpec);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl,
aImapMailFolder, protocolInstance,
urlSpec);
if (NS_SUCCEEDED(rv) && imapUrl)
{
@ -536,9 +579,9 @@ nsImapService::Expunge(PLEventQueue * aClientEventQueue,
urlSpec.Append("/Expunge>");
urlSpec.Append(hierarchySeparator);
char *folderName = nsnull;
urlSpec.Append(folderName);
delete [] folderName;
nsString2 folderName("", eOneByte);
GetFolderName(imapUrl, aImapMailFolder, folderName);
urlSpec.Append(folderName.GetBuffer());
rv = imapUrl->SetSpec(urlSpec.GetBuffer());
imapUrl->RegisterListener(aUrlListener); // register listener if there is one.
protocolInstance->LoadUrl(imapUrl, nsnull);
@ -568,9 +611,11 @@ nsImapService::Biff(PLEventQueue * aClientEventQueue,
nsIImapProtocol * protocolInstance = nsnull;
nsIImapUrl * imapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsString2 urlSpec("",eOneByte);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl, protocolInstance, urlSpec);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl,
aImapMailFolder, protocolInstance,
urlSpec);
if (NS_SUCCEEDED(rv) && imapUrl)
{
@ -583,10 +628,9 @@ nsImapService::Biff(PLEventQueue * aClientEventQueue,
urlSpec.Append("/Biff>");
urlSpec.Append(hierarchySeparator);
char *folderName = nsnull;
aImapMailFolder->GetName(&folderName);
urlSpec.Append(folderName);
delete [] folderName;
nsString2 folderName("", eOneByte);
GetFolderName(imapUrl, aImapMailFolder, folderName);
urlSpec.Append(folderName.GetBuffer());
urlSpec.Append(">");
urlSpec.Append(uidHighWater, 10);
rv = imapUrl->SetSpec(urlSpec.GetBuffer());
@ -619,9 +663,11 @@ nsImapService::DeleteMessages(PLEventQueue * aClientEventQueue,
nsIImapProtocol * protocolInstance = nsnull;
nsIImapUrl * imapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsString2 urlSpec("",eOneByte);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl, protocolInstance, urlSpec);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl,
aImapMailFolder, protocolInstance,
urlSpec);
if (NS_SUCCEEDED(rv) && imapUrl)
{
@ -636,9 +682,9 @@ nsImapService::DeleteMessages(PLEventQueue * aClientEventQueue,
urlSpec.Append(messageIdsAreUID ? uidString : sequenceString);
urlSpec.Append(">");
urlSpec.Append(hierarchySeparator);
char *folderName = nsnull;
aImapMailFolder->GetName(&folderName);
urlSpec.Append(folderName);
nsString2 folderName("", eOneByte);
GetFolderName(imapUrl, aImapMailFolder, folderName);
urlSpec.Append(folderName.GetBuffer());
urlSpec.Append(">");
urlSpec.Append(messageIdentifierList);
rv = imapUrl->SetSpec(urlSpec.GetBuffer());
@ -667,9 +713,11 @@ nsImapService::DeleteAllMessages(PLEventQueue * aClientEventQueue,
nsIImapProtocol * protocolInstance = nsnull;
nsIImapUrl * imapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsString2 urlSpec("",eOneByte);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl, protocolInstance, urlSpec);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl,
aImapMailFolder, protocolInstance,
urlSpec);
if (NS_SUCCEEDED(rv) && imapUrl)
{
@ -682,10 +730,9 @@ nsImapService::DeleteAllMessages(PLEventQueue * aClientEventQueue,
urlSpec.Append("/deleteallmsgs>");
urlSpec.Append(hierarchySeparator);
char *folderName = nsnull;
aImapMailFolder->GetName(&folderName);
urlSpec.Append(folderName);
delete [] folderName;
nsString2 folderName("", eOneByte);
GetFolderName(imapUrl, aImapMailFolder, folderName);
urlSpec.Append(folderName.GetBuffer());
rv = imapUrl->SetSpec(urlSpec.GetBuffer());
imapUrl->RegisterListener(aUrlListener); // register listener if there is one.
protocolInstance->LoadUrl(imapUrl, nsnull);
@ -760,9 +807,11 @@ nsresult nsImapService::DiddleFlags(PLEventQueue * aClientEventQueue,
nsIImapProtocol * protocolInstance = nsnull;
nsIImapUrl * imapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsString2 urlSpec("",eOneByte);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl, protocolInstance, urlSpec);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, imapUrl,
aImapMailFolder, protocolInstance,
urlSpec);
if (NS_SUCCEEDED(rv) && imapUrl)
{
@ -779,10 +828,9 @@ nsresult nsImapService::DiddleFlags(PLEventQueue * aClientEventQueue,
urlSpec.Append(messageIdsAreUID ? uidString : sequenceString);
urlSpec.Append(">");
urlSpec.Append(hierarchySeparator);
char *folderName = nsnull;
aImapMailFolder->GetName(&folderName);
urlSpec.Append(folderName);
delete [] folderName;
nsString2 folderName("", eOneByte);
GetFolderName(imapUrl, aImapMailFolder, folderName);
urlSpec.Append(folderName.GetBuffer());
urlSpec.Append(">");
urlSpec.Append(messageIdentifierList);
urlSpec.Append('>');
@ -860,10 +908,11 @@ nsImapService::DiscoverAllFolders(PLEventQueue* aClientEventQueue,
nsIImapProtocol* aProtocol = nsnull;
nsIImapUrl* aImapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsString2 urlSpec("", eOneByte);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, aImapUrl,
aProtocol, urlSpec);
aImapMailFolder, aProtocol,
urlSpec);
if (NS_SUCCEEDED (rv) && aImapUrl && aProtocol)
{
rv = SetImapUrlSink(aImapMailFolder, aImapUrl);
@ -902,10 +951,11 @@ nsImapService::DiscoverAllAndSubscribedFolders(PLEventQueue* aClientEventQueue,
nsIImapProtocol* aProtocol = nsnull;
nsIImapUrl* aImapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsString2 urlSpec("",eOneByte);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, aImapUrl,
aProtocol, urlSpec);
aImapMailFolder, aProtocol,
urlSpec);
if (NS_SUCCEEDED (rv) && aImapUrl && aProtocol)
{
rv = SetImapUrlSink(aImapMailFolder, aImapUrl);
@ -944,10 +994,11 @@ nsImapService::DiscoverChildren(PLEventQueue* aClientEventQueue,
nsIImapProtocol* aProtocol = nsnull;
nsIImapUrl* aImapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsString2 urlSpec("", eOneByte);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, aImapUrl,
aProtocol, urlSpec);
aImapMailFolder, aProtocol,
urlSpec);
if (NS_SUCCEEDED (rv) && aImapUrl && aProtocol)
{
rv = SetImapUrlSink(aImapMailFolder, aImapUrl);
@ -955,14 +1006,13 @@ nsImapService::DiscoverChildren(PLEventQueue* aClientEventQueue,
if (NS_SUCCEEDED(rv))
{
PRBool gotFolder = PR_FALSE;
char *folderName = nsnull;
aImapMailFolder->GetName(&folderName);
if (folderName && *folderName != nsnull)
nsString2 folderName("", eOneByte);
GetFolderName(aImapUrl, aImapMailFolder, folderName);
if (folderName.Length() > 0)
{
// **** fix me with host specific hierarchySeparator please
urlSpec.Append("/discoverchildren>/");
urlSpec.Append(folderName);
urlSpec.Append(folderName.GetBuffer());
rv = aImapUrl->SetSpec(urlSpec.GetBuffer());
if (NS_SUCCEEDED(rv))
{
@ -979,7 +1029,6 @@ nsImapService::DiscoverChildren(PLEventQueue* aClientEventQueue,
{
rv = NS_ERROR_NULL_POINTER;
}
delete [] folderName;
}
}
NS_IF_RELEASE(aImapUrl);
@ -1001,10 +1050,10 @@ nsImapService::DiscoverLevelChildren(PLEventQueue* aClientEventQueue,
nsIImapProtocol* aProtocol = nsnull;
nsIImapUrl* aImapUrl = nsnull;
nsString2 urlSpec(eOneByte);
nsString2 urlSpec("", eOneByte);
nsresult rv = GetImapConnectionAndUrl(aClientEventQueue, aImapUrl,
aProtocol, urlSpec);
aImapMailFolder, aProtocol, urlSpec);
if (NS_SUCCEEDED (rv) && aImapUrl && aProtocol)
{
rv = SetImapUrlSink(aImapMailFolder, aImapUrl);
@ -1012,16 +1061,15 @@ nsImapService::DiscoverLevelChildren(PLEventQueue* aClientEventQueue,
if (NS_SUCCEEDED(rv))
{
PRBool gotFolder = PR_FALSE;
char *folderName = nsnull;
aImapMailFolder->GetName(&folderName);
if (folderName && *folderName != nsnull)
nsString2 folderName("", eOneByte);
GetFolderName(aImapUrl, aImapMailFolder, folderName);
if (folderName.Length() > 0)
{
urlSpec.Append("/discoverlevelchildren>");
urlSpec.Append(level);
// **** fix me with host specific hierarchySeparator please
urlSpec.Append("/"); // hierarchySeparator "/"
urlSpec.Append(folderName);
urlSpec.Append(folderName.GetBuffer());
rv = aImapUrl->SetSpec(urlSpec.GetBuffer());
if (NS_SUCCEEDED(rv))
{
@ -1038,7 +1086,6 @@ nsImapService::DiscoverLevelChildren(PLEventQueue* aClientEventQueue,
{
rv = NS_ERROR_NULL_POINTER;
}
delete [] folderName;
}
}
NS_IF_RELEASE(aImapUrl);

Просмотреть файл

@ -143,12 +143,18 @@ public:
nsIUrlListener * aUrlListener, nsIURL ** aURL);
protected:
nsresult GetFolderName(nsIImapUrl* aImapUrl, nsIMsgFolder* aImapFolder,
nsString2& folderName);
nsresult GetImapConnectionAndUrl(PLEventQueue * aClientEventQueue,
nsIImapUrl * &imapUrl,
nsIImapUrl * &imapUrl,
nsIMsgFolder* &aImapFolder,
nsIImapProtocol * &protocolInstance,
nsString2 &urlSpec);
nsresult CreateStartOfImapUrl(nsIImapUrl &imapUrl,
nsString2 &urlString);
nsString2 &urlString,
const char* hostName,
const char* userName);
nsresult SetImapUrlSink(nsIMsgFolder* aMsgFolder,
nsIImapUrl* aImapUrl);
nsresult DiddleFlags(PLEventQueue * aClientEventQueue,

Просмотреть файл

@ -34,6 +34,8 @@
#include "plstr.h"
#include "prprf.h"
#include "nsCRT.h"
#include "nsCOMPtr.h"
#include "nsIImapIncomingServer.h"
// we need this because of an egcs 1.0 (and possibly gcc) compiler bug
// that doesn't allow you to call ::nsISupports::GetIID() inside of a class
@ -170,40 +172,16 @@ NS_IMETHODIMP nsImapUrl::GetRequiredImapState(nsImapState * aImapUrlState)
return NS_OK;
}
NS_IMETHODIMP nsImapUrl::SetServer(nsIMsgIncomingServer * aServer)
{
if (aServer)
{
NS_IF_RELEASE(m_server);
m_server = aServer;
NS_ADDREF(m_server);
return NS_OK;
}
else
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP nsImapUrl::GetServer(nsIMsgIncomingServer **aServer)
{
nsresult rv = NS_OK;
nsresult rv = NS_ERROR_NULL_POINTER;
if (aServer) // valid argument to return result in?
{
// if we weren't given an server, let's be creative and go fetch the default current
// server.
if (!m_server)
{
NS_WITH_SERVICE(nsIMsgMailSession, session, kMsgMailSessionCID, &rv);
if (NS_SUCCEEDED(rv) && session)
// store the server in m_server so we don't have to do this again.
rv = session->GetCurrentServer(&m_server);
}
// if we were given a server then use it.
if (m_server)
{
*aServer = m_server;
NS_ADDREF(m_server);
rv = NS_OK;
}
else
*aServer = nsnull;
@ -584,6 +562,30 @@ nsresult nsImapUrl::ParseURL(const nsString& aSpec, const nsIURL* aURL)
ParseImapPart(imapPartOfUrl);
delete [] cSpec;
if (m_host)
{
nsresult rv;
NS_IF_RELEASE (m_server);
m_server = nsnull;
NS_WITH_SERVICE(nsIMsgMailSession, session, kMsgMailSessionCID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIMsgAccountManager> accountManager;
rv = session->GetAccountManager(getter_AddRefs(accountManager));
if(NS_FAILED(rv)) return rv;
nsCOMPtr<nsISupportsArray> servers;
rv = accountManager->FindServersByHostname(m_host,
nsIImapIncomingServer::GetIID(),
getter_AddRefs(servers));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIMsgIncomingServer>
server(do_QueryInterface(servers->ElementAt(0)));
if (NS_FAILED(rv)) return rv;
rv = server->QueryInterface(nsIMsgIncomingServer::GetIID(), (void**)
&m_server);
}
NS_UNLOCK_INSTANCE();
return NS_OK;
}

Просмотреть файл

@ -44,7 +44,6 @@ public:
///////////////////////////////////////////////////////////////////////////////
// we support the nsIImapUrl interface
///////////////////////////////////////////////////////////////////////////////
NS_IMETHOD SetServer(nsIMsgIncomingServer * aServer);
NS_IMETHOD GetServer(nsIMsgIncomingServer ** aServer);
NS_IMETHOD GetImapLog(nsIImapLog ** aImapLog);

Просмотреть файл

@ -155,6 +155,25 @@ nsImapURI2Name(const char* rootURI, char* uriStr, nsString& name)
return uri.Right(name, count);
}
nsresult
nsImapURI2FullName(const char* rootURI, const char* hostname, char* uriStr,
nsString& name)
{
nsAutoString uri = uriStr;
nsAutoString fullName;
if (uri.Find(rootURI) != 0) return NS_ERROR_FAILURE;
PRInt32 hostStart = uri.Find(hostname);
if (hostStart <= 0) return NS_ERROR_FAILURE;
uri.Right(fullName, uri.Length() - hostStart);
uri = fullName;
PRInt32 hostEnd = uri.Find('/');
if (hostEnd <= 0) return NS_ERROR_FAILURE;
uri.Right(fullName, uri.Length() - hostEnd - 1);
if (fullName == "") return NS_ERROR_FAILURE;
name = fullName;
return NS_OK;
}
/* parses ImapMessageURI */
nsresult nsParseImapMessageURI(const char* uri, nsString& folderURI, PRUint32 *key)
{

Просмотреть файл

@ -26,7 +26,7 @@ static const char kImapRootURI[] = "imap:/";
static const char kImapMessageRootURI[] = "imap_message:/";
extern nsresult
nsGetImapRoot(nsFileSpec &result);
nsGetImapRoot(const char* hostname, nsFileSpec &result);
extern nsresult
nsImapURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult);
@ -37,6 +37,10 @@ nsPath2ImapURI(const char* rootURI, const nsFileSpec& path, char* *uri);
extern nsresult
nsImapURI2Name(const char* rootURI, char* uriStr, nsString& name);
extern nsresult
nsImapURI2FullName(const char* rootURI, const char* hostname, char* uriStr,
nsString& name);
extern nsresult
nsParseImapMessageURI(const char* uri, nsString& folderURI, PRUint32 *key);