Fix Bug 353393 - Regression kAddressbook 5: Importing vCards from kMail does not...
[kdepim.git] / agents / mailfilteragent / filtermanager.h
blob25b698a8d3948a9b1ee6ebd50b35fecd356cf65a
1 /*
2 * kmail: KDE mail client
3 * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #ifndef FILTERMANAGER_H
21 #define FILTERMANAGER_H
23 #include <AkonadiCore/collection.h>
24 #include <AkonadiCore/item.h>
26 #include "MailCommon/SearchPattern"
28 namespace MailCommon
30 class MailFilter;
31 class ItemContext;
34 class FilterManager: public QObject
36 Q_OBJECT
38 public:
39 /**
40 * Describes the list of filters.
42 enum FilterSet {
43 NoSet = 0x0,
44 Inbound = 0x1,
45 Outbound = 0x2,
46 Explicit = 0x4,
47 BeforeOutbound = 0x8,
48 All = Inbound | BeforeOutbound | Outbound | Explicit
51 enum FilterRequires {
52 Unknown = 0,
53 HeaderMessage = 1,
54 FullMessage = 2
57 /**
58 * Creates a new filter manager.
60 * @param parent The parent object.
62 explicit FilterManager(QObject *parent = Q_NULLPTR);
64 /**
65 * Destroys the filter manager.
67 virtual ~FilterManager();
69 /**
70 * Clears the list of filters and deletes them.
72 void clear();
74 /**
75 * Reloads the filter rules from config file.
77 void readConfig();
79 /**
80 * Checks for existing filters with the @p name and extend the
81 * "name" to "name (i)" until no match is found for i=1..n
83 QString createUniqueName(const QString &name) const;
85 /**
86 * Process given message item by applying the filter rules one by
87 * one. You can select which set of filters (incoming or outgoing)
88 * should be used.
90 * @param item The message item to process.
91 * @param set Select the filter set to use.
92 * @param account @c true if an account id is specified else @c false
93 * @param accountId The id of the KMAccount that the message was retrieved from
95 * @return true if the filtering was successful, false in case of any error
97 bool process(const Akonadi::Item &item, bool needsFullPayload,
98 FilterSet set = Inbound,
99 bool account = false, const QString &accountId = QString());
101 bool process(const QList<MailCommon::MailFilter *> &mailFilters, const Akonadi::Item &item,
102 bool needsFullPayload, FilterSet set = Inbound,
103 bool account = false, const QString &accountId = QString());
106 * For ad-hoc filters.
108 * Applies @p filter to message @p item.
109 * Return codes are as with the above method.
111 bool process(const Akonadi::Item &item, bool needsFullPayload, const MailCommon::MailFilter *filter);
113 void filter(const Akonadi::Item &item, FilterManager::FilterSet set, const QString &resourceId);
114 void filter(const Akonadi::Item &item, const QString &filterId, const QString &resourceId);
116 void applySpecificFilters(const Akonadi::Item::List &selectedMessages, MailCommon::SearchRule::RequiredPart requiredPart, const QStringList &listFilters);
119 * Applies the filters on the given @p messages.
121 void applyFilters(const Akonadi::Item::List &messages, FilterSet set = Explicit);
124 * Returns whether the configured filters need the full mail content.
126 MailCommon::SearchRule::RequiredPart requiredPart(const QString &id) const;
128 void mailCollectionRemoved(const Akonadi::Collection &collection);
130 #ifndef NDEBUG
132 * Outputs all filter rules to console. Used for debugging.
134 void dump() const;
135 #endif
137 protected:
138 bool processContextItem(MailCommon::ItemContext context);
140 Q_SIGNALS:
142 * This signal is emitted whenever the filter list has been updated.
144 void filterListUpdated();
147 * This signal is emitted to notify that @p item has not been moved.
149 void filteringFailed(const Akonadi::Item &item);
151 void percent(int progress);
152 void progressMessage(const QString &message);
154 private:
155 //@cond PRIVATE
156 class Private;
157 Private *d;
159 Q_PRIVATE_SLOT(d, void itemsFetchJobForFilterDone(KJob *))
160 Q_PRIVATE_SLOT(d, void itemFetchJobForFilterDone(KJob *))
161 Q_PRIVATE_SLOT(d, void moveJobResult(KJob *))
162 Q_PRIVATE_SLOT(d, void modifyJobResult(KJob *))
163 Q_PRIVATE_SLOT(d, void deleteJobResult(KJob *))
164 Q_PRIVATE_SLOT(d, void slotItemsFetchedForFilter(const Akonadi::Item::List &))
165 //@endcond
168 #endif