Mailcommon

mailfilter.cpp
1 /*
2  * kmail: KDE mail client
3  * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <[email protected]>
4  * SPDX-FileCopyrightText: 2012 Andras Mantia <[email protected]>
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  *
8  */
9 
10 // my header
11 #include "mailfilter.h"
12 
13 // other kmail headers
14 #include "dialog/filteractionmissingaccountdialog.h"
15 #include "filteractions/filteraction.h"
16 #include "filteractions/filteractiondict.h"
17 #include "filterlog.h"
18 #include "filtermanager.h"
20 
21 #include <PimCommon/PimUtil>
22 
23 // KDEPIMLIBS headers
24 #include <Akonadi/AgentManager>
25 
26 // other KDE headers
27 #include <KConfig>
28 #include <KConfigGroup>
29 #include <KLocalizedString>
30 #include <KMessageBox>
31 #include <QPointer>
32 #include <krandom.h>
33 
34 #include <algorithm>
35 
36 using namespace MailCommon;
37 
39 {
40  generateRandomIdentifier();
41  bApplyOnInbound = true;
42  bApplyBeforeOutbound = false;
43  bApplyOnOutbound = false;
44  bApplyOnExplicit = true;
45  bApplyOnAllFolders = false;
46  bStopProcessingHere = true;
47  bConfigureShortcut = false;
48  bConfigureToolbar = false;
49  bAutoNaming = true;
50  mApplicability = All;
51  bEnabled = true;
52 }
53 
54 MailFilter::MailFilter(const KConfigGroup &aConfig, bool interactive, bool &needUpdate)
55 {
56  needUpdate = readConfig(aConfig, interactive);
57 }
58 
60 {
61  mIdentifier = aFilter.mIdentifier;
62  mPattern = aFilter.mPattern;
63 
64  bApplyOnInbound = aFilter.applyOnInbound();
65  bApplyBeforeOutbound = aFilter.applyBeforeOutbound();
66  bApplyOnOutbound = aFilter.applyOnOutbound();
67  bApplyOnExplicit = aFilter.applyOnExplicit();
68  bApplyOnAllFolders = aFilter.applyOnAllFoldersInbound();
69  bStopProcessingHere = aFilter.stopProcessingHere();
70  bConfigureShortcut = aFilter.configureShortcut();
71  bConfigureToolbar = aFilter.configureToolbar();
72  mToolbarName = aFilter.toolbarName();
73  mApplicability = aFilter.applicability();
74  bAutoNaming = aFilter.isAutoNaming();
75  bEnabled = aFilter.isEnabled();
76  mIcon = aFilter.icon();
77  mShortcut = aFilter.shortcut();
78 
79  QVectorIterator<FilterAction *> it(aFilter.mActions);
80  while (it.hasNext()) {
81  FilterAction *action = it.next();
82  FilterActionDesc *desc = FilterManager::filterActionDict()->value(action->name());
83  if (desc) {
84  FilterAction *f = desc->create();
85  if (f) {
86  f->argsFromString(action->argsAsString());
87  mActions.append(f);
88  }
89  }
90  }
91 
92  mAccounts.clear();
94  QStringList::ConstIterator end2 = aFilter.mAccounts.constEnd();
95  for (it2 = aFilter.mAccounts.constBegin(); it2 != end2; ++it2) {
96  mAccounts.append(*it2);
97  }
98 }
99 
101 {
102  qDeleteAll(mActions);
103 }
104 
105 int MailFilter::filterActionsMaximumSize()
106 {
107  return 8;
108 }
109 
110 void MailFilter::generateRandomIdentifier()
111 {
112  mIdentifier = KRandom::randomString(16);
113 }
114 
116 {
117  return mIdentifier;
118 }
119 
121 {
122  return mPattern.name();
123 }
124 
125 MailFilter::ReturnCode MailFilter::execActions(ItemContext &context, bool &stopIt, bool applyOnOutbound) const
126 {
127  QVector<FilterAction *>::const_iterator it(mActions.constBegin());
128  QVector<FilterAction *>::const_iterator end(mActions.constEnd());
129  for (; it != end; ++it) {
130  if (FilterLog::instance()->isLogging()) {
131  const QString logText(i18n("<b>Applying filter action:</b> %1", (*it)->displayString()));
133  }
134 
135  const FilterAction::ReturnCode result = (*it)->process(context, applyOnOutbound);
136 
137  switch (result) {
139  if (FilterLog::instance()->isLogging()) {
140  const QString logText = QStringLiteral("<font color=#FF0000>%1</font>").arg(i18n("A critical error occurred. Processing stops here."));
142  }
143  // in case it's a critical error: return immediately!
144  return CriticalError;
146  if (FilterLog::instance()->isLogging()) {
147  const QString logText = QStringLiteral("<font color=#FF0000>%1</font>").arg(i18n("A problem was found while applying this action."));
149  }
150  case FilterAction::GoOn:
152  break;
153  }
154  }
155 
156  stopIt = stopProcessingHere();
157 
158  return GoOn;
159 }
160 
162 {
163  return &mActions;
164 }
165 
167 {
168  return &mActions;
169 }
170 
172 {
173  return &mPattern;
174 }
175 
176 const SearchPattern *MailFilter::pattern() const
177 {
178  return &mPattern;
179 }
180 
182 {
183  bApplyOnOutbound = aApply;
184 }
185 
187 {
188  bApplyBeforeOutbound = aApply;
189 }
190 
192 {
193  return bApplyOnOutbound;
194 }
195 
197 {
198  return bApplyBeforeOutbound;
199 }
200 
202 {
203  bApplyOnInbound = aApply;
204 }
205 
207 {
208  return bApplyOnInbound;
209 }
210 
212 {
213  bApplyOnExplicit = aApply;
214 }
215 
217 {
218  return bApplyOnExplicit;
219 }
220 
222 {
223  bApplyOnAllFolders = aApply;
224 }
225 
227 {
228  return bApplyOnAllFolders;
229 }
230 
232 {
233  mApplicability = aApply;
234 }
235 
237 {
238  return mApplicability;
239 }
240 
242 {
243  // find the required message part needed for the filter
244  // this can be either only the Envelope, all Header or the CompleteMessage
245  // Makes the assumption that Envelope < Header < CompleteMessage
247 
248  if (!bEnabled || !applyOnAccount(id)) {
249  return static_cast<SearchRule::RequiredPart>(requiredPart);
250  }
251 
252  if (pattern()) {
253  requiredPart = qMax(requiredPart, static_cast<int>(pattern()->requiredPart())); // no pattern means always matches?
254  }
255 
256  int requiredPartByActions = SearchRule::Envelope;
257 
258  QVector<FilterAction *> actionList = *actions();
259  if (!actionList.isEmpty()) {
260  requiredPartByActions = (*std::max_element(actionList.constBegin(), actionList.constEnd(), [](auto *lhs, auto *rhs) {
261  return lhs->requiredPart() < rhs->requiredPart();
262  }))->requiredPart();
263  }
264  requiredPart = qMax(requiredPart, requiredPartByActions);
265 
266  return static_cast<SearchRule::RequiredPart>(requiredPart);
267 }
268 
269 void MailFilter::agentRemoved(const QString &identifier)
270 {
271  mAccounts.removeAll(identifier);
272 }
273 
275 {
276  QVectorIterator<FilterAction *> it(mActions);
277  while (it.hasNext()) {
278  it.next()->folderRemoved(aFolder, aNewFolder);
279  }
280 }
281 
282 void MailFilter::clearApplyOnAccount()
283 {
284  mAccounts.clear();
285 }
286 
287 void MailFilter::setApplyOnAccount(const QString &id, bool aApply)
288 {
289  if (aApply && !mAccounts.contains(id)) {
290  mAccounts.append(id);
291  } else if (!aApply && mAccounts.contains(id)) {
292  mAccounts.removeAll(id);
293  }
294 }
295 
296 bool MailFilter::applyOnAccount(const QString &id) const
297 {
298  if (applicability() == All) {
299  return true;
300  }
301  if (applicability() == ButImap) {
303  if (instance.isValid()) {
304  return !PimCommon::Util::isImapResource(instance.type().identifier());
305  } else {
306  return false;
307  }
308  }
309  if (applicability() == Checked) {
310  return mAccounts.contains(id);
311  }
312 
313  return false;
314 }
315 
316 void MailFilter::setStopProcessingHere(bool aStop)
317 {
318  bStopProcessingHere = aStop;
319 }
320 
321 bool MailFilter::stopProcessingHere() const
322 {
323  return bStopProcessingHere;
324 }
325 
327 {
328  bConfigureShortcut = aShort;
329  bConfigureToolbar = (bConfigureToolbar && bConfigureShortcut);
330 }
331 
333 {
334  return bConfigureShortcut;
335 }
336 
338 {
339  bConfigureToolbar = (aTool && bConfigureShortcut);
340 }
341 
343 {
344  return bConfigureToolbar;
345 }
346 
347 void MailFilter::setToolbarName(const QString &toolbarName)
348 {
349  mToolbarName = toolbarName;
350 }
351 
353 {
354  mShortcut = shortcut;
355 }
356 
358 {
359  return mShortcut;
360 }
361 
362 void MailFilter::setIcon(const QString &icon)
363 {
364  mIcon = icon;
365 }
366 
368 {
369  return mIcon;
370 }
371 
372 void MailFilter::setAutoNaming(bool useAutomaticNames)
373 {
374  bAutoNaming = useAutomaticNames;
375 }
376 
378 {
379  return bAutoNaming;
380 }
381 
382 //-----------------------------------------------------------------------------
383 bool MailFilter::readConfig(const KConfigGroup &config, bool interactive)
384 {
385  bool needUpdate = false;
386  // MKSearchPattern::readConfig ensures
387  // that the pattern is purified.
388  mPattern.readConfig(config);
389  mIdentifier = config.readEntry("identifier", KRandom::randomString(16));
390 
391  const QStringList sets = config.readEntry("apply-on", QStringList());
392  if (sets.isEmpty() && !config.hasKey("apply-on")) {
393  bApplyBeforeOutbound = false;
394  bApplyOnOutbound = false;
395  bApplyOnInbound = true;
396  bApplyOnExplicit = true;
397  bApplyOnAllFolders = false;
398  mApplicability = ButImap;
399  } else {
400  bApplyBeforeOutbound = bool(sets.contains(QLatin1String("before-send-mail")));
401  bApplyOnInbound = bool(sets.contains(QLatin1String("check-mail")));
402  bApplyOnOutbound = bool(sets.contains(QLatin1String("send-mail")));
403  bApplyOnExplicit = bool(sets.contains(QLatin1String("manual-filtering")));
404  bApplyOnAllFolders = bool(sets.contains(QLatin1String("all-folders")));
405  mApplicability = static_cast<AccountType>(config.readEntry("Applicability", static_cast<int>(ButImap)));
406  }
407 
408  bStopProcessingHere = config.readEntry("StopProcessingHere", true);
409  bConfigureShortcut = config.readEntry("ConfigureShortcut", false);
410  QString shortcut(config.readEntry("Shortcut", QString()));
411  if (!shortcut.isEmpty()) {
413  setShortcut(sc);
414  }
415  bConfigureToolbar = config.readEntry("ConfigureToolbar", false);
416  bConfigureToolbar = bConfigureToolbar && bConfigureShortcut;
417  mToolbarName = config.readEntry("ToolbarName", name());
418  mIcon = config.readEntry("Icon", "system-run");
419  bAutoNaming = config.readEntry("AutomaticName", false);
420  bEnabled = config.readEntry("Enabled", true);
421 
422  mActions.clear();
423 
424  int numActions = config.readEntry("actions", 0);
425  if (numActions > filterActionsMaximumSize()) {
426  numActions = filterActionsMaximumSize();
427  KMessageBox::information(nullptr, i18n("<qt>Too many filter actions in filter rule <b>%1</b>.</qt>", mPattern.name()));
428  }
429 
430  for (int i = 0; i < numActions; ++i) {
431  const QString actName = QStringLiteral("action-name-%1").arg(i);
432  const QString argsName = QStringLiteral("action-args-%1").arg(i);
433  // get the action description...
434  const QString resultActName = config.readEntry(actName, QString());
435  FilterActionDesc *desc = FilterManager::filterActionDict()->value(resultActName);
436  if (desc) {
437  //...create an instance...
438  FilterAction *fa = desc->create();
439  if (fa) {
440  //...load it with it's parameter...
441  if (interactive) {
442  const bool ret = fa->argsFromStringInteractive(config.readEntry(argsName, QString()), name());
443  if (ret) {
444  needUpdate = true;
445  }
446  } else {
447  fa->argsFromString(config.readEntry(argsName, QString()));
448  }
449  //...check if it's empty and...
450  if (!fa->isEmpty()) {
451  //...append it if it's not and...
452  mActions.append(fa);
453  } else {
454  //...delete is else.
455  delete fa;
456  }
457  }
458  } else {
460  nullptr /* app-global modal dialog box */,
461  i18n("<qt>Unknown filter action <b>%1</b><br />in filter rule <b>%2</b>.<br />Ignoring it.</qt>", resultActName, mPattern.name()));
462  }
463  }
464 
465  mAccounts = config.readEntry("accounts-set", QStringList());
466  if (!mAccounts.isEmpty() && interactive) {
467  if (!MailCommon::FilterActionMissingAccountDialog::allAccountExist(mAccounts)) {
468  QPointer<MailCommon::FilterActionMissingAccountDialog> dlg = new MailCommon::FilterActionMissingAccountDialog(mAccounts, name());
469  if (dlg->exec()) {
470  mAccounts = dlg->selectedAccount();
471  needUpdate = true;
472  }
473  delete dlg;
474  }
475  }
476  return needUpdate;
477 }
478 
479 void MailFilter::generateSieveScript(QStringList &requiresModules, QString &code)
480 {
481  mPattern.generateSieveScript(requiresModules, code);
482 
484  QVector<FilterAction *>::const_iterator end(mActions.constEnd());
485 
486  const QString indentationStr{QStringLiteral(" ")};
487  code += QLatin1String(")\n{\n");
488  bool firstAction = true;
489  for (it = mActions.constBegin(); it != end; ++it) {
490  // Add endline here.
491  if (firstAction) {
492  firstAction = false;
493  } else {
494  code += QLatin1Char('\n');
495  }
496  code += indentationStr + (*it)->sieveCode();
497  const QStringList lstRequires = (*it)->sieveRequires();
498  for (const QString &str : lstRequires) {
499  if (!requiresModules.contains(str)) {
500  requiresModules.append(str);
501  }
502  }
503  }
504  if (bStopProcessingHere) {
505  code += QLatin1Char('\n') + indentationStr + QStringLiteral("stop;");
506  }
507  code += QLatin1String("\n}\n");
508 }
509 
510 void MailFilter::writeConfig(KConfigGroup &config, bool exportFilter) const
511 {
512  mPattern.writeConfig(config);
513  config.writeEntry("identifier", mIdentifier);
514 
515  QStringList sets;
516  if (bApplyOnInbound) {
517  sets.append(QStringLiteral("check-mail"));
518  }
519  if (bApplyBeforeOutbound) {
520  sets.append(QStringLiteral("before-send-mail"));
521  }
522  if (bApplyOnOutbound) {
523  sets.append(QStringLiteral("send-mail"));
524  }
525  if (bApplyOnExplicit) {
526  sets.append(QStringLiteral("manual-filtering"));
527  }
528  if (bApplyOnAllFolders) {
529  sets.append(QStringLiteral("all-folders"));
530  }
531  config.writeEntry("apply-on", sets);
532 
533  config.writeEntry("StopProcessingHere", bStopProcessingHere);
534  config.writeEntry("ConfigureShortcut", bConfigureShortcut);
535  if (!mShortcut.isEmpty()) {
536  config.writeEntry("Shortcut", mShortcut.toString());
537  }
538  config.writeEntry("ConfigureToolbar", bConfigureToolbar);
539  config.writeEntry("ToolbarName", mToolbarName);
540  if (!mIcon.isEmpty()) {
541  config.writeEntry("Icon", mIcon);
542  }
543  config.writeEntry("AutomaticName", bAutoNaming);
544  config.writeEntry("Applicability", static_cast<int>(mApplicability));
545  config.writeEntry("Enabled", bEnabled);
546  int i;
547 
549  QVector<FilterAction *>::const_iterator end(mActions.constEnd());
550 
551  for (i = 0, it = mActions.constBegin(); it != end; ++it, ++i) {
552  config.writeEntry(QStringLiteral("action-name-%1").arg(i), (*it)->name());
553  config.writeEntry(QStringLiteral("action-args-%1").arg(i), exportFilter ? (*it)->argsAsStringReal() : (*it)->argsAsString());
554  }
555  config.writeEntry("actions", i);
556  if (!mAccounts.isEmpty()) {
557  config.writeEntry("accounts-set", mAccounts);
558  }
559 }
560 
561 QString MailFilter::purify(bool removeAction)
562 {
563  QString informationAboutNotValidAction = mPattern.purify(removeAction);
564 
565  if (mActions.isEmpty()) {
566  if (!informationAboutNotValidAction.isEmpty()) {
567  informationAboutNotValidAction += QLatin1Char('\n');
568  }
569  informationAboutNotValidAction += i18n("Any action defined.");
570  } else {
571  QVectorIterator<FilterAction *> it(mActions);
572  it.toBack();
573  while (it.hasPrevious()) {
574  FilterAction *action = it.previous();
575  if (action->isEmpty()) {
576  if (!informationAboutNotValidAction.isEmpty()) {
577  informationAboutNotValidAction += QLatin1Char('\n');
578  }
579  informationAboutNotValidAction += action->informationAboutNotValidAction();
580  if (removeAction) {
581  mActions.removeAll(action);
582  }
583  }
584  }
585  }
586 
587  if (!Akonadi::AgentManager::self()->instances().isEmpty()) { // safety test to ensure that Akonadi system is ready
588  // Remove invalid accounts from mAccounts - just to be tidy
589  QStringList::Iterator it2 = mAccounts.begin();
590  while (it2 != mAccounts.end()) {
591  if (!Akonadi::AgentManager::self()->instance(*it2).isValid()) {
592  it2 = mAccounts.erase(it2);
593  } else {
594  ++it2;
595  }
596  }
597  }
598  return informationAboutNotValidAction;
599 }
600 
602 {
603  return (mPattern.isEmpty() && mActions.isEmpty()) || ((applicability() == Checked) && (bApplyOnInbound && mAccounts.isEmpty()));
604 }
605 
607 {
608  if (mToolbarName.isEmpty()) {
609  return name();
610  } else {
611  return mToolbarName;
612  }
613 }
614 
616 {
617  QString result;
618 
619  result += QLatin1String("Filter name: ") + name() + QLatin1String(" (") + mIdentifier + QLatin1String(")\n");
620  result += mPattern.asString() + QLatin1Char('\n');
621 
622  result += QStringLiteral("Filter is %1\n").arg(bEnabled ? QStringLiteral("enabled") : QStringLiteral("disabled"));
623 
624  QVector<FilterAction *>::const_iterator it(mActions.constBegin());
625  QVector<FilterAction *>::const_iterator end(mActions.constEnd());
626  for (; it != end; ++it) {
627  result += QStringLiteral(" action: ");
628  result += (*it)->label();
629  result += QLatin1Char(' ');
630  result += (*it)->argsAsString();
631  result += QLatin1Char('\n');
632  }
633  result += QStringLiteral("This filter belongs to the following sets:");
634  if (bApplyOnInbound) {
635  result += QStringLiteral(" Inbound");
636  }
637  if (bApplyBeforeOutbound) {
638  result += QStringLiteral(" before-Outbound");
639  }
640  if (bApplyOnOutbound) {
641  result += QStringLiteral(" Outbound");
642  }
643  if (bApplyOnExplicit) {
644  result += QStringLiteral(" Explicit");
645  }
646  if (bApplyOnAllFolders) {
647  result += QStringLiteral(" All Folders");
648  }
649  result += QLatin1Char('\n');
650  if (bApplyOnInbound && mApplicability == All) {
651  result += QStringLiteral("This filter applies to all accounts.\n");
652  } else if (bApplyOnInbound && mApplicability == ButImap) {
653  result += QStringLiteral("This filter applies to all but IMAP accounts.\n");
654  } else if (bApplyOnInbound) {
655  result += QStringLiteral("This filter applies to the following accounts:");
656  if (mAccounts.isEmpty()) {
657  result += QStringLiteral(" None");
658  } else {
659  for (QStringList::ConstIterator it2 = mAccounts.begin(), it2End = mAccounts.end(); it2 != it2End; ++it2) {
660  if (Akonadi::AgentManager::self()->instance(*it2).isValid()) {
661  result += QLatin1Char(' ') + Akonadi::AgentManager::self()->instance(*it2).name();
662  }
663  }
664  }
665  result += QLatin1Char('\n');
666  }
667  if (bStopProcessingHere) {
668  result += QStringLiteral("If it matches, processing stops at this filter.\n");
669  }
670 
671  return result;
672 }
673 
674 QDataStream &MailCommon::operator<<(QDataStream &stream, const MailCommon::MailFilter &filter)
675 {
676  stream << filter.mIdentifier;
677  stream << filter.mPattern.serialize();
678 
679  stream << filter.mActions.count();
680  QVectorIterator<FilterAction *> it(filter.mActions);
681  while (it.hasNext()) {
682  const FilterAction *action = it.next();
683  stream << action->name();
684  stream << action->argsAsString();
685  }
686 
687  stream << filter.mAccounts;
688  stream << filter.mIcon;
689  stream << filter.mToolbarName;
690  stream << filter.mShortcut;
691  stream << filter.bApplyOnInbound;
692  stream << filter.bApplyBeforeOutbound;
693  stream << filter.bApplyOnOutbound;
694  stream << filter.bApplyOnExplicit;
695  stream << filter.bApplyOnAllFolders;
696  stream << filter.bStopProcessingHere;
697  stream << filter.bConfigureShortcut;
698  stream << filter.bConfigureToolbar;
699  stream << filter.bAutoNaming;
700  stream << filter.mApplicability;
701  stream << filter.bEnabled;
702 
703  return stream;
704 }
705 
706 QDataStream &MailCommon::operator>>(QDataStream &stream, MailCommon::MailFilter &filter)
707 {
709  int numberOfActions;
711  bool bApplyOnInbound;
712  bool bApplyBeforeOutbound;
713  bool bApplyOnOutbound;
714  bool bApplyOnExplicit;
715  bool bApplyOnAllFolders;
716  bool bStopProcessingHere;
717  bool bConfigureShortcut;
718  bool bConfigureToolbar;
719  bool bAutoNaming;
720  int applicability;
721  bool bEnabled;
722 
723  stream >> filter.mIdentifier;
724  stream >> pattern;
725 
726  stream >> numberOfActions;
727  qDeleteAll(filter.mActions);
728  filter.mActions.clear();
729 
730  for (int i = 0; i < numberOfActions; ++i) {
731  QString actionName;
732  QString actionArguments;
733 
734  stream >> actionName;
735  stream >> actionArguments;
736 
737  FilterActionDesc *description = FilterManager::filterActionDict()->value(actionName);
738  if (description) {
739  FilterAction *filterAction = description->create();
740  if (filterAction) {
741  filterAction->argsFromString(actionArguments);
742  filter.mActions.append(filterAction);
743  }
744  }
745  }
746 
747  stream >> filter.mAccounts;
748  stream >> filter.mIcon;
749  stream >> filter.mToolbarName;
750  stream >> shortcut;
751  stream >> bApplyOnInbound;
752  stream >> bApplyBeforeOutbound;
753  stream >> bApplyOnOutbound;
754  stream >> bApplyOnExplicit;
755  stream >> bApplyOnAllFolders;
756  stream >> bStopProcessingHere;
757  stream >> bConfigureShortcut;
758  stream >> bConfigureToolbar;
759  stream >> bAutoNaming;
760  stream >> applicability;
761  stream >> bEnabled;
762 
763  filter.mPattern.deserialize(pattern);
764  filter.mShortcut = shortcut;
765  filter.bApplyOnInbound = bApplyOnInbound;
766  filter.bApplyBeforeOutbound = bApplyBeforeOutbound;
767  filter.bApplyOnOutbound = bApplyOnOutbound;
768  filter.bApplyOnExplicit = bApplyOnExplicit;
769  filter.bApplyOnAllFolders = bApplyOnAllFolders;
770  filter.bStopProcessingHere = bStopProcessingHere;
771  filter.bConfigureShortcut = bConfigureShortcut;
772  filter.bConfigureToolbar = bConfigureToolbar;
773  filter.bAutoNaming = bAutoNaming;
774  filter.bEnabled = bEnabled;
775  filter.mApplicability = static_cast<MailCommon::MailFilter::AccountType>(applicability);
776 
777  return stream;
778 }
779 
781 {
782  return bEnabled;
783 }
784 
785 void MailFilter::setEnabled(bool enabled)
786 {
787  bEnabled = enabled;
788 }
void setAutoNaming(bool useAutomaticNames)
Set the mode for using automatic naming for the filter.
Definition: mailfilter.cpp:372
void append(const T &value)
@ ErrorButGoOn
A non-critical error occurred.
Definition: filteraction.h:48
bool isEmpty() const const
KCOREADDONS_EXPORT QString randomString(int length)
@ ErrorNeedComplete
Could not process because a complete message is needed.
Definition: filteraction.h:46
const T & next()
QString purify(bool removeAction=true)
Removes all empty rules from the list.
const T & previous()
const QList< QKeySequence > & shortcut(StandardShortcut id)
QString name() const
Equivalent to pattern()->name().
Definition: mailfilter.cpp:120
AgentType type() const
QString pattern(Mode mode=Reading)
int removeAll(const T &value)
void writeConfig(KConfigGroup &config) const
Writes itself into config.
const QString asString() const
Returns the filter in a human-readable form.
Definition: mailfilter.cpp:615
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
bool isEmpty() const
Check for empty pattern and action list.
Definition: mailfilter.cpp:601
bool isEnabled() const
Return if filter is enabled or not.
Definition: mailfilter.cpp:780
QVector::const_iterator constEnd() const const
QList::const_iterator constBegin() const const
void writeConfig(KConfigGroup &config, bool exportFilter) const
Write contents to given config group.
Definition: mailfilter.cpp:510
The MailFilter class.
Definition: mailfilter.h:28
bool applyOnOutbound() const
Definition: mailfilter.cpp:191
KMail Filter Log Collector.
Definition: filterlog.h:32
ReturnCode execActions(ItemContext &context, bool &stopIt, bool applyOnOutbound) const
Execute the filter action(s) on the given message.
Definition: mailfilter.cpp:125
MailFilter()
Constructor that initializes basic settings.
Definition: mailfilter.cpp:38
@ AppliedAction
Log all applied actions.
Definition: filterlog.h:55
AgentInstance instance(const QString &identifier) const
AccountType
Account type codes used by setApplicability.
Definition: mailfilter.h:56
bool isAutoNaming() const
Definition: mailfilter.cpp:377
const QKeySequence & shortcut() const
Definition: mailfilter.cpp:357
QString name() const
Returns identifier name, ie.
Abstract base class for mail filter actions.
Definition: filteraction.h:38
QString i18n(const char *text, const TYPE &arg...)
void setApplyOnOutbound(bool aApply)
Set whether this filter should be applied on outbound messages (aApply == true) or not.
Definition: mailfilter.cpp:181
QString toolbarName() const
Definition: mailfilter.cpp:606
bool applyBeforeOutbound() const
Definition: mailfilter.cpp:196
bool hasPrevious() const const
void folderRemoved(const Akonadi::Collection &aFolder, const Akonadi::Collection &aNewFolder)
Called from the filter manager when a folder is moved.
Definition: mailfilter.cpp:274
RequiredPart
Possible required parts.
Definition: searchrule.h:68
bool isEmpty() const const
QString toString(QKeySequence::SequenceFormat format) const const
static FilterLog * instance()
Returns the single global instance of the filter log.
Definition: filterlog.cpp:72
bool configureToolbar() const
Definition: mailfilter.cpp:342
QFuture< void > filter(Sequence &sequence, KeepFunctor filterFunction)
bool isEmpty() const const
void setApplyOnAccount(const QString &id, bool aApply=true)
Set whether this filter should be applied on inbound messages for the account with id (id).
Definition: mailfilter.cpp:287
void setToolbarName(const QString &toolbarName)
This sets the toolbar name for this filter.
Definition: mailfilter.cpp:347
void setConfigureShortcut(bool aShort)
Set whether this filter should be plugged into the filter menu.
Definition: mailfilter.cpp:326
void setApplicability(AccountType aApply=All)
Set whether this filter should be applied on inbound messages for all accounts (aApply == All) or inb...
Definition: mailfilter.cpp:231
bool applyOnAllFoldersInbound() const
Returns whether the filter should be applied on inbound emails in all folders, not just Inbox.
Definition: mailfilter.cpp:226
bool configureShortcut() const
Definition: mailfilter.cpp:332
@ GoOn
Go on with applying filter actions.
Definition: filteraction.h:47
bool applyOnAccount(const QString &id) const
Definition: mailfilter.cpp:296
QString name() const
QVector< FilterAction * > * actions()
Provides a reference to the internal action list.
Definition: mailfilter.cpp:161
QString icon() const
Definition: mailfilter.cpp:367
void setIcon(const QString &icon)
Set the icon to be used if plugged into the filter menu or toolbar.
Definition: mailfilter.cpp:362
ReturnCode
Result codes returned by process.
Definition: mailfilter.h:45
typedef ConstIterator
A helper class for the filtering process.
Definition: itemcontext.h:26
ReturnCode
Describes the possible return codes of filter processing:
Definition: filteraction.h:45
void setApplyOnInbound(bool aApply)
Set whether this filter should be applied on inbound messages (aApply == true) or not.
Definition: mailfilter.cpp:201
typedef Iterator
QString purify(bool removeAction=true)
Remove empty rules (and actions one day).
Definition: mailfilter.cpp:561
static FilterActionDict * filterActionDict()
Returns the global filter action dictionary.
QList::const_iterator constEnd() const const
SearchPattern * pattern()
Provides a reference to the internal pattern.
Definition: mailfilter.cpp:171
QString identifier() const
QList::iterator erase(QList::iterator pos)
bool applyOnInbound() const
Definition: mailfilter.cpp:206
This class is an abstraction of a search over messages.
Definition: searchpattern.h:58
void setApplyOnExplicit(bool aApply)
Set whether this filter should be applied on explicit (CTRL-J) filtering (aApply == true) or not.
Definition: mailfilter.cpp:211
QString identifier() const
Returns the unique identifier of this filter.
Definition: mailfilter.cpp:115
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void readConfig(const KConfigGroup &config)
Reads a search pattern from a KConfigGroup.
virtual bool argsFromStringInteractive(const QString &argsStr, const QString &filterName)
Read extra arguments from given string.
AccountType applicability() const
Definition: mailfilter.cpp:236
void clear()
bool applyOnExplicit() const
Definition: mailfilter.cpp:216
void setApplyOnAllFoldersInbound(bool aApply)
Sets whether the filter should be applied on inbound emails in all folders, not just Inbox.
Definition: mailfilter.cpp:221
static AgentManager * self()
QList::iterator begin()
void add(const QString &entry, ContentType type)
Adds the given log entry under the given content type to the log.
Definition: filterlog.cpp:129
bool readConfig(const KConfigGroup &config, bool interactive=false)
Initialize from given config group.
Definition: mailfilter.cpp:383
QString name() const
Returns the name of the search pattern.
SearchRule::RequiredPart requiredPart(const QString &id) const
Returns the required part from the item that is needed for the filter to operate.
Definition: mailfilter.cpp:241
void information(QWidget *parent, const QString &text, const QString &title=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
bool hasNext() const const
QVector::const_iterator constBegin() const const
void setApplyBeforeOutbound(bool aApply)
Set whether this filter should be applied on outbound messages before sending (aApply == TRUE) or not...
Definition: mailfilter.cpp:186
QList::iterator end()
bool isEmpty() const const
Auxiliary struct for FilterActionDict.
virtual void argsFromString(const QString &argsStr)=0
Read extra arguments from given string.
QString asString() const
Returns the pattern as string.
The filter dialog.
virtual QString argsAsString() const =0
Return extra arguments as string.
void setShortcut(const QKeySequence &shortcut)
Set the shortcut to be used if plugged into the filter menu or toolbar.
Definition: mailfilter.cpp:352
virtual bool isEmpty() const
Determines whether this action is valid.
void setConfigureToolbar(bool aTool)
Set whether this filter should be plugged into the toolbar.
Definition: mailfilter.cpp:337
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Oct 1 2022 04:00:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.