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 ) const
00042 {
00043
00044 if( !active )
00045 return FActPass;
00046
00047
00048 FilterAction_Type action = senderlist.check( from );
00049 if( action != FActNone ) return action;
00050
00051
00052 QListIterator<FilterItem*> it( filters );
00053 while( it.hasNext() )
00054 {
00055 FilterItem* filter = it.next();
00056 action = filter->check( from, to, size, subject, header, account, mailboxName );
00057
00058 if( action != FActNone ) return action;
00059 }
00060
00061
00062 if( defaultAction == FActMove )
00063 {
00064 mailboxName.remove( 0, mailboxName.length() );
00065 mailboxName.append( mailbox );
00066 }
00067 return defaultAction;
00068
00069 }
00070
00071 void HeaderFilter::load( )
00072 {
00073
00074 senderlist.load();
00075
00076
00077 KConfigGroup* configFilter = new KConfigGroup( config, CONFIG_GROUP_FILTER );
00078
00079
00080 active = configFilter->readEntry( CONFIG_ENTRY_FILTER_ACTIVE, DEFAULT_FILTER_ACTIVE );
00081
00082
00083 numberFilterItems = configFilter->readEntry( CONFIG_ENTRY_FILTER_NUMBER_OF_FILTERS, 0 );
00084
00085
00086 switch( configFilter->readEntry( CONFIG_ENTRY_FILTER_OTHERS_ACTION, DEFAULT_FILTER_OTHERS_ACTION ) )
00087 {
00088 case CONFIG_VALUE_FILTER_OTHERS_ACTION_PASS : defaultAction = FActPass; break;
00089 case CONFIG_VALUE_FILTER_OTHERS_ACTION_DELETE : defaultAction = FActDelete; break;
00090 case CONFIG_VALUE_FILTER_OTHERS_ACTION_MARK : defaultAction = FActMark; break;
00091 case CONFIG_VALUE_FILTER_OTHERS_ACTION_MOVE : defaultAction = FActMove; break;
00092 case CONFIG_VALUE_FILTER_OTHERS_ACTION_IGNORE : defaultAction = FActIgnore; break;
00093 case CONFIG_VALUE_FILTER_OTHERS_ACTION_SPAMCHECK : defaultAction = FActSpamcheck; break;
00094 default : kdError() << "Header Filter: Unknown default filter action. Set PASS." << endl;
00095 defaultAction = FActPass;
00096 break;
00097 }
00098
00099
00100 if( defaultAction == FActMove )
00101 mailbox = configFilter->readEntry( CONFIG_ENTRY_FILTER_OTHERS_MAILBOX, DEFAULT_FILTER_ACTION_MOVE_MAILBOX );
00102
00103
00104
00105 filters.clear();
00106
00107 for( uint filterNr = 1; filterNr <= numberFilterItems; filterNr++ )
00108 {
00109 filters.append( new FilterItem( filterNr ) );
00110 }
00111 }
00112
00113 void HeaderFilter::print( )
00114 {
00115 kdDebug() << "Header Filter Settings:" << endl;
00116 kdDebug() << "-----------------------" << endl;
00117
00118
00119 if( active )
00120 kdDebug() << "Header filter is active." << endl;
00121 else
00122 kdDebug() << "Header filter is not active." << endl;
00123
00124
00125 senderlist.print();
00126
00127
00128 kdDebug() << endl;
00129 kdDebug() << "Number of filters: " << numberFilterItems << endl << endl;
00130
00131 QListIterator<FilterItem*> it( filters );
00132 while( it.hasNext() )
00133 {
00134 FilterItem* filter = it.next();
00135 filter->print();
00136 kdDebug() << endl;
00137 }
00138
00139
00140 switch( defaultAction )
00141 {
00142 case FActPass : kdDebug() << "Default action for other mails: PASS" << endl; break;
00143 case FActDelete : kdDebug() << "Default action for other mails: DELETE" << endl; break;
00144 case FActMark : kdDebug() << "Default action for other mails: MARK" << endl; break;
00145 case FActIgnore : kdDebug() << "Default action for other mails: IGNORE" << endl;
00146 case FActMove : kdDebug() << "Default action for other mails: MOVE to " << mailbox << endl; break;
00147 case FActSpamcheck : kdDebug() << "Default action for other mails: SPAMCHECK" << endl; break;
00148 default : kdDebug() << "Unknown default action for other mails" << endl; break;
00149 }
00150
00151
00152 }
00153
00154 bool HeaderFilter::isActive()
00155 {
00156 return active;
00157 }
00158
00159