mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-06 09:05:45 +00:00
Bug #368074 --> look for isp spam .sfd files in extension directories.
r=neil sr=bienvenu
This commit is contained in:
parent
efed0d38ec
commit
8d14fcb7f5
@ -111,6 +111,8 @@
|
||||
#include "nsMsgTagService.h"
|
||||
#include "nsMsgFolderNotificationService.h"
|
||||
|
||||
#include "nsMailDirProvider.h"
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include "nsMessengerWinIntegration.h"
|
||||
#endif
|
||||
@ -189,6 +191,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMessengerUnixIntegration, Init)
|
||||
#endif
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMessengerContentHandler)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgContentPolicy, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMailDirProvider)
|
||||
|
||||
static NS_METHOD
|
||||
RegisterMailnewsContentPolicy(nsIComponentManager *aCompMgr, nsIFile *aPath,
|
||||
@ -467,6 +470,14 @@ static const nsModuleComponentInfo gComponents[] = {
|
||||
NS_MSGCONTENTPOLICY_CONTRACTID,
|
||||
nsMsgContentPolicyConstructor,
|
||||
RegisterMailnewsContentPolicy, UnregisterMailnewsContentPolicy
|
||||
},
|
||||
{
|
||||
"mail director provider",
|
||||
MAILDIRPROVIDER_CID,
|
||||
NS_MAILDIRPROVIDER_CONTRACTID,
|
||||
nsMailDirProviderConstructor,
|
||||
nsMailDirProvider::Register,
|
||||
nsMailDirProvider::Unregister
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -42,12 +42,7 @@ VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
ifdef MOZ_XUL_APP
|
||||
EXPORT_DIR = $(DIST)/bin/isp
|
||||
else
|
||||
EXPORT_DIR = $(DIST)/bin/defaults/isp
|
||||
EXPORT_DIR_L10N = $(DIST)/bin/defaults/isp/$(AB_CD)
|
||||
endif
|
||||
|
||||
EXPORT_RESOURCE_FILES = gmail.rdf \
|
||||
$(NULL)
|
||||
@ -75,11 +70,4 @@ libs:: $(EXPORT_RESOURCE_FILES)
|
||||
install:: $(EXPORT_RESOURCE_FILES)
|
||||
$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/defaults/isp
|
||||
|
||||
ifndef MOZ_XUL_APP
|
||||
libs:: $(EXPORT_RESOURCE_FILES)
|
||||
$(INSTALL) $^ $(EXPORT_DIR_L10N)
|
||||
|
||||
install:: $(EXPORT_RESOURCE_FILES)
|
||||
$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/defaults/isp/$(AB_CD)
|
||||
endif
|
||||
endif
|
||||
|
@ -36,8 +36,8 @@
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
*/
|
||||
const KEY_APPDIR = "XCurProcD";
|
||||
const KEY_PROFILEDIR = "PrefD";
|
||||
|
||||
const KEY_ISP_DIRECTORY_LIST = "ISPDL";
|
||||
|
||||
function onInit(aPageId, aServerId)
|
||||
{
|
||||
@ -120,19 +120,16 @@ function onActionTargetChange(aMenuList, aWSMElementId)
|
||||
|
||||
function buildServerFilterMenuList()
|
||||
{
|
||||
// First, scan the profile directory for any .sfd files we may have there.
|
||||
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Components.interfaces.nsIProperties);
|
||||
|
||||
var profileDir = fileLocator.get(KEY_PROFILEDIR, Components.interfaces.nsIFile);
|
||||
buildServerFilterListFromDir(profileDir);
|
||||
|
||||
// Then, fall back to defaults\messenger and list the default sfd files we shipped with
|
||||
var appDir = fileLocator.get(KEY_APPDIR, Components.interfaces.nsIFile);
|
||||
appDir.append('defaults');
|
||||
appDir.append('messenger');
|
||||
|
||||
buildServerFilterListFromDir(appDir);
|
||||
// Now walk through the isp directories looking for sfd files
|
||||
var ispDirectories = fileLocator.get(KEY_ISP_DIRECTORY_LIST, Components.interfaces.nsISimpleEnumerator);
|
||||
while (ispDirectories.hasMoreElements())
|
||||
{
|
||||
ispDirectory = ispDirectories.getNext().QueryInterface(Components.interfaces.nsIFile);
|
||||
if (ispDirectory)
|
||||
buildServerFilterListFromDir(ispDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
// helper function called by buildServerFilterMenuList. Enumerates over the passed in
|
||||
|
@ -44,8 +44,9 @@
|
||||
interface nsIOutputStream;
|
||||
interface nsIMsgIncomingServer;
|
||||
interface nsIMsgDBHdr;
|
||||
interface nsIFile;
|
||||
|
||||
[scriptable, uuid(A2C3A171-5A1B-41e2-AB43-3C4F22E96638)]
|
||||
[scriptable, uuid(60BF2B22-AA8C-4cb2-80C8-ADC8B508E425)]
|
||||
interface nsISpamSettings: nsISupports {
|
||||
/**
|
||||
* 0 for nothing, 100 for highest
|
||||
@ -93,6 +94,7 @@ interface nsISpamSettings: nsISupports {
|
||||
*/
|
||||
attribute boolean useServerFilter;
|
||||
attribute ACString serverFilterName;
|
||||
readonly attribute nsIFile serverFilterFile;
|
||||
const long TRUST_POSITIVES = 1;
|
||||
const long TRUST_NEGATIVES = 2;
|
||||
attribute long serverFilterTrustFlags;
|
||||
|
@ -47,7 +47,7 @@ XPIDL_MODULE = msgsearch
|
||||
LIBRARY_NAME = msgsearch_s
|
||||
META_COMPONENT = mail
|
||||
MOZILLA_INTERNAL_API = 1
|
||||
EXPORT_DIR = $(DIST)/bin/defaults/messenger
|
||||
EXPORT_DIR = $(DIST)/bin/isp
|
||||
|
||||
REQUIRES = xpcom \
|
||||
xpcom_obsolete \
|
||||
|
@ -130,6 +130,7 @@ CPPSRCS = \
|
||||
nsMsgContentPolicy.cpp \
|
||||
nsMsgTagService.cpp\
|
||||
nsMsgFolderNotificationService.cpp\
|
||||
nsMailDirProvider.cpp\
|
||||
$(NULL)
|
||||
|
||||
# MacOSX requires the MoreFiles module
|
||||
@ -158,10 +159,6 @@ ifneq (,$(filter $(MOZ_WIDGET_TOOLKIT),gtk gtk2))
|
||||
CPPSRCS += nsMessengerUnixIntegration.cpp
|
||||
endif
|
||||
|
||||
ifdef MOZ_XUL_APP
|
||||
CPPSRCS += nsMailDirProvider.cpp
|
||||
endif
|
||||
|
||||
ifdef MOZ_LDAP_XPCOM
|
||||
REQUIRES += mozldap \
|
||||
$(NULL)
|
||||
|
@ -37,7 +37,9 @@
|
||||
|
||||
#include "nsMailDirProvider.h"
|
||||
#include "nsMailDirServiceDefs.h"
|
||||
#ifdef MOZ_XUL_APP
|
||||
#include "nsXULAppAPI.h"
|
||||
#endif
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "nsArrayEnumerator.h"
|
||||
#include "nsCOMArray.h"
|
||||
@ -78,29 +80,27 @@ nsMailDirProvider::GetFiles(const char *aKey,
|
||||
nsresult rv = dirSvc->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
|
||||
NS_GET_IID(nsIFile), getter_AddRefs(currentProcessDir));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// now turn this into an enumerator, is there a more direct way to do this?
|
||||
nsCOMArray<nsIFile> directories;
|
||||
directories.AppendObject(currentProcessDir);
|
||||
nsCOMPtr<nsISimpleEnumerator> currentProcessDirEnum;
|
||||
NS_NewArrayEnumerator(getter_AddRefs(currentProcessDirEnum), directories);
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> appEnum = new AppendingEnumerator(currentProcessDirEnum);
|
||||
if (!appEnum)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsCOMPtr<nsISimpleEnumerator> directoryEnumerator;
|
||||
rv = NS_NewSingletonEnumerator(getter_AddRefs(directoryEnumerator), currentProcessDir);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> list;
|
||||
nsCOMPtr<nsISimpleEnumerator> combinedEnumerator;
|
||||
|
||||
#ifdef MOZ_XUL_APP
|
||||
nsCOMPtr<nsISimpleEnumerator> extensionsEnum;
|
||||
rv = dirSvc->Get(XRE_EXTENSIONS_DIR_LIST,
|
||||
NS_GET_IID(nsISimpleEnumerator),
|
||||
getter_AddRefs(list));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
getter_AddRefs(extensionsEnum));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> extensionsEnum = new AppendingEnumerator(list);
|
||||
if (!extensionsEnum)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = NS_NewUnionEnumerator(getter_AddRefs(combinedEnumerator), directoryEnumerator, extensionsEnum);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
#else
|
||||
directoryEnumerator.swap(combinedEnumerator);
|
||||
#endif
|
||||
|
||||
// now combine the app enumerator with the extensions enumerator
|
||||
rv = NS_NewUnionEnumerator(aResult, appEnum, extensionsEnum);
|
||||
NS_IF_ADDREF(*aResult = new AppendingEnumerator(combinedEnumerator));
|
||||
return NS_SUCCESS_AGGREGATE_RESULT;
|
||||
}
|
||||
|
||||
|
@ -51,13 +51,11 @@
|
||||
#include "nsIMsgMailSession.h"
|
||||
#include "nsMsgBaseCID.h"
|
||||
|
||||
#ifdef MOZ_XUL_APP
|
||||
#include "nsMailDirServiceDefs.h"
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsIDirectoryEnumerator.h"
|
||||
#endif
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID);
|
||||
@ -81,47 +79,10 @@ nsMsgServiceProviderService::Init()
|
||||
mInnerDataSource = do_CreateInstance(kRDFCompositeDataSourceCID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
#ifdef MOZ_XUL_APP
|
||||
LoadISPFiles();
|
||||
#else
|
||||
nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// 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
|
||||
PRBool isexists = PR_FALSE;
|
||||
rv = dataFilesDir->Exists(&isexists);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
if (isexists) {
|
||||
// now enumerate every file in the directory, and suck it into the datasource
|
||||
PRBool hasMore = PR_FALSE;
|
||||
nsCOMPtr<nsISimpleEnumerator> dirIterator;
|
||||
rv = dataFilesDir->GetDirectoryEntries(getter_AddRefs(dirIterator));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFile> dirEntry;
|
||||
|
||||
while ((rv = dirIterator->HasMoreElements(&hasMore)) == NS_OK && hasMore) {
|
||||
rv = dirIterator->GetNext((nsISupports**)getter_AddRefs(dirEntry));
|
||||
if (NS_FAILED(rv))
|
||||
continue;
|
||||
|
||||
nsCAutoString urlSpec;
|
||||
rv = NS_GetURLSpecFromFile(dirEntry, urlSpec);
|
||||
rv = LoadDataSource(urlSpec.get());
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed reading in the datasource\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef MOZ_XUL_APP
|
||||
/**
|
||||
* Looks for ISP configuration files in <.exe>\isp and any sub directories called isp
|
||||
* located in the user's extensions directory.
|
||||
@ -189,7 +150,6 @@ void nsMsgServiceProviderService::LoadISPFilesFromDir(nsIFile* aDir)
|
||||
LoadDataSource(urlSpec.get());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
nsresult
|
||||
nsMsgServiceProviderService::LoadDataSource(const char *aURI)
|
||||
|
@ -60,9 +60,7 @@ class nsMsgServiceProviderService : public nsIRDFDataSource
|
||||
nsCOMPtr<nsIRDFCompositeDataSource> mInnerDataSource;
|
||||
nsresult LoadDataSource(const char *aURL);
|
||||
|
||||
#ifdef MOZ_XUL_APP
|
||||
void LoadISPFilesFromDir(nsIFile* aDir);
|
||||
void LoadISPFiles();
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
@ -59,6 +59,12 @@
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsDateTimeFormatCID.h"
|
||||
|
||||
#include "nsMailDirServiceDefs.h"
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsIDirectoryEnumerator.h"
|
||||
|
||||
nsSpamSettings::nsSpamSettings()
|
||||
{
|
||||
mLevel = 0;
|
||||
@ -486,9 +492,56 @@ NS_IMETHODIMP nsSpamSettings::GetServerFilterName(nsACString &aFilterName)
|
||||
NS_IMETHODIMP nsSpamSettings::SetServerFilterName(const nsACString &aFilterName)
|
||||
{
|
||||
mServerFilterName = aFilterName;
|
||||
mServerFilterFile = nsnull; // clear out our stored location value
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSpamSettings::GetServerFilterFile(nsIFile ** aFile)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFile);
|
||||
if (!mServerFilterFile)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCAutoString serverFilterFileName;
|
||||
GetServerFilterName(serverFilterFileName);
|
||||
serverFilterFileName.Append(".sfd");
|
||||
|
||||
nsCOMPtr<nsIProperties> dirSvc = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Walk through the list of isp directories
|
||||
nsCOMPtr<nsISimpleEnumerator> ispDirectories;
|
||||
rv = dirSvc->Get(ISP_DIRECTORY_LIST, NS_GET_IID(nsISimpleEnumerator), getter_AddRefs(ispDirectories));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRBool hasMore;
|
||||
nsCOMPtr<nsIFile> file;
|
||||
while (NS_SUCCEEDED(ispDirectories->HasMoreElements(&hasMore)) && hasMore)
|
||||
{
|
||||
nsCOMPtr<nsISupports> elem;
|
||||
ispDirectories->GetNext(getter_AddRefs(elem));
|
||||
file = do_QueryInterface(elem);
|
||||
|
||||
if (file)
|
||||
{
|
||||
// append our desired leaf name then test to see if the file exists. If it does, we've found
|
||||
// mServerFilterFile.
|
||||
file->AppendNative(serverFilterFileName);
|
||||
PRBool exists;
|
||||
if (NS_SUCCEEDED(file->Exists(&exists)) && exists)
|
||||
{
|
||||
file.swap(mServerFilterFile);
|
||||
break;
|
||||
}
|
||||
} // if file
|
||||
} // until we find the location of mServerFilterName
|
||||
} // if we haven't already stored mServerFilterFile
|
||||
|
||||
NS_IF_ADDREF(*aFile = mServerFilterFile);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_GETSET(nsSpamSettings, ServerFilterTrustFlags, PRBool, mServerFilterTrustFlags)
|
||||
|
||||
#define LOG_ENTRY_START_TAG "<p>\n"
|
||||
|
@ -78,6 +78,7 @@ private:
|
||||
nsCString mCurrentJunkFolderURI; // used to detect changes to the spam folder in ::initialize
|
||||
|
||||
nsCString mServerFilterName;
|
||||
nsCOMPtr<nsIFile> mServerFilterFile;
|
||||
PRInt32 mServerFilterTrustFlags;
|
||||
|
||||
nsCOMPtr<nsIDateTimeFormat> mDateFormatter;
|
||||
|
@ -1955,37 +1955,13 @@ nsMsgIncomingServer::ConfigureTemporaryServerSpamFilters(nsIMsgFilterList *filte
|
||||
if (newFilter)
|
||||
return NS_OK;
|
||||
|
||||
nsCAutoString serverFilterFileName(serverFilterName);
|
||||
serverFilterFileName.Append(".sfd");
|
||||
nsCOMPtr<nsIFile> file;
|
||||
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
spamSettings->GetServerFilterFile(getter_AddRefs(file));
|
||||
|
||||
rv = file->AppendNative(serverFilterFileName);
|
||||
|
||||
// if the file doesn't exist, we should try to get it from the defaults directory and copy it over
|
||||
PRBool exists = PR_FALSE;
|
||||
file->Exists(&exists);
|
||||
if (!exists)
|
||||
{
|
||||
nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIFile> defaultServerFilterFile;
|
||||
rv = mailSession->GetDataFilesDir("messenger", getter_AddRefs(defaultServerFilterFile));
|
||||
rv = defaultServerFilterFile->AppendNative(serverFilterFileName);
|
||||
|
||||
nsCOMPtr<nsIFileSpec> defaultServerFilterSpec;
|
||||
rv = NS_NewFileSpecFromIFile(defaultServerFilterFile, getter_AddRefs(defaultServerFilterSpec));
|
||||
|
||||
// get the profile directory
|
||||
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(defaultServerFilterFile));
|
||||
|
||||
// convert to spec
|
||||
nsCOMPtr<nsIFileSpec> profileDirSpec;
|
||||
rv = NS_NewFileSpecFromIFile(defaultServerFilterFile, getter_AddRefs(profileDirSpec));
|
||||
// now copy the file over to the profile directory
|
||||
defaultServerFilterSpec->CopyToDir(profileDirSpec);
|
||||
}
|
||||
// it's possible that we can no longer find the sfd file (i.e. the user disabled an extnsion that
|
||||
// was supplying the .sfd file.
|
||||
if (!file)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIFileSpec> serverFilterSpec;
|
||||
rv = NS_NewFileSpecFromIFile(file, getter_AddRefs(serverFilterSpec));
|
||||
|
Loading…
Reference in New Issue
Block a user