00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "headerfilter.h"
00019
00020 HeaderFilter::HeaderFilter()
00021 {
00022
00023 config = KGlobal::config();
00024
00025
00026 load();
00027 }
00028
00029
00030 HeaderFilter::~HeaderFilter()
00031 {
00032
00033 QListIterator<FilterItem*> it( filters );
00034 while( it.hasNext() )
00035 {
00036 FilterItem* item = it.next();
00037 delete item;
00038 }
00039 }
00040
00041 FilterAction_Type HeaderFilter::check( QString from, QString to, uint size, QString subject, QStringList header, QString account, QString& mailboxName, QString& filterName ) const
00042 {
00043
00044
00045 filterName.remove( 0, filterName.length() );
00046
00047
00048 if( !active )
00049 return FActPass;
00050
00051
00052 FilterAction_Type action = senderlist.check( from );
00053 if( action != FActNone ) {
00054
00055
00056
00057 if( action == FActPass ) {
00058 filterName.append( "Whitelist" );
00059 } else {
00060 filterName.append( "Blacklist" );
00061 }
00062
00063 return action;
00064 }
00065
00066
00067 QListIterator<FilterItem*> it( filters );
00068 while( it.hasNext() )
00069 {
00070 FilterItem* filter = it.next();
00071 action = filter->check( from, to, size, subject, header, account, mailboxName );
00072
00073 if( action != FActNone ) {
00074 filterName.append( filter->getName() );
00075 return action;
00076 }
00077 }
00078
00079
00080 if( defaultAction == FActMove )
00081 {
00082 mailboxName.remove( 0, mailboxName.length() );
00083 mailboxName.append( mailbox );
00084 }
00085
00086
00087 filterName.append( i18nc( "@info The default action which has caught this mail", "Default Action" ) );
00088
00089 return defaultAction;
00090
00091 }
00092
00093 void HeaderFilter::load( )
00094 {
00095
00096 senderlist.load();
00097
00098
00099 KConfigGroup* configFilter = new KConfigGroup( config, CONFIG_GROUP_FILTER );
00100
00101
00102 active = configFilter->readEntry( CONFIG_ENTRY_FILTER_ACTIVE, DEFAULT_FILTER_ACTIVE );
00103
00104
00105 numberFilterItems = configFilter->readEntry( CONFIG_ENTRY_FILTER_NUMBER_OF_FILTERS, 0 );
00106
00107
00108 switch( configFilter->readEntry( CONFIG_ENTRY_FILTER_OTHERS_ACTION, DEFAULT_FILTER_OTHERS_ACTION ) )
00109 {
00110 case CONFIG_VALUE_FILTER_OTHERS_ACTION_PASS : defaultAction = FActPass; break;
00111 case CONFIG_VALUE_FILTER_OTHERS_ACTION_DELETE : defaultAction = FActDelete; break;
00112 case CONFIG_VALUE_FILTER_OTHERS_ACTION_MARK : defaultAction = FActMark; break;
00113 case CONFIG_VALUE_FILTER_OTHERS_ACTION_MOVE : defaultAction = FActMove; break;
00114 case CONFIG_VALUE_FILTER_OTHERS_ACTION_IGNORE : defaultAction = FActIgnore; break;
00115 case CONFIG_VALUE_FILTER_OTHERS_ACTION_SPAMCHECK : defaultAction = FActSpamcheck; break;
00116 default : kdError() << "Header Filter: Unknown default filter action. Set PASS." << endl;
00117 defaultAction = FActPass;
00118 break;
00119 }
00120
00121
00122 if( defaultAction == FActMove )
00123 mailbox = configFilter->readEntry( CONFIG_ENTRY_FILTER_OTHERS_MAILBOX, DEFAULT_FILTER_ACTION_MOVE_MAILBOX );
00124
00125
00126
00127 filters.clear();
00128
00129 for( uint filterNr = 1; filterNr <= numberFilterItems; filterNr++ )
00130 {
00131 filters.append( new FilterItem( filterNr ) );
00132 }
00133 }
00134
00135 void HeaderFilter::print( )
00136 {
00137 kdDebug() << "Header Filter Settings:" << endl;
00138 kdDebug() << "-----------------------" << endl;
00139
00140
00141 if( active )
00142 kdDebug() << "Header filter is active." << endl;
00143 else
00144 kdDebug() << "Header filter is not active." << endl;
00145
00146
00147 senderlist.print();
00148
00149
00150 kdDebug() << endl;
00151 kdDebug() << "Number of filters: " << numberFilterItems << endl << endl;
00152
00153 QListIterator<FilterItem*> it( filters );
00154 while( it.hasNext() )
00155 {
00156 FilterItem* filter = it.next();
00157 filter->print();
00158 kdDebug() << endl;
00159 }
00160
00161
00162 switch( defaultAction )
00163 {
00164 case FActPass : kdDebug() << "Default action for other mails: PASS" << endl; break;
00165 case FActDelete : kdDebug() << "Default action for other mails: DELETE" << endl; break;
00166 case FActMark : kdDebug() << "Default action for other mails: MARK" << endl; break;
00167 case FActIgnore : kdDebug() << "Default action for other mails: IGNORE" << endl;
00168 case FActMove : kdDebug() << "Default action for other mails: MOVE to " << mailbox << endl; break;
00169 case FActSpamcheck : kdDebug() << "Default action for other mails: SPAMCHECK" << endl; break;
00170 default : kdDebug() << "Unknown default action for other mails" << endl; break;
00171 }
00172
00173
00174 }
00175
00176 bool HeaderFilter::isActive()
00177 {
00178 return active;
00179 }
00180
00181