File: mailfilter_plugin.cpp

package info (click to toggle)
aethera 0.9.3-7
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,588 kB
  • ctags: 7,282
  • sloc: cpp: 64,544; sh: 9,913; perl: 1,756; makefile: 1,680; python: 258
file content (114 lines) | stat: -rw-r--r-- 2,520 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

#include <kore/version.h>
#include <kore/servicemanager.h>

#include <iostream>

#include "mailfilter_plugin.h"
#include "mailfilterdialog.h"


#define MF_MAJOR 0
#define MF_MINOR 0
#define MF_REVISION 0
#define MF_VERSION "0.0.0"
#define MF_API_MAJOR 0
#define MF_API_MINOR 0
#define MF_API_REVISION 0
#define MF_API_VERSION "0.0.0"
#define MF_NAME "Mail Filter Plugin"
#define MF_TYPE MAILFILTER_TYPE
#define MF_DESCRIPTION "This plugin for filtering your emails."
#define MF_SERVICE MAILFILTER_SERVICE "/filter"
#define MF_SERVICE_DESCRIPTION "'mailfilter'-based '" MAILFILTER_SERVICE "' service"

#include <kconfig.h>
#include <kapp.h>


#include "messagedevice.h"
#include "indexclass.h"
#include "filter.h"

extern KConfig *GlobalConfig;

MailFilter::MailFilter()
{
    _mfVersion = new Version(MF_MAJOR,MF_MINOR,MF_REVISION,MF_VERSION);
    _mfAPIVersion = new Version(MF_API_MAJOR,MF_API_MINOR,MF_API_REVISION,MF_API_VERSION);
    _mfInfo = new Info(this, MF_NAME, MF_TYPE, MF_DESCRIPTION, _mfVersion, _mfAPIVersion);
    setInfo(_mfInfo);
    _mfService = new Service(this, MF_SERVICE, MF_SERVICE_DESCRIPTION);
    addService(_mfService);
    _mfeService = new Service(this, MAILFILTER_SERVICE, MF_SERVICE_DESCRIPTION);
    addService(_mfeService);

    qDebug("Mail Filter loaded");

    filters.setAutoDelete(true);

    readConfig();

}

MailFilter::~MailFilter()
{
    delete _mfInfo;
    delete _mfVersion;
    delete _mfAPIVersion;
    delete _mfService;
    delete _mfeService;
}

void MailFilter::applyFilter( IndexClass *idx, bool useForwardActions )
{
  Filter *f;
  MessageDevice dev(idx);
  dev.loadDescriptor();

  for ( f=filters.first(); f != 0; f=filters.next() )
    if ( f->match( &dev ) )
       f->apply( idx, &dev, useForwardActions );
}

QString MailFilter::messageFolder( MessageClass* message )
{
  Filter *f;
  QString res;

  for ( f=filters.first(); f != 0; f=filters.next() ) {
    res = f->messageFolder(message);
    if ( !res.isNull() )
      return res;
  }

  return QString();
}

void MailFilter::configure(QWidget *w,const char *n)
{
  MailFilterDialog *dlg = new MailFilterDialog(w,n,true);
  dlg->load();

  if ( dlg->exec() ) {
    dlg->sync();
    readConfig();
  }
  delete dlg;
}


void MailFilter::readConfig()
{
   filters.clear();
   KConfig *config = GlobalConfig;
   config->setGroup("MailFilters");
   int fCount = config->readNumEntry("filters_count",0);

   for (int i=0; i<fCount; i++) {
     filters.append( new Filter( config, "MailFilters", i) );
   }

}