1
/* -*- mode: C++; c-file-style: "gnu" -*-
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.
23
#include "kmsearchpattern.h"
24
#include "kmpopheaders.h"
26
#include <kshortcut.h>
35
// maximum number of filter actions per filter
36
const int FILTER_MAX_ACTIONS = 8;
41
/** Result codes returned by process. They mean:
43
@param GoOn Everything OK. You are still the owner of the
44
message and you should continue applying filter actions to this
47
@param CriticalError A critical error occurred (e.g. "disk full").
49
@param NoResult For internal use only!
52
enum ReturnCode { NoResult, GoOn, CriticalError };
54
/** Account type codes used by setApplicability. They mean:
56
@param All Apply to all accounts
58
@param ButImap Apply to all but online-IMAP accounts
60
@param Checked apply to all accounts specified by setApplyOnAccount
63
enum AccountType { All, ButImap, Checked };
65
/** Constructor that initializes basic settings. */
66
KMFilter( bool popFilter = false);
68
/** Constructor that initializes from given config group.
69
* Filters are stored one by one in config groups, i.e.
70
* one filter, one group. */
71
explicit KMFilter( KConfigGroup & aConfig, bool popFilter = false);
73
/** Copy constructor. Constructs a deep copy of @p aFilter. */
74
KMFilter( const KMFilter & other );
79
/** Equivalent to @pattern()->name(). @return name of the filter */
80
QString name() const {
81
return mPattern.name();
84
/** Execute the filter action(s) on the given message.
86
@li 2 if a critical error occurred,
87
@li 1 if the caller is still
88
the owner of the message,
89
@li 0 if processed successfully.
90
@param msg The message to which the actions should be applied.
91
@param stopIt Contains
92
true if the caller may apply other filters and false if he shall
93
stop the filtering of this message.
95
ReturnCode execActions( KMMessage* msg, bool& stopIt ) const ;
97
/** Determines if the filter depends on the body of the message
99
bool requiresBody(KMMsgBase* msgBase);
101
/** No descriptions */
102
KMPopFilterAction action();
104
/** No descriptions */
105
void setAction(const KMPopFilterAction aAction);
107
/** Write contents to given config group. */
108
void writeConfig( KConfigGroup& config ) const;
110
/** Initialize from given config group. */
111
void readConfig( KConfigGroup& config );
113
/** Remove empty rules (and actions one day). */
116
/** Check for empty pattern and action list. */
117
bool isEmpty() const;
119
/** Provides a reference to the internal action list. If your used
120
the @p setAction() and @p action() functions before, please
121
convert to using myFilter->actions()->at() and friends now. */
122
QList<KMFilterAction*>* actions() { return &mActions; }
124
/** Provides a reference to the internal action list. Const version. */
125
const QList<KMFilterAction*>* actions() const { return &mActions; }
127
/** Provides a reference to the internal pattern. If you used the
128
@p matches() function before, please convert to using
129
myFilter->pattern()->matches() now. */
130
KMSearchPattern* pattern() { return &mPattern; }
132
/** Provides a reference to the internal pattern. If you used the
133
@p matches() function before, please convert to using
134
myFilter->pattern()->matches() now. */
135
const KMSearchPattern* pattern() const { return &mPattern; }
137
/** Set whether this filter should be applied on
138
outbound messages (@p aApply == true) or not.
139
See applyOnOutbound applyOnInbound setApplyOnInbound
141
void setApplyOnOutbound( bool aApply=true ) { bApplyOnOutbound = aApply; }
143
/** Set whether this filter should be applied on
144
outbound messages before sending (@p aApply == TRUE) or not.
145
See applyOnOutbound applyOnInbound setApplyOnInbound
147
void setApplyBeforeOutbound( bool aApply=true ) { bApplyBeforeOutbound = aApply; }
149
/** @return true if this filter should be applied on
150
outbound messages, false otherwise.
151
@see setApplyOnOutbound applyOnInbound setApplyOnInbound
153
bool applyOnOutbound() const { return bApplyOnOutbound; }
155
/** @return TRUE if this filter should be applied on
156
outbound messages before they are sent, FALSE otherwise.
157
@see setApplyOnOutbound applyOnInbound setApplyOnInbound
159
bool applyBeforeOutbound() const { return bApplyBeforeOutbound; }
161
/** Set whether this filter should be applied on
162
inbound messages (@p aApply == true) or not.
163
@see setApplyOnOutbound applyOnInbound applyOnOutbound
165
void setApplyOnInbound( bool aApply=true ) { bApplyOnInbound = aApply; }
167
/** @return true if this filter should be applied on
168
inbound messages, false otherwise.
169
@see setApplyOnOutbound applyOnOutbound setApplyOnInbound
171
bool applyOnInbound() const { return bApplyOnInbound; }
173
/** Set whether this filter should be applied on
174
explicit (CTRL-J) filtering (@p aApply == true) or not.
175
@see setApplyOnOutbound applyOnInbound applyOnOutbound
177
void setApplyOnExplicit( bool aApply=true ) { bApplyOnExplicit = aApply; }
179
/** @return true if this filter should be applied on
180
explicit (CTRL-J) filtering, false otherwise.
181
@see setApplyOnOutbound applyOnOutbound setApplyOnInbound
183
bool applyOnExplicit() const { return bApplyOnExplicit; }
185
/** Set whether this filter should be applied on
186
inbound messages for all accounts (@p aApply == All) or
187
inbound messages for all but nline IMAP accounts (@p aApply == ButImap) or
188
for a specified set of accounts only.
189
Only applicable to filters that are applied on inbound messages.
190
@see setApplyOnInbound setApplyOnAccount
192
void setApplicability( AccountType aApply=All ) { mApplicability = aApply; }
194
/** @return true if this filter should be applied on
195
inbound messages for all accounts, or false if this filter
196
is to be applied on a specified set of accounts only.
197
Only applicable to filters that are applied on inbound messages.
198
@see setApplicability
200
AccountType applicability() const { return mApplicability; }
202
/** Set whether this filter should be applied on
203
inbound messages for the account with id (@p id).
204
Only applicable to filters that are only applied to a specified
206
@see setApplicability applyOnAccount
208
void setApplyOnAccount( uint id, bool aApply=true );
210
/** @return true if this filter should be applied on
211
inbound messages from the account with id (@p id), false otherwise.
212
@see setApplicability
214
bool applyOnAccount( uint id ) const;
216
void setStopProcessingHere( bool aStop ) { bStopProcessingHere = aStop; }
217
bool stopProcessingHere() const { return bStopProcessingHere; }
219
/** Set whether this filter should be plugged into the filter menu.
221
void setConfigureShortcut( bool aShort ) {
222
bConfigureShortcut = aShort;
223
bConfigureToolbar = bConfigureToolbar && bConfigureShortcut;
226
/** @return true if this filter should be plugged into the filter menu,
228
@see setConfigureShortcut
230
bool configureShortcut() const { return bConfigureShortcut; }
232
/** Set whether this filter should be plugged into the toolbar.
233
This can be done only if a shortcut is defined.
234
@see setConfigureShortcut
236
void setConfigureToolbar( bool aTool ) {
237
bConfigureToolbar = aTool && bConfigureShortcut;
240
/** @return true if this filter should be plugged into the toolbar,
242
@see setConfigureToolbar
244
bool configureToolbar() const { return bConfigureToolbar; }
246
/** @return The toolbar name of this filter.
247
* @see setToolbarName
249
QString toolbarName() const;
251
/** This sets the toolbar name for this filter.
252
* The toolbar name is the text to be displayed underneath the toolbar icon
253
* for this filter. This is usually the same as name(), expect when
254
* explicitly set by this function.
255
* This is useful if the normal filter mame is too long for the toolbar.
256
* @see toolbarName, name
258
void setToolbarName( QString toolbarName ) {
259
mToolbarName = toolbarName;
262
/** Set the shortcut to be used if plugged into the filter menu
263
or toolbar. Default is no shortcut.
264
@see setConfigureShortcut setConfigureToolbar
266
void setShortcut( const KShortcut & shortcut ) { mShortcut = shortcut; }
268
/** @return The shortcut assigned to the filter.
271
const KShortcut & shortcut() const { return mShortcut; }
273
/** Set the icon to be used if plugged into the filter menu
274
or toolbar. Default is the gear icon.
275
@see setConfigureShortcut setConfigureToolbar
277
void setIcon( QString icon ) { mIcon = icon; }
279
/** @return The name of the icon to be used.
282
QString icon() const { return mIcon; }
285
* Called from the filter manager when a folder is moved.
286
* Tests if the folder aFolder is used in any action. Changes it
287
* to aNewFolder folder in this case.
288
* @return true if a change in some action occurred,
289
* false if no action was affected.
291
bool folderRemoved( KMFolder* aFolder, KMFolder* aNewFolder );
293
/** Returns the filter in a human-readable form. useful for
294
debugging but not much else. Don't use, as it may well go away
297
const QString asString() const;
300
/** No descriptions */
301
bool isPopFilter() const {
305
/** Set the mode for using automatic naming for the filter.
306
If the feature is enabled, the name is derived from the
309
void setAutoNaming( bool useAutomaticNames ) {
310
bAutoNaming = useAutomaticNames;
313
/** @return Tells, if an automatic name is used for the filter
315
bool isAutoNaming() const { return bAutoNaming; }
318
KMSearchPattern mPattern;
319
QList<KMFilterAction*> mActions;
320
QList<int> mAccounts;
321
KMPopFilterAction mAction;
323
QString mToolbarName;
326
bool bApplyOnInbound : 1;
327
bool bApplyBeforeOutbound : 1;
328
bool bApplyOnOutbound : 1;
329
bool bApplyOnExplicit : 1;
330
bool bStopProcessingHere : 1;
331
bool bConfigureShortcut : 1;
332
bool bConfigureToolbar : 1;
333
bool bAutoNaming : 1;
334
AccountType mApplicability;
337
#endif /*kmfilter_h*/