7#include "filterimportersylpheed.h"
8#include "filter/mailfilter.h"
9#include "mailcommon_debug.h"
16FilterImporterSylpheed::FilterImporterSylpheed(
QFile *file)
17 : FilterImporterAbstract()
20 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;
40FilterImporterSylpheed::~FilterImporterSylpheed() =
default;
42QString FilterImporterSylpheed::defaultFiltersSettingsPath()
47void FilterImporterSylpheed::parseConditions(
const QDomElement &e, MailCommon::MailFilter *filter)
50 const QString attr = e.
attribute(QStringLiteral(
"bool"));
51 if (attr == QLatin1StringView(
"and")) {
52 filter->pattern()->setOp(SearchPattern::OpAnd);
53 }
else if (attr == QLatin1StringView(
"or")) {
54 filter->pattern()->setOp(SearchPattern::OpOr);
56 qCDebug(MAILCOMMON_LOG) <<
" bool not defined: " << attr;
59 for (QDomElement ruleFilter = e.
firstChildElement(); !ruleFilter.
isNull(); ruleFilter = ruleFilter.nextSiblingElement()) {
64 const QString nexttag = ruleFilter.tagName();
65 if (nexttag == QLatin1StringView(
"match-header")) {
66 if (ruleFilter.hasAttribute(QStringLiteral(
"name"))) {
67 const QString attr = ruleFilter.attribute(QStringLiteral(
"name"));
68 if (attr == QLatin1StringView(
"From")) {
70 }
else if (attr == QLatin1StringView(
"Cc")) {
72 }
else if (attr == QLatin1StringView(
"To")) {
74 }
else if (attr == QLatin1StringView(
"Reply-To")) {
75 fieldName =
"reply-to";
76 }
else if (attr == QLatin1StringView(
"Subject")) {
77 fieldName =
"subject";
78 }
else if (attr == QLatin1StringView(
"List-Id")) {
79 fieldName =
"list-id";
80 }
else if (attr == QLatin1StringView(
"X-ML-Name")) {
81 fieldName =
"x-mailing-list";
84 qCDebug(MAILCOMMON_LOG) <<
" match-header not implemented " << attr;
87 contentsName = ruleFilter.text();
88 }
else if (nexttag == QLatin1StringView(
"match-any-header")) {
89 fieldName =
"<any header>";
90 contentsName = ruleFilter.text();
91 }
else if (nexttag == QLatin1StringView(
"match-to-or-cc")) {
92 fieldName =
"<recipients>";
93 contentsName = ruleFilter.text();
94 }
else if (nexttag == QLatin1StringView(
"match-body-text")) {
96 contentsName = ruleFilter.text();
97 }
else if (nexttag == QLatin1StringView(
"command-test")) {
100 }
else if (nexttag == QLatin1StringView(
"size")) {
101 fieldName =
"<size>";
103 }
else if (nexttag == QLatin1StringView(
"age")) {
104 fieldName =
"<age in days>";
105 contentsName = ruleFilter.text();
106 }
else if (nexttag == QLatin1StringView(
"unread")) {
107 fieldName =
"<status>";
108 contentsName = QStringLiteral(
"Unread");
109 }
else if (nexttag == QLatin1StringView(
"mark")) {
111 }
else if (nexttag == QLatin1StringView(
"color-label")) {
113 }
else if (nexttag == QLatin1StringView(
"mime")) {
115 }
else if (nexttag == QLatin1StringView(
"account-id")) {
117 }
else if (nexttag == QLatin1StringView(
"target-folder")) {
120 qCDebug(MAILCOMMON_LOG) <<
" tag not recognize " << nexttag;
123 qCDebug(MAILCOMMON_LOG) <<
" field not implemented " << nexttag;
126 if (ruleFilter.hasAttribute(QStringLiteral(
"type"))) {
127 const QString attr = ruleFilter.attribute(QStringLiteral(
"type"));
128 if (attr == QLatin1StringView(
"not-contain")) {
129 functionName = SearchRule::FuncContainsNot;
130 }
else if (attr == QLatin1StringView(
"contains")) {
131 functionName = SearchRule::FuncContains;
132 }
else if (attr == QLatin1StringView(
"is-not")) {
133 functionName = SearchRule::FuncNotEqual;
134 }
else if (attr == QLatin1StringView(
"is")) {
135 functionName = SearchRule::FuncEquals;
136 }
else if (attr == QLatin1StringView(
"not-regex")) {
137 functionName = SearchRule::FuncNotRegExp;
138 }
else if (attr == QLatin1StringView(
"regex")) {
139 functionName = SearchRule::FuncRegExp;
140 }
else if (attr == QLatin1StringView(
"not-in-addressbook")) {
141 functionName = SearchRule::FuncIsNotInAddressbook;
142 }
else if (attr == QLatin1StringView(
"in-addressbook")) {
143 functionName = SearchRule::FuncIsInAddressbook;
144 }
else if (attr == QLatin1StringView(
"gt")) {
145 functionName = SearchRule::FuncIsGreater;
146 }
else if (attr == QLatin1StringView(
"lt")) {
147 functionName = SearchRule::FuncIsLess;
149 qCDebug(MAILCOMMON_LOG) <<
" Attr type not implemented :" << attr;
153 filter->pattern()->append(rule);
157void FilterImporterSylpheed::parseActions(
const QDomElement &e, MailCommon::MailFilter *filter)
159 for (QDomElement ruleFilter = e.
firstChildElement(); !ruleFilter.
isNull(); ruleFilter = ruleFilter.nextSiblingElement()) {
161 const QString nexttag = ruleFilter.tagName();
162 QString value = ruleFilter.text();
163 if (nexttag == QLatin1StringView(
"move")) {
164 actionName = QStringLiteral(
"transfer");
165 value = ruleFilter.text();
166 }
else if (nexttag == QLatin1StringView(
"copy")) {
167 actionName = QStringLiteral(
"copy");
168 value = ruleFilter.text();
169 }
else if (nexttag == QLatin1StringView(
"not-receive")) {
171 }
else if (nexttag == QLatin1StringView(
"delete")) {
172 actionName = QStringLiteral(
"delete");
173 }
else if (nexttag == QLatin1StringView(
"exec")) {
174 actionName = QStringLiteral(
"execute");
175 value = ruleFilter.text();
176 }
else if (nexttag == QLatin1StringView(
"exec-async")) {
177 actionName = QStringLiteral(
"filter app");
178 value = ruleFilter.text();
179 }
else if (nexttag == QLatin1StringView(
"mark")) {
181 }
else if (nexttag == QLatin1StringView(
"color-label")) {
183 }
else if (nexttag == QLatin1StringView(
"mark-as-read")) {
184 actionName = QStringLiteral(
"set status");
185 value = QStringLiteral(
"R");
186 }
else if (nexttag == QLatin1StringView(
"forward")) {
187 actionName = QStringLiteral(
"forward");
188 value = ruleFilter.text();
189 }
else if (nexttag == QLatin1StringView(
"forward-as-attachment")) {
191 }
else if (nexttag == QLatin1StringView(
"redirect")) {
192 actionName = QStringLiteral(
"redirect");
193 value = ruleFilter.text();
194 }
else if (nexttag == QLatin1StringView(
"stop-eval")) {
195 filter->setStopProcessingHere(
true);
200 qCDebug(MAILCOMMON_LOG) <<
" tag not recognize " << nexttag;
202 createFilterAction(filter, actionName, value);
206void FilterImporterSylpheed::parseFilters(
const QDomElement &e)
208 auto filter =
new MailCommon::MailFilter();
210 const QString attr = e.
attribute(QStringLiteral(
"enabled"));
211 if (attr == QLatin1StringView(
"false")) {
212 filter->setEnabled(
false);
217 const QString attr = e.
attribute(QStringLiteral(
"name"));
218 filter->pattern()->setName(attr);
219 filter->setToolbarName(attr);
223 const QString attr = e.
attribute(QStringLiteral(
"timing"));
224 if (attr == QLatin1StringView(
"any")) {
225 filter->setApplyOnInbound(
true);
226 filter->setApplyOnExplicit(
true);
227 }
else if (attr == QLatin1StringView(
"receiver")) {
228 filter->setApplyOnInbound(
true);
229 }
else if (attr == QLatin1StringView(
"manual")) {
230 filter->setApplyOnInbound(
false);
231 filter->setApplyOnExplicit(
true);
233 qCDebug(MAILCOMMON_LOG) <<
" timing not defined: " << attr;
236 for (QDomElement ruleFilter = e.
firstChildElement(); !ruleFilter.
isNull(); ruleFilter = ruleFilter.nextSiblingElement()) {
237 const QString nexttag = ruleFilter.tagName();
238 if (nexttag == QLatin1StringView(
"condition-list")) {
239 parseConditions(ruleFilter, filter);
240 }
else if (nexttag == QLatin1StringView(
"action-list")) {
241 parseActions(ruleFilter, filter);
243 qCDebug(MAILCOMMON_LOG) <<
" next tag not implemented " << nexttag;
247 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...
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
QDomElement firstChildElement(const QString &tagName, const QString &namespaceURI) const const
bool isNull() const const
QString arg(Args &&... args) const const
bool isEmpty() const const
QString number(double n, char format, int precision)
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)