Fixing bug 4198. This fix allows ISPs to add a customized signature file to their user mail accounts. r=ducarroz, sr=sspitzer

git-svn-id: svn://10.0.0.236/trunk@113293 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
racham%netscape.com 2002-01-31 05:15:27 +00:00
parent 1cbad10dec
commit d3e9affe90
5 changed files with 98 additions and 74 deletions

View File

@ -53,6 +53,7 @@
#include "nsIAtom.idl"
interface nsIMsgWindow;
interface nsIFile;
[scriptable, uuid(D5124440-D59E-11d2-806A-006008128C4E)]
interface nsIMsgMailSession : nsISupports {
@ -67,5 +68,6 @@ interface nsIMsgMailSession : nsISupports {
boolean IsFolderOpenInWindow(in nsIMsgFolder folder);
string ConvertMsgURIToMsgURL(in string aURI, in nsIMsgWindow aMsgWindow);
nsIFile getDataFilesDir(in string dirName);
};

View File

@ -46,6 +46,9 @@
#include "nsIURI.h"
#include "nsXPIDLString.h"
#include "nsIMsgAccountManager.h"
#include "nsIChromeRegistry.h"
#include "nsIDirectoryService.h"
#include "nsAppDirectoryServiceDefs.h"
NS_IMPL_THREADSAFE_ADDREF(nsMsgMailSession)
NS_IMPL_THREADSAFE_RELEASE(nsMsgMailSession)
@ -452,3 +455,77 @@ nsMsgMailSession::ConvertMsgURIToMsgURL(const char *aURI, nsIMsgWindow *aMsgWind
}
return rv;
}
//----------------------------------------------------------------------------------------
// GetSelectedLocaleDataDir - If a locale is selected, appends the selected locale to the
// defaults data dir and returns that new defaults data dir
//----------------------------------------------------------------------------------------
nsresult
nsMsgMailSession::GetSelectedLocaleDataDir(nsIFile *defaultsDir)
{
NS_ENSURE_ARG_POINTER(defaultsDir);
nsresult rv;
PRBool baseDirExists = PR_FALSE;
rv = defaultsDir->Exists(&baseDirExists);
NS_ENSURE_SUCCESS(rv,rv);
if (baseDirExists) {
nsCOMPtr<nsIChromeRegistry> chromeRegistry = do_GetService("@mozilla.org/chrome/chrome-registry;1", &rv);
if (NS_SUCCEEDED(rv)) {
nsXPIDLString localeName;
rv = chromeRegistry->GetSelectedLocale(NS_LITERAL_STRING("global-region").get(), getter_Copies(localeName));
if (NS_SUCCEEDED(rv) && !localeName.IsEmpty()) {
PRBool localeDirExists = PR_FALSE;
nsCOMPtr<nsIFile> localeDataDir;
rv = defaultsDir->Clone(getter_AddRefs(localeDataDir));
NS_ENSURE_SUCCESS(rv,rv);
rv = localeDataDir->AppendUnicode(localeName);
NS_ENSURE_SUCCESS(rv,rv);
rv = localeDataDir->Exists(&localeDirExists);
NS_ENSURE_SUCCESS(rv,rv);
if (localeDirExists) {
// use locale provider instead
rv = defaultsDir->AppendUnicode(localeName);
NS_ENSURE_SUCCESS(rv,rv);
}
}
}
}
return NS_OK;
}
//----------------------------------------------------------------------------------------
// GetDataFilesDir - Gets the application's default folder and then appends the
// subdirectory named passed in as param dirName. If there is a seleccted
// locale, will append that to the dir path before returning the value
//----------------------------------------------------------------------------------------
NS_IMETHODIMP
nsMsgMailSession::GetDataFilesDir(const char* dirName, nsIFile **dataFilesDir)
{
NS_ENSURE_ARG_POINTER(dataFilesDir);
nsresult rv;
nsCOMPtr<nsIProperties> directoryService =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIFile> defaultsDir;
rv = directoryService->Get(NS_APP_DEFAULTS_50_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(defaultsDir));
NS_ENSURE_SUCCESS(rv,rv);
rv = defaultsDir->Append(dirName);
if (NS_SUCCEEDED(rv))
rv = GetSelectedLocaleDataDir(defaultsDir);
NS_IF_ADDREF(*dataFilesDir = defaultsDir);
return rv;
}

View File

@ -66,6 +66,8 @@ public:
NS_DECL_NSIFOLDERLISTENER
nsresult Init();
nsresult GetSelectedLocaleDataDir(nsIFile *defaultsDir);
protected:
nsCOMPtr<nsISupportsArray> mListeners;
nsUInt32Array mListenerNotifyFlags;

View File

@ -45,16 +45,15 @@
#include "nsIRDFService.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIChromeRegistry.h" // for chrome registry
#include "nsIFileChannel.h"
#include "nsIFileSpec.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsNetUtil.h"
#include "nsIMsgMailSession.h"
#include "nsMsgBaseCID.h"
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID);
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
static NS_DEFINE_CID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID);
nsMsgServiceProviderService::nsMsgServiceProviderService()
{
@ -79,11 +78,13 @@ nsMsgServiceProviderService::Init()
mInnerDataSource = do_CreateInstance(kRDFCompositeDataSourceCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIFile> dataFilesDir;
rv = NS_GetSpecialDirectory(NS_APP_DEFAULTS_50_DIR, getter_AddRefs(dataFilesDir));
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = dataFilesDir->Append("isp");
// Get defaults directory for isp files. MailSession service appends 'isp' to the
// the app defaults folder and returns it. Locale will be added to the path, if there is one.
nsCOMPtr<nsIFile> dataFilesDir;
rv = mailSession->GetDataFilesDir("isp", getter_AddRefs(dataFilesDir));
NS_ENSURE_SUCCESS(rv,rv);
// test if there is a locale provider
@ -91,27 +92,6 @@ nsMsgServiceProviderService::Init()
rv = dataFilesDir->Exists(&isexists);
NS_ENSURE_SUCCESS(rv,rv);
if (isexists) {
nsCOMPtr<nsIChromeRegistry> chromeRegistry = do_GetService(kChromeRegistryCID, &rv);
if (NS_SUCCEEDED(rv)) {
nsXPIDLString lc_name;
rv = chromeRegistry->GetSelectedLocale(NS_LITERAL_STRING("global-region").get(), getter_Copies(lc_name));
if (NS_SUCCEEDED(rv) && (const PRUnichar *)lc_name && nsCRT::strlen((const PRUnichar *)lc_name)) {
nsCOMPtr<nsIFile> tmpdataFilesDir;
rv = dataFilesDir->Clone(getter_AddRefs(tmpdataFilesDir));
NS_ENSURE_SUCCESS(rv,rv);
rv = tmpdataFilesDir->AppendUnicode(lc_name);
NS_ENSURE_SUCCESS(rv,rv);
rv = tmpdataFilesDir->Exists(&isexists);
NS_ENSURE_SUCCESS(rv,rv);
if (isexists) {
// use locale provider instead
rv = dataFilesDir->AppendUnicode(lc_name);
NS_ENSURE_SUCCESS(rv,rv);
}
}
}
// now enumerate every file in the directory, and suck it into the datasource
PRBool hasMore = PR_FALSE;
nsCOMPtr<nsISimpleEnumerator> dirIterator;

View File

@ -50,11 +50,8 @@
#include "nsMsgLocalCID.h"
#include "nsMsgFolderFlags.h"
#include "nsIMsgLocalMailFolder.h"
#include "nsIChromeRegistry.h"
#include "nsIDirectoryService.h"
#include "nsAppDirectoryServiceDefs.h"
static NS_DEFINE_CID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID);
#include "nsIMsgMailSession.h"
#include "nsMsgBaseCID.h"
NS_IMPL_ISUPPORTS_INHERITED2(nsNoIncomingServer,
nsMsgIncomingServer,
@ -108,48 +105,14 @@ NS_IMETHODIMP nsNoIncomingServer::CopyDefaultMessages(const char *folderNameOnDi
PRBool exists;
if (!folderNameOnDisk || !parentDir) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIFile> defaultMessagesFile;
rv = NS_GetSpecialDirectory(NS_APP_DEFAULTS_50_DIR, getter_AddRefs(defaultMessagesFile));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
// bin/defaults better exist
rv = defaultMessagesFile->Exists(&exists);
if (NS_FAILED(rv)) return rv;
if (!exists) return NS_ERROR_FAILURE;
// bin/defaults/messenger doesn't have to exist
// if not, return.
rv = defaultMessagesFile->Append("messenger");
if (NS_FAILED(rv)) return rv;
rv = defaultMessagesFile->Exists(&exists);
if (NS_FAILED(rv)) return rv;
if (!exists) return NS_OK;
// test if there is a locale provider
// this code stolen from nsMsgServiceProvider.cpp
nsCOMPtr<nsIChromeRegistry> chromeRegistry = do_GetService(kChromeRegistryCID, &rv);
if (NS_SUCCEEDED(rv)) {
nsXPIDLString lc_name;
nsAutoString tmpstr(NS_LITERAL_STRING("global-region"));
rv = chromeRegistry->GetSelectedLocale(tmpstr.get(), getter_Copies(lc_name));
if (NS_SUCCEEDED(rv)) {
nsAutoString localeStr(lc_name);
if (!localeStr.IsEmpty()) {
nsCOMPtr<nsIFile> tmpdataFilesDir;
rv = defaultMessagesFile->Clone(getter_AddRefs(tmpdataFilesDir));
NS_ENSURE_SUCCESS(rv,rv);
rv = tmpdataFilesDir->AppendUnicode(lc_name);
NS_ENSURE_SUCCESS(rv,rv);
rv = tmpdataFilesDir->Exists(&exists);
NS_ENSURE_SUCCESS(rv,rv);
if (exists && (const PRUnichar *)lc_name) {
// use locale provider instead
rv = defaultMessagesFile->AppendUnicode(lc_name);
NS_ENSURE_SUCCESS(rv,rv);
}
}
}
}
// Get defaults directory for messenger files. MailSession service appends 'messenger' to the
// the app defaults folder and returns it. Locale will be added to the path, if there is one.
nsCOMPtr<nsIFile> defaultMessagesFile;
rv = mailSession->GetDataFilesDir("messenger", getter_AddRefs(defaultMessagesFile));
NS_ENSURE_SUCCESS(rv,rv);
// check if bin/defaults/messenger/<folderNameOnDisk>
// (or bin/defaults/messenger/<locale>/<folderNameOnDisk> if we had a locale provide) exists.