diff --git a/mailnews/base/build/nsMsgBaseCID.h b/mailnews/base/build/nsMsgBaseCID.h index ea6a2b0d58b4..2c3530b09675 100644 --- a/mailnews/base/build/nsMsgBaseCID.h +++ b/mailnews/base/build/nsMsgBaseCID.h @@ -43,5 +43,19 @@ 0x14495573, 0xe945, 0x11d2, \ {0x8a, 0x52, 0x0, 0x60, 0xb0, 0xfc, 0x4, 0xd2}} +#define NS_MSGACCOUNTMANAGER_CID \ +{ /* D2876E50-E62C-11d2-B7FC-00805F05FFA5 */ \ + 0xd2876e50, 0xe62c, 0x11d2, \ + {0xb7, 0xfc, 0x0, 0x80, 0x5f, 0x5, 0xff, 0xa5 }} + +#define NS_MSGIDENTITY_CID \ +{ /* 8fbf6ac0-ebcc-11d2-b7fc-00805f05ffa5 */ \ + 0x8fbf6ac0, 0xebcc, 0x11d2, \ + {0xb7, 0xfc, 0x0, 0x80, 0x5f, 0x5, 0xff, 0xa5 }} + +#define NS_MSGACCOUNT_CID \ +{ /* 68b25510-e641-11d2-b7fc-00805f05ffa5 */ \ + 0x68b25510, 0xe641, 0x11d2, \ + {0xb7, 0xfc, 0x0, 0x80, 0x5f, 0x5, 0xff, 0xa5 }} #endif // nsMessageBaseCID_h__ diff --git a/mailnews/base/build/nsMsgFactory.cpp b/mailnews/base/build/nsMsgFactory.cpp index 538043b80265..4c7741db552c 100644 --- a/mailnews/base/build/nsMsgFactory.cpp +++ b/mailnews/base/build/nsMsgFactory.cpp @@ -41,6 +41,9 @@ #include "nsIUrlListenerManager.h" #include "nsUrlListenerManager.h" #include "nsMsgMailSession.h" +#include "nsMsgAccount.h" +#include "nsMsgAccountManager.h" +#include "nsMsgIdentity.h" #include "nsMessageViewDataSource.h" static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); @@ -60,6 +63,10 @@ static NS_DEFINE_CID(kCMsgGroupRecordCID, NS_MSGGROUPRECORD_CID); static NS_DEFINE_CID(kCMessageViewDataSourceCID, NS_MESSAGEVIEWDATASOURCE_CID); +static NS_DEFINE_CID(kCMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_CID); +static NS_DEFINE_CID(kCMsgAccountCID, NS_MSGACCOUNT_CID); + +static NS_DEFINE_CID(kCMsgIdentityCID, NS_MSGIDENTITY_CID); //////////////////////////////////////////////////////////// // @@ -146,14 +153,11 @@ nsMsgFactory::CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult) { - nsresult res = NS_OK; - if (aResult == NULL) return NS_ERROR_NULL_POINTER; *aResult = NULL; - nsISupports *inst = nsnull; // ClassID check happens here // Whenever you add a new class that supports an interface, plug it in here!!! @@ -197,6 +201,22 @@ nsMsgFactory::CreateInstance(nsISupports *aOuter, { return NS_NewMsgAppCore(aIID, aResult); } + + else if (mClassID.Equals(kCMsgAccountManagerCID)) + { + return NS_NewMsgAccountManager(aIID, aResult); + } + + else if (mClassID.Equals(kCMsgAccountCID)) + { + return NS_NewMsgAccount(aIID, aResult); + } + + else if (mClassID.Equals(kCMsgIdentityCID)) { + nsMsgIdentity* identity = new nsMsgIdentity(); + return identity->QueryInterface(aIID, aResult); + } + else if (mClassID.Equals(kCMessageViewDataSourceCID)) { nsMessageViewDataSource * msgView = new nsMessageViewDataSource(); @@ -297,6 +317,25 @@ NSRegisterSelf(nsISupports* aServMgr, const char* path) "component://netscape/appcores/messenger", path, PR_TRUE, PR_TRUE); + + rv = compMgr->RegisterComponent(kCMsgAccountManagerCID, + "Messenger Account Manager", + "component://netscape/messenger/account-manager", + path, + PR_TRUE, PR_TRUE); + + rv = compMgr->RegisterComponent(kCMsgAccountCID, + "Messenger User Account", + "component://netscape/messenger/account", + path, + PR_TRUE, PR_TRUE); + + rv = compMgr->RegisterComponent(kCMsgIdentityCID, + "Messenger User Identity", + "component://netscape/messenger/identity", + path, + PR_TRUE, PR_TRUE); + if (NS_FAILED(rv)) goto done; #if 0 rv = compMgr->RegisterComponent(kCMsgGroupRecordCID, diff --git a/mailnews/base/public/Makefile.in b/mailnews/base/public/Makefile.in index f9ad6e481dfc..4649bd11f666 100644 --- a/mailnews/base/public/Makefile.in +++ b/mailnews/base/public/Makefile.in @@ -27,6 +27,7 @@ IDLSRCS = \ nsIMsgFolder.idl \ nsIDOMMsgAppCore.idl \ nsIMsgGroupRecord.idl \ + nsIMsgIncomingServer.idl \ $(NULL) EXPORTS = \ @@ -51,6 +52,12 @@ EXPORTS = \ nsIFolderListener.h \ nsIDOMMsgAppCore.h \ nsIMsgGroupRecord.h \ + nsIMsgSignature.h \ + nsIMsgVCard.h \ + nsIMsgAccount.h \ + nsIMsgAccountManager.h \ + nsIMsgIdentity.h \ + nsIMsgIncomingServer.h \ nsICopyMessageListener.h \ nsIMessageView.h \ $(NULL) diff --git a/mailnews/base/public/makefile.win b/mailnews/base/public/makefile.win index e2d4a3b80d32..e6dedc81daf0 100644 --- a/mailnews/base/public/makefile.win +++ b/mailnews/base/public/makefile.win @@ -26,6 +26,7 @@ IDLSRCS = \ nsIFolderListener.idl \ nsIMsgGroupRecord.idl \ nsICopyMessageListener.idl \ + nsIMsgIncomingServer.idl \ $(NULL) EXPORTS = \ @@ -51,6 +52,12 @@ EXPORTS = \ nsIMsgGroupRecord.h \ nsICopyMessageListener.h \ nsIMessageView.h \ + nsIMsgSignature.h \ + nsIMsgVCard.h \ + nsIMsgAccount.h \ + nsIMsgAccountManager.h \ + nsIMsgIdentity.h \ + nsIMsgIncomingServer.h \ $(NULL) MODULE=mailnews diff --git a/mailnews/base/public/nsIMsgIdentity.h b/mailnews/base/public/nsIMsgIdentity.h index 424db2c9b679..fb4ff6e3a21e 100644 --- a/mailnews/base/public/nsIMsgIdentity.h +++ b/mailnews/base/public/nsIMsgIdentity.h @@ -1,69 +1,86 @@ -/* -*- Mode: C++; tab-width: 4; 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. +/* + * DO NOT EDIT. THIS FILE IS GENERATED FROM nsIMsgIdentity.idl */ -#ifndef nsIMsgIdentity_h___ -#define nsIMsgIdentity_h___ +#ifndef __gen_nsIMsgIdentity_h__ +#define __gen_nsIMsgIdentity_h__ -#include "nsISupports.h" +#include "nsISupports.h" /* interface nsISupports */ +#include "nsIMsgSignature.h" /* interface nsIMsgSignature */ +#include "nsIMsgVCard.h" /* interface nsIMsgVCard */ +#include "nsIPref.h" /* interface nsIPref */ +#include "nsID.h" /* interface nsID */ -/* D3B4A420-D5AC-11d2-806A-006008128C4E */ +#ifdef XPIDL_JS_STUBS +#include "jsapi.h" +#endif -#define NS_IMSGIDENTITY_IID \ -{ 0xd3b4a420, 0xd5ac, 0x11d2, \ - { 0x80, 0x6a, 0x0, 0x60, 0x8, 0x12, 0x8c, 0x4e } } +/* starting interface: nsIMsgIdentity */ -/* E7F875B0-D5AC-11d2-806A-006008128C4E */ -#define NS_IMSGIDENTITY_CID \ -{ 0xe7f875b0, 0xd5ac, 0x11d2, \ - { 0x80, 0x6a, 0x0, 0x60, 0x8, 0x12, 0x8c, 0x4e } } +/* {D3B4A420-D5AC-11d2-806A-006008128C4E} */ +#define NS_IMSGIDENTITY_IID_STR "D3B4A420-D5AC-11d2-806A-006008128C4E" +#define NS_IMSGIDENTITY_IID \ + {0xD3B4A420, 0xD5AC, 0x11d2, \ + { 0x80, 0x6A, 0x00, 0x60, 0x08, 0x12, 0x8C, 0x4E }} -/////////////////////////////////////////////////////////////////////////////////// -// an identity is an object designed to encapsulate all the information we need -// to know about a user identity. I expect this interface to grow and change a lot -// as we flesh out our thoughts on multiple identities and what properties go into -// these identities. -////////////////////////////////////////////////////////////////////////////////// +class nsIMsgIdentity : public nsISupports { + public: + static const nsIID& GetIID() { + static nsIID iid = NS_IMSGIDENTITY_IID; + return iid; + } -class nsIMsgIdentity : public nsISupports -{ -public: - static const nsIID& GetIID() { static nsIID iid = NS_IMSGIDENTITY_IID; return iid; } + /* attribute string identityName; */ + NS_IMETHOD GetIdentityName(char * *aIdentityName) = 0; + NS_IMETHOD SetIdentityName(char * aIdentityName) = 0; - /////////////////////////////////////////////////////////////////////////////////// - // The user's current identity is used to abstract out information such as the - // user name, pwd, mail server to use, etc.... - ////////////////////////////////////////////////////////////////////////////////// - NS_IMETHOD GetRootFolderPath(const char ** aRootFolderPath) = 0; + /* attribute string fullName; */ + NS_IMETHOD GetFullName(char * *aFullName) = 0; + NS_IMETHOD SetFullName(char * aFullName) = 0; - NS_IMETHOD GetPopName(const char ** aPopName) = 0; // right now it is pop & smtp user name - NS_IMETHOD GetSmtpName(const char ** aSmtpName) = 0; + /* attribute string email; */ + NS_IMETHOD GetEmail(char * *aEmail) = 0; + NS_IMETHOD SetEmail(char * aEmail) = 0; - NS_IMETHOD GetOrganization(const char ** aOrganization) = 0; - NS_IMETHOD GetUserFullName(const char ** aUserFullName) = 0; // User real name - NS_IMETHOD GetUserEmail(const char ** aUserEmail) = 0; - NS_IMETHOD GetPopPassword(const char ** aUserPassword) = 0; - NS_IMETHOD GetPopServer(const char ** aHostName) = 0; - NS_IMETHOD GetSmtpServer(const char ** aHostName) = 0; - NS_IMETHOD GetReplyTo(const char ** aReplyTo) = 0; - NS_IMETHOD GetImapServer(const char ** aHostName) = 0; - NS_IMETHOD GetImapName(const char ** aImapName) = 0; - NS_IMETHOD GetImapPassword(const char ** aImapPassword) = 0; + /* attribute string replyTo; */ + NS_IMETHOD GetReplyTo(char * *aReplyTo) = 0; + NS_IMETHOD SetReplyTo(char * aReplyTo) = 0; + /* attribute string organization; */ + NS_IMETHOD GetOrganization(char * *aOrganization) = 0; + NS_IMETHOD SetOrganization(char * aOrganization) = 0; + + /* attribute boolean useHtml; */ + NS_IMETHOD GetUseHtml(PRBool *aUseHtml) = 0; + NS_IMETHOD SetUseHtml(PRBool aUseHtml) = 0; + + /* attribute nsIMsgSignature signature; */ + NS_IMETHOD GetSignature(nsIMsgSignature * *aSignature) = 0; + NS_IMETHOD SetSignature(nsIMsgSignature * aSignature) = 0; + + /* attribute nsIMsgVCard vCard; */ + NS_IMETHOD GetVCard(nsIMsgVCard * *aVCard) = 0; + NS_IMETHOD SetVCard(nsIMsgVCard * aVCard) = 0; + + /* attribute string smtpHostname; */ + NS_IMETHOD GetSmtpHostname(char * *aSmtpHostname) = 0; + NS_IMETHOD SetSmtpHostname(char * aSmtpHostname) = 0; + + /* attribute string smtpUsername; */ + NS_IMETHOD GetSmtpUsername(char * *aSmtpUsername) = 0; + NS_IMETHOD SetSmtpUsername(char * aSmtpUsername) = 0; + + /* attribute string key; */ + NS_IMETHOD GetKey(char * *aKey) = 0; + NS_IMETHOD SetKey(char * aKey) = 0; + + /* void LoadPreferences (in nsIPref prefs, in string identityKey); */ + NS_IMETHOD LoadPreferences(nsIPref *prefs, const char *identityKey) = 0; + +#ifdef XPIDL_JS_STUBS + static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx); + static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIMsgIdentity *priv); +#endif }; -#endif /* nsIMsgIdentity_h___ */ +#endif /* __gen_nsIMsgIdentity_h__ */ diff --git a/mailnews/base/public/nsIMsgMailSession.h b/mailnews/base/public/nsIMsgMailSession.h index 0cc13c2e7bb1..3a31fd7fef86 100644 --- a/mailnews/base/public/nsIMsgMailSession.h +++ b/mailnews/base/public/nsIMsgMailSession.h @@ -41,7 +41,8 @@ // cruft in it.... ////////////////////////////////////////////////////////////////////////////////// -class nsIMsgIdentity; +#include "nsIMsgIdentity.h" +#include "nsIMsgIncomingServer.h" class nsIMsgMailSession : public nsISupports { @@ -54,6 +55,7 @@ public: ////////////////////////////////////////////////////////////////////////////////// NS_IMETHOD GetCurrentIdentity(nsIMsgIdentity ** aIdentity) = 0; + NS_IMETHOD GetCurrentServer(nsIMsgIncomingServer* *aServer) = 0; }; #endif /* nsIMsgMailSession_h___ */ diff --git a/mailnews/base/src/Makefile.in b/mailnews/base/src/Makefile.in index 4478d011b8b4..3359d82ce9b6 100644 --- a/mailnews/base/src/Makefile.in +++ b/mailnews/base/src/Makefile.in @@ -26,13 +26,14 @@ MODULE=mailnewsbase LIBRARY_NAME=mailnewsbase_s EXPORTS = \ - nsMessenger.h \ - nsMsgKeyArray.h\ - nsMsgRFC822Parser.h \ - nsUrlListenerManager.h \ - nsMsgMailSession.h \ - nsMsgIdentity.h \ - nsMsgAppCore.h \ + nsMessenger.h \ + nsMsgKeyArray.h \ + nsMsgRFC822Parser.h \ + nsUrlListenerManager.h \ + nsMsgMailSession.h \ + nsMsgAppCore.h \ + nsMsgAccountManager.h \ + nsMsgAccount.h \ nsMessageViewDataSource.h \ $(NULL) @@ -45,10 +46,11 @@ CPPSRCS = \ nsMsgImapMailFolder.cpp \ nsUrlListenerManager.cpp \ nsMsgMailSession.cpp \ - nsMsgIdentity.cpp \ nsMsgAppCore.cpp \ nsJSMsgAppCore.cpp \ - nsMsgMD5.cpp \ + nsMsgMD5.cpp \ + nsMsgAccountManager.cpp \ + nsMsgAccount.cpp \ nsCopyMessageStreamListener.cpp \ nsMessageViewDataSource.cpp \ $(NULL) diff --git a/mailnews/base/src/makefile.win b/mailnews/base/src/makefile.win index 8556bff31916..a1056a02aebd 100644 --- a/mailnews/base/src/makefile.win +++ b/mailnews/base/src/makefile.win @@ -35,11 +35,12 @@ CPPSRCS= \ nsMsgImapMailFolder.cpp \ nsUrlListenerManager.cpp \ nsMsgMailSession.cpp \ - nsMsgIdentity.cpp \ nsJSMsgAppCore.cpp \ nsMsgAppCore.cpp \ nsCopyMessageStreamListener.cpp \ nsMessageViewDataSource.cpp \ + nsMsgAccountManager.cpp \ + nsMsgAccount.cpp \ $(NULL) @@ -53,11 +54,12 @@ CPP_OBJS= \ .\$(OBJDIR)\nsMsgImapMailFolder.obj \ .\$(OBJDIR)\nsUrlListenerManager.obj \ .\$(OBJDIR)\nsMsgMailSession.obj \ - .\$(OBJDIR)\nsMsgIdentity.obj \ .\$(OBJDIR)\nsMsgAppCore.obj \ .\$(OBJDIR)\nsJSMsgAppCore.obj \ .\$(OBJDIR)\nsCopyMessageStreamListener.obj \ .\$(OBJDIR)\nsMessageViewDataSource.obj \ + .\$(OBJDIR)\nsMsgAccountManager.obj \ + .\$(OBJDIR)\nsMsgAccount.obj \ $(NULL) @@ -67,7 +69,6 @@ EXPORTS= \ nsMsgKeyArray.h \ nsUrlListenerManager.h \ nsMsgMailSession.h \ - nsMsgIdentity.h \ nsMsgAppCore.h \ nsMessageViewDataSource.h \ $(NULL) diff --git a/mailnews/base/src/nsMsgAppCore.cpp b/mailnews/base/src/nsMsgAppCore.cpp index 5c00d1b3c76c..b7d2b2600188 100644 --- a/mailnews/base/src/nsMsgAppCore.cpp +++ b/mailnews/base/src/nsMsgAppCore.cpp @@ -16,6 +16,8 @@ * Reserved. */ +#include "prsystem.h" + #include "nsIDOMMsgAppCore.h" #include "nsMsgAppCore.h" #include "nsIScriptObjectOwner.h" @@ -39,7 +41,8 @@ #include "nsIDocumentViewer.h" #include "nsIMsgMailSession.h" -#include "nsIMsgIdentity.h" +#include "nsIMsgIncomingServer.h" +#include "nsIPop3IncomingServer.h" #include "nsIMailboxService.h" #include "nsINntpService.h" #include "nsFileSpec.h" @@ -436,7 +439,6 @@ nsMsgAppCore::Open3PaneWindow() nsresult nsMsgAppCore::GetNewMail() { - printf("nsMsgAppCore::GetNewMail()\n"); // get the pop3 service and ask it to fetch new mail.... nsIPop3Service * pop3Service = nsnull; nsresult rv = nsServiceManager::GetService(kCPop3ServiceCID, nsIPop3Service::GetIID(), @@ -514,27 +516,34 @@ void nsMsgAppCore::InitializeFolderRoot() (nsISupports **) &mailSession); if (NS_SUCCEEDED(rv) && mailSession) { - nsIMsgIdentity * identity = nsnull; - rv = mailSession->GetCurrentIdentity(&identity); - if (NS_SUCCEEDED(rv) && identity) + nsIMsgIncomingServer* server = nsnull; + rv = mailSession->GetCurrentServer(&server); + if (NS_SUCCEEDED(rv) && server) { - const char * folderRoot = nsnull; - identity->GetRootFolderPath(&folderRoot); - if (folderRoot) - { - // everyone should have a inbox so let's tack that folder name on to the root path... - // mscott: this only works on windows...add - char * fullPath = PR_smprintf("%s\\%s", folderRoot, "Inbox"); - if (fullPath) - { - m_folderPath = fullPath; - PR_Free(fullPath); - } - } // if we have a folder root for the current identity - - NS_IF_RELEASE(identity); - } // if we have an identity - + char * folderRoot = nsnull; + nsIPop3IncomingServer *popServer; + rv = server->QueryInterface(nsIPop3IncomingServer::GetIID(), + (void **)&popServer); + if (NS_SUCCEEDED(rv)) { + popServer->GetRootFolderPath(&folderRoot); + if (folderRoot) + { + // everyone should have a inbox so let's + // tack that folder name on to the root path... + char * fullPath = + PR_smprintf("%s%c%s", folderRoot, + PR_GetDirectorySeparator(), + "Inbox"); + if (fullPath) + { + m_folderPath = fullPath; + PR_Free(fullPath); + } + } // if we have a folder root for the current identity + NS_IF_RELEASE(popServer); + } + NS_IF_RELEASE(server); + } // if we have an server // now release the mail service because we are done with it nsServiceManager::ReleaseService(kCMsgMailSessionCID, mailSession); } // if we have a mail session @@ -563,7 +572,7 @@ nsMsgAppCore::OpenURL(const char * url) } if (PL_strncmp(url, "mailbox:", 8) == 0 || PL_strncmp(url, kMessageRootURI, PL_strlen(kMessageRootURI)) == 0) { - PRUint32 msgIndex; + PRUint32 msgIndex=0; nsFileSpec folderPath; PRBool displayNumber; if(isdigit(url[8])) diff --git a/mailnews/base/src/nsMsgIdentity.cpp b/mailnews/base/src/nsMsgIdentity.cpp deleted file mode 100644 index e709df1750b7..000000000000 --- a/mailnews/base/src/nsMsgIdentity.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; 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 -#include "nsMsgIdentity.h" -#include "nsIPref.h" - -static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID); -static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); - -NS_IMPL_ISUPPORTS(nsMsgIdentity, nsIMsgIdentity::GetIID()); - - -nsMsgIdentity::nsMsgIdentity() -{ - NS_INIT_REFCNT(); - - m_popName = nsnull; - m_smtpName = nsnull; - m_smtpHost = nsnull; - m_popHost = nsnull; - - m_organization = nsnull; - m_userFullName = nsnull; - m_userEmail = nsnull; - m_userPassword = nsnull; - m_replyTo = nsnull; - - m_rootPath = nsnull; - - m_imapName = nsnull; - m_imapHost = nsnull; - m_imapPassword = nsnull; - - InitializeIdentity(); -} - -nsMsgIdentity::~nsMsgIdentity() -{ - PR_FREEIF(m_smtpName); - PR_FREEIF(m_popName); - PR_FREEIF(m_organization); - PR_FREEIF(m_userFullName); - PR_FREEIF(m_userEmail); - PR_FREEIF(m_userPassword); - PR_FREEIF(m_replyTo); - PR_FREEIF(m_smtpHost); - PR_FREEIF(m_popHost); - PR_FREEIF(m_rootPath); - PR_FREEIF(m_imapName); - PR_FREEIF(m_imapHost); - PR_FREEIF(m_imapPassword); -} - -void nsMsgIdentity::InitializeIdentity() -{ - // propogating bienvenu's preferences hack..... - #define PREF_LENGTH 128 - char prefValue[PREF_LENGTH]; - PRInt32 prefLength = PREF_LENGTH; - nsIPref* prefs = nsnull; - nsresult rv; - rv = nsServiceManager::GetService(kPrefCID, kIPrefIID, (nsISupports**)&prefs); - if (prefs && NS_SUCCEEDED(rv)) - { - prefs->Startup("prefs.js"); - - prefLength = PREF_LENGTH; - rv = prefs->GetCharPref("mail.rootFolder", prefValue, &prefLength); - if (NS_SUCCEEDED(rv) && prefLength > 0) - m_rootPath = PL_strdup(prefValue); - - prefLength = PREF_LENGTH; - rv = prefs->GetCharPref("mail.identity.organization", prefValue, &prefLength); - if (NS_SUCCEEDED(rv) && prefLength > 0) - m_organization = PL_strdup(prefValue); - - prefLength = PREF_LENGTH; - rv = prefs->GetCharPref("mail.identity.username", prefValue, &prefLength); - if (NS_SUCCEEDED(rv) && prefLength > 0) - m_userFullName = PL_strdup(prefValue); - - prefLength = PREF_LENGTH; - rv = prefs->GetCharPref("mail.identity.useremail", prefValue, &prefLength); - if (NS_SUCCEEDED(rv) && prefLength > 0) - m_userEmail = PL_strdup(prefValue); - - prefLength = PREF_LENGTH; - rv = prefs->GetCharPref("mail.identity.reply_to", prefValue, &prefLength); - if (NS_SUCCEEDED(rv) && prefLength > 0) - m_replyTo = PL_strdup(prefValue); - - prefLength = PREF_LENGTH; - rv = prefs->GetCharPref("network.hosts.pop_server", prefValue, &prefLength); - if (NS_SUCCEEDED(rv) && prefLength > 0) - m_popHost = PL_strdup(prefValue); - - prefLength = PREF_LENGTH; - rv = prefs->GetCharPref("network.hosts.smtp_server", prefValue, &prefLength); - if (NS_SUCCEEDED(rv) && prefLength > 0) - m_smtpHost = PL_strdup(prefValue); - - prefLength = PREF_LENGTH; - rv = prefs->GetCharPref("mail.pop_name", prefValue, &prefLength); - if (NS_SUCCEEDED(rv) && prefLength > 0) - m_popName = PL_strdup(prefValue); - - prefLength = PREF_LENGTH; - rv = prefs->GetCharPref("mail.smtp_name", prefValue, &prefLength); - if (NS_SUCCEEDED(rv) && prefLength > 0) - m_smtpName = PL_strdup(prefValue); - - prefLength = PREF_LENGTH; - rv = prefs->GetCharPref("mail.pop_password", prefValue, &prefLength); - if (NS_SUCCEEDED(rv) && prefLength > 0) - m_userPassword = PL_strdup(prefValue); - - prefLength = PREF_LENGTH; - rv = prefs->GetCharPref("mail.imap_name", prefValue, &prefLength); - if (NS_SUCCEEDED(rv) && prefLength > 0) - m_imapName = PL_strdup(prefValue); - - prefLength = PREF_LENGTH; - rv = prefs->GetCharPref("mail.imap_password", prefValue, &prefLength); - if (NS_SUCCEEDED(rv) && prefLength > 0) - m_imapPassword = PL_strdup(prefValue); - - prefLength = PREF_LENGTH; - rv = prefs->GetCharPref("mail.imap_host", prefValue, &prefLength); - if (NS_SUCCEEDED(rv) && prefLength > 0) - m_imapHost = PL_strdup(prefValue); - - nsServiceManager::ReleaseService(kPrefCID, prefs); - } - else - NS_ASSERTION(0, "unable to create the prefs service!!"); -} - -nsresult nsMsgIdentity::GetPopName(const char ** aUserName) -{ - if (aUserName) - *aUserName = m_popName; - return NS_OK; -} - -nsresult nsMsgIdentity::GetSmtpName(const char ** aSmtpName) -{ - if (aSmtpName) - { - if (m_smtpName && *m_smtpName) - *aSmtpName = m_smtpName; - else // if we don't have a smtp name use the pop name... - return GetPopName(aSmtpName); - } - - return NS_OK; -} - -nsresult nsMsgIdentity::GetOrganization(const char ** aOrganization) -{ - if (aOrganization) - *aOrganization = m_organization; - return NS_OK; -} - -nsresult nsMsgIdentity::GetUserFullName(const char ** aUserFullName) -{ - if (aUserFullName) - *aUserFullName = m_userFullName; - return NS_OK; -} - -nsresult nsMsgIdentity::GetUserEmail(const char ** aUserEmail) -{ - if (aUserEmail) - *aUserEmail = m_userEmail; - return NS_OK; -} - -nsresult nsMsgIdentity::GetPopPassword(const char ** aUserPassword) -{ - if (aUserPassword) - *aUserPassword = m_userPassword; - return NS_OK; -} - - -nsresult nsMsgIdentity::GetPopServer(const char ** aHostName) -{ - if (aHostName) - *aHostName = m_popHost; - return NS_OK; -} - -nsresult nsMsgIdentity::GetSmtpServer(const char ** aHostName) -{ - if (aHostName) - *aHostName = m_smtpHost; - return NS_OK; -} - -nsresult nsMsgIdentity::GetRootFolderPath(const char ** aRootFolderPath) -{ - if (aRootFolderPath) - *aRootFolderPath = m_rootPath; - return NS_OK; -} - -nsresult nsMsgIdentity::GetReplyTo(const char ** aReplyTo) -{ - if (aReplyTo) - *aReplyTo = m_replyTo; - return NS_OK; -} - -nsresult nsMsgIdentity::GetImapServer(const char ** aHostName) -{ - if (aHostName) - *aHostName = m_imapHost; - return NS_OK; -} - -nsresult nsMsgIdentity::GetImapName(const char ** aImapName) -{ - if (aImapName) - *aImapName = m_imapName; - return NS_OK; -} - -nsresult nsMsgIdentity::GetImapPassword(const char ** aImapPassword) -{ - if (aImapPassword) - *aImapPassword = m_imapPassword; - return NS_OK; -} diff --git a/mailnews/base/src/nsMsgIdentity.h b/mailnews/base/src/nsMsgIdentity.h deleted file mode 100644 index 91443ec7eac7..000000000000 --- a/mailnews/base/src/nsMsgIdentity.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; 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. - */ - -#ifndef nsMsgIdentity_h___ -#define nsMsgIdentity_h___ - -#include "nsIMsgIdentity.h" - -/////////////////////////////////////////////////////////////////////////////////// -// an identity is an object designed to encapsulate all the information we need -// to know about a user identity. I expect this interface to grow and change a lot -// as we flesh out our thoughts on multiple identities and what properties go into -// these identities. -////////////////////////////////////////////////////////////////////////////////// - -class nsMsgIdentity : public nsIMsgIdentity -{ -public: - nsMsgIdentity(); - virtual ~nsMsgIdentity(); - - NS_DECL_ISUPPORTS - - /////////////////////////////////////////////////////////////////////////////////// - // The user's current identity is used to abstract out information such as the - // user name, pwd, mail server to use, etc.... - ////////////////////////////////////////////////////////////////////////////////// - NS_IMETHOD GetRootFolderPath(const char ** aRootFolderPath); - NS_IMETHOD GetPopName(const char ** aPopName); // right now it is pop & smtp user name - NS_IMETHOD GetSmtpName(const char ** aSmtpName); - NS_IMETHOD GetOrganization(const char ** aOrganization); - NS_IMETHOD GetUserFullName(const char ** aUserFullName); // User real name - NS_IMETHOD GetUserEmail(const char ** aUserEmail); - NS_IMETHOD GetPopPassword(const char ** aUserPassword); - NS_IMETHOD GetPopServer(const char ** aHostName); - NS_IMETHOD GetSmtpServer(const char ** aHostName); - NS_IMETHOD GetReplyTo(const char ** aReplyTo); - NS_IMETHOD GetImapServer(const char ** aHostName); - NS_IMETHOD GetImapName(const char ** aImapName); - NS_IMETHOD GetImapPassword(const char ** aImapPassword); - -protected: - char *m_popName; - char *m_smtpName; - char *m_organization; - char *m_userFullName; - char *m_userEmail; - char *m_userPassword; - char *m_smtpHost; - char *m_popHost; - char *m_rootPath; - char *m_replyTo; - char *m_imapName; - char *m_imapHost; - char *m_imapPassword; - - void InitializeIdentity(); -}; - -#endif /* nsMsgIdentity_h___ */ diff --git a/mailnews/base/src/nsMsgMailSession.cpp b/mailnews/base/src/nsMsgMailSession.cpp index 79070f3d6c25..53a35e228511 100644 --- a/mailnews/base/src/nsMsgMailSession.cpp +++ b/mailnews/base/src/nsMsgMailSession.cpp @@ -18,34 +18,83 @@ #include "msgCore.h" // for pre-compiled headers #include "nsIMsgIdentity.h" -#include "nsMsgIdentity.h" +#include "nsIMsgAccountManager.h" +#include "nsIPop3IncomingServer.h" #include "nsMsgMailSession.h" +#include "nsMsgLocalCID.h" +#include "nsMsgBaseCID.h" NS_IMPL_ISUPPORTS(nsMsgMailSession, nsIMsgMailSession::GetIID()); -nsMsgMailSession::nsMsgMailSession() +static NS_DEFINE_CID(kMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_CID); +static NS_DEFINE_CID(kMsgIdentityCID, NS_MSGIDENTITY_CID); +static NS_DEFINE_CID(kPop3IncomingServerCID, NS_POP3INCOMINGSERVER_CID); +static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); + + +nsMsgMailSession::nsMsgMailSession(): + m_accountManager(0) { NS_INIT_REFCNT(); - m_currentIdentity = new nsMsgIdentity(); - if (m_currentIdentity) - NS_ADDREF(m_currentIdentity); + + nsresult rv; + /* kick of the prefs now, we'll need them for the account manager */ + + nsIPref* prefs; + rv = nsServiceManager::GetService(kPrefCID, + nsIPref::GetIID(), + (nsISupports**)&prefs); + if (NS_FAILED(rv)) return; + + if (prefs && NS_SUCCEEDED(rv)) + rv = prefs->Startup("prefs.js"); + + (void)nsServiceManager::ReleaseService(kPrefCID, prefs); + + rv = nsComponentManager::CreateInstance(kMsgAccountManagerCID, + NULL, + nsIMsgAccountManager::GetIID(), + (void **)&m_accountManager); + if (NS_SUCCEEDED(rv)) + m_accountManager->LoadAccounts(); } nsMsgMailSession::~nsMsgMailSession() { - NS_IF_RELEASE(m_currentIdentity); + NS_IF_RELEASE(m_accountManager); } // nsIMsgMailSession nsresult nsMsgMailSession::GetCurrentIdentity(nsIMsgIdentity ** aIdentity) { - if (aIdentity) - { - *aIdentity = m_currentIdentity; - NS_IF_ADDREF(m_currentIdentity); - } + nsresult rv=NS_ERROR_UNEXPECTED; + nsIMsgAccount *defaultAccount; - return NS_OK; + if (m_accountManager) + rv = m_accountManager->GetDefaultAccount(&defaultAccount); + if (NS_FAILED(rv)) return rv; + + rv = defaultAccount->GetDefaultIdentity(aIdentity); + + NS_IF_RELEASE(defaultAccount); + + return rv; +} + +nsresult nsMsgMailSession::GetCurrentServer(nsIMsgIncomingServer ** aServer) +{ + nsresult rv=NS_ERROR_UNEXPECTED; + nsIMsgAccount *defaultAccount; + if (m_accountManager) + rv = m_accountManager->GetDefaultAccount(&defaultAccount); + + if (NS_FAILED(rv)) return rv; + + rv = defaultAccount->GetIncomingServer(aServer); + + NS_IF_RELEASE(defaultAccount); + + return rv; } diff --git a/mailnews/base/src/nsMsgMailSession.h b/mailnews/base/src/nsMsgMailSession.h index 12e678ec1d00..b500fcab8013 100644 --- a/mailnews/base/src/nsMsgMailSession.h +++ b/mailnews/base/src/nsMsgMailSession.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * 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 @@ -31,7 +31,7 @@ // cruft in it.... ////////////////////////////////////////////////////////////////////////////////// -class nsIMsgIdentity; +#include "nsIMsgAccountManager.h" class nsMsgMailSession : public nsIMsgMailSession { @@ -43,9 +43,10 @@ public: // nsIMsgMailSession support NS_IMETHOD GetCurrentIdentity(nsIMsgIdentity ** aIdentity); - + NS_IMETHOD GetCurrentServer(nsIMsgIncomingServer **aServer); + protected: - nsIMsgIdentity * m_currentIdentity; + nsIMsgAccountManager *m_accountManager; }; #endif /* nsMsgMailSession_h__ */ diff --git a/mailnews/base/util/Makefile.in b/mailnews/base/util/Makefile.in index 19318e684290..54be03d99436 100644 --- a/mailnews/base/util/Makefile.in +++ b/mailnews/base/util/Makefile.in @@ -32,6 +32,8 @@ EXPORTS = \ nsNewsSet.h \ nsMsgFolder.h \ nsLocalFolderSummarySpec.h \ + nsMsgIdentity.h \ + nsMsgIncomingServer.h \ $(NULL) CPPSRCS = \ @@ -41,6 +43,8 @@ CPPSRCS = \ nsUInt32Array.cpp \ nsNewsSet.cpp \ nsLocalFolderSummarySpec.cpp \ + nsMsgIdentity.cpp \ + nsMsgIncomingServer.cpp \ $(NULL) EXTRA_DSO_LDOPTS = \ diff --git a/mailnews/base/util/makefile.win b/mailnews/base/util/makefile.win index c5c0fb5c35ee..93db5a644f08 100644 --- a/mailnews/base/util/makefile.win +++ b/mailnews/base/util/makefile.win @@ -33,6 +33,8 @@ CPPSRCS= \ nsNewsSet.cpp \ nsMsgFolder.cpp \ nsLocalFolderSummarySpec.cpp \ + nsMsgIdentity.cpp \ + nsMsgIncomingServer.cpp \ $(NULL) @@ -44,6 +46,8 @@ CPP_OBJS= \ .\$(OBJDIR)\nsNewsSet.obj \ .\$(OBJDIR)\nsMsgFolder.obj \ .\$(OBJDIR)\nsLocalFolderSummarySpec.obj \ + .\$(OBJDIR)\nsMsgIdentity.obj \ + .\$(OBJDIR)\nsMsgIncomingServer.obj \ $(NULL) @@ -54,6 +58,8 @@ EXPORTS= \ nsNewsSet.h \ nsMsgFolder.h \ nsLocalFolderSummarySpec.h \ + nsMsgIdentity.h \ + nsMsgIncomingServer.h \ $(NULL) LINCS= \ diff --git a/mailnews/base/util/nsMsgFolder.cpp b/mailnews/base/util/nsMsgFolder.cpp index edf822ac98c4..7f453f384371 100644 --- a/mailnews/base/util/nsMsgFolder.cpp +++ b/mailnews/base/util/nsMsgFolder.cpp @@ -27,7 +27,13 @@ #include "nsISupportsArray.h" #include "nsIPref.h" -static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); +// stuff for temporary root folder hack +#include "nsIMsgMailSession.h" +#include "nsIMsgIncomingServer.h" +#include "nsIPop3IncomingServer.h" + +static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID); + // 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 @@ -1386,25 +1392,14 @@ NS_IMETHODIMP nsMsgFolder::GetHostName(char **hostName) #include "prprf.h" #include "prsystem.h" -static const char kMsgRootFolderPref[] = "mail.rootFolder"; - -char* gMailboxRoot = nsnull; +static char *gMailboxRoot = nsnull; nsresult nsGetMailboxRoot(nsFileSpec &result) { nsresult rv = NS_OK; - if (gMailboxRoot == nsnull) { - // get mailbox root preference and cache it permanently - this - // is extremely temporary...I'm waiting for hubie to check in the - // new preferences service stuff. -#if 1 - nsIPref* prefs; - rv = nsServiceManager::GetService(kPrefCID, nsIPref::GetIID(), (nsISupports**)&prefs); - if (NS_FAILED(rv)) return rv; - if (prefs && NS_SUCCEEDED(rv)) { - rv = prefs->Startup("prefs.js"); +#if 0 if (NS_SUCCEEDED(rv)) { #if defined(XP_MAC) char prefValue[1024]; @@ -1420,15 +1415,46 @@ nsGetMailboxRoot(nsFileSpec &result) #endif } } - (void)nsServiceManager::ReleaseService(kPrefCID, prefs); if (NS_FAILED(rv)) return rv; -#else - gMailboxRoot = nsCRT::strdup("d:\\program files\\netscape\\users\\warren\\mail"); -#endif + } result = gMailboxRoot; // XXX free gMailboxRoot somewhere (on shutdown?) - return rv; + return rv; + +#else + + // temporary stuff. for now get everything from the mail session + if (gMailboxRoot == nsnull) { + nsIMsgMailSession *session; + rv = nsServiceManager::GetService(kMsgMailSessionCID, + nsIMsgMailSession::GetIID(), + (nsISupports **)&session); + + if (NS_SUCCEEDED(rv)) { + nsIMsgIncomingServer *server; + rv = session->GetCurrentServer(&server); + if (NS_FAILED(rv)) printf("nsGetMailboxRoot: Couldn't get current server\n"); + if (NS_SUCCEEDED(rv)) { + nsIPop3IncomingServer *popServer; + rv = server->QueryInterface(nsIPop3IncomingServer::GetIID(), + (void **)&popServer); + if (NS_FAILED(rv)) printf("nsGetMailboxRoot: Couldn't get pop3 server\n"); + if (NS_SUCCEEDED(rv)) { + rv = popServer->GetRootFolderPath(&gMailboxRoot); + if (NS_FAILED(rv)) printf("nsGetMailboxRoot: Couldn't get root\n"); + NS_RELEASE(popServer); + } + NS_RELEASE(server); + + } + nsServiceManager::ReleaseService(kMsgMailSessionCID, session); + } + } /* if (gMailboxRoot == nsnull) .. */ + result = gMailboxRoot; + return rv; + +#endif } nsresult @@ -1450,6 +1476,10 @@ nsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult) { nsresult rv; +#ifdef DEBUG_alecf + printf("nsPath2URI(%s, %s, ??)", rootURI, uriStr); +#endif + nsAutoString sep; sep += PR_GetDirectorySeparator(); @@ -1508,6 +1538,10 @@ nsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult) if(path.Length() > 0) pathResult +=path; + +#ifdef DEBUG_alecf + printf("->%s\n", (const char *)pathResult); +#endif return NS_OK; }