224318 backend support for automatic server spam filter filters sr=mscott

This commit is contained in:
bienvenu%nventure.com 2004-04-13 18:16:35 +00:00
Родитель 74314dc1fa
Коммит d626970465
12 изменённых файлов: 199 добавлений и 21 удалений

Просмотреть файл

@ -359,16 +359,16 @@ interface nsIMsgIncomingServer : nsISupports {
readonly attribute boolean passwordPromptRequired;
/**
* This configures both the MDN filter, and the server-side
* spam filter filters, if needed.
*
* If we have set up to filter return receipts into
* our Sent folder, this utility method creates
* a filter to do that, and adds it to our filterList
* if it doesn't exist. If it does, it will enable it.
*
* If the user changes their prefs, to leave the
* return receipt in the inbox, this will disable
* the existing return receipts filter, if it exists.
*/
void configureTemporaryReturnReceiptsFilter(in nsIMsgFilterList filterList);
void configureTemporaryFilters(in nsIMsgFilterList filterList);
/**
* If Sent folder pref is changed we need to clear the temporary

Просмотреть файл

@ -89,6 +89,14 @@ interface nsISpamSettings: nsISupports {
const long MANUAL_MARK_MODE_MOVE = 0;
const long MANUAL_MARK_MODE_DELETE = 1;
/**
* integrate with server-side spam detection programs
*/
attribute ACString serverFilterName;
const long TRUST_POSITIVES = 1;
const long TRUST_NEGATIVES = 2;
attribute long serverFilterTrustFlags;
// for logging
attribute boolean loggingEnabled;
attribute nsIOutputStream logStream;

Просмотреть файл

@ -26,5 +26,29 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
PACKAGE_FILE = searchContent.pkg
EXPORT_DIR = $(DIST)/bin/defaults/messenger
EXPORT_L10N_DIR = $(EXPORT_DIR)/US
EXPORT_RESOURCE_FILES = \
Habeas.sfd \
SpamAssassin.sfd \
SpamCatcher.sfd \
SpamPal.sfd \
$(NULL)
include $(topsrcdir)/config/rules.mk
GARBAGE += $(addprefix $(EXPORT_DIR)/, $(EXPORT_RESOURCE_FILES)) \
$(addprefix $(EXPORT_L10N_DIR)/, $(EXPORT_RESOURCE_FILES))
libs:: $(EXPORT_RESOURCE_FILES)
$(INSTALL) $^ $(EXPORT_DIR)
$(INSTALL) $^ $(EXPORT_L10N_DIR)
install:: $(EXPORT_RESOURCE_FILES)
$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/defaults/messenger
$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/defaults/messenger/US

Просмотреть файл

@ -952,10 +952,12 @@ nsMsgFilterList::RemoveFilter(nsIMsgFilter *aFilter)
return m_filters->RemoveElement(NS_STATIC_CAST(nsISupports*, aFilter));
}
nsresult nsMsgFilterList::InsertFilterAt(PRUint32 filterIndex, nsIMsgFilter *filter)
nsresult nsMsgFilterList::InsertFilterAt(PRUint32 filterIndex, nsIMsgFilter *aFilter)
{
m_filters->InsertElementAt(filter, filterIndex);
return NS_OK;
nsMsgFilter *filter = NS_STATIC_CAST(nsMsgFilter *, aFilter);
filter->SetFilterList(this);
m_filters->InsertElementAt(aFilter, filterIndex);
return NS_OK;
}
// Attempt to move the filter at index filterIndex in the specified direction.

Просмотреть файл

@ -22,6 +22,7 @@
* Contributor(s):
* Seth Spitzer <sspitzer@netscape.com>
* Dan Mosedale <dmose@netscape.com>
* David Bienvenu <bienvenu@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -60,6 +61,9 @@ nsSpamSettings::nsSpamSettings()
mMoveTargetMode = nsISpamSettings::MOVE_TARGET_MODE_ACCOUNT;
mPurge = PR_FALSE;
mPurgeInterval = 14; // 14 days
mServerFilterTrustFlags = 0;
mUseWhiteList = PR_FALSE;
mLoggingEnabled = PR_FALSE;
mManualMark = PR_FALSE;
@ -373,10 +377,11 @@ NS_IMETHODIMP nsSpamSettings::Clone(nsISpamSettings *aSpamSettings)
NS_ENSURE_SUCCESS(rv,rv);
mWhiteListAbURI = whiteListAbURI;
PRBool loggingEnabled;
rv = aSpamSettings->GetLoggingEnabled(&loggingEnabled);
NS_ENSURE_SUCCESS(rv,rv);
mLoggingEnabled = loggingEnabled;
rv = aSpamSettings->GetLoggingEnabled(&mLoggingEnabled);
aSpamSettings->GetServerFilterName(mServerFilterName);
aSpamSettings->GetServerFilterTrustFlags(&mServerFilterTrustFlags);
return rv;
}
@ -438,6 +443,19 @@ NS_IMETHODIMP nsSpamSettings::GetSpamFolderURI(char **aSpamFolderURI)
return rv;
}
NS_IMETHODIMP nsSpamSettings::GetServerFilterName(nsACString &aFilterName)
{
aFilterName = mServerFilterName;
return NS_OK;
}
NS_IMETHODIMP nsSpamSettings::SetServerFilterName(const nsACString &aFilterName)
{
mServerFilterName = aFilterName;
return NS_OK;
}
NS_IMPL_GETSET(nsSpamSettings, ServerFilterTrustFlags, PRBool, mServerFilterTrustFlags);
#define LOG_ENTRY_START_TAG "<p>\n"
#define LOG_ENTRY_START_TAG_LEN (strlen(LOG_ENTRY_START_TAG))

Просмотреть файл

@ -22,6 +22,7 @@
* Contributor(s):
* Seth Spitzer <sspitzer@netscape.com>
* Dan Mosedale <dmose@netscape.com>
* David Bienvenu <bienvenu@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -76,7 +77,10 @@ private:
nsCString mActionTargetFolder;
nsCString mWhiteListAbURI;
nsCString mLogURL;
nsCString mServerFilterName;
PRInt32 mServerFilterTrustFlags;
nsresult GetLogFileSpec(nsIFileSpec **aFileSpec);
nsresult TruncateLog();
};

Просмотреть файл

@ -636,7 +636,7 @@ nsMsgIdentity::setFolderPref(const char *prefname, const char *value)
if (nsCRT::strcmp(prefname, "fcc_folder") == 0)
{
// Clear the temporary return receipt filter so that the new filter
// rule can be recreated (by ConfigureTemporaryReturnReceiptsFilter()).
// rule can be recreated (by ConfigureTemporaryFilters()).
nsCOMPtr<nsIMsgAccountManager> accountManager =
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);

Просмотреть файл

@ -21,6 +21,7 @@
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* David Bienvenu <bienvenu@nventure.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -58,7 +59,7 @@
#include "nsIMsgWindow.h"
#include "nsIMsgFilterService.h"
#include "nsIMsgProtocolInfo.h"
#include "nsIMsgMailSession.h"
#include "nsIPrefService.h"
#include "nsIDocShell.h"
#include "nsIWebShell.h"
@ -79,6 +80,7 @@
#include "nsIMsgMdnGenerator.h"
#include "nsMsgFolderFlags.h"
#include "nsMsgUtils.h"
#include "nsAppDirectoryServiceDefs.h"
#define PORT_NOT_SET -1
@ -1815,10 +1817,111 @@ nsMsgIncomingServer::GetPasswordPromptRequired(PRBool *aPasswordIsRequired)
return rv;
}
NS_IMETHODIMP
NS_IMETHODIMP nsMsgIncomingServer::ConfigureTemporaryFilters(nsIMsgFilterList *aFilterList)
{
nsresult rv = ConfigureTemporaryReturnReceiptsFilter(aFilterList);
NS_ENSURE_SUCCESS(rv, rv);
return ConfigureTemporaryServerSpamFilters(aFilterList);
}
nsresult
nsMsgIncomingServer::ConfigureTemporaryServerSpamFilters(nsIMsgFilterList *filterList)
{
nsCOMPtr<nsISpamSettings> spamSettings;
nsresult rv = GetSpamSettings(getter_AddRefs(spamSettings));
NS_ENSURE_SUCCESS(rv, rv);
// For performance reasons, we'll handle clearing of filters if the user turns
// off the server-side filters from the junk mail controls, in the junk mail controls.
nsCAutoString serverFilterName;
spamSettings->GetServerFilterName(serverFilterName);
if (serverFilterName.IsEmpty())
return NS_OK;
PRInt32 serverFilterTrustFlags = 0;
(void) spamSettings->GetServerFilterTrustFlags(&serverFilterTrustFlags);
if (!serverFilterTrustFlags)
return NS_OK;
// check if filters have been setup already.
nsAutoString yesFilterName, noFilterName;
yesFilterName.AppendWithConversion(serverFilterName);
yesFilterName.AppendWithConversion("Yes");
noFilterName.AppendWithConversion(serverFilterName);
noFilterName.AppendWithConversion("No");
nsCOMPtr<nsIMsgFilter> newFilter;
(void) filterList->GetFilterNamed(yesFilterName.get(),
getter_AddRefs(newFilter));
if (!newFilter)
(void) filterList->GetFilterNamed(noFilterName.get(),
getter_AddRefs(newFilter));
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);
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);
}
nsCOMPtr<nsIFileSpec> serverFilterSpec;
rv = NS_NewFileSpecFromIFile(file, getter_AddRefs(serverFilterSpec));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIMsgFilterService> filterService = do_GetService(NS_MSGFILTERSERVICE_CONTRACTID, &rv);
nsCOMPtr<nsIMsgFilterList> serverFilterList;
rv = filterService->OpenFilterList(serverFilterSpec, NULL, NULL, getter_AddRefs(serverFilterList));
NS_ENSURE_SUCCESS(rv, rv);
rv = serverFilterList->GetFilterNamed(yesFilterName.get(),
getter_AddRefs(newFilter));
if (newFilter && serverFilterTrustFlags & nsISpamSettings::TRUST_POSITIVES)
{
newFilter->SetTemporary(PR_TRUE);
filterList->InsertFilterAt(0, newFilter);
}
rv = serverFilterList->GetFilterNamed(noFilterName.get(),
getter_AddRefs(newFilter));
if (newFilter && serverFilterTrustFlags & nsISpamSettings::TRUST_NEGATIVES)
{
newFilter->SetTemporary(PR_TRUE);
filterList->InsertFilterAt(0, newFilter);
}
return rv;
}
nsresult
nsMsgIncomingServer::ConfigureTemporaryReturnReceiptsFilter(nsIMsgFilterList *filterList)
{
NS_ENSURE_ARG_POINTER(filterList);
nsresult rv;
nsCOMPtr<nsIMsgAccountManager> accountMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
@ -2062,6 +2165,14 @@ nsMsgIncomingServer::SetSpamSettings(nsISpamSettings *aSpamSettings)
rv = SetIntValue("purgeSpamInterval", purgeSpamInterval);
NS_ENSURE_SUCCESS(rv,rv);
nsCAutoString serverFilterName;
mSpamSettings->GetServerFilterName(serverFilterName);
SetCharValue("serverFilterName", serverFilterName.get());
PRInt32 serverFilterTrustFlags;
mSpamSettings->GetServerFilterTrustFlags(&serverFilterTrustFlags);
SetIntValue("serverFilterTrustFlags", serverFilterTrustFlags);
PRInt32 loggingEnabled;
rv = mSpamSettings->GetLoggingEnabled(&loggingEnabled);
NS_ENSURE_SUCCESS(rv,rv);
@ -2151,7 +2262,15 @@ nsMsgIncomingServer::GetSpamSettings(nsISpamSettings **aSpamSettings)
NS_ENSURE_SUCCESS(rv,rv);
rv = mSpamSettings->SetPurgeInterval(purgeSpamInterval);
NS_ENSURE_SUCCESS(rv,rv);
nsXPIDLCString serverFilterName;
rv = GetCharValue("serverFilterName", getter_Copies(serverFilterName));
if (NS_SUCCEEDED(rv))
mSpamSettings->SetServerFilterName(serverFilterName);
PRInt32 serverFilterTrustFlags = 0;
rv = GetIntValue("serverFilterTrustFlags", &serverFilterTrustFlags);
mSpamSettings->SetServerFilterTrustFlags(serverFilterTrustFlags);
PRInt32 loggingEnabled;
rv = GetBoolValue("spamLoggingEnabled", &loggingEnabled);
NS_ENSURE_SUCCESS(rv,rv);
@ -2174,9 +2293,8 @@ nsMsgIncomingServer::GetSpamFilterPlugin(nsIMsgFilterPlugin **aFilterPlugin)
// get the plugin service
mFilterPlugin = do_GetService("@mozilla.org/messenger/filter-plugin;1?name=bayesianfilter", &rv);
if (NS_FAILED(rv)) {
if (NS_FAILED(rv))
return rv;
}
}
NS_IF_ADDREF(*aFilterPlugin = mFilterPlugin);

Просмотреть файл

@ -79,6 +79,9 @@ protected:
void getPrefName(const char *serverKey, const char *pref, nsCString& fullPrefName);
void getDefaultPrefName(const char *pref, nsCString& fullPrefName);
nsresult ConfigureTemporaryReturnReceiptsFilter(nsIMsgFilterList *filterList);
nsresult ConfigureTemporaryServerSpamFilters(nsIMsgFilterList *filterList);
// these are private pref getters and setters for the password
// field. Callers should be using Get/Set Password
NS_IMETHOD GetPrefPassword(char * *aPassword);

Просмотреть файл

@ -648,7 +648,7 @@ nsImapMailFolder::UpdateFolder(nsIMsgWindow *msgWindow)
// can't file to the sent folder, so we don't add the filter for those servers
if (canFileMessagesOnServer)
{
rv = server->ConfigureTemporaryReturnReceiptsFilter(m_filterList);
rv = server->ConfigureTemporaryFilters(m_filterList);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to add MDN filter");
}
}

Просмотреть файл

@ -1461,7 +1461,7 @@ nsParseNewMailState::Init(nsIMsgFolder *rootFolder, nsIMsgFolder *downloadFolder
rv = server->GetFilterList(aMsgWindow, getter_AddRefs(m_filterList));
if (m_filterList)
rv = server->ConfigureTemporaryReturnReceiptsFilter(m_filterList);
rv = server->ConfigureTemporaryFilters(m_filterList);
m_disableFilters = PR_FALSE;
return NS_OK;

Просмотреть файл

@ -11,6 +11,7 @@ mailnews/base/build/Makefile
mailnews/base/search/Makefile
mailnews/base/search/public/Makefile
mailnews/base/search/src/Makefile
mailnews/base/search/resources/content/Makefile
mailnews/base/resources/Makefile
mailnews/base/resources/content/Makefile
mailnews/base/resources/content/unix/Makefile