7#include "filterimporterevolution.h"
8#include "filter/mailfilter.h"
10#include "mailcommon_debug.h"
15FilterImporterEvolution::FilterImporterEvolution(
QFile *file)
16 : FilterImporterAbstract()
19 if (!loadDomElement(doc, file)) {
26 qCDebug(MAILCOMMON_LOG) <<
"No filters defined";
31 const QString tag = e.tagName();
32 if (tag == QLatin1StringView(
"rule")) {
35 qCDebug(MAILCOMMON_LOG) <<
" unknown tag " << tag;
40FilterImporterEvolution::~FilterImporterEvolution() =
default;
42QString FilterImporterEvolution::defaultFiltersSettingsPath()
44 return QStringLiteral(
"%1/.config/evolution/mail/filters.xml").
arg(
QDir::homePath());
50 const QString nexttag = partFilter.tagName();
52 if (partFilter.hasAttribute(QStringLiteral(
"name"))) {
53 const QString name = partFilter.attribute(QStringLiteral(
"name"));
54 qCDebug(MAILCOMMON_LOG) <<
" parsePartAction name attribute :" <<
name;
55 if (type == FilterImporterEvolution::PartType) {
70 fieldName =
"subject";
72 fieldName =
"<any header>";
88 fieldName =
"<status>";
96 fieldName =
"list-id";
106 filter->pattern()->setOp(SearchPattern::OpAll);
109 qCDebug(MAILCOMMON_LOG) <<
" parttype part : name : not implemented :" <<
name;
112 qCDebug(MAILCOMMON_LOG) <<
" parttype part : name : not implemented :" <<
name;
119 const QString valueTag = valueFilter.tagName();
122 if (valueFilter.hasAttribute(QStringLiteral(
"name"))) {
123 const QString name = valueFilter.attribute(QStringLiteral(
"name"));
125 const QString flag = valueFilter.attribute(QStringLiteral(
"value"));
126 qCDebug(MAILCOMMON_LOG) <<
" flag :" << flag;
128 contents = QStringLiteral(
"Read");
130 contents = QStringLiteral(
"Sent");
134 contents = QStringLiteral(
"Important");
136 contents = QStringLiteral(
"Spam");
138 qCDebug(MAILCOMMON_LOG) <<
" unknown status flags " << flag;
141 qCDebug(MAILCOMMON_LOG) <<
" value filter name :" <<
name;
143 if (valueFilter.hasAttribute(QStringLiteral(
"type"))) {
144 const QString name = valueFilter.attribute(QStringLiteral(
"type"));
149 contents =
string.text();
153 contents = folder.
attribute(QStringLiteral(
"uri"));
155 contents.
remove(QStringLiteral(
"folder://"));
162 if (valueFilter.hasAttribute(QStringLiteral(
"integer"))) {
163 contents = valueFilter.attribute(QStringLiteral(
"integer"));
164 int val = contents.
toInt();
169 qCDebug(MAILCOMMON_LOG) <<
" type not implemented " <<
name;
172 if (valueFilter.hasAttribute(QStringLiteral(
"value"))) {
173 const QString value = valueFilter.attribute(QStringLiteral(
"value"));
174 qCDebug(MAILCOMMON_LOG) <<
" value filter value :" <<
name;
176 functionName = SearchRule::FuncContains;
178 functionName = SearchRule::FuncContainsNot;
180 functionName = SearchRule::FuncNotEqual;
182 functionName = SearchRule::FuncEquals;
188 functionName = SearchRule::FuncNotStartWith;
190 functionName = SearchRule::FuncEndWith;
192 functionName = SearchRule::FuncNotEndWith;
202 functionName = SearchRule::FuncIsGreater;
204 functionName = SearchRule::FuncIsLess;
206 functionName = SearchRule::FuncStartWith;
212 filter->pattern()->append(rule);
213 }
else if (type == FilterImporterEvolution::ActionType) {
216 filter->setStopProcessingHere(
true);
219 actionName = QStringLiteral(
"transfer");
221 actionName = QStringLiteral(
"copy");
223 actionName = QStringLiteral(
"delete");
233 actionName = QStringLiteral(
"set status");
235 actionName = QStringLiteral(
"unset status");
237 actionName = QStringLiteral(
"play sound");
239 actionName = QStringLiteral(
"execute");
241 actionName = QStringLiteral(
"filter app");
243 actionName = QStringLiteral(
"forward");
246 qCDebug(MAILCOMMON_LOG) <<
" actiontype part : name : not implemented :" <<
name;
250 const QString valueTag = valueFilter.tagName();
252 if (valueFilter.hasAttribute(QStringLiteral(
"name"))) {
253 const QString name = valueFilter.attribute(QStringLiteral(
"name"));
254 qCDebug(MAILCOMMON_LOG) <<
" value filter name :" <<
name;
256 if (valueFilter.hasAttribute(QStringLiteral(
"type"))) {
257 const QString name = valueFilter.attribute(QStringLiteral(
"type"));
258 qCDebug(MAILCOMMON_LOG) <<
" value filter type :" <<
name;
267 value = folder.
attribute(QStringLiteral(
"uri"));
269 value.
remove(QStringLiteral(
"folder://"));
271 qCDebug(MAILCOMMON_LOG) <<
" contents folder :" << value;
277 if (valueFilter.hasAttribute(QStringLiteral(
"value"))) {
278 const QString name = valueFilter.attribute(QStringLiteral(
"value"));
279 qCDebug(MAILCOMMON_LOG) <<
" value filter value :" <<
name;
286 createFilterAction(filter, actionName, value);
293void FilterImporterEvolution::parseFilters(
const QDomElement &e)
299 filter->setEnabled(
false);
306 filter->pattern()->setOp(SearchPattern::OpAnd);
308 filter->pattern()->setOp(SearchPattern::OpOr);
310 qCDebug(MAILCOMMON_LOG) <<
" grouping not implemented: " << attr;
317 filter->setApplyOnInbound(
true);
319 filter->setApplyOnInbound(
false);
320 filter->setApplyOnOutbound(
true);
322 qCDebug(MAILCOMMON_LOG) <<
" source not implemented :" << attr;
328 filter->pattern()->setName(ruleFilter.
text());
331 parsePartAction(ruleFilter, filter, PartType);
333 parsePartAction(ruleFilter, filter, ActionType);
335 qCDebug(MAILCOMMON_LOG) <<
" tag not implemented : " << nexttag;
339 appendFilter(filter);
std::shared_ptr< SearchRule > Ptr
Defines a pointer to a search rule.
Function
Describes operators for comparison of field and contents.
static SearchRule::Ptr createInstance(const QByteArray &field=QByteArray(), Function function=FuncContains, const QString &contents=QString())
Creates a new search rule of a certain type by instantiating the appropriate subclass depending on th...
PostalAddress address(const QVariant &location)
QString name(StandardAction id)
bool isEmpty() const const
QDomElement documentElement() const const
QString attribute(const QString &name, const QString &defValue) const const
bool hasAttribute(const QString &name) const const
QString tagName() const const
QString text() const const
QDomElement firstChildElement(const QString &tagName, const QString &namespaceURI) const const
bool isNull() const const
QDomElement nextSiblingElement(const QString &tagName, const QString &namespaceURI) const const
QString arg(Args &&... args) const const
bool isEmpty() const const
QString number(double n, char format, int precision)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
int toInt(bool *ok, int base) const const
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)