blob: 881a3768826539631941b88811a5bd219af71d05 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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 = TDEApplication::kApplication()->config();
//load the setup
load();
}
SenderListFilter::~SenderListFilter()
{
}
FilterAction_Type SenderListFilter::check( TQString 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( TQStringList list, TQString 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( TQStringList::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( TQStringList::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( TQStringList::Iterator it = whitelist.begin(); it != whitelist.end(); ++it )
{
kdDebug() << *it << endl;
}
}
|