support server wide news filters

r/sr=bienvenu
This commit is contained in:
scott%scott-macgregor.org 2004-04-19 05:15:39 +00:00
Родитель 1f918a157d
Коммит 1760d6b13f
10 изменённых файлов: 85 добавлений и 33 удалений

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

@ -359,7 +359,7 @@ interface nsIMsgIncomingServer : nsISupports {
readonly attribute boolean passwordPromptRequired;
/**
* This configures both the MDN filter, and the server-side
* for mail, 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
@ -367,6 +367,7 @@ interface nsIMsgIncomingServer : nsISupports {
* a filter to do that, and adds it to our filterList
* if it doesn't exist. If it does, it will enable it.
*
* this is not used by news filters (yet).
*/
void configureTemporaryFilters(in nsIMsgFilterList filterList);

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

@ -161,12 +161,11 @@ function onCancel()
}
*/
function onServerClick(event)
function onFilterServerClick(selection)
{
var itemURI = event.target.id;
var itemURI = selection.getAttribute('id');
// Return if same server is selected.
if (itemURI == gCurrentServerURI)
if (!itemURI || itemURI == gCurrentServerURI)
return;
// Save the current filters to disk before switching because

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

@ -65,7 +65,7 @@
<label value="&filtersForPrefix.label;"
accesskey="&filtersForPrefix.accesskey;" control="serverMenu"/>
<menulist oncommand="onServerClick(event);" id="serverMenu"
<menulist id="serverMenu"
datasources="rdf:msgaccountmanager rdf:mailnewsfolders"
sortResource="http://home.netscape.com/NC-rdf#FolderTreeName"
sortDirection="ascending"
@ -74,18 +74,23 @@
<rule iscontainer="true" isempty="false" nc:ServerType="nntp">
<menupopup>
<menu uri="..."
oncommand="onFilterServerClick(event.target)"
class="folderMenuItem menu-iconic"
IsServer="rdf:http://home.netscape.com/NC-rdf#IsServer"
IsSecure="rdf:http://home.netscape.com/NC-rdf#IsSecure"
ServerType="rdf:http://home.netscape.com/NC-rdf#ServerType"
label="rdf:http://home.netscape.com/NC-rdf#Name">
<menupopup class="menulist-menupopup"/>
<menupopup class="menulist-menupopup">
<menuitem label="&choosethisnewsserver.label;"
oncommand="onFilterServerClick(event.target.parentNode.parentNode)"/>
<menuseparator/>
</menupopup>
</menu>
</menupopup>
</rule>
<rule nc:ServerType="nntp">
<menupopup>
<menuitem uri="..." value="..."
<menuitem uri="..." value="..."
class="folderMenuItem menuitem-iconic"
IsServer="rdf:http://home.netscape.com/NC-rdf#IsServer"
IsSecure="rdf:http://home.netscape.com/NC-rdf#IsSecure"
@ -96,6 +101,7 @@
<rule nc:SupportsFilters="true">
<menupopup>
<menuitem uri="..." value="..."
oncommand="onFilterServerClick(event.target)"
class="folderMenuItem menuitem-iconic"
IsServer="rdf:http://home.netscape.com/NC-rdf#IsServer"
IsSecure="rdf:http://home.netscape.com/NC-rdf#IsSecure"

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

@ -23,5 +23,6 @@
<!ENTITY folderPickerPrefix.label "Run selected filter(s) on:">
<!ENTITY folderPickerPrefix.accesskey "i">
<!ENTITY choosethis.label "choose this folder">
<!ENTITY choosethisnewsserver.label "choose this news server">
<!ENTITY helpButton.label "Help">
<!ENTITY helpButton.accesskey "H">

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

@ -183,13 +183,18 @@ nsMsgFilterList::GetLogFileSpec(nsIFileSpec **aFileSpec)
rv = server->GetType(getter_Copies(type));
NS_ENSURE_SUCCESS(rv,rv);
// for news, the filter file is
PRBool isServer = PR_FALSE;
rv = folder->GetIsServer(&isServer);
NS_ENSURE_SUCCESS(rv,rv);
// for news folders (not servers), the filter file is
// mcom.test.dat
// where the summary file is
// mcom.test.msf
// since the log is an html file we make it
// mcom.test.htm
if (type.Equals("nntp")) {
if (type.Equals("nntp") && !isServer)
{
nsCOMPtr<nsIFileSpec> thisFolder;
rv = m_folder->GetPath(getter_AddRefs(thisFolder));
NS_ENSURE_SUCCESS(rv, rv);

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

@ -588,29 +588,48 @@ nsNNTPNewsgroupList::ParseLine(char *line, PRUint32 * message_number)
GET_TOKEN (); /* xref */
// apply filters
// XXX todo, and then do spam classification
// XXX TODO
// do spam classification for news
nsCOMPtr <nsIMsgFolder> folder = do_QueryInterface(m_newsFolder, &rv);
NS_ENSURE_SUCCESS(rv,rv);
if (!m_filterList) {
if (!m_filterList)
{
rv = folder->GetFilterList(m_msgWindow, getter_AddRefs(m_filterList));
NS_ENSURE_SUCCESS(rv,rv);
}
if (!m_serverFilterList)
{
nsCOMPtr<nsIMsgIncomingServer> server;
rv = folder->GetServer(getter_AddRefs(server));
NS_ENSURE_SUCCESS(rv,rv);
rv = server->GetFilterList(m_msgWindow, getter_AddRefs(m_serverFilterList));
NS_ENSURE_SUCCESS(rv,rv);
}
// flag for kill
// if the action is Delete, and we get a hit (see ApplyFilterHit())
// we set this to PR_FALSE. if false, we won't add it to the db
// we set this to PR_FALSE. if false, we won't add it to the db.
m_addHdrToDB = PR_TRUE;
PRUint32 filterCount = 0;
if (m_filterList) {
rv = m_filterList->GetFilterCount(&filterCount);
NS_ENSURE_SUCCESS(rv,rv);
}
PRUint32 serverFilterCount = 0;
if (m_serverFilterList) {
rv = m_serverFilterList->GetFilterCount(&serverFilterCount);
NS_ENSURE_SUCCESS(rv,rv);
}
// only do this if we have filters
if (filterCount) {
if (filterCount || serverFilterCount)
{
// build up a "headers" for filter code
nsXPIDLCString subject;
rv = newMsgHdr->GetSubject(getter_Copies(subject));
@ -671,8 +690,21 @@ nsNNTPNewsgroupList::ParseLine(char *line, PRUint32 * message_number)
// so keep track of the header
m_newMsgHdr = newMsgHdr;
rv = m_filterList->ApplyFiltersToHdr(nsMsgFilterType::NewsRule, newMsgHdr, folder, m_newsDB,
headers, headersSize, this, m_msgWindow);
// the per-newsgroup filters should probably go first. It doesn't matter
// right now since nothing stops filter execution for newsgroups, but if something
// does, like adding a "stop execution" action, then users should be able to
// override the global filters in the per-newsgroup filters.
if (filterCount)
{
rv = m_filterList->ApplyFiltersToHdr(nsMsgFilterType::NewsRule, newMsgHdr, folder, m_newsDB,
headers, headersSize, this, m_msgWindow);
}
if (serverFilterCount)
{
rv = m_serverFilterList->ApplyFiltersToHdr(nsMsgFilterType::NewsRule, newMsgHdr, folder, m_newsDB,
headers, headersSize, this, m_msgWindow);
}
PR_Free ((void*) headers);
NS_ENSURE_SUCCESS(rv,rv);
}
@ -681,8 +713,7 @@ nsNNTPNewsgroupList::ParseLine(char *line, PRUint32 * message_number)
// if we deleted it, don't add it
if (m_addHdrToDB) {
rv = m_newsDB->AddNewHdrToDB(newMsgHdr, PR_TRUE);
if (NS_FAILED(rv))
return rv;
NS_ENSURE_SUCCESS(rv,rv);
}
return NS_OK;
@ -709,8 +740,10 @@ NS_IMETHODIMP nsNNTPNewsgroupList::ApplyFilterHit(nsIMsgFilter *aFilter, nsIMsgW
NS_ENSURE_SUCCESS(rv, rv);
PRBool loggingEnabled = PR_FALSE;
if (m_filterList && numActions)
m_filterList->GetLoggingEnabled(&loggingEnabled);
nsCOMPtr<nsIMsgFilterList> currentFilterList;
rv = aFilter->GetFilterList(getter_AddRefs(currentFilterList));
if (NS_SUCCEEDED(rv) && currentFilterList && numActions)
currentFilterList->GetLoggingEnabled(&loggingEnabled);
for (PRUint32 actionIndex = 0; actionIndex < numActions; actionIndex++)
{
@ -737,7 +770,7 @@ NS_IMETHODIMP nsNNTPNewsgroupList::ApplyFilterHit(nsIMsgFilter *aFilter, nsIMsgW
m_newMsgHdr->OrFlags(MSG_FLAG_IGNORED, &newFlags);
}
break;
case nsMsgFilterAction::WatchThread:
case nsMsgFilterAction::WatchThread:
{
PRUint32 newFlags;
m_newMsgHdr->OrFlags(MSG_FLAG_WATCHED, &newFlags);

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

@ -127,6 +127,7 @@ protected:
private:
nsCOMPtr <nsIMsgWindow> m_msgWindow;
nsCOMPtr <nsIMsgFilterList> m_filterList;
nsCOMPtr <nsIMsgFilterList> m_serverFilterList;
nsCOMPtr <nsIMsgDBHdr> m_newMsgHdr; /* current message header we're building */
PRBool m_addHdrToDB;
};

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

@ -1867,6 +1867,14 @@ NS_IMETHODIMP nsMsgNewsFolder::Shutdown(PRBool shutdownChildren)
NS_IMETHODIMP
nsMsgNewsFolder::SetFilterList(nsIMsgFilterList *aFilterList)
{
if (mIsServer)
{
nsCOMPtr<nsIMsgIncomingServer> server;
nsresult rv = GetServer(getter_AddRefs(server));
NS_ENSURE_SUCCESS(rv,rv);
return server->SetFilterList(aFilterList);
}
mFilterList = aFilterList;
return NS_OK;
}
@ -1874,6 +1882,14 @@ nsMsgNewsFolder::SetFilterList(nsIMsgFilterList *aFilterList)
NS_IMETHODIMP
nsMsgNewsFolder::GetFilterList(nsIMsgWindow *aMsgWindow, nsIMsgFilterList **aResult)
{
if (mIsServer)
{
nsCOMPtr<nsIMsgIncomingServer> server;
nsresult rv = GetServer(getter_AddRefs(server));
NS_ENSURE_SUCCESS(rv,rv);
return server->GetFilterList(aMsgWindow, aResult);
}
if (!mFilterList)
{
nsCOMPtr<nsIFileSpec> thisFolder;

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

@ -119,9 +119,7 @@ nsNntpIncomingServer::nsNntpIncomingServer() : nsMsgLineBuffer(nsnull, PR_FALSE)
mSubscribedAtom = do_GetAtom("subscribed");
mNntpAtom = do_GetAtom("nntp");
// our filters are on the server, they are on a per newsgroup basis
// but this will make the filter UI enable for news accounts
// which is what we want
// we have server wide and per group filters
m_canHaveFilters = PR_TRUE;
SetupNewsrcSaveTimer();
@ -612,13 +610,6 @@ nsNntpIncomingServer::PerformExpand(nsIMsgWindow *aMsgWindow)
return NS_OK;
}
NS_IMETHODIMP
nsNntpIncomingServer::GetFilterList(nsIMsgWindow *aMsgWindow, nsIMsgFilterList **aResult)
{
// news servers don't have filters, each newsgroup does.
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsNntpIncomingServer::GetNumGroupsNeedingCounts(PRInt32 *aNumGroupsNeedingCounts)
{

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

@ -86,7 +86,6 @@ public:
NS_IMETHOD CloseCachedConnections();
NS_IMETHOD PerformBiff(nsIMsgWindow *aMsgWindow);
NS_IMETHOD PerformExpand(nsIMsgWindow *aMsgWindow);
NS_IMETHOD GetFilterList(nsIMsgWindow *aMsgWindow, nsIMsgFilterList **aResult);
NS_IMETHOD OnUserOrHostNameChanged(const char *oldName, const char *newName);
// for nsMsgLineBuffer