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());
47void FilterImporterEvolution::parsePartAction(
const QDomElement &ruleFilter, MailCommon::MailFilter *filter, parseType type)
49 for (QDomElement partFilter = ruleFilter.
firstChildElement(); !partFilter.
isNull(); partFilter = partFilter.nextSiblingElement()) {
50 const QString nexttag = partFilter.tagName();
51 if (nexttag == QLatin1StringView(
"part")) {
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::FilterImporterEvolution::parseType::PartType) {
58 if (name == QLatin1StringView(
"to")) {
60 }
else if (name == QLatin1StringView(
"sender")) {
62 }
else if (name == QLatin1StringView(
"cc")) {
64 }
else if (name == QLatin1StringView(
"bcc")) {
67 }
else if (name == QLatin1StringView(
"senderto")) {
69 }
else if (name == QLatin1StringView(
"subject")) {
70 fieldName =
"subject";
71 }
else if (name == QLatin1StringView(
"header")) {
72 fieldName =
"<any header>";
73 }
else if (name == QLatin1StringView(
"body")) {
75 }
else if (name == QLatin1StringView(
"sexp")) {
77 }
else if (name == QLatin1StringView(
"sent-date")) {
79 }
else if (name == QLatin1StringView(
"recv-date")) {
81 }
else if (name == QLatin1StringView(
"label")) {
83 }
else if (name == QLatin1StringView(
"score")) {
85 }
else if (name == QLatin1StringView(
"size")) {
87 }
else if (name == QLatin1StringView(
"status")) {
88 fieldName =
"<status>";
89 }
else if (name == QLatin1StringView(
"follow-up")) {
91 }
else if (name == QLatin1StringView(
"completed-on")) {
93 }
else if (name == QLatin1StringView(
"attachments")) {
95 }
else if (name == QLatin1StringView(
"mlist")) {
96 fieldName =
"list-id";
97 }
else if (name == QLatin1StringView(
"regex")) {
99 }
else if (name == QLatin1StringView(
"source")) {
101 }
else if (name == QLatin1StringView(
"pipe")) {
103 }
else if (name == QLatin1StringView(
"junk")) {
105 }
else if (name == QLatin1StringView(
"all")) {
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;
118 for (QDomElement valueFilter = partFilter.firstChildElement(); !valueFilter.isNull(); valueFilter = valueFilter.nextSiblingElement()) {
119 const QString valueTag = valueFilter.tagName();
121 if (valueTag == QLatin1StringView(
"value")) {
122 if (valueFilter.hasAttribute(QStringLiteral(
"name"))) {
123 const QString
name = valueFilter.attribute(QStringLiteral(
"name"));
124 if (name == QLatin1StringView(
"flag")) {
125 const QString flag = valueFilter.attribute(QStringLiteral(
"value"));
126 qCDebug(MAILCOMMON_LOG) <<
" flag :" << flag;
127 if (flag == QLatin1StringView(
"Seen")) {
128 contents = QStringLiteral(
"Read");
129 }
else if (flag == QLatin1StringView(
"Answered")) {
130 contents = QStringLiteral(
"Sent");
131 }
else if (flag == QLatin1StringView(
"Draft")) {
133 }
else if (flag == QLatin1StringView(
"Flagged")) {
134 contents = QStringLiteral(
"Important");
135 }
else if (flag == QLatin1StringView(
"Junk")) {
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"));
145 if (name == QLatin1StringView(
"option")) {
147 }
else if (name == QLatin1StringView(
"string")) {
148 QDomElement
string = valueFilter.firstChildElement();
149 contents =
string.text();
150 }
else if (name == QLatin1StringView(
"folder")) {
151 QDomElement folder = valueFilter.firstChildElement();
153 contents = folder.
attribute(QStringLiteral(
"uri"));
155 contents.
remove(QStringLiteral(
"folder://"));
158 }
else if (name == QLatin1StringView(
"address")) {
159 QDomElement
address = valueFilter.firstChildElement();
161 }
else if (name == QLatin1StringView(
"integer")) {
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;
175 if (value == QLatin1StringView(
"contains")) {
176 functionName = SearchRule::FuncContains;
177 }
else if (value == QLatin1StringView(
"not contains")) {
178 functionName = SearchRule::FuncContainsNot;
179 }
else if (value == QLatin1StringView(
"is not")) {
180 functionName = SearchRule::FuncNotEqual;
181 }
else if (value == QLatin1StringView(
"is")) {
182 functionName = SearchRule::FuncEquals;
183 }
else if (value == QLatin1StringView(
"exist")) {
185 }
else if (value == QLatin1StringView(
"not exist")) {
187 }
else if (value == QLatin1StringView(
"not starts with")) {
188 functionName = SearchRule::FuncNotStartWith;
189 }
else if (value == QLatin1StringView(
"ends with")) {
190 functionName = SearchRule::FuncEndWith;
191 }
else if (value == QLatin1StringView(
"not ends with")) {
192 functionName = SearchRule::FuncNotEndWith;
193 }
else if (value == QLatin1StringView(
"matches soundex")) {
195 }
else if (value == QLatin1StringView(
"not match soundex")) {
197 }
else if (value == QLatin1StringView(
"before")) {
199 }
else if (value == QLatin1StringView(
"after")) {
201 }
else if (value == QLatin1StringView(
"greater-than")) {
202 functionName = SearchRule::FuncIsGreater;
203 }
else if (value == QLatin1StringView(
"less-than")) {
204 functionName = SearchRule::FuncIsLess;
205 }
else if (value == QLatin1StringView(
"starts with")) {
206 functionName = SearchRule::FuncStartWith;
212 filter->pattern()->append(rule);
213 }
else if (type == FilterImporterEvolution::FilterImporterEvolution::parseType::ActionType) {
215 if (name == QLatin1StringView(
"stop")) {
216 filter->setStopProcessingHere(
true);
218 }
else if (name == QLatin1StringView(
"move-to-folder")) {
219 actionName = QStringLiteral(
"transfer");
220 }
else if (name == QLatin1StringView(
"copy-to-folder")) {
221 actionName = QStringLiteral(
"copy");
222 }
else if (name == QLatin1StringView(
"delete")) {
223 actionName = QStringLiteral(
"delete");
224 }
else if (name == QLatin1StringView(
"label")) {
226 }
else if (name == QLatin1StringView(
"colour")) {
228 }
else if (name == QLatin1StringView(
"score")) {
230 }
else if (name == QLatin1StringView(
"adj-score")) {
232 }
else if (name == QLatin1StringView(
"set-status")) {
233 actionName = QStringLiteral(
"set status");
234 }
else if (name == QLatin1StringView(
"unset-status")) {
235 actionName = QStringLiteral(
"unset status");
236 }
else if (name == QLatin1StringView(
"play-sound")) {
237 actionName = QStringLiteral(
"play sound");
238 }
else if (name == QLatin1StringView(
"shell")) {
239 actionName = QStringLiteral(
"execute");
240 }
else if (name == QLatin1StringView(
"pipe")) {
241 actionName = QStringLiteral(
"filter app");
242 }
else if (name == QLatin1StringView(
"forward")) {
243 actionName = QStringLiteral(
"forward");
246 qCDebug(MAILCOMMON_LOG) <<
" actiontype part : name : not implemented :" <<
name;
249 for (QDomElement valueFilter = partFilter.firstChildElement(); !valueFilter.isNull(); valueFilter = valueFilter.nextSiblingElement()) {
250 const QString valueTag = valueFilter.tagName();
251 if (valueTag == QLatin1StringView(
"value")) {
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;
259 if (name == QLatin1StringView(
"option")) {
261 }
else if (name == QLatin1StringView(
"string")) {
263 }
else if (name == QLatin1StringView(
"folder")) {
267 value = folder.
attribute(QStringLiteral(
"uri"));
269 value.
remove(QStringLiteral(
"folder://"));
271 qCDebug(MAILCOMMON_LOG) <<
" contents folder :" << value;
273 }
else if (name == QLatin1StringView(
"address")) {
277 if (valueFilter.hasAttribute(QStringLiteral(
"value"))) {
278 const QString
name = valueFilter.attribute(QStringLiteral(
"value"));
279 qCDebug(MAILCOMMON_LOG) <<
" value filter value :" <<
name;
280 if (value == QLatin1StringView(
"contains")) {
286 createFilterAction(filter, actionName, value);
293void FilterImporterEvolution::parseFilters(
const QDomElement &e)
295 auto filter =
new MailCommon::MailFilter();
297 const QString attr = e.
attribute(QStringLiteral(
"enabled"));
298 if (attr == QLatin1StringView(
"false")) {
299 filter->setEnabled(
false);
304 const QString attr = e.
attribute(QStringLiteral(
"grouping"));
305 if (attr == QLatin1StringView(
"all")) {
306 filter->pattern()->setOp(SearchPattern::OpAnd);
307 }
else if (attr == QLatin1StringView(
"any")) {
308 filter->pattern()->setOp(SearchPattern::OpOr);
310 qCDebug(MAILCOMMON_LOG) <<
" grouping not implemented: " << attr;
315 const QString attr = e.
attribute(QStringLiteral(
"source"));
316 if (attr == QLatin1StringView(
"incoming")) {
317 filter->setApplyOnInbound(
true);
318 }
else if (attr == QLatin1StringView(
"outgoing")) {
319 filter->setApplyOnInbound(
false);
320 filter->setApplyOnOutbound(
true);
322 qCDebug(MAILCOMMON_LOG) <<
" source not implemented :" << attr;
326 const QString nexttag = ruleFilter.
tagName();
327 if (nexttag == QLatin1StringView(
"title")) {
328 filter->pattern()->setName(ruleFilter.
text());
330 }
else if (nexttag == QLatin1StringView(
"partset")) {
331 parsePartAction(ruleFilter, filter, FilterImporterEvolution::parseType::PartType);
332 }
else if (nexttag == QLatin1StringView(
"actionset")) {
333 parsePartAction(ruleFilter, filter, FilterImporterEvolution::parseType::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...
QString name(const QVariant &location)
PostalAddress address(const QVariant &location)
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)