restructure filter application to do imap filters

This commit is contained in:
bienvenu%netscape.com 1999-06-11 07:01:39 +00:00
Родитель 9baf9b5cf2
Коммит b839da424a
7 изменённых файлов: 110 добавлений и 7 удалений

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

@ -28,6 +28,7 @@ EXPORTS= \
nsIMsgFilterService.h \
nsMsgFilterCore.h \
nsIMsgFilterList.h \
nsIMsgFilterHitNotify.h \
nsIMsgSearchSession.h \
nsIMsgSearchAdapter.h \
nsMsgSearchAdapter.h \

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

@ -24,6 +24,7 @@ EXPORTS = \
nsIMsgFilter.h \
nsIMsgFilterService.h \
nsMsgFilterCore.h \
nsIMsgFilterHitNotify.h \
nsIMsgFilterList.h \
nsIMsgSearchSession.h \
nsIMsgSearchAdapter.h \

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

@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _nsIMsgFilterHitNotify_H_
#define _nsIMsgFilterHitNotify_H_
#include "nscore.h"
#include "nsISupports.h"
#include "nsMsgFilterCore.h"
////////////////////////////////////////////////////////////////////////////////////////
// nsIMsgFilterHitNotify is an interface designed to make evaluating filters
// easier. Clients typically open a filter list and ask the filter list to
// evaluate the filters for a particular message, and pass in an interface pointer
// to be notified of hits. The filter list will call the ApplyFilterHit method on the
// interface pointer in case of hits, along with the desired action and value.
// applyMore is an out parameter used to indicate whether the
// filter list should continue trying to apply filters or not.
//
////////////////////////////////////////////////////////////////////////////////////////
// c9f15174-1f3f-11d3-a51b-0060b0fc04b7
#define NS_IMSGFILTERHITNOTIFY_IID \
{ 0xc9f15174, 0x1f3f, 0x11d3, \
{ 0xa5, 0x1b, 0x0, 0x60, 0xb0, 0xfc, 0x04, 0xb7 } }
class nsIMsgFilter;
class nsIMsgFilterHitNotify : public nsISupports
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IMSGFILTERHITNOTIFY_IID; return iid; }
NS_IMETHOD ApplyFilterHit(nsIMsgFilter *filter, PRBool *applyMore) = 0;
};
#endif

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

@ -38,6 +38,7 @@ class nsIOFileStream;
{ 0xa5, 0x0a, 0x0, 0x60, 0xb0, 0xfc, 0x04, 0xb7 } }
class nsIMsgFilter;
class nsIMsgFilterHitNotify;
class nsIMsgFilterList : public nsISupports
{
@ -56,10 +57,13 @@ public:
NS_IMETHOD InsertFilterAt(PRUint32 filterIndex, nsIMsgFilter *filter)= 0;
NS_IMETHOD EnableLogging(PRBool enable)= 0;
NS_IMETHOD IsLoggingEnabled(PRBool *aResult)= 0;
NS_IMETHOD LoggingEnabled(PRBool *aResult)= 0;
NS_IMETHOD CreateFilter(char *name, nsIMsgFilter **result)= 0;
NS_IMETHOD SaveToFile(nsIOFileStream *stream) = 0;
NS_IMETHOD ApplyFiltersToHdr(nsMsgFilterType filterType, nsIMsgDBHdr *msgHdr, nsIMsgFolder *folder, nsIMsgDatabase *db,
char *headers, PRUint32 headersSize, nsIMsgFilterHitNotify *listener) = 0;
};
#endif

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

@ -51,6 +51,7 @@ typedef enum
nsMsgFilterDown
} nsMsgFilterMotion;
typedef PRInt32 nsMsgFilterIndex;

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

@ -21,7 +21,7 @@
#include "msgCore.h"
#include "nsMsgFilterList.h"
#include "nsMsgFilter.h"
#include "nsIMsgFilterHitNotify.h"
#include "nsFileStream.h"
#include "nsMsgUtils.h"
@ -84,10 +84,7 @@ NS_IMETHODIMP nsMsgFilterList::GetFolderForFilterList(class nsIMsgFolder **aFold
return NS_ERROR_NOT_IMPLEMENTED;
}
//static enum nsMsgRuleActionType __cdecl nsMsgFilter::GetActionForFilingStr(class nsString2 &)" (?GetActionForFilingStr@nsMsgFilter@@SA?AW4nsMsgRuleActionType@@A
//AVnsString2@@@Z)
NS_IMETHODIMP nsMsgFilterList::IsLoggingEnabled(PRBool *aResult)
NS_IMETHODIMP nsMsgFilterList::LoggingEnabled(PRBool *aResult)
{
if (!aResult)
return NS_ERROR_NULL_POINTER;
@ -104,6 +101,46 @@ NS_IMETHODIMP nsMsgFilterList::SaveToFile(nsIOFileStream *stream)
return SaveTextFilters();
}
NS_IMETHODIMP nsMsgFilterList::ApplyFiltersToHdr(nsMsgFilterType filterType, nsIMsgDBHdr *msgHdr, nsIMsgFolder *folder, nsIMsgDatabase *db,
char *headers, PRUint32 headersSize, nsIMsgFilterHitNotify *listener)
{
nsIMsgFilter *filter;
PRUint32 filterCount = 0;
nsresult ret = NS_OK;
GetFilterCount(&filterCount);
for (PRUint32 filterIndex = 0; filterIndex < filterCount; filterIndex++)
{
if (NS_SUCCEEDED(GetFilterAt(filterIndex, &filter)))
{
PRBool isEnabled;
nsMsgFilterType curFilterType;
filter->IsFilterEnabled(&isEnabled);
if (!isEnabled)
continue;
filter->GetFilterType(&curFilterType);
if (curFilterType & filterType)
{
nsresult matchTermStatus = NS_OK;
matchTermStatus = filter->MatchHdr(msgHdr, folder, db, headers, headersSize);
if (NS_SUCCEEDED(matchTermStatus) && listener)
{
PRBool applyMore;
ret = listener->ApplyFilterHit(filter, &applyMore);
if (!NS_SUCCEEDED(ret) || !applyMore)
break;
}
}
}
}
return ret;
}
#if 0
nsresult nsMsgFilterList::Open(nsMsgFilterType type, nsIMsgFolder *folder, nsIMsgFilterList **filterList)
{
@ -697,6 +734,7 @@ nsresult nsMsgFilterList::MoveFilterAt(PRUint32 filterIndex,
return NS_OK;
}
#ifdef DEBUG
void nsMsgFilterList::Dump()
{

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

@ -71,11 +71,14 @@ public:
NS_IMETHOD InsertFilterAt(PRUint32 filterIndex, nsIMsgFilter *filter);
NS_IMETHOD EnableLogging(PRBool enable);
NS_IMETHOD IsLoggingEnabled(PRBool *aResult);
NS_IMETHOD LoggingEnabled(PRBool *aResult);
NS_IMETHOD CreateFilter(char *name, nsIMsgFilter **result);
NS_IMETHOD SaveToFile(nsIOFileStream *stream);
NS_IMETHOD ApplyFiltersToHdr(nsMsgFilterType filterType, nsIMsgDBHdr *msgHdr, nsIMsgFolder *folder, nsIMsgDatabase *db,
char *headers, PRUint32 headersSize, nsIMsgFilterHitNotify *listener);
nsresult Close();
nsresult LoadTextFilters();