• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
  • antispam-virus
antispamwizard.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KMail.
3  Copyright (c) 2003 Andreas Gungl <a.gungl@gmx.de>
4 
5  KMail is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License, version 2, as
7  published by the Free Software Foundation.
8 
9  KMail is distributed in the hope that it will be useful, but
10  WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 
18  In addition, as a special exception, the copyright holders give
19  permission to link the code of this program with any edition of
20  the Qt library by Trolltech AS, Norway (or with modified versions
21  of Qt that use the same license as Qt), and distribute linked
22  combinations including the two. You must obey the GNU General
23  Public License in all respects for all of the code used other than
24  Qt. If you modify this file, you may extend this exception to
25  your version of the file, but you are not obligated to do so. If
26  you do not wish to do so, delete this exception statement from
27  your version.
28 */
29 
30 
31 #include "antispamwizard.h"
32 #ifndef QT_NO_CURSOR
33 #include "messageviewer/utils/kcursorsaver.h"
34 #endif
35 #include "kmkernel.h"
36 #include "kmmainwin.h"
37 #include "folderrequester.h"
38 #include "foldertreewidget.h"
39 #include "foldertreeview.h"
40 #include "foldertreewidgetproxymodel.h"
41 #include "mailcommon/pop3settings.h"
42 #include "mailcommon/util/mailutil.h"
43 #include "pimcommon/imapresourcesettings.h"
44 #include "mailcommon/kernel/mailkernel.h"
45 #include "mailcommon/filter/mailfilter.h"
46 #include "mailcommon/filter/filteraction.h"
47 #include "mailcommon/filter/filteractiondict.h"
48 #include "mailcommon/filter/filtermanager.h"
49 
50 #include "pimcommon/util/pimutil.h"
51 
52 #include <Akonadi/AgentInstance>
53 
54 #include <kdebug.h>
55 #include <kdialog.h>
56 #include <kiconloader.h>
57 #include <klocale.h>
58 #include <KProcess>
59 #include <ktoolinvocation.h>
60 #include <kconfiggroup.h>
61 
62 #include <QLabel>
63 #include <QTextEdit>
64 #include <QTimer>
65 #include <QGridLayout>
66 #include <QHBoxLayout>
67 #include <QBoxLayout>
68 #include <QVBoxLayout>
69 #include <QCheckBox>
70 #include <QListWidget>
71 
72 using namespace KMail;
73 using namespace MailCommon;
74 
75 AntiSpamWizard::AntiSpamWizard( WizardMode mode,
76  QWidget* parent )
77  : KAssistantDialog( parent ),
78  mInfoPage( 0 ),
79  mSpamRulesPage( 0 ),
80  mVirusRulesPage( 0 ),
81  mSummaryPage( 0 ),
82  mMode( mode )
83 {
84  // read the configuration for the anti-spam tools
85  ConfigReader reader( mMode, mToolList );
86  reader.readAndMergeConfig();
87  mToolList = reader.getToolList();
88 
89 #ifndef NDEBUG
90  if ( mMode == AntiSpam )
91  kDebug() << endl <<"Considered anti-spam tools:";
92  else
93  kDebug() << endl <<"Considered anti-virus tools:";
94  QList<SpamToolConfig>::ConstIterator end( mToolList.constEnd() );
95  for ( QList<SpamToolConfig>::ConstIterator it = mToolList.constBegin();
96  it != end; ++it ) {
97  kDebug() << "Predefined tool:" << (*it).getId();
98  kDebug() << "Config version:" << (*it).getVersion();
99  kDebug() << "Selection priority:" << (*it).getPrio();
100  kDebug() << "Displayed name:" << (*it).getVisibleName();
101  kDebug() << "Executable:" << (*it).getExecutable();
102  kDebug() << "WhatsThis URL:" << (*it).getWhatsThisText();
103  kDebug() << "Filter name:" << (*it).getFilterName();
104  kDebug() << "Detection command:" << (*it).getDetectCmd();
105  kDebug() << "Learn spam command:" << (*it).getSpamCmd();
106  kDebug() << "Learn ham command:" << (*it).getHamCmd();
107  kDebug() << "Detection header:" << (*it).getDetectionHeader();
108  kDebug() << "Detection pattern:" << (*it).getDetectionPattern();
109  kDebug() << "Use as RegExp:" << (*it).isUseRegExp();
110  kDebug() << "Supports Bayes Filter:" << (*it).useBayesFilter();
111  kDebug() << "Type:" << (*it).getType();
112  }
113 #endif
114 
115  const bool isAntiSpam = (mMode == AntiSpam);
116  setWindowTitle( isAntiSpam ? i18n( "Anti-Spam Wizard" )
117  : i18n( "Anti-Virus Wizard" ) );
118  mInfoPage = new ASWizInfoPage( mMode, 0, QString() );
119  mInfoPageItem = addPage( mInfoPage,
120  isAntiSpam
121  ? i18n( "Welcome to the KMail Anti-Spam Wizard" )
122  : i18n( "Welcome to the KMail Anti-Virus Wizard" ) );
123  connect( mInfoPage, SIGNAL(selectionChanged()),
124  this, SLOT(checkProgramsSelections()) );
125 
126  if ( isAntiSpam ) {
127  mSpamRulesPage = new ASWizSpamRulesPage( 0, QString() );
128  mSpamRulesPageItem = addPage( mSpamRulesPage, i18n( "Options to fine-tune the handling of spam messages" ));
129  connect( mSpamRulesPage, SIGNAL(selectionChanged()),
130  this, SLOT(slotBuildSummary()) );
131 
132  mSummaryPage = new ASWizSummaryPage( 0, QString() );
133  mSummaryPageItem = addPage( mSummaryPage, i18n( "Summary of changes to be made by this wizard" ) );
134  } else {
135  mVirusRulesPage = new ASWizVirusRulesPage( 0, QString() );
136  mVirusRulesPageItem = addPage( mVirusRulesPage, i18n( "Options to fine-tune the handling of virus messages" ));
137  connect( mVirusRulesPage, SIGNAL(selectionChanged()),
138  this, SLOT(checkVirusRulesSelections()) );
139  }
140 
141  connect( this, SIGNAL(helpClicked()),
142  this, SLOT(slotHelpClicked()) );
143 
144  QTimer::singleShot( 0, this, SLOT(checkToolAvailability()) );
145 }
146 
147 
148 void AntiSpamWizard::accept()
149 {
150  if ( mSpamRulesPage ) {
151  kDebug() << "Folder name for messages classified as spam is"
152  << mSpamRulesPage->selectedSpamCollectionId();
153  kDebug() << "Folder name for messages classified as unsure is"
154  << mSpamRulesPage->selectedUnsureCollectionId();
155  }
156  if ( mVirusRulesPage ) {
157  kDebug() << "Folder name for viruses is"
158  << mVirusRulesPage->selectedFolderName();
159  }
160 
161  FilterActionDict dict;
162  QList<MailFilter*> filterList;
163  bool replaceExistingFilters = false;
164 
165  // Let's start with virus detection and handling,
166  // so we can avoid spam checks for viral messages
167  if ( mMode == AntiVirus ) {
168  if ( !mVirusToolsUsed ) {
169  KDialog::accept();
170  return;
171  }
172  QList<SpamToolConfig>::const_iterator end( mToolList.constEnd() );
173  for ( QList<SpamToolConfig>::const_iterator it = mToolList.constBegin();
174  it != end; ++it ) {
175  if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) &&
176  ( mVirusRulesPage->pipeRulesSelected() && (*it).isVirusTool() ) ) {
177  // pipe messages through the anti-virus tools,
178  // one single filter for each tool
179  // (could get combined but so it's easier to understand for the user)
180  MailFilter* pipeFilter = new MailFilter();
181  QList<FilterAction*> *pipeFilterActions = pipeFilter->actions();
182  FilterAction* pipeFilterAction = dict.value( QLatin1String("filter app") )->create();
183  pipeFilterAction->argsFromString( (*it).getDetectCmd() );
184  pipeFilterActions->append( pipeFilterAction );
185  SearchPattern* pipeFilterPattern = pipeFilter->pattern();
186  pipeFilterPattern->setName( uniqueNameFor( (*it).getFilterName() ) );
187  pipeFilterPattern->append( SearchRule::createInstance( "<size>",
188  SearchRule::FuncIsGreaterOrEqual, QLatin1String("0") ) );
189  pipeFilter->setApplyOnOutbound( false);
190  pipeFilter->setApplyOnInbound();
191  pipeFilter->setApplyOnExplicit();
192  pipeFilter->setStopProcessingHere( false );
193  pipeFilter->setConfigureShortcut( false );
194 
195  filterList.append( pipeFilter );
196  }
197  }
198 
199  if ( mVirusRulesPage->moveRulesSelected() ) {
200  // Sort out viruses depending on header fields set by the tools
201  MailFilter* virusFilter = new MailFilter();
202  QList<FilterAction*> *virusFilterActions = virusFilter->actions();
203  FilterAction* virusFilterAction1 = dict.value( QLatin1String("transfer") )->create();
204  virusFilterAction1->argsFromString( mVirusRulesPage->selectedFolderName() );
205  virusFilterActions->append( virusFilterAction1 );
206  if ( mVirusRulesPage->markReadRulesSelected() ) {
207  FilterAction* virusFilterAction2 = dict.value( QLatin1String("set status" ))->create();
208  virusFilterAction2->argsFromString( QLatin1String("R") ); // Read
209  virusFilterActions->append( virusFilterAction2 );
210  }
211  SearchPattern* virusFilterPattern = virusFilter->pattern();
212  virusFilterPattern->setName( uniqueNameFor( i18n( "Virus handling" ) ) );
213  virusFilterPattern->setOp( SearchPattern::OpOr );
214  QList<SpamToolConfig>::ConstIterator endSpamTool( mToolList.constEnd() );
215  for ( QList<SpamToolConfig>::ConstIterator it = mToolList.constBegin();
216  it != endSpamTool; ++it ) {
217  if ( mInfoPage->isProgramSelected( (*it).getVisibleName() )) {
218  if ( (*it).isVirusTool() ) {
219  const QByteArray header = (*it).getDetectionHeader().toLatin1();
220  const QString & pattern = (*it).getDetectionPattern();
221  if ( (*it).isUseRegExp() )
222  virusFilterPattern->append(
223  SearchRule::createInstance( header,
224  SearchRule::FuncRegExp, pattern ) );
225  else
226  virusFilterPattern->append(
227  SearchRule::createInstance( header,
228  SearchRule::FuncContains, pattern ) );
229  }
230  }
231  }
232  virusFilter->setApplyOnOutbound( false);
233  virusFilter->setApplyOnInbound();
234  virusFilter->setApplyOnExplicit();
235  virusFilter->setStopProcessingHere( true );
236  virusFilter->setConfigureShortcut( false );
237 
238  filterList.append( virusFilter );
239  }
240  } else { // AntiSpam mode
241  if ( !mSpamToolsUsed ) {
242  KDialog::accept();
243  return;
244  }
245  // TODO Existing filters with same name are replaced. This is hardcoded
246  // ATM and needs to be replaced with a value from a (still missing)
247  // checkbox in the GUI. At least, the replacement is announced in the GUI.
248  replaceExistingFilters = true;
249  QList<SpamToolConfig>::ConstIterator end( mToolList.constEnd() );
250  for ( QList<SpamToolConfig>::ConstIterator it = mToolList.constBegin();
251  it != end; ++it ) {
252  if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) &&
253  (*it).isSpamTool() && !(*it).isDetectionOnly() ) {
254  // pipe messages through the anti-spam tools,
255  // one single filter for each tool
256  // (could get combined but so it's easier to understand for the user)
257  MailFilter* pipeFilter = new MailFilter();
258  QList<FilterAction*> *pipeFilterActions = pipeFilter->actions();
259  FilterAction* pipeFilterAction = dict.value(QLatin1String("filter app") )->create();
260  pipeFilterAction->argsFromString( (*it).getDetectCmd() );
261  pipeFilterActions->append( pipeFilterAction );
262  SearchPattern* pipeFilterPattern = pipeFilter->pattern();
263  if ( replaceExistingFilters )
264  pipeFilterPattern->setName( (*it).getFilterName() );
265  else
266  pipeFilterPattern->setName( uniqueNameFor( (*it).getFilterName() ) );
267  pipeFilterPattern->append( SearchRule::createInstance( "<size>",
268  SearchRule::FuncIsLessOrEqual, QLatin1String("256000") ) );
269  pipeFilter->setApplyOnOutbound( false);
270  pipeFilter->setApplyOnInbound();
271  pipeFilter->setApplyOnExplicit();
272  pipeFilter->setStopProcessingHere( false );
273  pipeFilter->setConfigureShortcut( false );
274 
275  filterList.append( pipeFilter );
276  }
277  }
278 
279  // Sort out spam depending on header fields set by the tools
280  MailFilter* spamFilter = new MailFilter();
281  QList<FilterAction*> *spamFilterActions = spamFilter->actions();
282  if ( mSpamRulesPage->moveSpamSelected() ) {
283  FilterAction* spamFilterAction1 = dict.value( QLatin1String("transfer") )->create();
284  spamFilterAction1->argsFromString( mSpamRulesPage->selectedSpamCollectionId() );
285  spamFilterActions->append( spamFilterAction1 );
286  }
287  FilterAction* spamFilterAction2 = dict.value( QLatin1String("set status") )->create();
288  spamFilterAction2->argsFromString( QLatin1String("P") ); // Spam
289  spamFilterActions->append( spamFilterAction2 );
290  if ( mSpamRulesPage->markAsReadSelected() ) {
291  FilterAction* spamFilterAction3 = dict.value( QLatin1String("set status") )->create();
292  spamFilterAction3->argsFromString( QLatin1String("R") ); // Read
293  spamFilterActions->append( spamFilterAction3 );
294  }
295  SearchPattern* spamFilterPattern = spamFilter->pattern();
296  if ( replaceExistingFilters )
297  spamFilterPattern->setName( i18n( "Spam Handling" ) );
298  else
299  spamFilterPattern->setName( uniqueNameFor( i18n( "Spam Handling" ) ) );
300  spamFilterPattern->setOp( SearchPattern::OpOr );
301  QList<SpamToolConfig>::ConstIterator endToolList( mToolList.constEnd() );
302  for ( QList<SpamToolConfig>::ConstIterator it = mToolList.constBegin();
303  it != endToolList; ++it ) {
304  if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) ) {
305  if ( (*it).isSpamTool() ) {
306  const QByteArray header = (*it).getDetectionHeader().toLatin1();
307  const QString & pattern = (*it).getDetectionPattern();
308  if ( (*it).isUseRegExp() )
309  spamFilterPattern->append(
310  SearchRule::createInstance( header,
311  SearchRule::FuncRegExp, pattern ) );
312  else
313  spamFilterPattern->append(
314  SearchRule::createInstance( header,
315  SearchRule::FuncContains, pattern ) );
316  }
317  }
318  }
319  spamFilter->setApplyOnOutbound( false);
320  spamFilter->setApplyOnInbound();
321  spamFilter->setApplyOnExplicit();
322  spamFilter->setStopProcessingHere( true );
323  spamFilter->setConfigureShortcut( false );
324  filterList.append( spamFilter );
325 
326  if ( mSpamRulesPage->moveUnsureSelected() ) {
327  // Sort out messages classified as unsure
328  bool atLeastOneUnsurePattern = false;
329  MailFilter* unsureFilter = new MailFilter();
330  QList<FilterAction*> *unsureFilterActions = unsureFilter->actions();
331  FilterAction* unsureFilterAction1 = dict.value( QLatin1String("transfer") )->create();
332  unsureFilterAction1->argsFromString( mSpamRulesPage->selectedUnsureCollectionId() );
333  unsureFilterActions->append( unsureFilterAction1 );
334  SearchPattern* unsureFilterPattern = unsureFilter->pattern();
335  if ( replaceExistingFilters )
336  unsureFilterPattern->setName( i18n( "Semi spam (unsure) handling" ) );
337  else
338  unsureFilterPattern->setName( uniqueNameFor( i18n( "Semi spam (unsure) handling" ) ) );
339  unsureFilterPattern->setOp( SearchPattern::OpOr );
340  QList<SpamToolConfig>::ConstIterator end( mToolList.constEnd() );
341  for ( QList<SpamToolConfig>::ConstIterator it = mToolList.constBegin();
342  it != end; ++it ) {
343  if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) )
344  {
345  if ( (*it).isSpamTool() && (*it).hasTristateDetection())
346  {
347  atLeastOneUnsurePattern = true;
348  const QByteArray header = (*it).getDetectionHeader().toLatin1();
349  const QString & pattern = (*it).getDetectionPattern2();
350  if ( (*it).isUseRegExp() )
351  unsureFilterPattern->append(
352  SearchRule::createInstance( header,
353  SearchRule::FuncRegExp, pattern ) );
354  else
355  unsureFilterPattern->append(
356  SearchRule::createInstance( header,
357  SearchRule::FuncContains, pattern ) );
358  }
359  }
360  }
361  unsureFilter->setApplyOnOutbound( false);
362  unsureFilter->setApplyOnInbound();
363  unsureFilter->setApplyOnExplicit();
364  unsureFilter->setStopProcessingHere( true );
365  unsureFilter->setConfigureShortcut( false );
366 
367  if ( atLeastOneUnsurePattern )
368  filterList.append( unsureFilter );
369  else
370  delete unsureFilter;
371  }
372 
373  // Classify messages manually as Spam
374  MailFilter* classSpamFilter = new MailFilter();
375  classSpamFilter->setIcon( QLatin1String("mail-mark-junk") );
376  QList<FilterAction*> *classSpamFilterActions = classSpamFilter->actions();
377  FilterAction* classSpamFilterActionFirst = dict.value( QLatin1String("set status") )->create();
378  classSpamFilterActionFirst->argsFromString( QLatin1String("P") );
379  classSpamFilterActions->append( classSpamFilterActionFirst );
380  QList<SpamToolConfig>::ConstIterator endToolList2( mToolList.constEnd() );
381  for ( QList<SpamToolConfig>::ConstIterator it = mToolList.constBegin();
382  it != endToolList2; ++it ) {
383  if ( mInfoPage->isProgramSelected( (*it).getVisibleName() )
384  && (*it).useBayesFilter() && !(*it).isDetectionOnly() )
385  {
386  FilterAction* classSpamFilterAction = dict.value( QLatin1String("execute") )->create();
387  classSpamFilterAction->argsFromString( (*it).getSpamCmd() );
388  classSpamFilterActions->append( classSpamFilterAction );
389  }
390  }
391  if ( mSpamRulesPage->moveSpamSelected() ) {
392  FilterAction* classSpamFilterActionLast = dict.value( QLatin1String("transfer" ))->create();
393  classSpamFilterActionLast->argsFromString( mSpamRulesPage->selectedSpamCollectionId() );
394  classSpamFilterActions->append( classSpamFilterActionLast );
395  }
396 
397  SearchPattern* classSpamFilterPattern = classSpamFilter->pattern();
398  if ( replaceExistingFilters )
399  classSpamFilterPattern->setName( i18n( "Classify as Spam" ) );
400  else
401  classSpamFilterPattern->setName( uniqueNameFor( i18n( "Classify as Spam" ) ) );
402  classSpamFilterPattern->append( SearchRule::createInstance( "<size>",
403  SearchRule::FuncIsGreaterOrEqual, QLatin1String("0") ) );
404  classSpamFilter->setApplyOnOutbound( false);
405  classSpamFilter->setApplyOnInbound( false );
406  classSpamFilter->setApplyOnExplicit( false );
407  classSpamFilter->setStopProcessingHere( true );
408  classSpamFilter->setConfigureShortcut( true );
409  classSpamFilter->setConfigureToolbar( true );
410  classSpamFilter->setToolbarName( i18n( "Spam" ) );
411  filterList.append( classSpamFilter );
412 
413  // Classify messages manually as not Spam / as Ham
414  MailFilter* classHamFilter = new MailFilter();
415  classHamFilter->setIcon( QLatin1String("mail-mark-notjunk") );
416  QList<FilterAction*> *classHamFilterActions = classHamFilter->actions();
417  FilterAction* classHamFilterActionFirst = dict.value( QLatin1String("set status") )->create();
418  classHamFilterActionFirst->argsFromString( QLatin1String("H") );
419  classHamFilterActions->append( classHamFilterActionFirst );
420  end = mToolList.constEnd();
421  for ( QList<SpamToolConfig>::ConstIterator it = mToolList.constBegin();
422  it != end; ++it ) {
423  if ( mInfoPage->isProgramSelected( (*it).getVisibleName() )
424  && (*it).useBayesFilter() && !(*it).isDetectionOnly() )
425  {
426  FilterAction* classHamFilterAction = dict.value( QLatin1String("execute") )->create();
427  classHamFilterAction->argsFromString( (*it).getHamCmd() );
428  classHamFilterActions->append( classHamFilterAction );
429  }
430  }
431  end = mToolList.constEnd();
432  for ( QList<SpamToolConfig>::ConstIterator it = mToolList.constBegin();
433  it != end; ++it ) {
434  if ( mInfoPage->isProgramSelected( (*it).getVisibleName() )
435  && (*it).useBayesFilter() && !(*it).isDetectionOnly() )
436  {
437  FilterAction* classHamFilterAction = dict.value( QLatin1String("filter app") )->create();
438  classHamFilterAction->argsFromString( (*it).getNoSpamCmd() );
439  classHamFilterActions->append( classHamFilterAction );
440  }
441  }
442  SearchPattern* classHamFilterPattern = classHamFilter->pattern();
443  if ( replaceExistingFilters )
444  classHamFilterPattern->setName( i18n( "Classify as NOT Spam" ) );
445  else
446  classHamFilterPattern->setName( uniqueNameFor( i18n( "Classify as NOT Spam" ) ) );
447  classHamFilterPattern->append( SearchRule::createInstance( "<size>",
448  SearchRule::FuncIsGreaterOrEqual, QLatin1String("0") ) );
449  classHamFilter->setApplyOnOutbound( false);
450  classHamFilter->setApplyOnInbound( false );
451  classHamFilter->setApplyOnExplicit( false );
452  classHamFilter->setStopProcessingHere( true );
453  classHamFilter->setConfigureShortcut( true );
454  classHamFilter->setConfigureToolbar( true );
455  classHamFilter->setToolbarName( i18n( "Ham" ) );
456  filterList.append( classHamFilter );
457  }
458 
459  /* Now that all the filters have been added to the list, tell
460  * the filter manager about it. That will emit filterListUpdate
461  * which will result in the filter list in kmmainwidget being
462  * initialized. This should happend only once. */
463  if ( !filterList.isEmpty() )
464  MailCommon::FilterManager::instance()->appendFilters( filterList, replaceExistingFilters );
465 
466  KDialog::accept();
467 }
468 
469 
470 void AntiSpamWizard::checkProgramsSelections()
471 {
472  bool supportUnsure = false;
473 
474  mSpamToolsUsed = false;
475  mVirusToolsUsed = false;
476  QList<SpamToolConfig>::ConstIterator end( mToolList.constEnd() );
477  for ( QList<SpamToolConfig>::ConstIterator it = mToolList.constBegin();
478  it != end; ++it ) {
479  if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) ) {
480  if ( (*it).isSpamTool() ) {
481  mSpamToolsUsed = true;
482  if ( (*it).hasTristateDetection() )
483  supportUnsure = true;
484  }
485  if ( (*it).isVirusTool() )
486  mVirusToolsUsed = true;
487 
488  if ( mSpamToolsUsed && mVirusToolsUsed && supportUnsure )
489  break;
490  }
491  }
492 
493  if ( mMode == AntiSpam ) {
494  mSpamRulesPage->allowUnsureFolderSelection( supportUnsure );
495  mSpamRulesPage->allowMoveSpam( mSpamToolsUsed );
496  slotBuildSummary();
497  setAppropriate( mSpamRulesPageItem, mSpamToolsUsed );
498  setAppropriate( mSummaryPageItem, mSpamToolsUsed );
499  }
500  else if ( mMode == AntiVirus ) {
501  if ( mVirusToolsUsed )
502  checkVirusRulesSelections();
503  setAppropriate( mVirusRulesPageItem, mVirusToolsUsed );
504  }
505 }
506 
507 
508 void AntiSpamWizard::checkVirusRulesSelections()
509 {
510  //setFinishEnabled( mVirusRulesPage, anyVirusOptionChecked() );
511 }
512 
513 
514 void AntiSpamWizard::checkToolAvailability()
515 {
516  // this can take some time to find the tools
517 #ifndef QT_NO_CURSOR
518  MessageViewer::KCursorSaver busy( MessageViewer::KBusyPtr::busy() );
519 #endif
520  bool found = false;
521  QList<SpamToolConfig>::ConstIterator end( mToolList.constEnd() );
522  for ( QList<SpamToolConfig>::ConstIterator it = mToolList.constBegin();
523  it != end; ++it ) {
524  const QString text( i18n("Scanning for %1...", (*it).getId() ) );
525  mInfoPage->setScanProgressText( text );
526  if ( (*it).isSpamTool() && (*it).isServerBased() ) {
527  // check the configured account for pattern in <server>
528  QString pattern = (*it).getServerPattern();
529  kDebug() << "Testing for server pattern:" << pattern;
530  const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances();
531  foreach( const Akonadi::AgentInstance& type, lst ) {
532  if ( type.status() == Akonadi::AgentInstance::Broken )
533  continue;
534  if ( type.identifier().contains( IMAP_RESOURCE_IDENTIFIER ) ) {
535  OrgKdeAkonadiImapSettingsInterface *iface = PimCommon::Util::createImapSettingsInterface( type.identifier() );
536  if ( iface->isValid() ) {
537  const QString host = iface->imapServer();
538  if ( host.toLower().contains( pattern.toLower() ) ) {
539  mInfoPage->addAvailableTool( (*it).getVisibleName() );
540  found = true;
541  }
542  }
543  delete iface;
544  }
545  else if ( type.identifier().contains( POP3_RESOURCE_IDENTIFIER ) ) {
546  OrgKdeAkonadiPOP3SettingsInterface *iface = MailCommon::Util::createPop3SettingsInterface( type.identifier() );
547  if ( iface->isValid() ) {
548  const QString host = iface->host();
549  if ( host.toLower().contains( pattern.toLower() ) ) {
550  mInfoPage->addAvailableTool( (*it).getVisibleName() );
551  found = true;
552  }
553  }
554  delete iface;
555  }
556  }
557  }
558  else {
559  // check the availability of the application
560  qApp->processEvents( QEventLoop::ExcludeUserInputEvents, 200 );
561  if ( !checkForProgram( (*it).getExecutable() ) ) {
562  mInfoPage->addAvailableTool( (*it).getVisibleName() );
563  found = true;
564  }
565  }
566  }
567  if ( found )
568  mInfoPage->setScanProgressText( ( mMode == AntiSpam )
569  ? i18n("Scanning for anti-spam tools finished.")
570  : i18n("Scanning for anti-virus tools finished.") );
571  else {
572  mInfoPage->setScanProgressText( ( mMode == AntiSpam )
573  ? i18n("<p>Sorry, no spam detection tools have been found. "
574  "Install your spam detection software and "
575  "re-run this wizard.</p>")
576  : i18n("Scanning complete. No anti-virus tools found.") );
577  }
578  checkProgramsSelections();
579 }
580 
581 
582 void AntiSpamWizard::slotHelpClicked()
583 {
584  if ( mMode == AntiSpam )
585  KToolInvocation::invokeHelp( QLatin1String("the-anti-spam-wizard"), QLatin1String("kmail") );
586  else
587  KToolInvocation::invokeHelp( QLatin1String("the-anti-virus-wizard"), QLatin1String("kmail") );
588 }
589 
590 
591 void AntiSpamWizard::slotBuildSummary()
592 {
593  QString text;
594  QString newFilters;
595  QString replaceFilters;
596 
597  if ( mMode == AntiVirus ) {
598  text.clear(); // TODO add summary for the virus part
599  }
600  else { // AntiSpam mode
601  if ( mSpamRulesPage->markAsReadSelected() ) {
602  if ( mSpamRulesPage->moveSpamSelected() )
603  text = i18n( "<p>Messages classified as spam are marked as read."
604  "<br />Spam messages are moved into the folder named <i>%1</i>.</p>"
605  , mSpamRulesPage->selectedSpamCollectionName() );
606  else
607  text = i18n( "<p>Messages classified as spam are marked as read."
608  "<br />Spam messages are not moved into a certain folder.</p>" );
609  }
610  else {
611  if ( mSpamRulesPage->moveSpamSelected() )
612  text = i18n( "<p>Messages classified as spam are not marked as read."
613  "<br />Spam messages are moved into the folder named <i>%1</i>.</p>"
614  , mSpamRulesPage->selectedSpamCollectionName() );
615  else
616  text = i18n( "<p>Messages classified as spam are not marked as read."
617  "<br />Spam messages are not moved into a certain folder.</p>" );
618  }
619  QList<SpamToolConfig>::ConstIterator end( mToolList.constEnd() );
620  for ( QList<SpamToolConfig>::ConstIterator it = mToolList.constBegin();
621  it != end; ++it ) {
622  if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) &&
623  (*it).isSpamTool() && !(*it).isDetectionOnly() ) {
624  sortFilterOnExistance( (*it).getFilterName(), newFilters, replaceFilters );
625  }
626  }
627  sortFilterOnExistance( i18n( "Spam Handling" ), newFilters, replaceFilters );
628 
629  // The need for a andling of status "probably spam" depends on the tools chosen
630  if ( mSpamRulesPage->moveUnsureSelected() ) {
631  bool atLeastOneUnsurePattern = false;
632  end = mToolList.constEnd();
633  for ( QList<SpamToolConfig>::ConstIterator it = mToolList.constBegin();
634  it != end; ++it ) {
635  if ( mInfoPage->isProgramSelected( (*it).getVisibleName() ) ) {
636  if ( (*it).isSpamTool() && (*it).hasTristateDetection()) {
637  atLeastOneUnsurePattern = true;
638  break;
639  }
640  }
641  }
642  if ( atLeastOneUnsurePattern ) {
643  sortFilterOnExistance( i18n( "Semi spam (unsure) handling" ),
644  newFilters, replaceFilters );
645  text += i18n( "<p>The folder for messages classified as unsure (probably spam) is <i>%1</i>.</p>"
646  , mSpamRulesPage->selectedUnsureCollectionName() );
647  }
648  }
649 
650  // Manual classification via toolbar icon / manually applied filter action
651  sortFilterOnExistance( i18n( "Classify as Spam" ),
652  newFilters, replaceFilters );
653  sortFilterOnExistance( i18n( "Classify as NOT Spam" ),
654  newFilters, replaceFilters );
655 
656  // Show the filters in the summary
657  if ( !newFilters.isEmpty() )
658  text += i18n( "<p>The wizard will create the following filters:<ul>%1</ul></p>"
659  , newFilters );
660  if ( !replaceFilters.isEmpty() )
661  text += i18n( "<p>The wizard will replace the following filters:<ul>%1</ul></p>"
662  , replaceFilters );
663  }
664 
665  mSummaryPage->setSummaryText( text );
666 }
667 
668 
669 int AntiSpamWizard::checkForProgram( const QString &executable ) const
670 {
671  kDebug() << "Testing for executable:" << executable;
672  KProcess process;
673  process.setShellCommand( executable );
674  return process.execute ();
675 }
676 
677 
678 bool AntiSpamWizard::anyVirusOptionChecked() const
679 {
680  return ( mVirusRulesPage->moveRulesSelected()
681  || mVirusRulesPage->pipeRulesSelected() );
682 }
683 
684 
685 const QString AntiSpamWizard::uniqueNameFor( const QString & name )
686 {
687  return MailCommon::FilterManager::instance()->createUniqueFilterName( name );
688 }
689 
690 
691 void AntiSpamWizard::sortFilterOnExistance(
692  const QString & intendedFilterName,
693  QString & newFilters, QString & replaceFilters )
694 {
695  if ( uniqueNameFor( intendedFilterName ) == intendedFilterName )
696  newFilters += QLatin1String("<li>") + intendedFilterName + QLatin1String("</li>");
697  else
698  replaceFilters += QLatin1String("<li>") + intendedFilterName + QLatin1String("</li>");
699 }
700 
701 
702 //---------------------------------------------------------------------------
703 AntiSpamWizard::SpamToolConfig::SpamToolConfig( const QString &toolId,
704  int configVersion, int prio, const QString &name, const QString &exec,
705  const QString &url, const QString &filter, const QString &detection,
706  const QString &spam, const QString &ham, const QString &noSpam,
707  const QString &header, const QString &pattern, const QString &pattern2,
708  const QString &serverPattern, bool detectionOnly, bool regExp,
709  bool bayesFilter, bool tristateDetection, WizardMode type )
710  : mId( toolId ), mVersion( configVersion ), mPrio( prio ),
711  mVisibleName( name ), mExecutable( exec ), mWhatsThisText( url ),
712  mFilterName( filter ), mDetectCmd( detection ), mSpamCmd( spam ),
713  mHamCmd( ham ), mNoSpamCmd( noSpam ), mDetectionHeader( header ),
714  mDetectionPattern( pattern ), mDetectionPattern2( pattern2 ),
715  mServerPattern( serverPattern ), mDetectionOnly( detectionOnly ),
716  mUseRegExp( regExp ), mSupportsBayesFilter( bayesFilter ),
717  mSupportsUnsure( tristateDetection ), mType( type )
718 {
719 }
720 
721 
722 bool AntiSpamWizard::SpamToolConfig::isServerBased() const
723 {
724  return !mServerPattern.isEmpty();
725 }
726 
727 
728 //---------------------------------------------------------------------------
729 AntiSpamWizard::ConfigReader::ConfigReader( WizardMode mode,
730  QList<SpamToolConfig> & configList )
731  : mToolList( configList ),
732  mMode( mode )
733 {
734  if ( mMode == AntiSpam )
735  mConfig = KSharedConfig::openConfig( QLatin1String("kmail.antispamrc") );
736  else
737  mConfig = KSharedConfig::openConfig( QLatin1String("kmail.antivirusrc") );
738 }
739 
740 AntiSpamWizard::ConfigReader::~ConfigReader( )
741 {
742 }
743 
744 
745 void AntiSpamWizard::ConfigReader::readAndMergeConfig()
746 {
747  QString groupName = ( mMode == AntiSpam )
748  ? QString::fromLatin1("Spamtool #%1")
749  : QString::fromLatin1("Virustool #%1");
750  // read the configuration from the global config file
751  mConfig->setReadDefaults( true );
752  KConfigGroup general( mConfig, "General" );
753  const int registeredTools = general.readEntry( "tools", 0 );
754  for (int i = 1; i <= registeredTools; ++i)
755  {
756  KConfigGroup toolConfig( mConfig, groupName.arg( i ) );
757  if( !toolConfig.readEntry( "HeadersOnly", false ) )
758  mToolList.append( readToolConfig( toolConfig ) );
759  }
760 
761  // read the configuration from the user config file
762  // and merge newer config data
763  mConfig->setReadDefaults( false );
764  KConfigGroup user_general( mConfig, "General" );
765  const int user_registeredTools = user_general.readEntry( "tools", 0 );
766  for (int i = 1; i <= user_registeredTools; ++i)
767  {
768  KConfigGroup toolConfig( mConfig, groupName.arg( i ) );
769  if( !toolConfig.readEntry( "HeadersOnly", false ) )
770  mergeToolConfig( readToolConfig( toolConfig ) );
771  }
772  // Make sure to have add least one tool listed even when the
773  // config file was not found or whatever went wrong
774  // Currently only works for spam tools
775  if ( mMode == AntiSpam ) {
776  if ( registeredTools < 1 && user_registeredTools < 1 )
777  mToolList.append( createDummyConfig() );
778  sortToolList();
779  }
780 }
781 
782 
783 AntiSpamWizard::SpamToolConfig
784 AntiSpamWizard::ConfigReader::readToolConfig( KConfigGroup & configGroup )
785 {
786  const QString id = configGroup.readEntry( "Ident" );
787  const int version = configGroup.readEntry( "Version", 0 );
788 #ifndef NDEBUG
789  kDebug() << "Found predefined tool:" << id;
790  kDebug() << "With config version :" << version;
791 #endif
792  const int prio = configGroup.readEntry( "Priority", 1 );
793  const QString name = configGroup.readEntry( "VisibleName" );
794  const QString executable = configGroup.readEntry( "Executable" );
795  const QString url = configGroup.readEntry( "URL" );
796  const QString filterName = configGroup.readEntry( "PipeFilterName" );
797  const QString detectCmd = configGroup.readEntry( "PipeCmdDetect" );
798  const QString spamCmd = configGroup.readEntry( "ExecCmdSpam" );
799  const QString hamCmd = configGroup.readEntry( "ExecCmdHam" );
800  const QString noSpamCmd = configGroup.readEntry( "PipeCmdNoSpam" );
801  const QString header = configGroup.readEntry( "DetectionHeader" );
802  const QString pattern = configGroup.readEntry( "DetectionPattern" );
803  const QString pattern2 = configGroup.readEntry( "DetectionPattern2" );
804  const QString serverPattern = configGroup.readEntry( "ServerPattern" );
805  const bool detectionOnly = configGroup.readEntry( "DetectionOnly", false );
806  const bool useRegExp = configGroup.readEntry( "UseRegExp", false );
807  const bool supportsBayes = configGroup.readEntry( "SupportsBayes", false );
808  const bool supportsUnsure = configGroup.readEntry( "SupportsUnsure", false );
809  return SpamToolConfig( id, version, prio, name, executable, url,
810  filterName, detectCmd, spamCmd, hamCmd, noSpamCmd,
811  header, pattern, pattern2, serverPattern,
812  detectionOnly, useRegExp,
813  supportsBayes, supportsUnsure, mMode );
814 }
815 
816 
817 AntiSpamWizard::SpamToolConfig AntiSpamWizard::ConfigReader::createDummyConfig()
818 {
819  return SpamToolConfig( QLatin1String("spamassassin"), 0, 1,
820  QLatin1String("SpamAssassin"), QLatin1String("spamassassin -V"),
821  QLatin1String("http://spamassassin.org"), QLatin1String("SpamAssassin Check"),
822  QLatin1String("spamassassin -L"),
823  QLatin1String("sa-learn -L --spam --no-sync --single"),
824  QLatin1String("sa-learn -L --ham --no-sync --single"),
825  QLatin1String("spamassassin -d"),
826  QLatin1String("X-Spam-Flag"), QLatin1String("yes"), QString(), QString(),
827  false, false, true, false, AntiSpam );
828 }
829 
830 
831 void AntiSpamWizard::ConfigReader::mergeToolConfig( const AntiSpamWizard::SpamToolConfig &config )
832 {
833  bool found = false;
834  QList<SpamToolConfig>::Iterator end( mToolList.end() );
835  for ( QList<SpamToolConfig>::Iterator it = mToolList.begin();
836  it != end; ++it ) {
837 #ifndef NDEBUG
838  kDebug() << "Check against tool:" << (*it).getId();
839  kDebug() << "Against version :" << (*it).getVersion();
840 #endif
841  if ( (*it).getId() == config.getId() )
842  {
843  found = true;
844  if ( (*it).getVersion() < config.getVersion() )
845  {
846 #ifndef NDEBUG
847  kDebug() << "Replacing config ...";
848 #endif
849  mToolList.erase( it );
850  mToolList.append( config );
851  }
852  break;
853  }
854  }
855  if ( !found )
856  mToolList.append( config );
857 }
858 
859 
860 void AntiSpamWizard::ConfigReader::sortToolList()
861 {
862  QList<SpamToolConfig> tmpList;
863  SpamToolConfig config;
864 
865  while ( !mToolList.isEmpty() ) {
866  QList<SpamToolConfig>::Iterator highest;
867  int priority = 0; // ascending
868  QList<SpamToolConfig>::Iterator end( mToolList.end() );
869  for ( QList<SpamToolConfig>::Iterator it = mToolList.begin();
870  it != end; ++it ) {
871  if ( (*it).getPrio() > priority ) {
872  priority = (*it).getPrio();
873  highest = it;
874  }
875  }
876  config = (*highest);
877  tmpList.append( config );
878  mToolList.erase( highest );
879  }
880  QList<SpamToolConfig>::ConstIterator end( tmpList.constEnd() );
881  for ( QList<SpamToolConfig>::ConstIterator it = tmpList.constBegin();
882  it != end; ++it ) {
883  mToolList.append( (*it) );
884  }
885 }
886 
887 
888 //---------------------------------------------------------------------------
889 ASWizPage::ASWizPage( QWidget * parent, const QString & name,
890  const QString *bannerName )
891  : QWidget( parent )
892 {
893  setObjectName( name );
894  QString banner = QLatin1String("kmwizard.png");
895  if ( bannerName && !bannerName->isEmpty() )
896  banner = *bannerName;
897  mLayout = new QHBoxLayout( this );
898  mLayout->setSpacing( KDialog::spacingHint() );
899  mLayout->setMargin( KDialog::marginHint() );
900 
901  QVBoxLayout * sideLayout = new QVBoxLayout();
902  mLayout->addItem( sideLayout );
903  mLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
904 
905  mBannerLabel = new QLabel( this );
906  mBannerLabel->setPixmap( UserIcon(banner) );
907  mBannerLabel->setScaledContents( false );
908  mBannerLabel->setFrameShape( QFrame::StyledPanel );
909  mBannerLabel->setFrameShadow( QFrame::Sunken );
910  mBannerLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
911 
912  sideLayout->addWidget( mBannerLabel );
913  sideLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
914 }
915 
916 
917 //---------------------------------------------------------------------------
918 ASWizInfoPage::ASWizInfoPage(AntiSpamWizard::WizardMode mode,
919  QWidget * parent, const QString &name )
920  : ASWizPage( parent, name )
921 {
922  QBoxLayout * layout = new QVBoxLayout();
923  mLayout->addItem( layout );
924 
925  mIntroText = new QTextEdit( this );
926  mIntroText->setText(
927  ( mode == AntiSpamWizard::AntiSpam )
928  ? i18n(
929  "The wizard will search for any tools to do spam detection\n"
930  "and setup KMail to work with them."
931  )
932  : i18n(
933  "<p>Here you can get some assistance in setting up KMail's filter "
934  "rules to use some commonly-known anti-virus tools.</p>"
935  "<p>The wizard can detect those tools on your computer as "
936  "well as create filter rules to classify messages using these "
937  "tools and to separate messages containing viruses. "
938  "The wizard will not take any existing filter "
939  "rules into consideration: it will always append the new rules.</p>"
940  "<p><b>Warning:</b> As KMail appears to be frozen during the scan of the "
941  "messages for viruses, you may encounter problems with "
942  "the responsiveness of KMail because anti-virus tool "
943  "operations are usually time consuming; please consider "
944  "deleting the filter rules created by the wizard to get "
945  "back to the former behavior.</p>"
946  ) );
947  mIntroText->setReadOnly( true );
948  mIntroText->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
949  layout->addWidget( mIntroText );
950 
951  mScanProgressText = new QLabel( this );
952  mScanProgressText->clear();
953  mScanProgressText->setWordWrap( true );
954  layout->addWidget( mScanProgressText );
955 
956  mToolsList = new QListWidget( this );
957  mToolsList->hide();
958  mToolsList->setSelectionMode( QAbstractItemView::MultiSelection );
959  mToolsList->setLayoutMode( QListView::Batched );
960  mToolsList->setBatchSize( 10 );
961  mToolsList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum ) );
962  layout->addWidget( mToolsList );
963  connect( mToolsList->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
964  this, SLOT(processSelectionChange()) );
965 
966  mSelectionHint = new QLabel( this );
967  mSelectionHint->clear();
968  mSelectionHint->setWordWrap( true );
969  layout->addWidget( mSelectionHint );
970 }
971 
972 
973 void ASWizInfoPage::setScanProgressText( const QString &toolName )
974 {
975  mScanProgressText->setText( toolName );
976 }
977 
978 
979 void ASWizInfoPage::addAvailableTool( const QString &visibleName )
980 {
981  mToolsList->addItem( visibleName );
982  if ( !mToolsList->isVisible() )
983  {
984  mToolsList->show();
985  mToolsList->selectionModel()->clearSelection();
986  mToolsList->setCurrentRow( 0 );
987  mSelectionHint->setText( i18n("<p>Please select the tools to be used "
988  "for the detection and go "
989  "to the next page.</p>") );
990  }
991 }
992 
993 bool ASWizInfoPage::isProgramSelected( const QString &visibleName ) const
994 {
995  const QList<QListWidgetItem*> foundItems = mToolsList->findItems( visibleName, Qt::MatchFixedString );
996  return (!foundItems.isEmpty() && foundItems[0]->isSelected());
997 }
998 
999 
1000 void ASWizInfoPage::processSelectionChange()
1001 {
1002  emit selectionChanged();
1003 }
1004 
1005 
1006 //---------------------------------------------------------------------------
1007 ASWizSpamRulesPage::ASWizSpamRulesPage( QWidget * parent, const QString &name)
1008  : ASWizPage( parent, name )
1009 {
1010  QVBoxLayout *layout = new QVBoxLayout();
1011  mLayout->addItem( layout );
1012 
1013  mMarkRules = new QCheckBox( i18n("&Mark detected spam messages as read"), this );
1014  mMarkRules->setWhatsThis(
1015  i18n( "Mark messages which have been classified as spam as read.") );
1016  layout->addWidget( mMarkRules);
1017 
1018  mMoveSpamRules = new QCheckBox( i18n("Move &known spam to:"), this );
1019  mMoveSpamRules->setWhatsThis(
1020  i18n( "The default folder for spam messages is the trash folder, "
1021  "but you may change that in the folder view below.") );
1022  layout->addWidget( mMoveSpamRules );
1023 
1024  mFolderReqForSpamFolder = new FolderRequester( this );
1025  mFolderReqForSpamFolder->setCollection( CommonKernel->trashCollectionFolder() );
1026  mFolderReqForSpamFolder->setMustBeReadWrite( true );
1027  mFolderReqForSpamFolder->setShowOutbox( false );
1028 
1029  QHBoxLayout *hLayout1 = new QHBoxLayout();
1030  layout->addItem( hLayout1 );
1031  hLayout1->addSpacing( KDialog::spacingHint() * 3 );
1032  hLayout1->addWidget( mFolderReqForSpamFolder );
1033 
1034  mMoveUnsureRules = new QCheckBox( i18n("Move &probable spam to:"), this );
1035  mMoveUnsureRules->setWhatsThis(
1036  i18n( "The default folder is the inbox folder, but you may change that "
1037  "in the folder view below.<p>"
1038  "Not all tools support a classification as unsure. If you have not "
1039  "selected a capable tool, you cannot select a folder as well.</p>") );
1040  layout->addWidget( mMoveUnsureRules );
1041 
1042  mFolderReqForUnsureFolder = new FolderRequester( this );
1043  mFolderReqForUnsureFolder->setCollection( CommonKernel->inboxCollectionFolder() );
1044  mFolderReqForUnsureFolder->setMustBeReadWrite( true );
1045  mFolderReqForUnsureFolder->setShowOutbox( false );
1046 
1047  QHBoxLayout *hLayout2 = new QHBoxLayout();
1048  layout->addItem( hLayout2 );
1049  hLayout2->addSpacing( KDialog::spacingHint() * 3 );
1050  hLayout2->addWidget( mFolderReqForUnsureFolder );
1051 
1052  layout->addStretch();
1053 
1054  connect( mMarkRules, SIGNAL(clicked()),
1055  this, SLOT(processSelectionChange()) );
1056  connect( mMoveSpamRules, SIGNAL(clicked()),
1057  this, SLOT(processSelectionChange()) );
1058  connect( mMoveUnsureRules, SIGNAL(clicked()),
1059  this, SLOT(processSelectionChange()) );
1060  connect( mFolderReqForSpamFolder, SIGNAL(folderChanged(Akonadi::Collection)),
1061  this, SLOT(processSelectionChange(Akonadi::Collection)) );
1062  connect( mFolderReqForUnsureFolder, SIGNAL(folderChanged(Akonadi::Collection)),
1063  this, SLOT(processSelectionChange(Akonadi::Collection)) );
1064 
1065  mMarkRules->setChecked( true );
1066  mMoveSpamRules->setChecked( true );
1067 }
1068 
1069 
1070 bool ASWizSpamRulesPage::markAsReadSelected() const
1071 {
1072  return mMarkRules->isChecked();
1073 }
1074 
1075 
1076 bool ASWizSpamRulesPage::moveSpamSelected() const
1077 {
1078  return mMoveSpamRules->isChecked();
1079 }
1080 
1081 
1082 bool ASWizSpamRulesPage::moveUnsureSelected() const
1083 {
1084  return mMoveUnsureRules->isChecked();
1085 }
1086 
1087 QString ASWizSpamRulesPage::selectedSpamCollectionId() const
1088 {
1089  return QString::number( selectedSpamCollection().id() );
1090 }
1091 
1092 QString ASWizSpamRulesPage::selectedSpamCollectionName() const
1093 {
1094  return selectedSpamCollection().name();
1095 }
1096 
1097 Akonadi::Collection ASWizSpamRulesPage::selectedSpamCollection() const
1098 {
1099  if ( mFolderReqForSpamFolder->hasCollection() )
1100  return mFolderReqForSpamFolder->collection();
1101  else
1102  return CommonKernel->trashCollectionFolder();
1103 }
1104 
1105 
1106 Akonadi::Collection ASWizSpamRulesPage::selectedUnsureCollection() const
1107 {
1108  if ( mFolderReqForUnsureFolder->hasCollection() )
1109  return mFolderReqForUnsureFolder->collection();
1110  else
1111  return CommonKernel->inboxCollectionFolder();
1112 }
1113 
1114 QString ASWizSpamRulesPage::selectedUnsureCollectionName() const
1115 {
1116  return selectedUnsureCollection().name();
1117 }
1118 
1119 QString ASWizSpamRulesPage::selectedUnsureCollectionId() const
1120 {
1121  return QString::number( selectedUnsureCollection().id() );
1122 }
1123 
1124 
1125 void ASWizSpamRulesPage::processSelectionChange()
1126 {
1127  mFolderReqForSpamFolder->setEnabled( mMoveSpamRules->isChecked() );
1128  mFolderReqForUnsureFolder->setEnabled( mMoveUnsureRules->isChecked() );
1129  emit selectionChanged();
1130 }
1131 
1132 
1133 void ASWizSpamRulesPage::processSelectionChange( const Akonadi::Collection& )
1134 {
1135  processSelectionChange();
1136 }
1137 
1138 
1139 void ASWizSpamRulesPage::allowUnsureFolderSelection( bool enabled )
1140 {
1141  mMoveUnsureRules->setEnabled( enabled );
1142  mMoveUnsureRules->setVisible( enabled );
1143  mFolderReqForUnsureFolder->setEnabled( enabled );
1144  mFolderReqForUnsureFolder->setVisible( enabled );
1145 }
1146 
1147 void ASWizSpamRulesPage::allowMoveSpam( bool enabled )
1148 {
1149  mMarkRules->setEnabled( enabled );
1150  mMarkRules->setChecked( enabled );
1151  mMoveSpamRules->setEnabled( enabled );
1152  mMoveSpamRules->setChecked( enabled );
1153 }
1154 
1155 
1156 //---------------------------------------------------------------------------
1157 ASWizVirusRulesPage::ASWizVirusRulesPage( QWidget * parent, const QString & name )
1158  : ASWizPage( parent, name )
1159 {
1160  QGridLayout *grid = new QGridLayout();
1161  mLayout->addItem( grid );
1162  grid->setSpacing( KDialog::spacingHint() );
1163 
1164  mPipeRules = new QCheckBox( i18n("Check messages using the anti-virus tools"), this );
1165  mPipeRules->setWhatsThis(
1166  i18n( "Let the anti-virus tools check your messages. The wizard "
1167  "will create appropriate filters. The messages are usually "
1168  "marked by the tools so that following filters can react "
1169  "on this and, for example, move virus messages to a special folder.") );
1170  grid->addWidget( mPipeRules, 0, 0 );
1171 
1172  mMoveRules = new QCheckBox( i18n("Move detected viral messages to the selected folder"), this );
1173  mMoveRules->setWhatsThis(
1174  i18n( "A filter to detect messages classified as virus-infected and to move "
1175  "those messages into a predefined folder is created. The "
1176  "default folder is the trash folder, but you may change that "
1177  "in the folder view.") );
1178  grid->addWidget( mMoveRules, 1, 0 );
1179 
1180  mMarkRules = new QCheckBox( i18n("Additionally, mark detected viral messages as read"), this );
1181  mMarkRules->setEnabled( false );
1182  mMarkRules->setWhatsThis(
1183  i18n( "Mark messages which have been classified as "
1184  "virus-infected as read, as well as moving them "
1185  "to the selected folder.") );
1186  grid->addWidget( mMarkRules, 2, 0 );
1187  FolderTreeWidget::TreeViewOptions opt = FolderTreeWidget::None;
1188  opt |= FolderTreeWidget::UseDistinctSelectionModel;
1189 
1190  FolderTreeWidgetProxyModel::FolderTreeWidgetProxyModelOptions optReadableProxy = FolderTreeWidgetProxyModel::None;
1191  optReadableProxy |= FolderTreeWidgetProxyModel::HideVirtualFolder;
1192  optReadableProxy |= FolderTreeWidgetProxyModel::HideOutboxFolder;
1193 
1194  mFolderTree = new FolderTreeWidget( this, 0, opt, optReadableProxy );
1195  mFolderTree->readConfig();
1196  mFolderTree->folderTreeView()->expandAll();
1197  mFolderTree->folderTreeWidgetProxyModel()->setAccessRights( Akonadi::Collection::CanCreateCollection );
1198 
1199  mFolderTree->selectCollectionFolder( CommonKernel->trashCollectionFolder() );
1200  mFolderTree->folderTreeView()->setDragDropMode( QAbstractItemView::NoDragDrop );
1201 
1202  mFolderTree->disableContextMenuAndExtraColumn();
1203  grid->addWidget( mFolderTree, 3, 0 );
1204 
1205  connect( mPipeRules, SIGNAL(clicked()),
1206  this, SLOT(processSelectionChange()) );
1207  connect( mMoveRules, SIGNAL(clicked()),
1208  this, SLOT(processSelectionChange()) );
1209  connect( mMarkRules, SIGNAL(clicked()),
1210  this, SLOT(processSelectionChange()) );
1211  connect( mMoveRules, SIGNAL(toggled(bool)),
1212  mMarkRules, SLOT(setEnabled(bool)) );
1213 
1214 }
1215 
1216 bool ASWizVirusRulesPage::pipeRulesSelected() const
1217 {
1218  return mPipeRules->isChecked();
1219 }
1220 
1221 
1222 bool ASWizVirusRulesPage::moveRulesSelected() const
1223 {
1224  return mMoveRules->isChecked();
1225 }
1226 
1227 bool ASWizVirusRulesPage::markReadRulesSelected() const
1228 {
1229  return mMarkRules->isChecked();
1230 }
1231 
1232 
1233 QString ASWizVirusRulesPage::selectedFolderName() const
1234 {
1235  if ( mFolderTree->selectedCollection().isValid() )
1236  return QString::number( mFolderTree->selectedCollection().id() );
1237  else
1238  return QString::number( CommonKernel->trashCollectionFolder().id() );
1239 }
1240 
1241 void ASWizVirusRulesPage::processSelectionChange()
1242 {
1243  emit selectionChanged();
1244 }
1245 
1246 
1247 //---------------------------------------------------------------------------
1248 ASWizSummaryPage::ASWizSummaryPage(QWidget * parent, const QString &name )
1249  : ASWizPage( parent, name )
1250 {
1251  QBoxLayout * layout = new QVBoxLayout();
1252  mLayout->addItem( layout );
1253 
1254  mSummaryText = new QLabel( this );
1255  layout->addWidget( mSummaryText );
1256  layout->addStretch();
1257 }
1258 
1259 
1260 void ASWizSummaryPage::setSummaryText( const QString & text )
1261 {
1262  mSummaryText->setText( text );
1263 }
1264 
1265 
1266 #include "antispamwizard.moc"
KMail::ASWizSpamRulesPage::selectedUnsureCollection
Akonadi::Collection selectedUnsureCollection() const
Definition: antispamwizard.cpp:1106
KMail::ASWizSummaryPage::setSummaryText
void setSummaryText(const QString &text)
Definition: antispamwizard.cpp:1260
KMail::ASWizSpamRulesPage::selectedUnsureCollectionName
QString selectedUnsureCollectionName() const
Definition: antispamwizard.cpp:1114
KMail::ASWizPage::ASWizPage
ASWizPage(QWidget *parent, const QString &name, const QString *bannerName=0)
Definition: antispamwizard.cpp:889
KMail::ASWizInfoPage::addAvailableTool
void addAvailableTool(const QString &visibleName)
Definition: antispamwizard.cpp:979
antispamwizard.h
KMail::ASWizSpamRulesPage::markAsReadSelected
bool markAsReadSelected() const
Definition: antispamwizard.cpp:1070
KMail::AntiSpamWizard::checkProgramsSelections
void checkProgramsSelections()
Modify the status of the wizard to reflect the selection of spam tools.
Definition: antispamwizard.cpp:470
KMail::ASWizPage::mLayout
QBoxLayout * mLayout
Definition: antispamwizard.h:301
KMail::ASWizSpamRulesPage::selectedSpamCollectionName
QString selectedSpamCollectionName() const
Definition: antispamwizard.cpp:1092
text
virtual QByteArray text(quint32 serialNumber) const =0
KMail::AntiSpamWizard::WizardMode
WizardMode
The wizard can be used for setting up anti-spam tools and for setting up anti-virus tools...
Definition: antispamwizard.h:113
KMail::AntiSpamWizard::SpamToolConfig::isServerBased
bool isServerBased() const
Definition: antispamwizard.cpp:722
QWidget
KMail::AntiSpamWizard::ConfigReader::readAndMergeConfig
void readAndMergeConfig()
Definition: antispamwizard.cpp:745
QListWidget
KMail::ASWizSpamRulesPage::selectionChanged
void selectionChanged()
KMail::ASWizVirusRulesPage
Definition: antispamwizard.h:374
kmmainwin.h
KMail::ASWizSummaryPage::ASWizSummaryPage
ASWizSummaryPage(QWidget *parent, const QString &name)
Definition: antispamwizard.cpp:1248
KMail::ASWizPage
Definition: antispamwizard.h:294
KAssistantDialog
KMail::ASWizInfoPage
Definition: antispamwizard.h:308
KMail::ASWizSpamRulesPage::moveUnsureSelected
bool moveUnsureSelected() const
Definition: antispamwizard.cpp:1082
KMail::ASWizVirusRulesPage::selectionChanged
void selectionChanged()
KMail::AntiSpamWizard::ConfigReader::getToolList
QList< SpamToolConfig > & getToolList()
Definition: antispamwizard.h:227
KMail::ASWizSpamRulesPage
Definition: antispamwizard.h:334
KMail::AntiSpamWizard::AntiSpamWizard
AntiSpamWizard(WizardMode mode, QWidget *parent)
Constructor that needs to initialize from the main folder tree of KMail.
Definition: antispamwizard.cpp:75
KMail::ASWizVirusRulesPage::selectedFolderName
QString selectedFolderName() const
Definition: antispamwizard.cpp:1233
KMail::ASWizVirusRulesPage::ASWizVirusRulesPage
ASWizVirusRulesPage(QWidget *parent, const QString &name)
Definition: antispamwizard.cpp:1157
KMail::AntiSpamWizard::SpamToolConfig::getVersion
int getVersion() const
Definition: antispamwizard.h:146
KMail::ASWizSummaryPage
Definition: antispamwizard.h:400
KMail::ASWizSpamRulesPage::selectedUnsureCollectionId
QString selectedUnsureCollectionId() const
Definition: antispamwizard.cpp:1119
KMail::ASWizVirusRulesPage::markReadRulesSelected
bool markReadRulesSelected() const
Definition: antispamwizard.cpp:1227
kmkernel.h
KMail::ASWizInfoPage::selectionChanged
void selectionChanged()
KMail::AntiSpamWizard::ConfigReader::~ConfigReader
~ConfigReader()
Definition: antispamwizard.cpp:740
KMail::AntiSpamWizard::ConfigReader::ConfigReader
ConfigReader(WizardMode mode, QList< SpamToolConfig > &configList)
Definition: antispamwizard.cpp:729
KMail::AntiSpamWizard::slotBuildSummary
void slotBuildSummary()
Create the summary text based on the current settings.
Definition: antispamwizard.cpp:591
KMail::AntiSpamWizard::SpamToolConfig::getId
QString getId() const
Definition: antispamwizard.h:148
KMail::AntiSpamWizard::SpamToolConfig::SpamToolConfig
SpamToolConfig()
Definition: antispamwizard.h:135
QLabel
KMail::AntiSpamWizard::SpamToolConfig
Instances of this class store the settings for one tool as read from the config file.
Definition: antispamwizard.h:132
KMail::ASWizInfoPage::setScanProgressText
void setScanProgressText(const QString &toolName)
Definition: antispamwizard.cpp:973
KMail::AntiSpamWizard::AntiSpam
Definition: antispamwizard.h:113
KMail::AntiSpamWizard::accept
void accept()
Evaluate the settings made and create the appropriate filter rules.
Definition: antispamwizard.cpp:148
KMail::ASWizSpamRulesPage::allowUnsureFolderSelection
void allowUnsureFolderSelection(bool enabled)
Definition: antispamwizard.cpp:1139
KMail::ASWizInfoPage::isProgramSelected
bool isProgramSelected(const QString &visibleName) const
Definition: antispamwizard.cpp:993
KMail::ASWizSpamRulesPage::selectedSpamCollection
Akonadi::Collection selectedSpamCollection() const
Definition: antispamwizard.cpp:1097
KMail::AntiSpamWizard::ConfigReader
Instances of this class control reading the configuration of the anti-spam tools from global and user...
Definition: antispamwizard.h:220
KMail::ASWizSpamRulesPage::ASWizSpamRulesPage
ASWizSpamRulesPage(QWidget *parent, const QString &name)
Definition: antispamwizard.cpp:1007
KMail::ASWizSpamRulesPage::allowMoveSpam
void allowMoveSpam(bool enabled)
Definition: antispamwizard.cpp:1147
KMail::ASWizVirusRulesPage::pipeRulesSelected
bool pipeRulesSelected() const
Definition: antispamwizard.cpp:1216
KMail::AntiSpamWizard::slotHelpClicked
void slotHelpClicked()
Show a help topic.
Definition: antispamwizard.cpp:582
KMail::AntiSpamWizard::checkVirusRulesSelections
void checkVirusRulesSelections()
Modify the status of the wizard to reflect the selected functionality.
Definition: antispamwizard.cpp:508
KMail::ASWizVirusRulesPage::moveRulesSelected
bool moveRulesSelected() const
Definition: antispamwizard.cpp:1222
KMail::AntiSpamWizard::AntiVirus
Definition: antispamwizard.h:113
KMail::ASWizSpamRulesPage::moveSpamSelected
bool moveSpamSelected() const
Definition: antispamwizard.cpp:1076
KMail::ASWizSpamRulesPage::selectedSpamCollectionId
QString selectedSpamCollectionId() const
Definition: antispamwizard.cpp:1087
QList
KMail::ASWizInfoPage::ASWizInfoPage
ASWizInfoPage(AntiSpamWizard::WizardMode mode, QWidget *parent, const QString &name)
Definition: antispamwizard.cpp:918
KMail::AntiSpamWizard::checkToolAvailability
void checkToolAvailability()
Check if the spam tools are available via the PATH.
Definition: antispamwizard.cpp:514
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal