From 7804e3805c47893b91a5328985608fc7a6da93a4 Mon Sep 17 00:00:00 2001 From: "tonyr%fbdesigns.com" Date: Sun, 9 Jan 2000 17:30:18 +0000 Subject: [PATCH] Update to changed nsIMsgAccountManager interfaces --- mailnews/import/eudora/src/nsEudoraMac.cpp | 12 +- mailnews/import/eudora/src/nsEudoraWin32.cpp | 12 +- mailnews/import/oexpress/nsOESettings.cpp | 8 +- .../import/outlook/src/nsOutlookSettings.cpp | 12 +- mailnews/import/src/nsImportFactory.cpp | 262 +----------------- mailnews/import/src/nsImportMail.cpp | 6 +- mailnews/import/src/nsImportMimeEncode.cpp | 5 - mailnews/import/src/nsImportService.cpp | 31 ++- 8 files changed, 55 insertions(+), 293 deletions(-) diff --git a/mailnews/import/eudora/src/nsEudoraMac.cpp b/mailnews/import/eudora/src/nsEudoraMac.cpp index 57966afe56d1..fe0fa4f9d560 100644 --- a/mailnews/import/eudora/src/nsEudoraMac.cpp +++ b/mailnews/import/eudora/src/nsEudoraMac.cpp @@ -682,11 +682,11 @@ PRBool nsEudoraMac::BuildPOPAccount( nsIMsgAccountManager *accMgr, nsCString **p nsresult rv = accMgr->FindServer( *(pStrs[kPopAccountNameStr]), *(pStrs[kPopServerStr]), "pop3", getter_AddRefs( in)); if (NS_FAILED( rv) || (in == nsnull)) { // Create the incoming server and an account for it? - rv = accMgr->CreateIncomingServer( "pop3", getter_AddRefs( in)); + rv = accMgr->CreateIncomingServer( *(pStrs[kPopAccountNameStr]), *(pStrs[kPopServerStr]), "pop3", getter_AddRefs( in)); if (NS_SUCCEEDED( rv) && in) { rv = in->SetType( "pop3"); - rv = in->SetHostName( *(pStrs[kPopServerStr])); - rv = in->SetUsername( *(pStrs[kPopAccountNameStr])); + // rv = in->SetHostName( *(pStrs[kPopServerStr])); + // rv = in->SetUsername( *(pStrs[kPopAccountNameStr])); IMPORT_LOG2( "Created POP3 server named: %s, userName: %s\n", (const char *)(*(pStrs[kPopServerStr])), (const char *)(*(pStrs[kPopAccountNameStr]))); @@ -730,11 +730,11 @@ PRBool nsEudoraMac::BuildIMAPAccount( nsIMsgAccountManager *accMgr, nsCString ** nsresult rv = accMgr->FindServer( *(pStrs[kPopAccountNameStr]), *(pStrs[kPopServerStr]), "imap", getter_AddRefs( in)); if (NS_FAILED( rv) || (in == nsnull)) { // Create the incoming server and an account for it? - rv = accMgr->CreateIncomingServer( "imap", getter_AddRefs( in)); + rv = accMgr->CreateIncomingServer( *(pStrs[kPopAccountNameStr]), *(pStrs[kPopServerStr]), "imap", getter_AddRefs( in)); if (NS_SUCCEEDED( rv) && in) { rv = in->SetType( "imap"); - rv = in->SetHostName( *(pStrs[kPopServerStr])); - rv = in->SetUsername( *(pStrs[kPopAccountNameStr])); + // rv = in->SetHostName( *(pStrs[kPopServerStr])); + // rv = in->SetUsername( *(pStrs[kPopAccountNameStr])); IMPORT_LOG2( "Created IMAP server named: %s, userName: %s\n", (const char *)(*(pStrs[kPopServerStr])), (const char *)(*(pStrs[kPopAccountNameStr]))); diff --git a/mailnews/import/eudora/src/nsEudoraWin32.cpp b/mailnews/import/eudora/src/nsEudoraWin32.cpp index 322e694d6723..e6ea76e48ffd 100644 --- a/mailnews/import/eudora/src/nsEudoraWin32.cpp +++ b/mailnews/import/eudora/src/nsEudoraWin32.cpp @@ -710,11 +710,11 @@ PRBool nsEudoraWin32::BuildPOPAccount( nsIMsgAccountManager *accMgr, const char nsresult rv = accMgr->FindServer( userName, serverName, "pop3", getter_AddRefs( in)); if (NS_FAILED( rv) || (in == nsnull)) { // Create the incoming server and an account for it? - rv = accMgr->CreateIncomingServer( "pop3", getter_AddRefs( in)); + rv = accMgr->CreateIncomingServer( userName, serverName, "pop3", getter_AddRefs( in)); if (NS_SUCCEEDED( rv) && in) { rv = in->SetType( "pop3"); - rv = in->SetHostName( serverName); - rv = in->SetUsername( userName); + // rv = in->SetHostName( serverName); + // rv = in->SetUsername( userName); IMPORT_LOG2( "Created POP3 server named: %s, userName: %s\n", (const char *)serverName, (const char *)userName); @@ -766,11 +766,11 @@ PRBool nsEudoraWin32::BuildIMAPAccount( nsIMsgAccountManager *accMgr, const char nsresult rv = accMgr->FindServer( userName, serverName, "imap", getter_AddRefs( in)); if (NS_FAILED( rv) || (in == nsnull)) { // Create the incoming server and an account for it? - rv = accMgr->CreateIncomingServer( "imap", getter_AddRefs( in)); + rv = accMgr->CreateIncomingServer( userName, serverName, "imap", getter_AddRefs( in)); if (NS_SUCCEEDED( rv) && in) { rv = in->SetType( "imap"); - rv = in->SetHostName( serverName); - rv = in->SetUsername( userName); + // rv = in->SetHostName( serverName); + // rv = in->SetUsername( userName); IMPORT_LOG2( "Created IMAP server named: %s, userName: %s\n", (const char *)serverName, (const char *)userName); diff --git a/mailnews/import/oexpress/nsOESettings.cpp b/mailnews/import/oexpress/nsOESettings.cpp index 5c42e94b3650..5c060d3ec328 100644 --- a/mailnews/import/oexpress/nsOESettings.cpp +++ b/mailnews/import/oexpress/nsOESettings.cpp @@ -319,11 +319,11 @@ PRBool OESettings::DoIMAPServer( nsIMsgAccountManager *pMgr, HKEY hKey, char *pS nsresult rv = pMgr->FindServer( (const char *)pBytes, pServerName, "imap", getter_AddRefs( in)); if (NS_FAILED( rv) || (in == nsnull)) { // Create the incoming server and an account for it? - rv = pMgr->CreateIncomingServer( "imap", getter_AddRefs( in)); + rv = pMgr->CreateIncomingServer( (const char *)pBytes, pServerName, "imap", getter_AddRefs( in)); if (NS_SUCCEEDED( rv) && in) { rv = in->SetType( "imap"); - rv = in->SetHostName( pServerName); - rv = in->SetUsername( (char *)pBytes); + // rv = in->SetHostName( pServerName); + // rv = in->SetUsername( (char *)pBytes); IMPORT_LOG2( "Created IMAP server named: %s, userName: %s\n", pServerName, (char *)pBytes); @@ -384,7 +384,7 @@ PRBool OESettings::DoPOP3Server( nsIMsgAccountManager *pMgr, HKEY hKey, char *pS nsresult rv = pMgr->FindServer( (const char *)pBytes, pServerName, "pop3", getter_AddRefs( in)); if (NS_FAILED( rv) || (in == nsnull)) { // Create the incoming server and an account for it? - rv = pMgr->CreateIncomingServer( "pop3", getter_AddRefs( in)); + rv = pMgr->CreateIncomingServer( (const char *)pBytes, pServerName, "pop3", getter_AddRefs( in)); if (NS_SUCCEEDED( rv) && in) { rv = in->SetType( "pop3"); rv = in->SetHostName( pServerName); diff --git a/mailnews/import/outlook/src/nsOutlookSettings.cpp b/mailnews/import/outlook/src/nsOutlookSettings.cpp index fb14c38883b0..a1df4b6cd223 100644 --- a/mailnews/import/outlook/src/nsOutlookSettings.cpp +++ b/mailnews/import/outlook/src/nsOutlookSettings.cpp @@ -269,11 +269,11 @@ PRBool OutlookSettings::DoIMAPServer( nsIMsgAccountManager *pMgr, HKEY hKey, cha nsresult rv = pMgr->FindServer( (const char *)pBytes, pServerName, "imap", getter_AddRefs( in)); if (NS_FAILED( rv) || (in == nsnull)) { // Create the incoming server and an account for it? - rv = pMgr->CreateIncomingServer( "imap", getter_AddRefs( in)); + rv = pMgr->CreateIncomingServer( (const char *)pBytes, pServerName, "imap", getter_AddRefs( in)); if (NS_SUCCEEDED( rv) && in) { rv = in->SetType( "imap"); - rv = in->SetHostName( pServerName); - rv = in->SetUsername( (char *)pBytes); + // rv = in->SetHostName( pServerName); + // rv = in->SetUsername( (char *)pBytes); IMPORT_LOG2( "Created IMAP server named: %s, userName: %s\n", pServerName, (char *)pBytes); @@ -334,11 +334,11 @@ PRBool OutlookSettings::DoPOP3Server( nsIMsgAccountManager *pMgr, HKEY hKey, cha nsresult rv = pMgr->FindServer( (const char *)pBytes, pServerName, "pop3", getter_AddRefs( in)); if (NS_FAILED( rv) || (in == nsnull)) { // Create the incoming server and an account for it? - rv = pMgr->CreateIncomingServer( "pop3", getter_AddRefs( in)); + rv = pMgr->CreateIncomingServer( (const char *)pBytes, pServerName, "pop3", getter_AddRefs( in)); if (NS_SUCCEEDED( rv) && in) { rv = in->SetType( "pop3"); - rv = in->SetHostName( pServerName); - rv = in->SetUsername( (char *)pBytes); + // rv = in->SetHostName( pServerName); + // rv = in->SetUsername( (char *)pBytes); IMPORT_LOG2( "Created POP3 server named: %s, userName: %s\n", pServerName, (char *)pBytes); diff --git a/mailnews/import/src/nsImportFactory.cpp b/mailnews/import/src/nsImportFactory.cpp index 8228bffb551c..3d8ed039918c 100644 --- a/mailnews/import/src/nsImportFactory.cpp +++ b/mailnews/import/src/nsImportFactory.cpp @@ -27,266 +27,26 @@ #include "ImportDebug.h" -static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID); -static NS_DEFINE_CID(kImportMimeEncodeCID, NS_IMPORTMIMEENCODE_CID); +extern NS_METHOD NS_NewImportService(nsISupports* aOuter, REFNSIID aIID, void **aResult); -extern nsresult NS_NewImportService(nsIImportService** aImportService); -extern nsresult NS_NewImportMimeEncode( nsIImportMimeEncode **aMimeEncode); - -// Module implementation for the import service library -class nsImportServiceModule : public nsIModule -{ -public: - nsImportServiceModule(); - virtual ~nsImportServiceModule(); - - NS_DECL_ISUPPORTS - - NS_DECL_NSIMODULE - -protected: - nsresult Initialize(); - - void Shutdown(); - - PRBool mInitialized; - nsCOMPtr mFactory; -}; //---------------------------------------------------------------------- -// Functions used to create new instances of a given object by the -// generic factory. - -#define MAKE_CTOR(_name) \ -static NS_IMETHODIMP \ -CreateNew##_name(nsISupports* aOuter, REFNSIID aIID, void **aResult) \ -{ \ - if (!aResult) { \ - return NS_ERROR_INVALID_POINTER; \ - } \ - if (aOuter) { \ - *aResult = nsnull; \ - return NS_ERROR_NO_AGGREGATION; \ - } \ - nsI##_name* inst; \ - nsresult rv = NS_New##_name(&inst); \ - if (NS_FAILED(rv)) { \ - *aResult = nsnull; \ - return rv; \ - } \ - rv = inst->QueryInterface(aIID, aResult); \ - if (NS_FAILED(rv)) { \ - *aResult = nsnull; \ - } \ - NS_RELEASE(inst); /* get rid of extra refcnt */ \ - return rv; \ -} - -MAKE_CTOR(ImportService) -MAKE_CTOR(ImportMimeEncode) - -//---------------------------------------------------------------------- - -static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID); - -nsImportServiceModule::nsImportServiceModule() - : mInitialized(PR_FALSE) -{ - NS_INIT_ISUPPORTS(); -} - -nsImportServiceModule::~nsImportServiceModule() -{ - Shutdown(); -} - -NS_IMPL_ISUPPORTS(nsImportServiceModule, kIModuleIID) - -// Perform our one-time intialization for this module -nsresult -nsImportServiceModule::Initialize() -{ - if (mInitialized) { - return NS_OK; - } - mInitialized = PR_TRUE; - return NS_OK; -} - -// Shutdown this module, releasing all of the module resources -void -nsImportServiceModule::Shutdown() -{ - // Release the factory object - mFactory = nsnull; -} - -// Create a factory object for creating instances of aClass. -NS_IMETHODIMP -nsImportServiceModule::GetClassObject(nsIComponentManager *aCompMgr, - const nsCID& aClass, - const nsIID& aIID, - void** r_classObj) -{ - 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 fact; - if (aClass.Equals(kImportServiceCID)) { - if (!mFactory) { - // Create and save away the factory object for creating - // new instances of Sample. This way if we are called - // again for the factory, we won't need to create a new - // one. - rv = NS_NewGenericFactory(getter_AddRefs(mFactory), - CreateNewImportService); - } - fact = mFactory; - } - else { - rv = NS_ERROR_FACTORY_NOT_REGISTERED; -#ifdef DEBUG - char* cs = aClass.ToString(); - printf("+++ nsImportServiceModule: unable to create factory for %s\n", cs); - nsCRT::free(cs); -#endif - } - - if (fact) { - rv = fact->QueryInterface(aIID, r_classObj); - } - - return rv; -} - //---------------------------------------- - -struct Components { - const char* mDescription; - const nsID* mCID; - const char* mProgID; +static nsModuleComponentInfo components[] = { + { + "Import Service Component", NS_IMPORTSERVICE_CID, + "component://mozilla/import/import-service", NS_NewImportService + }, + { + "Import Mime Encoder", NS_IMPORTMIMEENCODE_CID, + "component://mozilla/import/import-mimeencode", nsIImportMimeEncodeImpl::Create + } }; -// The list of components we register -static Components gComponents[] = { - { "Import Service Component", &kImportServiceCID, - "component://mozilla/import/import-service", }, - { "Import Mime Encoder", &kImportMimeEncodeCID, - "component://mozilla/import/import-mimeencode"}, -}; - -#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) - -NS_IMETHODIMP -nsImportServiceModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation, - const char* componentType) -{ - nsresult rv = NS_OK; - -#ifdef DEBUG - printf("*** Registering ImportService components\n"); -#endif - - 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)) { -#ifdef DEBUG - printf("nsImportServiceModule: unable to register %s component => %x\n", - cp->mDescription, rv); -#endif - break; - } - cp++; - } - - return rv; -} - -NS_IMETHODIMP -nsImportServiceModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation) -{ -#ifdef DEBUG - printf("*** Unregistering ImportService components\n"); -#endif - Components* cp = gComponents; - Components* end = cp + NUM_COMPONENTS; - while (cp < end) { - nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath); - if (NS_FAILED(rv)) { -#ifdef DEBUG - printf("nsImportServiceModule: unable to unregister %s component => %x\n", - cp->mDescription, rv); -#endif - } - cp++; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsImportServiceModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) -{ - if (!okToUnload) { - return NS_ERROR_INVALID_POINTER; - } - *okToUnload = PR_FALSE; - return NS_ERROR_FAILURE; -} - //---------------------------------------------------------------------- -static nsImportServiceModule *gModule = NULL; - -extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, - nsIModule** return_cobj) -{ - nsresult rv = NS_OK; - - NS_ASSERTION(return_cobj, "Null argument"); - NS_ASSERTION(gModule == NULL, "nsImportServiceModule: Module already created."); - - // Create an initialize the layout module instance - nsImportServiceModule *m = new nsImportServiceModule(); - if (!m) { - return NS_ERROR_OUT_OF_MEMORY; - } - - // Increase refcnt and store away nsIModule interface to m in return_cobj - rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj); - if (NS_FAILED(rv)) { - delete m; - m = nsnull; - } - gModule = m; // WARNING: Weak Reference - return rv; -} +NS_IMPL_NSGETMODULE( "nsImportServiceModule", components) diff --git a/mailnews/import/src/nsImportMail.cpp b/mailnews/import/src/nsImportMail.cpp index 4108fb97e713..ca1ec5b6817b 100644 --- a/mailnews/import/src/nsImportMail.cpp +++ b/mailnews/import/src/nsImportMail.cpp @@ -948,7 +948,7 @@ PRBool nsImportGenericMail::GetAccount( nsIMsgFolder **ppFolder) return( PR_FALSE); } - rv = accMgr->CreateIncomingServer( "none", getter_AddRefs( server)); + rv = accMgr->CreateIncomingServer( "import", hostName, "none", getter_AddRefs( server)); if (NS_FAILED( rv)) { IMPORT_LOG0( "*** Failed to create a 'none' incoming server\n"); return( PR_FALSE); @@ -959,8 +959,8 @@ PRBool nsImportGenericMail::GetAccount( nsIMsgFolder **ppFolder) GetUniquePrettyName( accMgr, prettyName); server->SetPrettyName( (PRUnichar *) prettyName.GetUnicode()); - server->SetHostName( hostName); - server->SetUsername( "import"); + // server->SetHostName( hostName); + // server->SetUsername( "import"); // create a new account with the server and identity. diff --git a/mailnews/import/src/nsImportMimeEncode.cpp b/mailnews/import/src/nsImportMimeEncode.cpp index 7f7aacdb1f8f..93b90d029710 100644 --- a/mailnews/import/src/nsImportMimeEncode.cpp +++ b/mailnews/import/src/nsImportMimeEncode.cpp @@ -455,8 +455,3 @@ NS_METHOD nsIImportMimeEncodeImpl::Initialize(nsIFileSpec *inFile, nsIFileSpec * return( NS_OK); } -nsresult NS_NewImportMimeEncode( nsIImportMimeEncode **aEncoder) -{ - return( nsIImportMimeEncodeImpl::Create( nsnull, nsIImportMimeEncode::GetIID(), (void **)aEncoder)); -} - diff --git a/mailnews/import/src/nsImportService.cpp b/mailnews/import/src/nsImportService.cpp index 7c29bf8d70f4..c18008d30f65 100644 --- a/mailnews/import/src/nsImportService.cpp +++ b/mailnews/import/src/nsImportService.cpp @@ -163,27 +163,34 @@ private: }; //////////////////////////////////////////////////////////////////////// -nsresult NS_NewImportService(nsIImportService** aImportService); - -nsresult NS_NewImportService(nsIImportService** aImportService) +NS_IMETHODIMP NS_NewImportService( nsISupports* aOuter, REFNSIID aIID, void **aResult) { - NS_PRECONDITION(aImportService != nsnull, "null ptr"); - if (! aImportService) - return NS_ERROR_NULL_POINTER; - + NS_PRECONDITION(aResult != nsnull, "null ptr"); + if (! aResult) + return( NS_ERROR_NULL_POINTER); + if (aOuter) { + *aResult = nsnull; + return( NS_ERROR_NO_AGGREGATION); + } + if (!gImportService) { gImportService = new nsImportService(); if (! gImportService) - return NS_ERROR_OUT_OF_MEMORY; + return( NS_ERROR_OUT_OF_MEMORY); } NS_ADDREF( gImportService); - - *aImportService = gImportService; - - return NS_OK; + + nsresult rv = gImportService->QueryInterface(aIID, aResult); + if (NS_FAILED(rv)) { + *aResult = nsnull; + } + NS_RELEASE( gImportService); + + return( rv); } + ////////////////////////////////////////////////////////////////////////