30 #include "antispamwizard.h"
31 #include "kcursorsaver.h"
32 #include "accountmanager.h"
34 #include "kmfilteraction.h"
35 #include "kmfiltermgr.h"
37 #include "kmfoldertree.h"
38 #include "kmmainwin.h"
39 #include "networkaccount.h"
40 #include "folderrequester.h"
42 #include <tdeaction.h>
43 #include <tdeapplication.h>
46 #include <kiconloader.h>
47 #include <tdelocale.h>
48 #include <tdemessagebox.h>
49 #include <tdeprocess.h>
54 #include <tqtooltip.h>
55 #include <tqwhatsthis.h>
57 using namespace KMail;
60 TQWidget* parent, KMFolderTree * mainFolderTree )
70 reader.readAndMergeConfig();
71 mToolList = reader.getToolList();
74 if ( mMode == AntiSpam )
75 kdDebug(5006) << endl <<
"Considered anti-spam tools: " << endl;
77 kdDebug(5006) << endl <<
"Considered anti-virus tools: " << endl;
79 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
80 it != mToolList.end(); ++it ) {
82 kdDebug(5006) <<
"Predefined tool: " << (*it).getId() << endl;
83 kdDebug(5006) <<
"Config version: " << (*it).getVersion() << endl;
84 kdDebug(5006) <<
"Selection priority: " << (*it).getPrio() << endl;
85 kdDebug(5006) <<
"Displayed name: " << (*it).getVisibleName() << endl;
86 kdDebug(5006) <<
"Executable: " << (*it).getExecutable() << endl;
87 kdDebug(5006) <<
"WhatsThis URL: " << (*it).getWhatsThisText() << endl;
88 kdDebug(5006) <<
"Filter name: " << (*it).getFilterName() << endl;
89 kdDebug(5006) <<
"Detection command: " << (*it).getDetectCmd() << endl;
90 kdDebug(5006) <<
"Learn spam command: " << (*it).getSpamCmd() << endl;
91 kdDebug(5006) <<
"Learn ham command: " << (*it).getHamCmd() << endl;
92 kdDebug(5006) <<
"Detection header: " << (*it).getDetectionHeader() << endl;
93 kdDebug(5006) <<
"Detection pattern: " << (*it).getDetectionPattern() << endl;
94 kdDebug(5006) <<
"Use as RegExp: " << (*it).isUseRegExp() << endl;
95 kdDebug(5006) <<
"Supports Bayes Filter: " << (*it).useBayesFilter() << endl;
96 kdDebug(5006) <<
"Type: " << (*it).getType() << endl << endl;
100 setCaption( ( mMode == AntiSpam ) ? i18n(
"Anti-Spam Wizard" )
101 : i18n(
"Anti-Virus Wizard" ) );
102 mInfoPage =
new ASWizInfoPage( mMode, 0,
"" );
104 ( mMode == AntiSpam )
105 ? i18n(
"Welcome to the KMail Anti-Spam Wizard" )
106 : i18n(
"Welcome to the KMail Anti-Virus Wizard" ) );
107 connect( mInfoPage, TQ_SIGNAL( selectionChanged(
void ) ),
110 if ( mMode == AntiSpam ) {
111 mSpamRulesPage =
new ASWizSpamRulesPage( 0,
"", mainFolderTree );
112 addPage( mSpamRulesPage, i18n(
"Options to fine-tune the handling of spam messages" ));
113 connect( mSpamRulesPage, TQ_SIGNAL( selectionChanged(
void ) ),
117 mVirusRulesPage =
new ASWizVirusRulesPage( 0,
"", mainFolderTree );
118 addPage( mVirusRulesPage, i18n(
"Options to fine-tune the handling of virus messages" ));
119 connect( mVirusRulesPage, TQ_SIGNAL( selectionChanged(
void ) ),
123 connect(
this, TQ_SIGNAL( helpClicked(
void) ),
126 setNextEnabled( mInfoPage,
false );
128 if ( mMode == AntiSpam ) {
129 mSummaryPage =
new ASWizSummaryPage( 0,
"" );
130 addPage( mSummaryPage, i18n(
"Summary of changes to be made by this wizard" ) );
131 setNextEnabled( mSpamRulesPage,
true );
132 setFinishEnabled( mSummaryPage,
true );
141 if ( mSpamRulesPage ) {
142 kdDebug( 5006 ) <<
"Folder name for messages classified as spam is "
143 << mSpamRulesPage->selectedSpamFolderName() << endl;
144 kdDebug( 5006 ) <<
"Folder name for messages classified as unsure is "
145 << mSpamRulesPage->selectedUnsureFolderName() << endl;
147 if ( mVirusRulesPage )
148 kdDebug( 5006 ) <<
"Folder name for viruses is "
149 << mVirusRulesPage->selectedFolderName() << endl;
152 TQValueList<KMFilter*> filterList;
153 bool replaceExistingFilters =
false;
157 if ( mMode == AntiVirus ) {
158 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
159 it != mToolList.end(); ++it ) {
160 if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) &&
161 ( mVirusRulesPage->pipeRulesSelected() && (*it).isVirusTool() ) )
166 KMFilter* pipeFilter =
new KMFilter();
167 TQPtrList<KMFilterAction>* pipeFilterActions = pipeFilter->actions();
170 pipeFilterActions->append( pipeFilterAction );
172 pipeFilterPattern->
setName( uniqueNameFor( (*it).getFilterName() ) );
174 KMSearchRule::FuncIsGreaterOrEqual,
"0" ) );
175 pipeFilter->setApplyOnOutbound(
false);
176 pipeFilter->setApplyOnInbound();
177 pipeFilter->setApplyOnExplicit();
178 pipeFilter->setStopProcessingHere(
false );
179 pipeFilter->setConfigureShortcut(
false );
181 filterList.append( pipeFilter );
185 if ( mVirusRulesPage->moveRulesSelected() )
188 KMFilter* virusFilter =
new KMFilter();
189 TQPtrList<KMFilterAction>* virusFilterActions = virusFilter->actions();
191 virusFilterAction1->
argsFromString( mVirusRulesPage->selectedFolderName() );
192 virusFilterActions->append( virusFilterAction1 );
193 if ( mVirusRulesPage->markReadRulesSelected() ) {
194 KMFilterAction* virusFilterAction2 = dict[
"set status"]->create();
196 virusFilterActions->append( virusFilterAction2 );
199 virusFilterPattern->
setName( uniqueNameFor( i18n(
"Virus handling" ) ) );
200 virusFilterPattern->
setOp( KMSearchPattern::OpOr );
201 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
202 it != mToolList.end(); ++it ) {
203 if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ))
205 if ( (*it).isVirusTool() )
207 const TQCString header = (*it).getDetectionHeader().ascii();
208 const TQString & pattern = (*it).getDetectionPattern();
209 if ( (*it).isUseRegExp() )
210 virusFilterPattern->append(
212 KMSearchRule::FuncRegExp, pattern ) );
214 virusFilterPattern->append(
216 KMSearchRule::FuncContains, pattern ) );
220 virusFilter->setApplyOnOutbound(
false);
221 virusFilter->setApplyOnInbound();
222 virusFilter->setApplyOnExplicit();
223 virusFilter->setStopProcessingHere(
true );
224 virusFilter->setConfigureShortcut(
false );
226 filterList.append( virusFilter );
233 replaceExistingFilters =
true;
234 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
235 it != mToolList.end(); ++it ) {
236 if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) &&
237 (*it).isSpamTool() && !(*it).isDetectionOnly() )
242 KMFilter* pipeFilter =
new KMFilter();
243 TQPtrList<KMFilterAction>* pipeFilterActions = pipeFilter->actions();
246 pipeFilterActions->append( pipeFilterAction );
248 if ( replaceExistingFilters )
249 pipeFilterPattern->
setName( (*it).getFilterName() );
251 pipeFilterPattern->
setName( uniqueNameFor( (*it).getFilterName() ) );
253 KMSearchRule::FuncIsLessOrEqual,
"256000" ) );
254 pipeFilter->setApplyOnOutbound(
false);
255 pipeFilter->setApplyOnInbound();
256 pipeFilter->setApplyOnExplicit();
257 pipeFilter->setStopProcessingHere(
false );
258 pipeFilter->setConfigureShortcut(
false );
260 filterList.append( pipeFilter );
265 KMFilter* spamFilter =
new KMFilter();
266 TQPtrList<KMFilterAction>* spamFilterActions = spamFilter->actions();
267 if ( mSpamRulesPage->moveSpamSelected() )
270 spamFilterAction1->
argsFromString( mSpamRulesPage->selectedSpamFolderName() );
271 spamFilterActions->append( spamFilterAction1 );
275 spamFilterActions->append( spamFilterAction2 );
276 if ( mSpamRulesPage->markAsReadSelected() ) {
279 spamFilterActions->append( spamFilterAction3 );
282 if ( replaceExistingFilters )
283 spamFilterPattern->
setName( i18n(
"Spam handling" ) );
285 spamFilterPattern->
setName( uniqueNameFor( i18n(
"Spam handling" ) ) );
286 spamFilterPattern->
setOp( KMSearchPattern::OpOr );
287 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
288 it != mToolList.end(); ++it ) {
289 if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) )
291 if ( (*it).isSpamTool() )
293 const TQCString header = (*it).getDetectionHeader().ascii();
294 const TQString & pattern = (*it).getDetectionPattern();
295 if ( (*it).isUseRegExp() )
296 spamFilterPattern->append(
298 KMSearchRule::FuncRegExp, pattern ) );
300 spamFilterPattern->append(
302 KMSearchRule::FuncContains, pattern ) );
306 spamFilter->setApplyOnOutbound(
false);
307 spamFilter->setApplyOnInbound();
308 spamFilter->setApplyOnExplicit();
309 spamFilter->setStopProcessingHere(
true );
310 spamFilter->setConfigureShortcut(
false );
311 filterList.append( spamFilter );
313 if ( mSpamRulesPage->moveUnsureSelected() )
316 bool atLeastOneUnsurePattern =
false;
317 KMFilter* unsureFilter =
new KMFilter();
318 TQPtrList<KMFilterAction>* unsureFilterActions = unsureFilter->actions();
320 unsureFilterAction1->
argsFromString( mSpamRulesPage->selectedUnsureFolderName() );
321 unsureFilterActions->append( unsureFilterAction1 );
323 if ( replaceExistingFilters )
324 unsureFilterPattern->
setName( i18n(
"Semi spam (unsure) handling" ) );
326 unsureFilterPattern->
setName( uniqueNameFor( i18n(
"Semi spam (unsure) handling" ) ) );
327 unsureFilterPattern->
setOp( KMSearchPattern::OpOr );
328 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
329 it != mToolList.end(); ++it ) {
330 if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) )
332 if ( (*it).isSpamTool() && (*it).hasTristateDetection())
334 atLeastOneUnsurePattern =
true;
335 const TQCString header = (*it).getDetectionHeader().ascii();
336 const TQString & pattern = (*it).getDetectionPattern2();
337 if ( (*it).isUseRegExp() )
338 unsureFilterPattern->append(
340 KMSearchRule::FuncRegExp, pattern ) );
342 unsureFilterPattern->append(
344 KMSearchRule::FuncContains, pattern ) );
348 unsureFilter->setApplyOnOutbound(
false);
349 unsureFilter->setApplyOnInbound();
350 unsureFilter->setApplyOnExplicit();
351 unsureFilter->setStopProcessingHere(
true );
352 unsureFilter->setConfigureShortcut(
false );
354 if ( atLeastOneUnsurePattern )
355 filterList.append( unsureFilter );
361 KMFilter* classSpamFilter =
new KMFilter();
362 classSpamFilter->setIcon(
"mail_spam" );
363 TQPtrList<KMFilterAction>* classSpamFilterActions = classSpamFilter->actions();
364 KMFilterAction* classSpamFilterActionFirst = dict[
"set status"]->create();
366 classSpamFilterActions->append( classSpamFilterActionFirst );
367 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
368 it != mToolList.end(); ++it ) {
369 if ( mInfoPage->isProgramSelected( (*it).getVisibleName() )
370 && (*it).useBayesFilter() && !(*it).isDetectionOnly() )
372 KMFilterAction* classSpamFilterAction = dict[
"execute"]->create();
374 classSpamFilterActions->append( classSpamFilterAction );
377 if ( mSpamRulesPage->moveSpamSelected() )
379 KMFilterAction* classSpamFilterActionLast = dict[
"transfer"]->create();
380 classSpamFilterActionLast->
argsFromString( mSpamRulesPage->selectedSpamFolderName() );
381 classSpamFilterActions->append( classSpamFilterActionLast );
385 if ( replaceExistingFilters )
386 classSpamFilterPattern->
setName( i18n(
"Classify as spam" ) );
388 classSpamFilterPattern->
setName( uniqueNameFor( i18n(
"Classify as spam" ) ) );
390 KMSearchRule::FuncIsGreaterOrEqual,
"0" ) );
391 classSpamFilter->setApplyOnOutbound(
false);
392 classSpamFilter->setApplyOnInbound(
false );
393 classSpamFilter->setApplyOnExplicit(
false );
394 classSpamFilter->setStopProcessingHere(
true );
395 classSpamFilter->setConfigureShortcut(
true );
396 classSpamFilter->setConfigureToolbar(
true );
397 filterList.append( classSpamFilter );
400 KMFilter* classHamFilter =
new KMFilter();
401 classHamFilter->setIcon(
"mail_ham" );
402 TQPtrList<KMFilterAction>* classHamFilterActions = classHamFilter->actions();
403 KMFilterAction* classHamFilterActionFirst = dict[
"set status"]->create();
405 classHamFilterActions->append( classHamFilterActionFirst );
406 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
407 it != mToolList.end(); ++it ) {
408 if ( mInfoPage->isProgramSelected( (*it).getVisibleName() )
409 && (*it).useBayesFilter() && !(*it).isDetectionOnly() )
413 classHamFilterActions->append( classHamFilterAction );
417 if ( replaceExistingFilters )
418 classHamFilterPattern->
setName( i18n(
"Classify as NOT spam" ) );
420 classHamFilterPattern->
setName( uniqueNameFor( i18n(
"Classify as NOT spam" ) ) );
422 KMSearchRule::FuncIsGreaterOrEqual,
"0" ) );
423 classHamFilter->setApplyOnOutbound(
false);
424 classHamFilter->setApplyOnInbound(
false );
425 classHamFilter->setApplyOnExplicit(
false );
426 classHamFilter->setStopProcessingHere(
true );
427 classHamFilter->setConfigureShortcut(
true );
428 classHamFilter->setConfigureToolbar(
true );
429 filterList.append( classHamFilter );
442 if ( !filterList.isEmpty() )
444 filterList, replaceExistingFilters );
453 bool supportUnsure =
false;
455 mSpamToolsUsed =
false;
456 mVirusToolsUsed =
false;
457 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
458 it != mToolList.end(); ++it ) {
459 if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) )
462 if ( (*it).isSpamTool() ) {
463 mSpamToolsUsed =
true;
464 if ( (*it).hasTristateDetection() )
465 supportUnsure =
true;
467 if ( (*it).isVirusTool() )
468 mVirusToolsUsed =
true;
472 if ( mMode == AntiSpam ) {
473 mSpamRulesPage->allowUnsureFolderSelection( supportUnsure );
477 if ( ( mMode == AntiVirus ) && mVirusToolsUsed )
480 setNextEnabled( mInfoPage, status );
486 setFinishEnabled( mVirusRulesPage, anyVirusOptionChecked() );
496 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
497 it != mToolList.end(); ++it ) {
498 TQString text( i18n(
"Scanning for %1...").arg( (*it).getId() ) );
499 mInfoPage->setScanProgressText( text );
500 if ( (*it).isSpamTool() && (*it).isServerBased() ) {
502 TQString pattern = (*it).getServerPattern();
503 kdDebug(5006) <<
"Testing for server pattern:" << pattern << endl;
506 KMAccount* account = mgr->
first();
508 if ( account->type() ==
"pop" || account->type().contains(
"imap" ) ) {
509 const NetworkAccount * n =
dynamic_cast<const NetworkAccount*
>( account );
510 if ( n && n->host().lower().contains( pattern.lower() ) ) {
511 mInfoPage->addAvailableTool( (*it).getVisibleName() );
515 account = mgr->
next();
520 TDEApplication::kApplication()->processEvents( 200 );
521 if ( !checkForProgram( (*it).getExecutable() ) ) {
522 mInfoPage->addAvailableTool( (*it).getVisibleName() );
528 mInfoPage->setScanProgressText( ( mMode == AntiSpam )
529 ? i18n(
"Scanning for anti-spam tools finished.")
530 : i18n(
"Scanning for anti-virus tools finished.") );
532 mInfoPage->setScanProgressText( ( mMode == AntiSpam )
533 ? i18n(
"<p>No spam detection tools have been found. "
534 "Install your spam detection software and "
535 "re-run this wizard.</p>")
536 : i18n(
"Scanning complete. No anti-virus tools found.") );
542 if ( mMode == AntiSpam )
543 kapp->invokeHelp(
"the-anti-spam-wizard",
"kmail" );
545 kapp->invokeHelp(
"the-anti-virus-wizard",
"kmail" );
553 TQString replaceFilters;
555 if ( mMode == AntiVirus ) {
559 if ( mSpamRulesPage->markAsReadSelected() )
560 text = i18n(
"<p>Messages classified as spam are marked as read." );
562 text = i18n(
"<p>Messages classified as spam are not marked as read." );
564 if ( mSpamRulesPage->moveSpamSelected() )
565 text += i18n(
"<br>Spam messages are moved into the folder named <i>" )
566 + mSpamRulesPage->selectedSpamFolderName() +
"</i>.</p>";
568 text += i18n(
"<br>Spam messages are not moved into a certain folder.</p>" );
570 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
571 it != mToolList.end(); ++it ) {
572 if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) &&
573 (*it).isSpamTool() && !(*it).isDetectionOnly() ) {
574 sortFilterOnExistance( (*it).getFilterName(), newFilters, replaceFilters );
577 sortFilterOnExistance( i18n(
"Spam handling" ), newFilters, replaceFilters );
580 if ( mSpamRulesPage->moveUnsureSelected() ) {
581 bool atLeastOneUnsurePattern =
false;
582 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
583 it != mToolList.end(); ++it ) {
584 if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) ) {
585 if ( (*it).isSpamTool() && (*it).hasTristateDetection())
586 atLeastOneUnsurePattern =
true;
589 if ( atLeastOneUnsurePattern ) {
590 sortFilterOnExistance( i18n(
"Semi spam (unsure) handling" ),
591 newFilters, replaceFilters );
592 text += i18n(
"<p>The folder for messages classified as unsure (probably spam) is <i>" )
593 + mSpamRulesPage->selectedUnsureFolderName() +
"</i>.</p>";
598 sortFilterOnExistance( i18n(
"Classify as spam" ),
599 newFilters, replaceFilters );
600 sortFilterOnExistance( i18n(
"Classify as NOT spam" ),
601 newFilters, replaceFilters );
604 if ( !newFilters.isEmpty() )
605 text += i18n(
"<p>The wizard will create the following filters:<ul>" )
606 + newFilters +
"</ul></p>";
607 if ( !replaceFilters.isEmpty() )
608 text += i18n(
"<p>The wizard will replace the following filters:<ul>" )
609 + replaceFilters +
"</ul></p>";
612 mSummaryPage->setSummaryText( text );
616 int AntiSpamWizard::checkForProgram(
const TQString &executable )
618 kdDebug(5006) <<
"Testing for executable:" << executable << endl;
620 process << executable;
621 process.setUseShell(
true );
622 process.start( TDEProcess::Block );
623 return process.exitStatus();
627 bool AntiSpamWizard::anyVirusOptionChecked()
629 return ( mVirusRulesPage->moveRulesSelected()
630 || mVirusRulesPage->pipeRulesSelected() );
634 const TQString AntiSpamWizard::uniqueNameFor(
const TQString & name )
640 void AntiSpamWizard::sortFilterOnExistance(
641 const TQString & intendedFilterName,
642 TQString & newFilters, TQString & replaceFilters )
644 if ( uniqueNameFor( intendedFilterName ) == intendedFilterName )
645 newFilters +=
"<li>" + intendedFilterName +
"</li>";
647 replaceFilters +=
"<li>" + intendedFilterName +
"</li>";
652 AntiSpamWizard::SpamToolConfig::SpamToolConfig( TQString toolId,
653 int configVersion,
int prio, TQString name, TQString exec,
654 TQString url, TQString filter, TQString detection, TQString spam, TQString ham,
655 TQString header, TQString pattern, TQString pattern2, TQString serverPattern,
656 bool detectionOnly,
bool regExp,
bool bayesFilter,
bool tristateDetection,
658 : mId( toolId ), mVersion( configVersion ), mPrio( prio ),
659 mVisibleName( name ), mExecutable( exec ), mWhatsThisText( url ),
660 mFilterName( filter ), mDetectCmd( detection ), mSpamCmd( spam ),
661 mHamCmd( ham ), mDetectionHeader( header ), mDetectionPattern( pattern ),
662 mDetectionPattern2( pattern2 ), mServerPattern( serverPattern ),
663 mDetectionOnly( detectionOnly ),
664 mUseRegExp( regExp ), mSupportsBayesFilter( bayesFilter ),
665 mSupportsUnsure( tristateDetection ), mType( type )
670 bool AntiSpamWizard::SpamToolConfig::isServerBased()
const
672 return !mServerPattern.isEmpty();
677 AntiSpamWizard::ConfigReader::ConfigReader(
WizardMode mode,
678 TQValueList<SpamToolConfig> & configList )
679 : mToolList( configList ),
682 if ( mMode == AntiSpam )
683 mConfig =
new TDEConfig(
"kmail.antispamrc",
true );
685 mConfig =
new TDEConfig(
"kmail.antivirusrc",
true );
688 AntiSpamWizard::ConfigReader::~ConfigReader( )
694 void AntiSpamWizard::ConfigReader::readAndMergeConfig()
696 TQString groupName = ( mMode == AntiSpam )
697 ? TQString(
"Spamtool #%1")
698 : TQString(
"Virustool #%1");
700 mConfig->setReadDefaults(
true );
701 TDEConfigGroup general( mConfig,
"General" );
702 int registeredTools = general.readNumEntry(
"tools", 0 );
703 for (
int i = 1; i <= registeredTools; i++)
705 TDEConfigGroup toolConfig( mConfig, groupName.arg( i ) );
706 if( !toolConfig.readBoolEntry(
"HeadersOnly",
false ) )
707 mToolList.append( readToolConfig( toolConfig ) );
712 mConfig->setReadDefaults(
false );
713 TDEConfigGroup user_general( mConfig,
"General" );
714 int user_registeredTools = user_general.readNumEntry(
"tools", 0 );
715 for (
int i = 1; i <= user_registeredTools; i++)
717 TDEConfigGroup toolConfig( mConfig, groupName.arg( i ) );
718 if( !toolConfig.readBoolEntry(
"HeadersOnly",
false ) )
719 mergeToolConfig( readToolConfig( toolConfig ) );
724 if ( mMode == AntiSpam ) {
725 if ( registeredTools < 1 && user_registeredTools < 1 )
726 mToolList.append( createDummyConfig() );
733 AntiSpamWizard::ConfigReader::readToolConfig( TDEConfigGroup & configGroup )
735 TQString
id = configGroup.readEntry(
"Ident" );
736 int version = configGroup.readNumEntry(
"Version" );
738 kdDebug(5006) <<
"Found predefined tool: " <<
id << endl;
739 kdDebug(5006) <<
"With config version : " << version << endl;
741 int prio = configGroup.readNumEntry(
"Priority", 1 );
742 TQString name = configGroup.readEntry(
"VisibleName" );
743 TQString executable = configGroup.readEntry(
"Executable" );
744 TQString url = configGroup.readEntry(
"URL" );
745 TQString filterName = configGroup.readEntry(
"PipeFilterName" );
746 TQString detectCmd = configGroup.readEntry(
"PipeCmdDetect" );
747 TQString spamCmd = configGroup.readEntry(
"ExecCmdSpam" );
748 TQString hamCmd = configGroup.readEntry(
"ExecCmdHam" );
749 TQString header = configGroup.readEntry(
"DetectionHeader" );
750 TQString pattern = configGroup.readEntry(
"DetectionPattern" );
751 TQString pattern2 = configGroup.readEntry(
"DetectionPattern2" );
752 TQString serverPattern = configGroup.readEntry(
"ServerPattern" );
753 bool detectionOnly = configGroup.readBoolEntry(
"DetectionOnly",
false );
754 bool useRegExp = configGroup.readBoolEntry(
"UseRegExp" );
755 bool supportsBayes = configGroup.readBoolEntry(
"SupportsBayes",
false );
756 bool supportsUnsure = configGroup.readBoolEntry(
"SupportsUnsure",
false );
757 return SpamToolConfig(
id, version, prio, name, executable, url,
758 filterName, detectCmd, spamCmd, hamCmd,
759 header, pattern, pattern2, serverPattern,
760 detectionOnly, useRegExp,
761 supportsBayes, supportsUnsure, mMode );
767 return SpamToolConfig(
"spamassassin", 0, 1,
768 "SpamAssassin",
"spamassassin -V",
769 "http://spamassassin.org",
"SpamAssassin Check",
771 "sa-learn -L --spam --no-rebuild --single",
772 "sa-learn -L --ham --no-rebuild --single",
773 "X-Spam-Flag",
"yes",
"",
"",
774 false,
false,
true,
false, AntiSpam );
781 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
782 it != mToolList.end(); ++it ) {
784 kdDebug(5006) <<
"Check against tool: " << (*it).getId() << endl;
785 kdDebug(5006) <<
"Against version : " << (*it).getVersion() << endl;
787 if ( (*it).getId() == config.getId() )
790 if ( (*it).getVersion() < config.getVersion() )
793 kdDebug(5006) <<
"Replacing config ..." << endl;
795 mToolList.remove( it );
796 mToolList.append( config );
802 mToolList.append( config );
806 void AntiSpamWizard::ConfigReader::sortToolList()
808 TQValueList<SpamToolConfig> tmpList;
809 SpamToolConfig config;
811 while ( !mToolList.isEmpty() ) {
812 TQValueListIterator<SpamToolConfig> highest;
814 for ( TQValueListIterator<SpamToolConfig> it = mToolList.begin();
815 it != mToolList.end(); ++it ) {
816 if ( (*it).getPrio() > priority ) {
817 priority = (*it).getPrio();
822 tmpList.append( config );
823 mToolList.remove( highest );
825 for ( TQValueListIterator<SpamToolConfig> it = tmpList.begin();
826 it != tmpList.end(); ++it ) {
827 mToolList.append( (*it) );
833 ASWizPage::ASWizPage( TQWidget * parent,
const char * name,
834 const TQString *bannerName )
835 : TQWidget( parent, name )
837 TQString banner =
"kmwizard.png";
838 if ( bannerName && !bannerName->isEmpty() )
839 banner = *bannerName;
841 mLayout =
new TQHBoxLayout(
this, KDialog::marginHint(), KDialog::spacingHint() );
842 mBannerLabel =
new TQLabel(
this );
843 mBannerLabel->setPixmap( UserIcon(banner) );
844 mBannerLabel->setScaledContents(
false );
845 mBannerLabel->setFrameShape( TQFrame::StyledPanel );
846 mBannerLabel->setFrameShadow( TQFrame::Sunken );
848 mLayout->addWidget( mBannerLabel );
849 mLayout->addItem(
new TQSpacerItem( 5, 5, TQSizePolicy::Minimum, TQSizePolicy::Expanding ) );
855 TQWidget * parent,
const char * name )
856 : ASWizPage( parent, name )
858 TQBoxLayout * layout =
new TQVBoxLayout( mLayout );
860 mIntroText =
new TQLabel(
this );
862 ( mode == AntiSpamWizard::AntiSpam )
864 "The wizard will search for any tools to do spam detection\n"
865 "and setup KMail to work with them."
868 "<p>Here you can get some assistance in setting up KMail's filter "
869 "rules to use some commonly-known anti-virus tools.</p>"
870 "<p>The wizard can detect those tools on your computer as "
871 "well as create filter rules to classify messages using these "
872 "tools and to separate messages containing viruses. "
873 "The wizard will not take any existing filter "
874 "rules into consideration: it will always append the new rules.</p>"
875 "<p><b>Warning:</b> As KMail appears to be frozen during the scan of the "
876 "messages for viruses, you may encounter problems with "
877 "the responsiveness of KMail because anti-virus tool "
878 "operations are usually time consuming; please consider "
879 "deleting the filter rules created by the wizard to get "
880 "back to the former behavior."
882 layout->addWidget( mIntroText );
884 mScanProgressText =
new TQLabel(
this );
885 mScanProgressText->setText(
"" ) ;
886 layout->addWidget( mScanProgressText );
888 mToolsList =
new TDEListBox(
this );
890 mToolsList->setSelectionMode( TQListBox::Multi );
891 mToolsList->setRowMode( TQListBox::FixedNumber );
892 mToolsList->setRowMode( 10 );
893 layout->addWidget( mToolsList );
894 connect( mToolsList, TQ_SIGNAL(selectionChanged()),
895 this, TQ_SLOT(processSelectionChange(
void)) );
897 mSelectionHint =
new TQLabel(
this );
898 mSelectionHint->setText(
"" );
899 layout->addWidget( mSelectionHint );
901 layout->addStretch();
905 void ASWizInfoPage::setScanProgressText(
const TQString &toolName )
907 mScanProgressText->setText( toolName );
911 void ASWizInfoPage::addAvailableTool(
const TQString &visibleName )
913 TQString listName = visibleName;
914 mToolsList->insertItem( listName );
915 if ( !mToolsList->isVisible() )
918 mToolsList->setSelected( 0,
true );
919 mSelectionHint->setText( i18n(
"<p>Please select the tools to be used "
920 "for the detection and go "
921 "to the next page.</p>") );
925 bool ASWizInfoPage::isProgramSelected(
const TQString &visibleName )
927 TQString listName = visibleName;
928 return mToolsList->isSelected( mToolsList->findItem( listName ) );
932 void ASWizInfoPage::processSelectionChange()
934 emit selectionChanged();
939 ASWizSpamRulesPage::ASWizSpamRulesPage( TQWidget * parent,
const char * name,
940 KMFolderTree * mainFolderTree )
941 : ASWizPage( parent, name )
943 TQVBoxLayout *layout =
new TQVBoxLayout( mLayout );
945 mMarkRules =
new TQCheckBox( i18n(
"&Mark detected spam messages as read"),
this );
946 TQWhatsThis::add( mMarkRules,
947 i18n(
"Mark messages which have been classified as spam as read.") );
948 layout->addWidget( mMarkRules);
950 mMoveSpamRules =
new TQCheckBox( i18n(
"Move &known spam to:"),
this );
951 TQWhatsThis::add( mMoveSpamRules,
952 i18n(
"The default folder for spam messages is the trash folder, "
953 "but you may change that in the folder view below.") );
954 layout->addWidget( mMoveSpamRules );
957 mFolderReqForSpamFolder->setFolder(
"trash" );
958 mFolderReqForSpamFolder->setMustBeReadWrite(
true );
959 mFolderReqForSpamFolder->setShowOutbox(
false );
960 mFolderReqForSpamFolder->setShowImapFolders(
false );
962 TQHBoxLayout *hLayout1 =
new TQHBoxLayout( layout );
963 hLayout1->addSpacing( KDialog::spacingHint() * 3 );
964 hLayout1->addWidget( mFolderReqForSpamFolder );
966 mMoveUnsureRules =
new TQCheckBox( i18n(
"Move &probable spam to:"),
this );
967 TQWhatsThis::add( mMoveUnsureRules,
968 i18n(
"The default folder is the inbox folder, but you may change that "
969 "in the folder view below.<p>"
970 "Not all tools support a classification as unsure. If you haven't "
971 "selected a capable tool, you can't select a folder as well.") );
972 layout->addWidget( mMoveUnsureRules );
974 mFolderReqForUnsureFolder =
new FolderRequester(
this, mainFolderTree );
975 mFolderReqForUnsureFolder->setFolder(
"inbox" );
976 mFolderReqForUnsureFolder->setMustBeReadWrite(
true );
977 mFolderReqForUnsureFolder->setShowOutbox(
false );
978 mFolderReqForUnsureFolder->setShowImapFolders(
false );
980 TQHBoxLayout *hLayout2 =
new TQHBoxLayout( layout );
981 hLayout2->addSpacing( KDialog::spacingHint() * 3 );
982 hLayout2->addWidget( mFolderReqForUnsureFolder );
984 layout->addStretch();
986 connect( mMarkRules, TQ_SIGNAL(clicked()),
987 this, TQ_SLOT(processSelectionChange(
void)) );
988 connect( mMoveSpamRules, TQ_SIGNAL(clicked()),
989 this, TQ_SLOT(processSelectionChange(
void)) );
990 connect( mMoveUnsureRules, TQ_SIGNAL(clicked()),
991 this, TQ_SLOT(processSelectionChange(
void)) );
992 connect( mFolderReqForSpamFolder, TQ_SIGNAL(folderChanged(
KMFolder*)),
993 this, TQ_SLOT(processSelectionChange(
KMFolder*)) );
994 connect( mFolderReqForUnsureFolder, TQ_SIGNAL(folderChanged(
KMFolder*)),
995 this, TQ_SLOT(processSelectionChange(
KMFolder*)) );
997 mMarkRules->setChecked(
true );
998 mMoveSpamRules->setChecked(
true );
1002 bool ASWizSpamRulesPage::markAsReadSelected()
const
1004 return mMarkRules->isChecked();
1008 bool ASWizSpamRulesPage::moveSpamSelected()
const
1010 return mMoveSpamRules->isChecked();
1014 bool ASWizSpamRulesPage::moveUnsureSelected()
const
1016 return mMoveUnsureRules->isChecked();
1020 TQString ASWizSpamRulesPage::selectedSpamFolderName()
const
1022 TQString name =
"trash";
1023 if ( mFolderReqForSpamFolder->folder() )
1024 name = mFolderReqForSpamFolder->folder()->idString();
1029 TQString ASWizSpamRulesPage::selectedUnsureFolderName()
const
1031 TQString name =
"inbox";
1032 if ( mFolderReqForUnsureFolder->folder() )
1033 name = mFolderReqForUnsureFolder->folder()->idString();
1038 void ASWizSpamRulesPage::processSelectionChange()
1040 mFolderReqForSpamFolder->setEnabled( mMoveSpamRules->isChecked() );
1041 mFolderReqForUnsureFolder->setEnabled( mMoveUnsureRules->isChecked() );
1042 emit selectionChanged();
1046 void ASWizSpamRulesPage::processSelectionChange(
KMFolder* )
1048 processSelectionChange();
1052 void ASWizSpamRulesPage::allowUnsureFolderSelection(
bool enabled )
1054 mMoveUnsureRules->setEnabled( enabled );
1055 mMoveUnsureRules->setShown( enabled );
1056 mFolderReqForUnsureFolder->setEnabled( enabled );
1057 mFolderReqForUnsureFolder->setShown( enabled );
1062 ASWizVirusRulesPage::ASWizVirusRulesPage( TQWidget * parent,
const char * name,
1063 KMFolderTree * mainFolderTree )
1064 : ASWizPage( parent, name )
1066 TQGridLayout *grid =
new TQGridLayout( mLayout, 5, 1, KDialog::spacingHint() );
1068 mPipeRules =
new TQCheckBox( i18n(
"Check messages using the anti-virus tools"),
this );
1069 TQWhatsThis::add( mPipeRules,
1070 i18n(
"Let the anti-virus tools check your messages. The wizard "
1071 "will create appropriate filters. The messages are usually "
1072 "marked by the tools so that following filters can react "
1073 "on this and, for example, move virus messages to a special folder.") );
1074 grid->addWidget( mPipeRules, 0, 0 );
1076 mMoveRules =
new TQCheckBox( i18n(
"Move detected viral messages to the selected folder"),
this );
1077 TQWhatsThis::add( mMoveRules,
1078 i18n(
"A filter to detect messages classified as virus-infected and to move "
1079 "those messages into a predefined folder is created. The "
1080 "default folder is the trash folder, but you may change that "
1081 "in the folder view.") );
1082 grid->addWidget( mMoveRules, 1, 0 );
1084 mMarkRules =
new TQCheckBox( i18n(
"Additionally, mark detected viral messages as read"),
this );
1085 mMarkRules->setEnabled(
false );
1086 TQWhatsThis::add( mMarkRules,
1087 i18n(
"Mark messages which have been classified as "
1088 "virus-infected as read, as well as moving them "
1089 "to the selected folder.") );
1090 grid->addWidget( mMarkRules, 2, 0 );
1092 TQString s =
"trash";
1093 mFolderTree =
new SimpleFolderTree(
this, mainFolderTree, s,
true );
1094 grid->addWidget( mFolderTree, 3, 0 );
1096 connect( mPipeRules, TQ_SIGNAL(clicked()),
1097 this, TQ_SLOT(processSelectionChange(
void)) );
1098 connect( mMoveRules, TQ_SIGNAL(clicked()),
1099 this, TQ_SLOT(processSelectionChange(
void)) );
1100 connect( mMarkRules, TQ_SIGNAL(clicked()),
1101 this, TQ_SLOT(processSelectionChange(
void)) );
1102 connect( mMoveRules, TQ_SIGNAL( toggled(
bool ) ),
1103 mMarkRules, TQ_SLOT( setEnabled(
bool ) ) );
1106 bool ASWizVirusRulesPage::pipeRulesSelected()
const
1108 return mPipeRules->isChecked();
1112 bool ASWizVirusRulesPage::moveRulesSelected()
const
1114 return mMoveRules->isChecked();
1117 bool ASWizVirusRulesPage::markReadRulesSelected()
const
1119 return mMarkRules->isChecked();
1123 TQString ASWizVirusRulesPage::selectedFolderName()
const
1125 TQString name =
"trash";
1126 if ( mFolderTree->folder() )
1127 name = mFolderTree->folder()->idString();
1131 void ASWizVirusRulesPage::processSelectionChange()
1133 emit selectionChanged();
1138 ASWizSummaryPage::ASWizSummaryPage( TQWidget * parent,
const char * name )
1139 : ASWizPage( parent, name )
1141 TQBoxLayout * layout =
new TQVBoxLayout( mLayout );
1143 mSummaryText =
new TQLabel(
this );
1144 layout->addWidget( mSummaryText );
1145 layout->addStretch();
1149 void ASWizSummaryPage::setSummaryText(
const TQString & text )
1151 mSummaryText->setText( text );
1155 #include "antispamwizard.moc"
sets a cursor and makes sure it's restored on destruction Create a KCursorSaver object when you want ...
Dictionary that contains a list of all registered filter actions with their creation functions.
Abstract base class for KMail's filter actions.
virtual void argsFromString(const TQString argsStr)=0
Read extra arguments from given string.
static KMKernel * self()
normal control stuff
This class is an abstraction of a search over messages.
void setOp(KMSearchPattern::Operator aOp)
Set the filter operator.
void setName(const TQString &newName)
Set the name of the search pattern.
static KMSearchRule * createInstance(const TQCString &field=0, Function function=FuncContains, const TQString &contents=TQString())
Create a search rule of a certain type by instantiating the appro- priate subclass depending on the f...
The account manager is responsible for creating accounts of various types via the factory method crea...
const KMAccount * first() const
First account of the list.
const KMAccount * next() const
Next account of the list.
Instances of this class control reading the configuration of the anti-spam tools from global and user...
void slotBuildSummary()
Create the summary text based on the current settings.
void checkToolAvailability()
Check if the spam tools are available via the PATH.
void checkProgramsSelections()
Modify the status of the wizard to reflect the selection of spam tools.
AntiSpamWizard(WizardMode mode, TQWidget *parent, KMFolderTree *mainFolderTree)
Constructor that needs to initialize from the main folder tree of KMail.
WizardMode
The wizard can be used for setting up anti-spam tools and for setting up anti-virus tools.
void checkVirusRulesSelections()
Modify the status of the wizard to reflect the selected functionality.
void slotHelpClicked()
Show a help topic.
void accept()
Evaluate the settings made and create the appropriate filter rules.
A widget that contains a KLineEdit which shows the current folder and a button that fires a KMFolderS...