diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-07-24 15:57:00 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-07-24 15:57:00 -0500 |
commit | b888c7edb54e483ec0e3c2e2ce0eafd73acdcc65 (patch) | |
tree | 7ca76d42f66fb21ea08142de9a8d3bf16e597404 /kshowmail/senderlistfilter.cpp | |
download | kshowmail-b888c7edb54e483ec0e3c2e2ce0eafd73acdcc65.tar.gz kshowmail-b888c7edb54e483ec0e3c2e2ce0eafd73acdcc65.zip |
Initial import from kshowmail 3.3.1 sources
Diffstat (limited to 'kshowmail/senderlistfilter.cpp')
-rw-r--r-- | kshowmail/senderlistfilter.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/kshowmail/senderlistfilter.cpp b/kshowmail/senderlistfilter.cpp new file mode 100644 index 0000000..fcb4e6d --- /dev/null +++ b/kshowmail/senderlistfilter.cpp @@ -0,0 +1,102 @@ +// +// C++ Implementation: senderlistfilter +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "senderlistfilter.h" + +SenderListFilter::SenderListFilter() +{ + + //get the application config object + config = KApplication::kApplication()->config(); + + //load the setup + load(); + +} + + +SenderListFilter::~SenderListFilter() +{ +} + +FilterAction_Type SenderListFilter::check( QString sender ) const +{ + //return with none action if the given string is empty + if( sender.isEmpty() ) return FActNone; + + //check the whitelist first + if( search( whitelist, sender ) ) return FActPass; + + //check blacklist + if( search( blacklist, sender ) ) return blacklistAction; + + //this is the default + return FActNone; +} + +void SenderListFilter::load( ) +{ + //set group + config->setGroup( CONFIG_GROUP_FILTER ); + + //get lists + blacklist = config->readListEntry( CONFIG_ENTRY_FILTER_BLACKLIST ); + whitelist = config->readListEntry( CONFIG_ENTRY_FILTER_WHITELIST ); + + //get blacklist action + switch( config->readNumEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, DEFAULT_FILTER_BLACKLIST_ACTION ) ) + { + case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE : blacklistAction = FActDelete; break; + case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_MARK : blacklistAction = FActMark; break; + default : blacklistAction = FActMark; break; + } +} + +bool SenderListFilter::search( QStringList list, QString sender ) const +{ + //return with FALSE if the list or the search string are empty + if( list.isEmpty() || sender.isEmpty() ) return false; + + //iterate over the list to search for the sender + bool found = false; + for( QStringList::Iterator it = list.begin(); it != list.end() && found == false; ++it ) + { + if( sender.contains( *it, false ) || (*it).contains( sender, false ) ) + found = true; + } + + return found; +} + +void SenderListFilter::print( ) +{ + kdDebug() << "Blacklist:" << endl; + for( QStringList::Iterator it = blacklist.begin(); it != blacklist.end(); ++it ) + { + kdDebug() << *it << endl; + } + + switch( blacklistAction ) + { + case FActDelete : kdDebug() << "Blacklist Action: DELETE" << endl; break; + case FActMark : kdDebug() << "Blacklist Action: MARK " << endl; break; + default : kdDebug() << "Blacklist Action: Unknown" << endl; break; + } + + kdDebug() << endl; + + kdDebug() << "Whitelist:" << endl; + for( QStringList::Iterator it = whitelist.begin(); it != whitelist.end(); ++it ) + { + kdDebug() << *it << endl; + } + +} |