зеркало из https://github.com/mozilla/pjs.git
support for imap and pop3 spam filters, not turned on yet r/sr=sspitzer 169557
This commit is contained in:
Родитель
1403610a36
Коммит
8c3b5179a8
|
@ -403,7 +403,7 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne
|
|||
|
||||
attribute nsIMsgRetentionSettings retentionSettings;
|
||||
attribute nsIMsgDownloadSettings downloadSettings;
|
||||
|
||||
void callFilterPlugins();
|
||||
/**
|
||||
* used for order in the folder pane, folder pickers, etc.
|
||||
*/
|
||||
|
|
|
@ -48,7 +48,7 @@ interface nsIMsgFilterList;
|
|||
interface nsIMsgRetentionSettings;
|
||||
interface nsIMsgDownloadSettings;
|
||||
interface nsISpamSettings;
|
||||
|
||||
interface nsIMsgFilterPlugin;
|
||||
/*
|
||||
* Interface for incoming mail/news host
|
||||
* this is the base interface for all mail server types (imap, pop, nntp, etc)
|
||||
|
@ -367,6 +367,7 @@ interface nsIMsgIncomingServer : nsISupports {
|
|||
* spam settings
|
||||
*/
|
||||
attribute nsISpamSettings spamSettings;
|
||||
readonly attribute nsIMsgFilterPlugin spamFilterPlugin;
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
|
|
@ -45,6 +45,7 @@ REQUIRES = xpcom \
|
|||
rdfutil \
|
||||
mime \
|
||||
msgcompose \
|
||||
addrbook \
|
||||
docshell \
|
||||
webshell \
|
||||
uriloader \
|
||||
|
|
|
@ -59,6 +59,16 @@
|
|||
#include "nsIPrompt.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsAbBaseCID.h"
|
||||
#include "nsIAbMDBDirectory.h"
|
||||
#include "nsISpamSettings.h"
|
||||
#include "nsIMsgFilterPlugin.h"
|
||||
#include "nsIMsgMailSession.h"
|
||||
#include "nsIRDFService.h"
|
||||
#ifdef DEBUG_bienvenu
|
||||
#define DO_FILTER_PLUGIN
|
||||
#endif
|
||||
|
||||
|
||||
#include <time.h>
|
||||
|
||||
|
@ -1675,3 +1685,136 @@ nsMsgDBFolder::SetStringProperty(const char *propertyName, const char *propertyV
|
|||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// sub-classes need to override
|
||||
nsresult
|
||||
nsMsgDBFolder::SpamFilterClassifyMessage(const char *aURI, nsIJunkMailPlugin *aJunkMailPlugin)
|
||||
{
|
||||
return aJunkMailPlugin->ClassifyMessage(aURI, nsnull);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the filter plugins (XXX currently just one)
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsMsgDBFolder::CallFilterPlugins()
|
||||
{
|
||||
|
||||
nsCOMPtr<nsIMsgIncomingServer> server;
|
||||
nsCOMPtr<nsISpamSettings> spamSettings;
|
||||
nsCOMPtr<nsIAbMDBDirectory> whiteListDirectory;
|
||||
PRBool useWhiteList = PR_FALSE;
|
||||
PRInt32 spamLevel = 0;
|
||||
nsXPIDLCString whiteListAbURI;
|
||||
|
||||
nsresult rv = GetServer(getter_AddRefs(server));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = server->GetSpamSettings(getter_AddRefs(spamSettings));
|
||||
nsCOMPtr <nsIMsgFilterPlugin> filterPlugin;
|
||||
server->GetSpamFilterPlugin(getter_AddRefs(filterPlugin));
|
||||
if (!filterPlugin) // it's not an error not to have the filter plugin.
|
||||
return NS_OK;
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
spamSettings->GetLevel(&spamLevel);
|
||||
if (spamLevel == 0)
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsIMsgMailSession> mailSession =
|
||||
do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!mDatabase)
|
||||
{
|
||||
rv = GetDatabase(nsnull); // XXX is nsnull a reasonable arg here?
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// get the list of new messages
|
||||
//
|
||||
nsMsgKeyArray *newMessageKeys;
|
||||
rv = mDatabase->GetNewList(&newMessageKeys);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// if there weren't any, just return
|
||||
//
|
||||
if (!newMessageKeys)
|
||||
return NS_OK;
|
||||
|
||||
spamSettings->GetUseWhiteList(&useWhiteList);
|
||||
if (useWhiteList)
|
||||
{
|
||||
spamSettings->GetWhiteListAbURI(getter_Copies(whiteListAbURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!whiteListAbURI.IsEmpty())
|
||||
{
|
||||
nsCOMPtr <nsIRDFService> rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1",&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr <nsIRDFResource> resource;
|
||||
rv = rdfService->GetResource(whiteListAbURI, getter_AddRefs(resource));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
whiteListDirectory = do_QueryInterface(resource, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
// if we can't get the db, we probably want to continue firing spam filters.
|
||||
}
|
||||
|
||||
// tell the plugin this is the beginning of a batch
|
||||
//
|
||||
(void)filterPlugin->SetBatchUpdate(PR_TRUE);
|
||||
|
||||
// for each message...
|
||||
//
|
||||
nsXPIDLCString uri;
|
||||
nsXPIDLCString url;
|
||||
|
||||
PRUint32 numNewMessages = newMessageKeys->GetSize();
|
||||
PRInt32 numClassifyRequests = 0;
|
||||
for ( PRUint32 i=0 ; i < numNewMessages ; ++i )
|
||||
{
|
||||
// check whitelist first:
|
||||
if (whiteListDirectory)
|
||||
{
|
||||
nsCOMPtr <nsIMsgDBHdr> msgHdr;
|
||||
rv = mDatabase->GetMsgHdrForKey(newMessageKeys->GetAt(i), getter_AddRefs(msgHdr));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRBool cardExists = PR_FALSE;
|
||||
nsXPIDLCString author;
|
||||
msgHdr->GetAuthor(getter_Copies(author));
|
||||
rv = whiteListDirectory->HasCardForEmailAddress(author, &cardExists);
|
||||
if (NS_SUCCEEDED(rv) && cardExists)
|
||||
continue; // skip this msg since it's in the white list
|
||||
}
|
||||
}
|
||||
|
||||
// generate a URI for the message
|
||||
//
|
||||
rv = GenerateMessageURI(newMessageKeys->GetAt(i), getter_Copies(uri));
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
NS_WARNING("nsMsgDBFolder::CallFilterPlugins(): could not"
|
||||
" generate URI for message");
|
||||
continue; // continue through the array
|
||||
}
|
||||
|
||||
// filterMsg
|
||||
//
|
||||
nsCOMPtr <nsIJunkMailPlugin> junkMailPlugin = do_QueryInterface(filterPlugin);
|
||||
rv = SpamFilterClassifyMessage(uri, junkMailPlugin);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
NS_WARNING("nsMsgDBFolder::CallFilterPlugins(): filter plugin"
|
||||
" call failed");
|
||||
continue; // continue through the array
|
||||
}
|
||||
}
|
||||
|
||||
// this batch is done
|
||||
(void)filterPlugin->SetBatchUpdate(PR_FALSE);
|
||||
|
||||
NS_DELETEXPCOM(newMessageKeys);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "nsITransport.h"
|
||||
#include "nsIMsgStringService.h"
|
||||
class nsIMsgFolderCacheElement;
|
||||
class nsIJunkMailPlugin;
|
||||
|
||||
/*
|
||||
* nsMsgDBFolder
|
||||
|
@ -121,6 +122,7 @@ public:
|
|||
NS_IMETHOD SetDBTransferInfo(nsIDBFolderInfo *aTransferInfo);
|
||||
NS_IMETHOD GetStringProperty(const char *propertyName, char **propertyValue);
|
||||
NS_IMETHOD SetStringProperty(const char *propertyName, const char *propertyValue);
|
||||
NS_IMETHOD CallFilterPlugins();
|
||||
|
||||
|
||||
protected:
|
||||
|
@ -147,6 +149,9 @@ protected:
|
|||
nsresult MsgFitsDownloadCriteria(nsMsgKey msgKey, PRBool *result);
|
||||
nsresult GetPromptPurgeThreshold(PRBool *aPrompt);
|
||||
nsresult GetPurgeThreshold(PRInt32 *aThreshold);
|
||||
|
||||
virtual nsresult SpamFilterClassifyMessage(const char *aURI, nsIJunkMailPlugin *aJunkMailPlugin);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIMsgDatabase> mDatabase;
|
||||
nsString mCharset;
|
||||
|
|
|
@ -1242,7 +1242,7 @@ nsMsgIncomingServer::SetRealUsername(const char *aUsername)
|
|||
nsresult rv = GetRealUsername(getter_Copies(oldName));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = SetCharValue("realuserName", aUsername);
|
||||
if (nsCRT::strcasecmp(aUsername, oldName.get()))
|
||||
if (!oldName.Equals(aUsername))
|
||||
rv = OnUserOrHostNameChanged(oldName.get(), aUsername);
|
||||
|
||||
return rv;
|
||||
|
@ -1979,3 +1979,28 @@ nsMsgIncomingServer::GetSpamSettings(nsISpamSettings **aSpamSettings)
|
|||
NS_ADDREF(*aSpamSettings = mSpamSettings);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::GetSpamFilterPlugin(nsIMsgFilterPlugin **aFilterPlugin)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFilterPlugin);
|
||||
if (!mFilterPlugin)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// create the plugin object
|
||||
//
|
||||
mFilterPlugin = do_CreateInstance(
|
||||
"@mozilla.org/messenger/filter-plugin;1?name=bayesianfilter", &rv);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsMsgIncomingServer::InitializeFilterPlugins():"
|
||||
" error creating filter plugin");
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
NS_IF_ADDREF(*aFilterPlugin = mFilterPlugin);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include "nsIMsgDatabase.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsISpamSettings.h"
|
||||
#include "nsIMsgFilterPlugin.h"
|
||||
|
||||
class nsIMsgFolderCache;
|
||||
class nsIMsgProtocolInfo;
|
||||
|
@ -105,6 +106,7 @@ private:
|
|||
PRUint32 m_biffState;
|
||||
PRPackedBool m_serverBusy;
|
||||
nsCOMPtr <nsISpamSettings> mSpamSettings;
|
||||
nsCOMPtr<nsIMsgFilterPlugin> mFilterPlugin; // XXX should be a list
|
||||
|
||||
protected:
|
||||
// member variable for canHaveFilters
|
||||
|
|
|
@ -39,7 +39,6 @@ REQUIRES = xpcom \
|
|||
necko \
|
||||
appshell \
|
||||
msgdb \
|
||||
addrbook \
|
||||
dom \
|
||||
uconv \
|
||||
unicharutil \
|
||||
|
|
|
@ -102,8 +102,6 @@
|
|||
#include "nsMsgMessageFlags.h"
|
||||
#include "nsIMimeHeaders.h"
|
||||
#include "nsIMsgMdnGenerator.h"
|
||||
#include "nsAbBaseCID.h"
|
||||
#include "nsIAbMDBDirectory.h"
|
||||
#include "nsISpamSettings.h"
|
||||
#include <time.h>
|
||||
|
||||
|
@ -625,30 +623,6 @@ nsresult nsImapMailFolder::GetDatabase(nsIMsgWindow *aMsgWindow)
|
|||
return folderOpen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize any message filtering plugin objects to be used by
|
||||
* this server.
|
||||
*
|
||||
* XXX note this currently only initializes the one m_filterPlugin;
|
||||
* it should really be initializing a list
|
||||
*/
|
||||
nsresult
|
||||
nsImapMailFolder::InitializeFilterPlugins(void)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// create the plugin object
|
||||
//
|
||||
m_filterPlugin = do_CreateInstance(
|
||||
"@mozilla.org/messenger/filter-plugin;1?name=bayesianfilter", &rv);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsImapMailFolder::InitializeFilterPlugins():"
|
||||
" error creating filter plugin");
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsImapMailFolder::UpdateFolder(nsIMsgWindow *msgWindow)
|
||||
|
@ -663,13 +637,6 @@ nsImapMailFolder::UpdateFolder(nsIMsgWindow *msgWindow)
|
|||
}
|
||||
}
|
||||
|
||||
// Initialize filter plugins. If this fails; just continue.
|
||||
//
|
||||
#ifdef DO_FILTER_PLUGIN
|
||||
if (!m_filterPlugin) {
|
||||
(void)InitializeFilterPlugins();
|
||||
}
|
||||
#endif
|
||||
if (m_filterList) {
|
||||
nsCOMPtr<nsIMsgIncomingServer> server;
|
||||
rv = GetServer(getter_AddRefs(server));
|
||||
|
@ -4941,9 +4908,12 @@ nsImapMailFolder::HeaderFetchCompleted(nsIImapProtocol* aProtocol)
|
|||
else
|
||||
aProtocol->NotifyBodysToDownload(nsnull, 0/*keysToFetch.GetSize() */);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_bienvenu
|
||||
#define DO_FILTER_PLUGIN
|
||||
#endif
|
||||
#ifdef DO_FILTER_PLUGIN
|
||||
CallFilterPlugins();
|
||||
|
||||
#endif
|
||||
if (m_filterList)
|
||||
(void)m_filterList->FlushLogIfNecessary();
|
||||
|
||||
|
@ -7127,6 +7097,14 @@ nsresult nsImapMailFolder::GetMoveCoalescer()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsImapMailFolder::SpamFilterClassifyMessage(const char *aURI, nsIJunkMailPlugin *aJunkMailPlugin)
|
||||
{
|
||||
++m_numFilterClassifyRequests;
|
||||
return aJunkMailPlugin->ClassifyMessage(aURI, this);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsImapMailFolder::OnMessageClassified(const char *aMsgURL, nsMsgJunkStatus aClassification)
|
||||
{
|
||||
|
@ -7136,8 +7114,8 @@ nsImapMailFolder::OnMessageClassified(const char *aMsgURL, nsMsgJunkStatus aClas
|
|||
nsCOMPtr <nsIMsgDBHdr> msgHdr;
|
||||
rv = GetMsgDBHdrFromURI(aMsgURL, getter_AddRefs(msgHdr));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
msgHdr->SetStringProperty("score", (aClassification == nsIJunkMailPlugin::JUNK) ? "100" : "0");
|
||||
if (aClassification == nsIJunkMailPlugin::JUNK)
|
||||
msgHdr->SetStringProperty("junkscore", (aClassification == nsIJunkMailPlugin::JUNK) ? "100" : "0");
|
||||
if (aClassification == nsIJunkMailPlugin::JUNK && ! (mFlags & MSG_FOLDER_FLAG_JUNK))
|
||||
{
|
||||
nsCOMPtr<nsISpamSettings> spamSettings;
|
||||
nsXPIDLCString spamFolderURI;
|
||||
|
@ -7194,131 +7172,13 @@ nsImapMailFolder::GetShouldDownloadAllHeaders(PRBool *aResult)
|
|||
if (*aResult)
|
||||
return rv;
|
||||
}
|
||||
// m_filterPlugin should already be initialized, if present
|
||||
return (m_filterPlugin) ? m_filterPlugin->GetShouldDownloadAllHeaders(aResult) : NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call the filter plugins (XXX currently just one)
|
||||
*/
|
||||
nsresult
|
||||
nsImapMailFolder::CallFilterPlugins(void)
|
||||
{
|
||||
if (!m_filterPlugin)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr <nsIMsgFilterPlugin> filterPlugin;
|
||||
nsCOMPtr<nsIMsgIncomingServer> server;
|
||||
nsCOMPtr<nsISpamSettings> spamSettings;
|
||||
nsCOMPtr<nsIAbMDBDirectory> whiteListDB;
|
||||
PRBool useWhiteList = PR_FALSE;
|
||||
PRInt32 spamLevel = 0;
|
||||
nsXPIDLCString whiteListAbURI;
|
||||
|
||||
nsresult rv = GetServer(getter_AddRefs(server));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = server->GetSpamSettings(getter_AddRefs(spamSettings));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
spamSettings->GetLevel(&spamLevel);
|
||||
if (spamLevel == 0)
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsIMsgMailSession> mailSession =
|
||||
do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (NS_SUCCEEDED(GetServer(getter_AddRefs(server))))
|
||||
server->GetSpamFilterPlugin(getter_AddRefs(filterPlugin));
|
||||
|
||||
if (!mDatabase)
|
||||
{
|
||||
rv = GetDatabase(nsnull); // XXX is nsnull a reasonable arg here?
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// get the list of new messages
|
||||
//
|
||||
nsMsgKeyArray *newMessageKeys;
|
||||
rv = mDatabase->GetNewList(&newMessageKeys);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// if there weren't any, just return
|
||||
//
|
||||
if (!newMessageKeys)
|
||||
return NS_OK;
|
||||
|
||||
spamSettings->GetUseWhiteList(&useWhiteList);
|
||||
if (useWhiteList)
|
||||
{
|
||||
spamSettings->GetWhiteListAbURI(getter_Copies(whiteListAbURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!whiteListAbURI.IsEmpty())
|
||||
{
|
||||
nsCOMPtr <nsIRDFService> rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1",&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr <nsIRDFResource> resource;
|
||||
rv = rdfService->GetResource(whiteListAbURI, getter_AddRefs(resource));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
whiteListDB = do_QueryInterface(resource, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
// if we can't get the db, we probably want to continue firing spam filters.
|
||||
}
|
||||
|
||||
// tell the plugin this is the beginning of a batch
|
||||
//
|
||||
(void)m_filterPlugin->SetBatchUpdate(PR_TRUE);
|
||||
|
||||
// for each message...
|
||||
//
|
||||
nsXPIDLCString uri;
|
||||
nsXPIDLCString url;
|
||||
|
||||
PRUint32 numNewMessages = newMessageKeys->GetSize();
|
||||
PRInt32 numClassifyRequests = 0;
|
||||
for ( PRUint32 i=0 ; i < numNewMessages ; ++i )
|
||||
{
|
||||
// check whitelist first:
|
||||
if (whiteListDB)
|
||||
{
|
||||
nsCOMPtr <nsIMsgDBHdr> msgHdr;
|
||||
rv = mDatabase->GetMsgHdrForKey(newMessageKeys->GetAt(i), getter_AddRefs(msgHdr));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRBool cardExists = PR_FALSE;
|
||||
nsXPIDLCString author;
|
||||
msgHdr->GetAuthor(getter_Copies(author));
|
||||
rv = whiteListDB->HasCardForEmailAddress(author, &cardExists);
|
||||
if (NS_SUCCEEDED(rv) && cardExists)
|
||||
continue; // skip this msg since it's in the white list
|
||||
}
|
||||
}
|
||||
|
||||
// generate a URI for the message
|
||||
//
|
||||
rv = GenerateMessageURI(newMessageKeys->GetAt(i), getter_Copies(uri));
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
NS_WARNING("nsImapMailFolder::CallFilterPlugins(): could not"
|
||||
" generate URI for message");
|
||||
continue; // continue through the array
|
||||
}
|
||||
|
||||
// filterMsg
|
||||
//
|
||||
nsCOMPtr <nsIJunkMailPlugin> junkMailPlugin = do_QueryInterface(m_filterPlugin);
|
||||
m_numFilterClassifyRequests++;
|
||||
rv = junkMailPlugin->ClassifyMessage(uri, this);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
NS_WARNING("nsImapMailFolder::CallFilterPlugins(): filter plugin"
|
||||
" call failed");
|
||||
continue; // continue through the array
|
||||
}
|
||||
}
|
||||
|
||||
// this batch is done
|
||||
(void)m_filterPlugin->SetBatchUpdate(PR_FALSE);
|
||||
|
||||
NS_DELETEXPCOM(newMessageKeys);
|
||||
return rv;
|
||||
return (filterPlugin) ? filterPlugin->GetShouldDownloadAllHeaders(aResult) : NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -347,8 +347,7 @@ public:
|
|||
const char *destFolder,
|
||||
nsIMsgFilter *filter,
|
||||
nsIMsgWindow *msgWindow);
|
||||
nsresult InitializeFilterPlugins(void);
|
||||
nsresult CallFilterPlugins(void);
|
||||
virtual nsresult SpamFilterClassifyMessage(const char *aURI, nsIJunkMailPlugin *aJunkMailPlugin);
|
||||
|
||||
static nsresult AllocateUidStringFromKeys(nsMsgKey *keys, PRInt32 numKeys, nsCString &msgIds);
|
||||
protected:
|
||||
|
|
|
@ -96,7 +96,7 @@
|
|||
#include "nsEscape.h"
|
||||
#include "nsLocalStringBundle.h"
|
||||
#include "nsIMsgMailNewsUrl.h"
|
||||
|
||||
#include "nsISpamSettings.h"
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kMailboxServiceCID, NS_MAILBOXSERVICE_CID);
|
||||
static NS_DEFINE_CID(kCMailDB, NS_MAILDB_CID);
|
||||
|
@ -147,7 +147,7 @@ nsLocalMailCopyState::~nsLocalMailCopyState()
|
|||
nsMsgLocalMailFolder::nsMsgLocalMailFolder(void)
|
||||
: mHaveReadNameFromDB(PR_FALSE), mGettingMail(PR_FALSE),
|
||||
mInitialized(PR_FALSE), mCopyState(nsnull), mType(nsnull),
|
||||
mCheckForNewMessagesAfterParsing(PR_FALSE)
|
||||
mCheckForNewMessagesAfterParsing(PR_FALSE), mNumFilterClassifyRequests(0)
|
||||
{
|
||||
// NS_INIT_ISUPPORTS(); done by superclass
|
||||
}
|
||||
|
@ -158,10 +158,11 @@ nsMsgLocalMailFolder::~nsMsgLocalMailFolder(void)
|
|||
|
||||
NS_IMPL_ADDREF_INHERITED(nsMsgLocalMailFolder, nsMsgFolder)
|
||||
NS_IMPL_RELEASE_INHERITED(nsMsgLocalMailFolder, nsMsgFolder)
|
||||
NS_IMPL_QUERY_INTERFACE_INHERITED2(nsMsgLocalMailFolder,
|
||||
NS_IMPL_QUERY_INTERFACE_INHERITED3(nsMsgLocalMailFolder,
|
||||
nsMsgDBFolder,
|
||||
nsICopyMessageListener,
|
||||
nsIMsgLocalMailFolder)
|
||||
nsIMsgLocalMailFolder,
|
||||
nsIJunkMailClassificationListener)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -3365,3 +3366,82 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Shutdown(PRBool shutdownChildren)
|
|||
return nsMsgDBFolder::Shutdown(shutdownChildren);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgLocalMailFolder::SpamFilterClassifyMessage(const char *aURI, nsIJunkMailPlugin *aJunkMailPlugin)
|
||||
{
|
||||
++mNumFilterClassifyRequests;
|
||||
return aJunkMailPlugin->ClassifyMessage(aURI, this);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgLocalMailFolder::OnMessageClassified(const char *aMsgURL, nsMsgJunkStatus aClassification)
|
||||
{
|
||||
nsCOMPtr<nsIMsgIncomingServer> server;
|
||||
nsresult rv = GetServer(getter_AddRefs(server));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr <nsIMsgDBHdr> msgHdr;
|
||||
rv = GetMsgDBHdrFromURI(aMsgURL, getter_AddRefs(msgHdr));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
msgHdr->SetStringProperty("junkscore", (aClassification == nsIJunkMailPlugin::JUNK) ? "100" : "0");
|
||||
nsCOMPtr<nsISpamSettings> spamSettings;
|
||||
nsXPIDLCString spamFolderURI;
|
||||
PRBool moveOnSpam = PR_FALSE;
|
||||
|
||||
rv = GetServer(getter_AddRefs(server));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = server->GetSpamSettings(getter_AddRefs(spamSettings));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (aClassification == nsIJunkMailPlugin::JUNK && ! (mFlags & MSG_FOLDER_FLAG_JUNK))
|
||||
{
|
||||
|
||||
spamSettings->GetMoveOnSpam(&moveOnSpam);
|
||||
if (moveOnSpam)
|
||||
{
|
||||
nsMsgKey msgKey;
|
||||
msgHdr->GetMessageKey(&msgKey);
|
||||
mSpamKeysToMove.Add(msgKey);
|
||||
}
|
||||
}
|
||||
if (--mNumFilterClassifyRequests == 0 && mSpamKeysToMove.GetSize() > 0)
|
||||
{
|
||||
spamSettings->GetSpamFolderURI(getter_Copies(spamFolderURI));
|
||||
if (!spamFolderURI.IsEmpty())
|
||||
{
|
||||
nsMsgKey msgKey;
|
||||
msgHdr->GetMessageKey(&msgKey);
|
||||
nsCOMPtr <nsIRDFService> rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1",&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIRDFResource> res;
|
||||
rv = rdfService->GetResource(spamFolderURI, getter_AddRefs(res));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIMsgFolder> folder(do_QueryInterface(res, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsISupportsArray> messages;
|
||||
NS_NewISupportsArray(getter_AddRefs(messages));
|
||||
for (PRUint32 keyIndex = 0; keyIndex < mSpamKeysToMove.GetSize(); keyIndex++)
|
||||
{
|
||||
nsCOMPtr<nsIMsgDBHdr> mailHdr = nsnull;
|
||||
rv = GetMessageHeader(mSpamKeysToMove.ElementAt(keyIndex), getter_AddRefs(mailHdr));
|
||||
if (NS_SUCCEEDED(rv) && mailHdr)
|
||||
{
|
||||
nsCOMPtr<nsISupports> iSupports = do_QueryInterface(mailHdr);
|
||||
messages->AppendElement(iSupports);
|
||||
}
|
||||
}
|
||||
folder->CreateStorageIfMissing(nsnull);
|
||||
nsCOMPtr<nsIMsgCopyService> copySvc = do_GetService(NS_MSGCOPYSERVICE_CONTRACTID);
|
||||
if (copySvc)
|
||||
rv = copySvc->CopyMessages(this, messages, folder, PR_TRUE,
|
||||
/*nsIMsgCopyServiceListener* listener*/ nsnull, nsnull, PR_FALSE /*allowUndo*/);
|
||||
}
|
||||
mSpamKeysToMove.RemoveAll();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
#include "nsITransactionManager.h"
|
||||
#include "nsIMsgLocalMailFolder.h"
|
||||
#include "nsIMsgStringService.h"
|
||||
|
||||
#include "nsIMsgFilterPlugin.h"
|
||||
#define COPY_BUFFER_SIZE 16384
|
||||
|
||||
struct nsLocalMailCopyState
|
||||
|
@ -95,13 +95,15 @@ struct nsLocalMailCopyState
|
|||
|
||||
class nsMsgLocalMailFolder : public nsMsgDBFolder,
|
||||
public nsIMsgLocalMailFolder,
|
||||
public nsICopyMessageListener
|
||||
public nsICopyMessageListener,
|
||||
public nsIJunkMailClassificationListener
|
||||
{
|
||||
public:
|
||||
nsMsgLocalMailFolder(void);
|
||||
virtual ~nsMsgLocalMailFolder(void);
|
||||
NS_DECL_NSICOPYMESSAGELISTENER
|
||||
NS_DECL_NSIMSGLOCALMAILFOLDER
|
||||
NS_DECL_NSIJUNKMAILCLASSIFICATIONLISTENER
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
#if 0
|
||||
static nsresult GetRoot(nsIMsgFolder* *result);
|
||||
|
@ -209,6 +211,7 @@ protected:
|
|||
PRBool isMove, nsIMsgCopyServiceListener* listener, nsIMsgWindow *msgWindow, PRBool isMoveFolder, PRBool allowUndo);
|
||||
nsresult OnCopyCompleted(nsISupports *srcSupport, PRBool moveCopySucceeded);
|
||||
virtual nsresult CreateBaseMessageURI(const char *aURI);
|
||||
nsresult SpamFilterClassifyMessage(const char *aURI, nsIJunkMailPlugin *aJunkMailPlugin);
|
||||
protected:
|
||||
PRBool mHaveReadNameFromDB;
|
||||
PRBool mGettingMail;
|
||||
|
@ -218,7 +221,8 @@ protected:
|
|||
const char *mType;
|
||||
PRBool mCheckForNewMessagesAfterParsing;
|
||||
nsCOMPtr<nsIMsgStringService> mMsgStringService;
|
||||
|
||||
PRInt32 mNumFilterClassifyRequests;
|
||||
nsMsgKeyArray mSpamKeysToMove;
|
||||
nsresult setSubfolderFlag(const char *aFolderName, PRUint32 flags);
|
||||
};
|
||||
|
||||
|
|
|
@ -239,7 +239,12 @@ nsPop3Sink::EndMailDelivery()
|
|||
|
||||
nsresult rv = ReleaseFolderLock();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv),"folder lock not released successfully");
|
||||
|
||||
#ifdef DEBUG_bienvenu
|
||||
#define DO_FILTER_PLUGIN
|
||||
#endif
|
||||
#ifdef DO_FILTER_PLUGIN
|
||||
m_folder->CallFilterPlugins();
|
||||
#endif
|
||||
nsCOMPtr<nsIMsgIncomingServer> server = do_QueryInterface(m_popServer);
|
||||
if (server) {
|
||||
nsCOMPtr <nsIMsgFilterList> filterList;
|
||||
|
|
Загрузка…
Ссылка в новой задаче