diff --git a/mailnews/base/search/public/Makefile.in b/mailnews/base/search/public/Makefile.in index 801ab37f9856..8156b5d101c6 100644 --- a/mailnews/base/search/public/Makefile.in +++ b/mailnews/base/search/public/Makefile.in @@ -28,6 +28,7 @@ EXPORTS= \ nsIMsgFilterService.h \ nsMsgFilterCore.h \ nsIMsgFilterList.h \ + nsIMsgFilterHitNotify.h \ nsIMsgSearchSession.h \ nsIMsgSearchAdapter.h \ nsMsgSearchAdapter.h \ diff --git a/mailnews/base/search/public/makefile.win b/mailnews/base/search/public/makefile.win index c855cd802664..988799a3815d 100644 --- a/mailnews/base/search/public/makefile.win +++ b/mailnews/base/search/public/makefile.win @@ -24,6 +24,7 @@ EXPORTS = \ nsIMsgFilter.h \ nsIMsgFilterService.h \ nsMsgFilterCore.h \ + nsIMsgFilterHitNotify.h \ nsIMsgFilterList.h \ nsIMsgSearchSession.h \ nsIMsgSearchAdapter.h \ diff --git a/mailnews/base/search/public/nsIMsgFilterHitNotify.h b/mailnews/base/search/public/nsIMsgFilterHitNotify.h new file mode 100644 index 000000000000..b8cbf5dc9056 --- /dev/null +++ b/mailnews/base/search/public/nsIMsgFilterHitNotify.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 + + + diff --git a/mailnews/base/search/public/nsIMsgFilterList.h b/mailnews/base/search/public/nsIMsgFilterList.h index 0b0aa32092c3..edbe2f50b95a 100644 --- a/mailnews/base/search/public/nsIMsgFilterList.h +++ b/mailnews/base/search/public/nsIMsgFilterList.h @@ -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 diff --git a/mailnews/base/search/public/nsMsgFilterCore.h b/mailnews/base/search/public/nsMsgFilterCore.h index bc9146dafe5e..0b5a8fe6ddff 100644 --- a/mailnews/base/search/public/nsMsgFilterCore.h +++ b/mailnews/base/search/public/nsMsgFilterCore.h @@ -51,6 +51,7 @@ typedef enum nsMsgFilterDown } nsMsgFilterMotion; + typedef PRInt32 nsMsgFilterIndex; diff --git a/mailnews/base/search/src/nsMsgFilterList.cpp b/mailnews/base/search/src/nsMsgFilterList.cpp index 4c8ffc6161ae..08e7bedf8725 100644 --- a/mailnews/base/search/src/nsMsgFilterList.cpp +++ b/mailnews/base/search/src/nsMsgFilterList.cpp @@ -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() { diff --git a/mailnews/base/search/src/nsMsgFilterList.h b/mailnews/base/search/src/nsMsgFilterList.h index 46081708b73f..66f767d48c59 100644 --- a/mailnews/base/search/src/nsMsgFilterList.h +++ b/mailnews/base/search/src/nsMsgFilterList.h @@ -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();