kmail

antispamwizard.h
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 TQt library by Trolltech AS, Norway (or with modified versions
21  of TQt that use the same license as TQt), 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  TQt. 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 #ifndef KMAIL_ANTISPAMWIZARD_H
30 #define KMAIL_ANTISPAMWIZARD_H
31 
32 #include "simplefoldertree.h"
33 
34 #include <tdeconfig.h>
35 #include <tdelistbox.h>
36 #include <kwizard.h>
37 
38 #include <tqcheckbox.h>
39 #include <tqdict.h>
40 #include <tqlayout.h>
41 
42 class TDEActionCollection;
43 class KMFolder;
44 class KMFolderTree;
45 class TQLabel;
46 
47 namespace KMail {
48 
49  class FolderRequester;
50 
51  class ASWizInfoPage;
52  class ASWizSpamRulesPage;
53  class ASWizVirusRulesPage;
54  class ASWizSummaryPage;
55 
56  //---------------------------------------------------------------------------
104  class AntiSpamWizard : public KWizard
105  {
106  TQ_OBJECT
107 
108 
109  public:
113  enum WizardMode { AntiSpam, AntiVirus };
114 
124  TQWidget * parent, KMFolderTree * mainFolderTree );
125 
126  protected:
133  {
134  public:
135  SpamToolConfig() {}
136  SpamToolConfig( TQString toolId, int configVersion, int prio,
137  TQString name, TQString exec, TQString url, TQString filter,
138  TQString detection, TQString spam, TQString ham,
139  TQString header, TQString pattern, TQString pattern2,
140  TQString serverPattern,
141  bool detectionOnly, bool regExp, bool bayesFilter,
142  bool tristateDetection, WizardMode type );
143 
144  int getVersion() const { return mVersion; }
145  int getPrio() const { return mPrio; }
146  TQString getId() const { return mId; }
147  TQString getVisibleName() const { return mVisibleName; }
148  TQString getExecutable() const { return mExecutable; }
149  TQString getWhatsThisText() const { return mWhatsThisText; }
150  TQString getFilterName() const { return mFilterName; }
151  TQString getDetectCmd() const { return mDetectCmd; }
152  TQString getSpamCmd() const { return mSpamCmd; }
153  TQString getHamCmd() const { return mHamCmd; }
154  TQString getDetectionHeader() const { return mDetectionHeader; }
155  TQString getDetectionPattern() const { return mDetectionPattern; }
156  TQString getDetectionPattern2() const { return mDetectionPattern2; }
157  TQString getServerPattern() const { return mServerPattern; }
158  bool isServerBased() const;
159  bool isDetectionOnly() const { return mDetectionOnly; }
160  bool isUseRegExp() const { return mUseRegExp; }
161  bool useBayesFilter() const { return mSupportsBayesFilter; }
162  bool hasTristateDetection() const { return mSupportsUnsure; }
163  WizardMode getType() const { return mType; }
164  // convinience methods for types
165  bool isSpamTool() const { return ( mType == AntiSpam ); }
166  bool isVirusTool() const { return ( mType == AntiVirus ); }
167 
168  private:
169  // used to identifiy configs for the same tool
170  TQString mId;
171  // The version of the config data, used for merging and
172  // detecting newer configs
173  int mVersion;
174  // the priority of the tool in the list presented to the user
175  int mPrio;
176  // the name as shown by the checkbox in the dialog page
177  TQString mVisibleName;
178  // the command to check the existance of the tool
179  TQString mExecutable;
180  // the What's This help text (e.g. url for the tool)
181  TQString mWhatsThisText;
182  // name for the created filter in the filter list
183  TQString mFilterName;
184  // pipe through cmd used to detect spam messages
185  TQString mDetectCmd;
186  // pipe through cmd to let the tool learn a spam message
187  TQString mSpamCmd;
188  // pipe through cmd to let the tool learn a ham message
189  TQString mHamCmd;
190  // by which header are messages marked as spam
191  TQString mDetectionHeader;
192  // what header pattern is used to mark spam messages
193  TQString mDetectionPattern;
194  // what header pattern is used to mark unsure messages
195  TQString mDetectionPattern2;
196  // what header pattern is used in the account to check for a certain server
197  TQString mServerPattern;
198  // filter cannot search actively but relies on pattern by regExp or contain rule
199  bool mDetectionOnly;
200  // filter searches for the pattern by regExp or contain rule
201  bool mUseRegExp;
202  // can the tool learn spam and ham, has it a bayesian algorithm
203  bool mSupportsBayesFilter;
204  // differentiate between ham, spam and a third "unsure" state
205  bool mSupportsUnsure;
206  // Is the tool AntiSpam or AntiVirus
207  WizardMode mType;
208  };
209 
216  {
217  public:
218  ConfigReader( WizardMode mode,
219  TQValueList<SpamToolConfig> & configList );
220  ~ConfigReader( );
221 
222  TQValueList<SpamToolConfig> & getToolList() { return mToolList; }
223 
224  void readAndMergeConfig();
225 
226  private:
227  TQValueList<SpamToolConfig> & mToolList;
228  TDEConfig *mConfig;
229  WizardMode mMode;
230 
231  SpamToolConfig readToolConfig( TDEConfigGroup & configGroup );
232  SpamToolConfig createDummyConfig();
233 
234  void mergeToolConfig( SpamToolConfig config );
235  void sortToolList();
236  };
237 
239  void accept();
240 
241  protected slots:
247  void checkToolAvailability();
249  void slotHelpClicked();
251  void slotBuildSummary();
252 
253  private:
254  /* Check for the availability of an executible along the PATH */
255  int checkForProgram( const TQString &executable );
256  /* generic checks if any option in a page is checked */
257  bool anyVirusOptionChecked();
258  /* convenience method calling the appropriate filter manager method */
259  const TQString uniqueNameFor( const TQString & name );
260  /* convenience method to sort out new and existing filters */
261  void sortFilterOnExistance( const TQString & intendedFilterName,
262  TQString & newFilters,
263  TQString & replaceFilters );
264 
265  /* The pages in the wizard */
266  ASWizInfoPage * mInfoPage;
267  ASWizSpamRulesPage * mSpamRulesPage;
268  ASWizVirusRulesPage * mVirusRulesPage;
269  ASWizSummaryPage * mSummaryPage;
270 
271  /* The configured tools and it's settings to be used in the wizard. */
272  TQValueList<SpamToolConfig> mToolList;
273 
274  /* Are any spam tools selected? */
275  bool mSpamToolsUsed;
276  /* Are any virus tools selected? */
277  bool mVirusToolsUsed;
278 
279  WizardMode mMode;
280  };
281 
282 
283  //---------------------------------------------------------------------------
284  class ASWizPage : public TQWidget
285  {
286  public:
287  ASWizPage( TQWidget *parent, const char *name,
288  const TQString *bannerName = 0);
289 
290  protected:
291  TQBoxLayout *mLayout;
292 
293  private:
294  TQLabel *mBannerLabel;
295  };
296 
297 
298  //---------------------------------------------------------------------------
299  class ASWizInfoPage : public ASWizPage
300  {
301  TQ_OBJECT
302 
303 
304  public:
305  ASWizInfoPage( AntiSpamWizard::WizardMode mode,
306  TQWidget *parent, const char *name );
307 
308  void setScanProgressText( const TQString &toolName );
309  void addAvailableTool( const TQString &visibleName );
310  bool isProgramSelected( const TQString &visibleName );
311 
312  private slots:
313  void processSelectionChange();
314 
315  signals:
316  void selectionChanged();
317 
318  private:
319  TQLabel *mIntroText;
320  TQLabel *mScanProgressText;
321  TQLabel *mSelectionHint;
322  TDEListBox *mToolsList;
323  };
324 
325  //---------------------------------------------------------------------------
326  class ASWizSpamRulesPage : public ASWizPage
327  {
328  TQ_OBJECT
329 
330 
331  public:
332  ASWizSpamRulesPage( TQWidget * parent, const char * name, KMFolderTree * mainFolderTree );
333 
334  bool markAsReadSelected() const;
335  bool moveSpamSelected() const;
336  bool moveUnsureSelected() const;
337 
338  TQString selectedSpamFolderName() const;
339  TQString selectedUnsureFolderName() const;
340 
341  void allowUnsureFolderSelection( bool enabled );
342 
343  private slots:
344  void processSelectionChange();
345  void processSelectionChange( KMFolder* );
346 
347  signals:
348  void selectionChanged();
349 
350  private:
351  TQCheckBox * mMarkRules;
352  TQCheckBox * mMoveSpamRules;
353  TQCheckBox * mMoveUnsureRules;
354  FolderRequester *mFolderReqForSpamFolder;
355  FolderRequester *mFolderReqForUnsureFolder;
356  };
357 
358  //-------------------------------------------------------------------------
359  class ASWizVirusRulesPage : public ASWizPage
360  {
361  TQ_OBJECT
362 
363 
364  public:
365  ASWizVirusRulesPage( TQWidget * parent, const char * name, KMFolderTree * mainFolderTree );
366 
367  bool pipeRulesSelected() const;
368  bool moveRulesSelected() const;
369  bool markReadRulesSelected() const;
370 
371  TQString selectedFolderName() const;
372 
373  private slots:
374  void processSelectionChange();
375  signals:
376  void selectionChanged();
377 
378  private:
379  TQCheckBox * mPipeRules;
380  TQCheckBox * mMoveRules;
381  SimpleFolderTree *mFolderTree;
382  TQCheckBox * mMarkRules;
383  };
384 
385  //---------------------------------------------------------------------------
386  class ASWizSummaryPage : public ASWizPage
387  {
388  TQ_OBJECT
389 
390 
391  public:
392  ASWizSummaryPage( TQWidget * parent, const char * name );
393 
394  void setSummaryText( const TQString & text );
395 
396  private:
397  TQLabel * mSummaryText;
398  };
399 
400 
401 } // namespace KMail
402 
403 #endif // KMAIL_ANTISPAMWIZARD_H
Mail folder.
Definition: kmfolder.h:69
Instances of this class control reading the configuration of the anti-spam tools from global and user...
Instances of this class store the settings for one tool as read from the config file.
KMail anti-spam wizard.
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.
folderdiaquotatab.h
Definition: aboutdata.cpp:40