adopt new msg uri scheme from scott, work on message loading

This commit is contained in:
bienvenu%netscape.com 1999-04-25 21:51:39 +00:00
Родитель 41a39fa613
Коммит f064c31fdb
6 изменённых файлов: 243 добавлений и 29 удалений

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

@ -41,7 +41,6 @@ static NS_DEFINE_CID(kCImapService, NS_IMAPSERVICE_CID);
static NS_DEFINE_CID(kCImapResource, NS_IMAPRESOURCE_CID);
static NS_DEFINE_CID(kCImapMessageResource, NS_IMAPMESSAGERESOURCE_CID);
////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////
@ -141,14 +140,21 @@ nsresult nsImapFactory::CreateInstance(nsISupports *aOuter, const nsIID &aIID, v
{
inst = NS_STATIC_CAST(nsIImapService *, new nsImapService());
}
else if (mClassID.Equals(kCImapMessageResource))
{
inst = NS_STATIC_CAST(nsIMessage*, new nsImapMessage());
}
else if (mClassID.Equals(kCImapResource))
{
inst = NS_STATIC_CAST(nsIMsgImapMailFolder *, new nsImapMailFolder());
}
else if (mClassID.Equals(kCImapMessageResource))
{
nsImapMessage * imapMessage = new nsImapMessage();
if (imapMessage)
rv = imapMessage->QueryInterface(aIID, aResult);
else
rv = NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv) && imapMessage)
delete imapMessage;
return rv;
}
if (inst == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
@ -225,23 +231,28 @@ NSRegisterSelf(nsISupports* aServMgr, const char* path)
if (NS_FAILED(rv)) goto done;
// register our RDF resource factories:
rv = compMgr->RegisterComponent(kCImapResource,
"Mail/News Imap Resource Factory",
NS_RDF_RESOURCE_FACTORY_PROGID_PREFIX "imap",
path, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done;
// rv = compMgr->RegisterComponent(kImapServiceCID, nsnull,
// "component://netscape/messenger/messageservice;type=imap_message",
// path, PR_TRUE, PR_TRUE);
// register our RDF resource factories:
rv = compMgr->RegisterComponent(kCImapResource,
"Mail/News Imap Resource Factory",
NS_RDF_RESOURCE_FACTORY_PROGID_PREFIX "imap",
path, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done;
rv = compMgr->RegisterComponent(kCImapService, nsnull,
"component://netscape/messenger/messageservice;type=imap_message",
path, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done;
rv = compMgr->RegisterComponent(kCImapService, nsnull, nsnull,
path, PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(kCImapMessageResource,
"Imap Message Resource Factory",
NS_RDF_RESOURCE_FACTORY_PROGID_PREFIX "imap_message",
path, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done;
done:
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;

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

@ -36,6 +36,7 @@
#include "nsImapUtils.h"
#include "nsMsgUtils.h"
#include "nsIMsgMailSession.h"
#include "nsImapMessage.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
@ -301,6 +302,28 @@ NS_IMETHODIMP nsImapMailFolder::GetSubFolders(nsIEnumerator* *result)
// doesn't end with .sbd
PRInt32 newFlags = MSG_FOLDER_FLAG_MAIL;
if (mDepth == 0)
{
#if 0
// temporary until we do folder discovery correctly.
nsAutoString name("Inbox");
nsIMsgFolder *child;
AddSubfolder(name, &child);
if (NS_SUCCEEDED(GetDatabase()))
{
nsIDBFolderInfo *dbFolderInfo = nsnull;
m_mailDatabase->GetDBFolderInfo(&dbFolderInfo);
if (dbFolderInfo)
{
dbFolderInfo->SetMailboxName(name);
NS_RELEASE(dbFolderInfo);
}
}
if (child)
NS_RELEASE(child);
#endif
}
if (path.IsDirectory()) {
newFlags |= (MSG_FOLDER_FLAG_DIRECTORY | MSG_FOLDER_FLAG_ELIDED);
SetFlag(newFlags);
@ -349,13 +372,13 @@ NS_IMETHODIMP nsImapMailFolder::ReplaceElement(nsISupports* element,
//returns NS_OK. Otherwise returns a failure error value.
nsresult nsImapMailFolder::GetDatabase()
{
nsresult folderOpen = NS_OK;
if (m_mailDatabase == nsnull)
{
nsNativeFileSpec path;
nsresult rv = GetPathName(path);
if (NS_FAILED(rv)) return rv;
nsresult folderOpen = NS_OK;
nsIMsgDatabase * mailDBFactory = nsnull;
rv = nsComponentManager::CreateInstance(kCImapDB, nsnull, nsIMsgDatabase::GetIID(), (void **) &mailDBFactory);
@ -382,7 +405,7 @@ nsresult nsImapMailFolder::GetDatabase()
}
}
}
return NS_OK;
return folderOpen;
}
@ -481,7 +504,9 @@ NS_IMETHODIMP nsImapMailFolder::CreateSubfolder(const char *folderName)
rv = unusedDB->GetDBFolderInfo(&folderInfo);
if(NS_SUCCEEDED(rv))
{
//folderInfo->SetMailboxName(leafNameFromUser);
nsString folderNameStr(folderName);
// ### DMB used to be leafNameFromUser?
folderInfo->SetMailboxName(folderNameStr);
NS_IF_RELEASE(folderInfo);
}
@ -540,6 +565,8 @@ NS_IMETHODIMP nsImapMailFolder::GetChildNamed(nsString& name, nsISupports **
NS_IMETHODIMP nsImapMailFolder::GetName(char ** name)
{
nsresult result = NS_OK;
if(!name)
return NS_ERROR_NULL_POINTER;
@ -551,13 +578,29 @@ NS_IMETHODIMP nsImapMailFolder::GetName(char ** name)
GetHostName(&hostName);
SetName(hostName);
PR_FREEIF(hostName);
m_haveReadNameFromDB = TRUE;
m_haveReadNameFromDB = PR_TRUE;
*name = mName.ToNewCString();
return NS_OK;
}
else
{
//Need to read the name from the database
result = GetDatabase();
if (NS_SUCCEEDED(result) && m_mailDatabase)
{
nsString folderName;
nsIDBFolderInfo *dbFolderInfo = nsnull;
m_mailDatabase->GetDBFolderInfo(&dbFolderInfo);
if (dbFolderInfo)
{
dbFolderInfo->GetMailboxName(folderName);
m_haveReadNameFromDB = PR_TRUE;
NS_RELEASE(dbFolderInfo);
*name = folderName.ToNewCString();
return NS_OK;
}
}
}
}
nsAutoString folderName;
@ -1044,10 +1087,48 @@ NS_IMETHODIMP nsImapMailFolder::AbortHeaderParseStream(nsIImapProtocol*
return rv;
}
NS_IMETHODIMP nsImapMailFolder::CreateMessageFromMsgDBHdr(nsIMsgDBHdr *msgHdr, nsIMessage **message)
NS_IMETHODIMP nsImapMailFolder::CreateMessageFromMsgDBHdr(nsIMsgDBHdr *msgDBHdr, nsIMessage **message)
{
nsresult rv;
NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
return NS_ERROR_FAILURE;
char* msgURI = nsnull;
nsFileSpec path;
nsMsgKey key;
nsIRDFResource* res;
rv = msgDBHdr->GetMessageKey(&key);
if(NS_SUCCEEDED(rv))
rv = GetPathName(path);
if(NS_SUCCEEDED(rv))
rv = nsBuildImapMessageURI(path, key, &msgURI);
if(NS_SUCCEEDED(rv))
{
rv = rdfService->GetResource(msgURI, &res);
}
if(msgURI)
PR_smprintf_free(msgURI);
if(NS_SUCCEEDED(rv))
{
nsIMessage *messageResource;
rv = res->QueryInterface(nsIMessage::GetIID(), (void**)&messageResource);
if(NS_SUCCEEDED(rv))
{
//We know from our factory that imap message resources are going to be
//nsImapMessages.
nsImapMessage *imapMessage = NS_STATIC_CAST(nsImapMessage*, messageResource);
imapMessage->SetMsgDBHdr(msgDBHdr);
*message = messageResource;
}
NS_IF_RELEASE(res);
}
return rv;
}

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

@ -32,10 +32,27 @@
#include "nsCOMPtr.h"
#include "nsIMsgFolder.h"
#include "nsImapUtils.h"
#include "nsIRDFService.h"
#include "nsIEventQueueService.h"
#include "nsRDFCID.h"
#include "nsXPComCIID.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
// that multiply inherits from nsISupports
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kCImapHostSessionList, NS_IIMAPHOSTSESSIONLIST_CID);
static NS_DEFINE_CID(kImapProtocolCID, NS_IMAPPROTOCOL_CID);
static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID);
NS_IMPL_THREADSAFE_ADDREF(nsImapService);
NS_IMPL_THREADSAFE_RELEASE(nsImapService);
nsImapService::nsImapService()
{
NS_INIT_REFCNT();
@ -53,7 +70,35 @@ nsImapService::~nsImapService()
(void)nsServiceManager::ReleaseService(kCImapHostSessionList, m_sessionList);
}
NS_IMPL_THREADSAFE_ISUPPORTS(nsImapService, nsIImapService::GetIID());
nsresult nsImapService::QueryInterface(const nsIID &aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsIImapService::GetIID()) || aIID.Equals(kISupportsIID))
{
*aInstancePtr = (void*) ((nsIImapService*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(nsIMsgMessageService::GetIID()))
{
*aInstancePtr = (void*) ((nsIMsgMessageService*)this);
AddRef();
return NS_OK;
}
#if defined(NS_DEBUG)
/*
* Check for the debug-only interface indicating thread-safety
*/
static NS_DEFINE_IID(kIsThreadsafeIID, NS_ISTHREADSAFE_IID);
if (aIID.Equals(kIsThreadsafeIID))
return NS_OK;
#endif
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsImapService::CreateImapConnection(PLEventQueue *aEventQueue,
@ -96,6 +141,7 @@ nsImapService::SelectFolder(PLEventQueue * aClientEventQueue,
protocolInstance, urlSpec);
if (NS_SUCCEEDED(rv) && imapUrl)
{
PRBool gotFolder = PR_FALSE;
rv = imapUrl->SetImapAction(nsIImapUrl::nsImapSelectFolder);
rv = SetImapUrlSink(aImapMailFolder, imapUrl);
@ -103,6 +149,7 @@ nsImapService::SelectFolder(PLEventQueue * aClientEventQueue,
{
char *folderName = nsnull;
aImapMailFolder->GetName(&folderName);
gotFolder = folderName && PL_strlen(folderName) > 0;
urlSpec.Append("/select>/");
urlSpec.Append(folderName);
rv = imapUrl->SetSpec(urlSpec.GetBuffer());
@ -110,7 +157,8 @@ nsImapService::SelectFolder(PLEventQueue * aClientEventQueue,
} // if we got a host name
imapUrl->RegisterListener(aUrlListener); // register listener if there is one.
protocolInstance->LoadUrl(imapUrl, nsnull);
if (gotFolder)
protocolInstance->LoadUrl(imapUrl, nsnull);
if (aURL)
*aURL = imapUrl;
else
@ -175,6 +223,70 @@ nsImapService::LiteSelectFolder(PLEventQueue * aClientEventQueue,
static const char *sequenceString = "SEQUENCE";
static const char *uidString = "UID";
NS_IMETHODIMP nsImapService::DisplayMessage(const char* aMessageURI, nsISupports * aDisplayConsumer,
nsIUrlListener * aUrlListener, nsIURL ** aURL)
{
nsImapUrl * imapUrl = nsnull;
nsIImapUrl * url = nsnull;
nsresult rv = NS_OK;
PLEventQueue *queue;
nsIRDFService* rdf = nsnull;
// get the Event Queue for this thread...
nsIEventQueueService* pEventQService = nsnull;
rv = nsServiceManager::GetService(kEventQueueServiceCID,
nsIEventQueueService::GetIID(),
(nsISupports**)&pEventQService);
if (NS_SUCCEEDED(rv) && pEventQService)
{
rv = pEventQService->GetThreadEventQueue(PR_GetCurrentThread(),&queue);
NS_RELEASE(pEventQService);
rv = nsServiceManager::GetService(kRDFServiceCID,
nsIRDFService::GetIID(),
(nsISupports**)&rdf);
}
nsString folderURI;
nsMsgKey msgKey;
rv = nsParseImapMessageURI(aMessageURI, folderURI, &msgKey);
if (NS_SUCCEEDED(rv))
{
nsIRDFResource* res;
rv = rdf->GetResource(nsAutoCString(folderURI), &res);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIMsgFolder> folder(do_QueryInterface(res, &rv));
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIImapMessageSink> imapMessageSink(do_QueryInterface(res, &rv));
if (NS_SUCCEEDED(rv))
{
nsString2 messageIdString(eOneByte);
messageIdString.Append(msgKey, 10);
rv = FetchMessage(queue, folder, imapMessageSink, aUrlListener,
aURL, messageIdString.GetBuffer(), PR_TRUE);
}
}
}
if (rdf)
(void)nsServiceManager::ReleaseService(kRDFServiceCID, rdf);
if (pEventQService)
(void)nsServiceManager::ReleaseService(kRDFServiceCID, pEventQService);
return rv;
}
NS_IMETHODIMP
nsImapService::CopyMessage(const char * aSrcMailboxURI, nsIStreamListener * aMailboxCopy, PRBool moveMessage,
nsIUrlListener * aUrlListener, nsIURL **aURL)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* fetching RFC822 messages */
/* imap4://HOST>fetch><UID/SEQUENCE>>MAILBOXPATH>x */
/* 'x' is the message UID or sequence number list */
@ -218,6 +330,7 @@ nsImapService::FetchMessage(PLEventQueue * aClientEventQueue,
char *folderName = nsnull;
aImapMailFolder->GetName(&folderName);
urlSpec.Append(folderName);
urlSpec.Append(">");
urlSpec.Append(messageIdentifierList);
delete [] folderName;
rv = imapUrl->SetSpec(urlSpec.GetBuffer());

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

@ -20,13 +20,14 @@
#define nsImapService_h___
#include "nsIImapService.h"
#include "nsIMsgMessageService.h"
class nsIImapHostSessionList;
class nsString2;
class nsIImapUrl;
class nsIMsgFolder;
class nsImapService : public nsIImapService
class nsImapService : public nsIImapService, public nsIMsgMessageService
{
public:
@ -110,6 +111,14 @@ public:
////////////////////////////////////////////////////////////////////////////////////////
// End support of nsIImapService interface
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
// we suppport the nsIMsgMessageService Interface
////////////////////////////////////////////////////////////////////////////////////////
NS_IMETHOD CopyMessage(const char * aSrcMailboxURI, nsIStreamListener * aMailboxCopy, PRBool moveMessage,
nsIUrlListener * aUrlListener, nsIURL **aURL);
NS_IMETHOD DisplayMessage(const char* aMessageURI, nsISupports * aDisplayConsumer,
nsIUrlListener * aUrlListener, nsIURL ** aURL);
protected:
nsresult GetImapConnectionAndUrl(PLEventQueue * aClientEventQueue,

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

@ -1060,7 +1060,7 @@ void nsImapUrl::ParseImapPart(char *imapPartOfUrl)
if (m_tokenPlaceHolder && *m_tokenPlaceHolder)
ParseListofMessageIds();
else
m_listOfMessageIds = "";
m_listOfMessageIds = PL_strdup("");
}
else if (!PL_strcasecmp(m_urlidSubString, "liteselect"))
{
@ -1070,14 +1070,14 @@ void nsImapUrl::ParseImapPart(char *imapPartOfUrl)
else if (!PL_strcasecmp(m_urlidSubString, "selectnoop"))
{
m_imapAction = nsImapSelectNoopFolder;
m_listOfMessageIds = "";
m_listOfMessageIds = PL_strdup("");
ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
}
else if (!PL_strcasecmp(m_urlidSubString, "expunge"))
{
m_imapAction = nsImapExpungeFolder;
ParseFolderPath(&m_sourceCanonicalFolderPathSubString);
m_listOfMessageIds = ""; // no ids to UNDO
m_listOfMessageIds = PL_strdup(""); // no ids to UNDO
}
else if (!PL_strcasecmp(m_urlidSubString, "create"))
{

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

@ -236,7 +236,7 @@ nsresult nsParseImapMessageURI(const char* uri, nsString& folderURI, PRUint32 *k
{
nsAutoString folderPath;
uriStr.Left(folderURI, keySeparator);
folderURI.Cut(4, 8); // cut out the _message part of imap_message:
nsAutoString keyStr;
uriStr.Right(keyStr, uriStr.Length() - (keySeparator + 1));
PRInt32 errorCode;