00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "senderlistfilter.h"
00019
00020 SenderListFilter::SenderListFilter()
00021 {
00022
00023
00024 config = KGlobal::config();
00025
00026
00027 load();
00028
00029 }
00030
00031
00032 SenderListFilter::~SenderListFilter()
00033 {
00034 }
00035
00036 FilterAction_Type SenderListFilter::check( QString sender ) const
00037 {
00038
00039 if( sender.isEmpty() ) return FActNone;
00040
00041
00042 if( search( whitelist, sender ) ) return FActPass;
00043
00044
00045 if( search( blacklist, sender ) ) return blacklistAction;
00046
00047
00048 return FActNone;
00049 }
00050
00051 void SenderListFilter::load( )
00052 {
00053
00054 KConfigGroup* configFilter = new KConfigGroup( config, CONFIG_GROUP_FILTER );
00055
00056
00057 blacklist = configFilter->readEntry( CONFIG_ENTRY_FILTER_BLACKLIST, QStringList() );
00058 whitelist = configFilter->readEntry( CONFIG_ENTRY_FILTER_WHITELIST, QStringList() );
00059
00060
00061 switch( configFilter->readEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, DEFAULT_FILTER_BLACKLIST_ACTION ) )
00062 {
00063 case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE : blacklistAction = FActDelete; break;
00064 case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_MARK : blacklistAction = FActMark; break;
00065 default : blacklistAction = FActMark; break;
00066 }
00067 }
00068
00069 bool SenderListFilter::search( QStringList list, QString sender ) const
00070 {
00071
00072 if( list.isEmpty() || sender.isEmpty() ) return false;
00073
00074
00075 bool found = false;
00076 for( QStringList::Iterator it = list.begin(); it != list.end() && found == false; ++it )
00077 {
00078 if( sender.contains( *it, Qt::CaseInsensitive ) || (*it).contains( sender, Qt::CaseInsensitive ) )
00079 found = true;
00080 }
00081
00082 return found;
00083 }
00084
00085 void SenderListFilter::print( )
00086 {
00087 kdDebug() << "Blacklist:" << endl;
00088 for( QStringList::Iterator it = blacklist.begin(); it != blacklist.end(); ++it )
00089 {
00090 kdDebug() << *it << endl;
00091 }
00092
00093 switch( blacklistAction )
00094 {
00095 case FActDelete : kdDebug() << "Blacklist Action: DELETE" << endl; break;
00096 case FActMark : kdDebug() << "Blacklist Action: MARK " << endl; break;
00097 default : kdDebug() << "Blacklist Action: Unknown" << endl; break;
00098 }
00099
00100 kdDebug() << endl;
00101
00102 kdDebug() << "Whitelist:" << endl;
00103 for( QStringList::Iterator it = whitelist.begin(); it != whitelist.end(); ++it )
00104 {
00105 kdDebug() << *it << endl;
00106 }
00107
00108 }