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"
34 class FilterManager
: public QObject
40 * Describes the list of filters.
48 All
= Inbound
| BeforeOutbound
| Outbound
| Explicit
58 * Creates a new filter manager.
60 * @param parent The parent object.
62 explicit FilterManager(QObject
*parent
= Q_NULLPTR
);
65 * Destroys the filter manager.
67 virtual ~FilterManager();
70 * Clears the list of filters and deletes them.
75 * Reloads the filter rules from config file.
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;
86 * Process given message item by applying the filter rules one by
87 * one. You can select which set of filters (incoming or outgoing)
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
);
132 * Outputs all filter rules to console. Used for debugging.
138 bool processContextItem(MailCommon::ItemContext context
);
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
);
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
&))