1999-03-18 01:09:50 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "msgCore.h" // for pre-compiled headers...
|
1999-10-04 00:27:42 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIModule.h"
|
|
|
|
#include "nsIGenericFactory.h"
|
|
|
|
|
1999-03-31 05:16:38 +00:00
|
|
|
#include "nsIMAPHostSessionList.h"
|
1999-04-08 02:48:56 +00:00
|
|
|
#include "nsImapIncomingServer.h"
|
|
|
|
#include "nsImapService.h"
|
1999-04-21 05:18:56 +00:00
|
|
|
#include "nsImapMailFolder.h"
|
1999-04-24 20:46:07 +00:00
|
|
|
#include "nsImapMessage.h"
|
1999-03-18 01:09:50 +00:00
|
|
|
#include "nsImapUrl.h"
|
|
|
|
#include "nsImapProtocol.h"
|
1999-06-22 05:00:12 +00:00
|
|
|
#include "nsMsgImapCID.h"
|
1999-03-18 01:09:50 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
|
|
|
static NS_DEFINE_CID(kCImapUrl, NS_IMAPURL_CID);
|
|
|
|
static NS_DEFINE_CID(kCImapProtocol, NS_IMAPPROTOCOL_CID);
|
1999-03-31 05:16:38 +00:00
|
|
|
static NS_DEFINE_CID(kCImapHostSessionList, NS_IIMAPHOSTSESSIONLIST_CID);
|
1999-04-08 02:48:56 +00:00
|
|
|
static NS_DEFINE_CID(kCImapIncomingServer, NS_IMAPINCOMINGSERVER_CID);
|
|
|
|
static NS_DEFINE_CID(kCImapService, NS_IMAPSERVICE_CID);
|
1999-04-21 05:18:56 +00:00
|
|
|
static NS_DEFINE_CID(kCImapResource, NS_IMAPRESOURCE_CID);
|
1999-04-24 20:46:07 +00:00
|
|
|
static NS_DEFINE_CID(kCImapMessageResource, NS_IMAPMESSAGERESOURCE_CID);
|
1999-09-12 05:13:04 +00:00
|
|
|
static NS_DEFINE_CID(kCImapMockChannel, NS_IMAPMOCKCHANNEL_CID);
|
1999-04-24 20:46:07 +00:00
|
|
|
|
1999-10-05 05:45:07 +00:00
|
|
|
// private factory declarations for each component we know how to produce
|
|
|
|
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImapUrl)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImapProtocol)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIMAPHostSessionList)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImapIncomingServer)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImapService)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImapMailFolder)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImapMockChannel)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImapMessage)
|
|
|
|
|
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
// Module implementation for the sample library
|
|
|
|
class nsMsgImapModule : public nsIModule
|
|
|
|
{
|
1999-03-18 01:09:50 +00:00
|
|
|
public:
|
1999-10-04 00:27:42 +00:00
|
|
|
nsMsgImapModule();
|
|
|
|
virtual ~nsMsgImapModule();
|
1999-03-18 01:09:50 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
1999-03-18 01:09:50 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
NS_DECL_NSIMODULE
|
1999-03-18 01:09:50 +00:00
|
|
|
|
|
|
|
protected:
|
1999-10-04 00:27:42 +00:00
|
|
|
nsresult Initialize();
|
|
|
|
|
|
|
|
void Shutdown();
|
1999-03-18 01:09:50 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
PRBool mInitialized;
|
1999-10-05 05:45:07 +00:00
|
|
|
nsCOMPtr<nsIGenericFactory> mImapUrlFactory;
|
|
|
|
nsCOMPtr<nsIGenericFactory> mImapProtocolFactory;
|
|
|
|
nsCOMPtr<nsIGenericFactory> mImapHostSessionFactory;
|
|
|
|
nsCOMPtr<nsIGenericFactory> mImapIncomingServerFactory;
|
|
|
|
nsCOMPtr<nsIGenericFactory> mImapServiceFactory;
|
|
|
|
nsCOMPtr<nsIGenericFactory> mImapMailFolderFactory;
|
|
|
|
nsCOMPtr<nsIGenericFactory> mImapMockChannelFactory;
|
|
|
|
nsCOMPtr<nsIGenericFactory> mImapMessageFactory;
|
1999-10-04 00:27:42 +00:00
|
|
|
};
|
1999-03-18 01:09:50 +00:00
|
|
|
|
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
nsMsgImapModule::nsMsgImapModule()
|
|
|
|
: mInitialized(PR_FALSE)
|
1999-03-18 01:09:50 +00:00
|
|
|
{
|
1999-10-04 00:27:42 +00:00
|
|
|
NS_INIT_ISUPPORTS();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMsgImapModule::~nsMsgImapModule()
|
1999-03-18 01:09:50 +00:00
|
|
|
{
|
1999-10-04 00:27:42 +00:00
|
|
|
Shutdown();
|
|
|
|
}
|
1999-03-18 01:09:50 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsMsgImapModule, NS_GET_IID(nsIModule))
|
1999-03-18 01:09:50 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
// Perform our one-time intialization for this module
|
|
|
|
nsresult nsMsgImapModule::Initialize()
|
|
|
|
{
|
|
|
|
if (mInitialized)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mInitialized = PR_TRUE;
|
|
|
|
return NS_OK;
|
1999-03-18 01:09:50 +00:00
|
|
|
}
|
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
// Shutdown this module, releasing all of the module resources
|
|
|
|
void nsMsgImapModule::Shutdown()
|
1999-03-18 01:09:50 +00:00
|
|
|
{
|
1999-10-04 00:27:42 +00:00
|
|
|
// Release the factory object
|
1999-10-05 05:45:07 +00:00
|
|
|
mImapUrlFactory = null_nsCOMPtr();
|
|
|
|
mImapProtocolFactory = null_nsCOMPtr();
|
|
|
|
mImapHostSessionFactory = null_nsCOMPtr();
|
|
|
|
mImapIncomingServerFactory = null_nsCOMPtr();
|
|
|
|
mImapServiceFactory = null_nsCOMPtr();
|
|
|
|
mImapMailFolderFactory = null_nsCOMPtr();
|
|
|
|
mImapMockChannelFactory = null_nsCOMPtr();
|
|
|
|
mImapMessageFactory = null_nsCOMPtr();
|
1999-03-18 01:09:50 +00:00
|
|
|
}
|
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
// Create a factory object for creating instances of aClass.
|
|
|
|
NS_IMETHODIMP nsMsgImapModule::GetClassObject(nsIComponentManager *aCompMgr,
|
|
|
|
const nsCID& aClass,
|
|
|
|
const nsIID& aIID,
|
|
|
|
void** r_classObj)
|
1999-03-18 01:09:50 +00:00
|
|
|
{
|
1999-10-04 00:27:42 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Defensive programming: Initialize *r_classObj in case of error below
|
|
|
|
if (!r_classObj)
|
|
|
|
return NS_ERROR_INVALID_POINTER;
|
|
|
|
|
|
|
|
*r_classObj = NULL;
|
|
|
|
|
|
|
|
// Do one-time-only initialization if necessary
|
|
|
|
if (!mInitialized)
|
|
|
|
{
|
|
|
|
rv = Initialize();
|
|
|
|
if (NS_FAILED(rv)) // Initialization failed! yikes!
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Choose the appropriate factory, based on the desired instance
|
|
|
|
// class type (aClass).
|
|
|
|
nsCOMPtr<nsIGenericFactory> fact;
|
|
|
|
|
|
|
|
if (aClass.Equals(kCImapUrl))
|
1999-10-05 05:45:07 +00:00
|
|
|
{
|
|
|
|
if (!mImapUrlFactory)
|
|
|
|
rv = NS_NewGenericFactory(getter_AddRefs(mImapUrlFactory), &nsImapUrlConstructor);
|
|
|
|
fact = mImapUrlFactory;
|
|
|
|
}
|
1999-10-04 00:27:42 +00:00
|
|
|
else if (aClass.Equals(kCImapProtocol))
|
1999-10-05 05:45:07 +00:00
|
|
|
{
|
|
|
|
if (!mImapProtocolFactory)
|
|
|
|
rv = NS_NewGenericFactory(getter_AddRefs(mImapProtocolFactory), &nsImapProtocolConstructor);
|
|
|
|
fact = mImapProtocolFactory;
|
|
|
|
}
|
1999-10-04 00:27:42 +00:00
|
|
|
else if (aClass.Equals(kCImapHostSessionList))
|
1999-10-05 05:45:07 +00:00
|
|
|
{
|
|
|
|
if (!mImapHostSessionFactory)
|
|
|
|
rv = NS_NewGenericFactory(getter_AddRefs(mImapHostSessionFactory), &nsIMAPHostSessionListConstructor);
|
|
|
|
fact = mImapHostSessionFactory;
|
|
|
|
}
|
1999-10-04 00:27:42 +00:00
|
|
|
else if (aClass.Equals(kCImapIncomingServer))
|
1999-10-05 05:45:07 +00:00
|
|
|
{
|
|
|
|
if (!mImapIncomingServerFactory)
|
|
|
|
rv = NS_NewGenericFactory(getter_AddRefs(mImapIncomingServerFactory), &nsImapIncomingServerConstructor);
|
|
|
|
fact = mImapIncomingServerFactory;
|
|
|
|
}
|
1999-10-04 00:27:42 +00:00
|
|
|
else if (aClass.Equals(kCImapService))
|
1999-10-05 05:45:07 +00:00
|
|
|
{
|
|
|
|
if (!mImapServiceFactory)
|
|
|
|
rv = NS_NewGenericFactory(getter_AddRefs(mImapServiceFactory), &nsImapServiceConstructor);
|
|
|
|
fact = mImapServiceFactory;
|
|
|
|
}
|
1999-10-04 00:27:42 +00:00
|
|
|
else if (aClass.Equals(kCImapResource))
|
1999-10-05 05:45:07 +00:00
|
|
|
{
|
|
|
|
if (!mImapMailFolderFactory)
|
|
|
|
rv = NS_NewGenericFactory(getter_AddRefs(mImapMailFolderFactory), &nsImapMailFolderConstructor);
|
|
|
|
fact = mImapMailFolderFactory;
|
|
|
|
}
|
1999-10-04 00:27:42 +00:00
|
|
|
else if (aClass.Equals(kCImapMockChannel))
|
1999-10-05 05:45:07 +00:00
|
|
|
{
|
|
|
|
if (!mImapMockChannelFactory)
|
|
|
|
rv = NS_NewGenericFactory(getter_AddRefs(mImapMockChannelFactory), &nsImapMockChannelConstructor);
|
|
|
|
fact = mImapMockChannelFactory;
|
|
|
|
}
|
1999-10-04 00:27:42 +00:00
|
|
|
else if (aClass.Equals(kCImapMessageResource))
|
1999-10-05 05:45:07 +00:00
|
|
|
{
|
|
|
|
if (!mImapMessageFactory)
|
|
|
|
rv = NS_NewGenericFactory(getter_AddRefs(mImapMessageFactory), &nsImapMessageConstructor);
|
|
|
|
fact = mImapMessageFactory;
|
|
|
|
}
|
1999-10-04 00:27:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (fact)
|
|
|
|
rv = fact->QueryInterface(aIID, r_classObj);
|
|
|
|
|
|
|
|
return rv;
|
1999-03-18 01:09:50 +00:00
|
|
|
}
|
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
struct Components {
|
|
|
|
const char* mDescription;
|
|
|
|
const nsID* mCID;
|
|
|
|
const char* mProgID;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The list of components we register
|
|
|
|
static Components gComponents[] = {
|
|
|
|
{ "Imap Url", &kCImapUrl,
|
|
|
|
nsnull },
|
|
|
|
{ "Imap Protocol Channel", &kCImapProtocol,
|
|
|
|
nsnull },
|
|
|
|
{ "Imap Mock Channel", &kCImapMockChannel,
|
|
|
|
nsnull },
|
|
|
|
{ "Imap Host Session List", &kCImapHostSessionList,
|
|
|
|
nsnull },
|
|
|
|
{ "Imap Incoming Server", &kCImapIncomingServer,
|
|
|
|
"component://netscape/messenger/server&type=imap" },
|
|
|
|
{ "Mail/News Imap Resource Factory", &kCImapResource,
|
|
|
|
NS_RDF_RESOURCE_FACTORY_PROGID_PREFIX "imap" },
|
|
|
|
{ "Imap Service", &kCImapService,
|
|
|
|
"component://netscape/messenger/messageservice;type=imap_message" },
|
|
|
|
{ "Imap Service", &kCImapService,
|
|
|
|
"component://netscape/messenger/messageservice;type=imap"},
|
|
|
|
{ "Imap Protocol Handler", &kCImapService,
|
|
|
|
NS_NETWORK_PROTOCOL_PROGID_PREFIX "imap"},
|
|
|
|
{ "Imap Protocol Handler", &kCImapService,
|
|
|
|
NS_IMAPPROTOCOLINFO_PROGID},
|
|
|
|
{ "Imap Message Resource Factory", &kCImapMessageResource,
|
|
|
|
NS_RDF_RESOURCE_FACTORY_PROGID_PREFIX "imap_message"}
|
|
|
|
|
|
|
|
};
|
|
|
|
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMsgImapModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
|
|
|
nsIFileSpec* aPath,
|
|
|
|
const char* registryLocation,
|
|
|
|
const char* componentType)
|
1999-03-18 01:09:50 +00:00
|
|
|
{
|
1999-10-04 00:27:42 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-03-18 01:09:50 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
Components* cp = gComponents;
|
|
|
|
Components* end = cp + NUM_COMPONENTS;
|
|
|
|
while (cp < end)
|
|
|
|
{
|
|
|
|
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
|
|
|
|
cp->mProgID, aPath, PR_TRUE,
|
|
|
|
PR_TRUE);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
cp++;
|
|
|
|
}
|
1999-03-18 01:09:50 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-03-18 01:09:50 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
NS_IMETHODIMP nsMsgImapModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
|
|
|
nsIFileSpec* aPath,
|
|
|
|
const char* registryLocation)
|
|
|
|
{
|
|
|
|
Components* cp = gComponents;
|
|
|
|
Components* end = cp + NUM_COMPONENTS;
|
|
|
|
while (cp < end)
|
|
|
|
{
|
1999-10-05 22:03:50 +00:00
|
|
|
aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
|
1999-10-04 00:27:42 +00:00
|
|
|
cp++;
|
|
|
|
}
|
1999-03-18 01:09:50 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-31 05:16:38 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
NS_IMETHODIMP nsMsgImapModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
|
|
|
{
|
|
|
|
if (!okToUnload)
|
|
|
|
return NS_ERROR_INVALID_POINTER;
|
1999-04-08 02:48:56 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
*okToUnload = PR_FALSE;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-04-08 02:48:56 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
//----------------------------------------------------------------------
|
1999-04-24 20:46:07 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
static nsMsgImapModule *gModule = NULL;
|
|
|
|
|
|
|
|
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
|
|
|
|
nsIFileSpec* location,
|
|
|
|
nsIModule** return_cobj)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1999-04-21 21:08:00 +00:00
|
|
|
|
1999-10-04 00:27:42 +00:00
|
|
|
NS_ASSERTION(return_cobj, "Null argument");
|
|
|
|
NS_ASSERTION(gModule == NULL, "nsMsgImapModule: Module already created.");
|
|
|
|
|
|
|
|
// Create an initialize the imap module instance
|
|
|
|
nsMsgImapModule *module = new nsMsgImapModule();
|
|
|
|
if (!module)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// Increase refcnt and store away nsIModule interface to m in return_cobj
|
|
|
|
rv = module->QueryInterface(nsIModule::GetIID(), (void**)return_cobj);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
delete module;
|
|
|
|
module = nsnull;
|
|
|
|
}
|
|
|
|
gModule = module; // WARNING: Weak Reference
|
|
|
|
return rv;
|
1999-03-18 01:09:50 +00:00
|
|
|
}
|