7#include "filterimporterthunderbird.h"
8#include "filter/mailfilter.h"
9#include "mailcommon_debug.h"
10#include <MailImporter/FilterIcedove>
11#include <MailImporter/FilterSeaMonkey>
12#include <MailImporter/FilterThunderbird>
19FilterImporterThunderbird::FilterImporterThunderbird(
QFile *file,
bool interactive)
20 : FilterImporterAbstract(interactive)
26FilterImporterThunderbird::FilterImporterThunderbird(
QString string,
bool interactive)
27 : FilterImporterAbstract(interactive)
33FilterImporterThunderbird::~FilterImporterThunderbird() =
default;
35void FilterImporterThunderbird::readStream(
QTextStream &stream)
38 while (!stream.
atEnd()) {
40 qCDebug(MAILCOMMON_LOG) <<
" line :" << line <<
" filter " <<
filter;
41 filter = parseLine(stream, line, filter);
47QString FilterImporterThunderbird::defaultSeaMonkeyFiltersSettingsPath()
49 return MailImporter::FilterSeaMonkey::defaultSettingsPath();
52QString FilterImporterThunderbird::defaultIcedoveFiltersSettingsPath()
54 return MailImporter::FilterIcedove::defaultSettingsPath();
57QString FilterImporterThunderbird::defaultThunderbirdFiltersSettingsPath()
59 return MailImporter::FilterThunderbird::defaultSettingsPath();
67 line = cleanArgument(line, QStringLiteral(
"name="));
68 filter->pattern()->setName(line);
69 filter->setToolbarName(line);
71 line = cleanArgument(line, QStringLiteral(
"action="));
73 QString actionName = extractActions(line, filter, value);
74 if (!stream.
atEnd()) {
77 value = cleanArgument(line, QStringLiteral(
"actionValue="));
81 lstValue << QStringLiteral(
"X-Priority");
83 value = QStringLiteral(
"1 (Highest)");
85 value = QStringLiteral(
"2 (High)");
87 value = QStringLiteral(
"3 (Normal)");
89 value = QStringLiteral(
"4 (Low)");
91 value = QStringLiteral(
"5 (Lowest)");
95 actionName = QStringLiteral(
"add header");
106 createFilterAction(filter, actionName, value);
108 createFilterAction(filter, actionName, value);
109 filter = parseLine(stream, line, filter);
112 createFilterAction(filter, actionName, value);
115 line = cleanArgument(line, QStringLiteral(
"enabled="));
117 filter->setEnabled(
false);
120 line = cleanArgument(line, QStringLiteral(
"condition="));
121 extractConditions(line, filter);
123 line = cleanArgument(line, QStringLiteral(
"type="));
124 extractType(line, filter);
126 line = cleanArgument(line, QStringLiteral(
"version="));
127 if (line.
toInt() != 9) {
128 qCDebug(MAILCOMMON_LOG) <<
" thunderbird filter version different of 9 need to look at if it changed";
131 line = cleanArgument(line, QStringLiteral(
"logging="));
137 qCDebug(MAILCOMMON_LOG) <<
" Logging option not implemented " << line;
140 qCDebug(MAILCOMMON_LOG) <<
"unknown tag : " << line;
148 filter->pattern()->setOp(SearchPattern::OpAnd);
150 const int numberOfCond(conditionsList.
count());
151 for (
int i = 0; i < numberOfCond; ++i) {
152 if (!conditionsList.
at(i).trimmed().isEmpty()) {
153 splitConditions(conditionsList.
at(i), filter);
157 filter->pattern()->setOp(SearchPattern::OpOr);
159 const int numberOfCond(conditionsList.
count());
160 for (
int i = 0; i < numberOfCond; ++i) {
161 if (!conditionsList.
at(i).trimmed().isEmpty()) {
162 splitConditions(conditionsList.
at(i), filter);
166 filter->pattern()->setOp(SearchPattern::OpAll);
168 qCDebug(MAILCOMMON_LOG) <<
" missing extract condition" << line;
206 if (listOfCond.
count() < 3) {
207 qCDebug(MAILCOMMON_LOG) <<
"We have a pb in cond:" << cond;
211 const QString function = listOfCond.
at(1);
212 const QString contents = listOfCond.
at(2);
216 fieldName =
"subject";
220 fieldName =
"<body>";
222 fieldName =
"<date>";
226 fieldName =
"<status>";
232 fieldName =
"<recipients>";
234 fieldName =
"<recipients>";
236 fieldName =
"<age in days>";
242 fieldName =
"<size>";
256 qCDebug(MAILCOMMON_LOG) <<
" Field not implemented: " << field;
281 functionName = SearchRule::FuncContains;
283 functionName = SearchRule::FuncContainsNot;
285 functionName = SearchRule::FuncEquals;
287 functionName = SearchRule::FuncNotEqual;
293 functionName = SearchRule::FuncIsLess;
295 functionName = SearchRule::FuncIsGreater;
297 functionName = SearchRule::FuncIsGreater;
299 functionName = SearchRule::FuncIsLess;
301 functionName = SearchRule::FuncStartWith;
303 functionName = SearchRule::FuncEndWith;
305 functionName = SearchRule::FuncIsInAddressbook;
307 functionName = SearchRule::FuncIsNotInAddressbook;
309 functionName = SearchRule::FuncIsGreater;
311 functionName = SearchRule::FuncIsLess;
313 functionName = SearchRule::FuncEquals;
315 functionName = SearchRule::FuncNotEqual;
318 if (functionName == SearchRule::FuncNone) {
319 qCDebug(MAILCOMMON_LOG) <<
" functionName not implemented: " << function;
322 if (fieldName ==
"<status>") {
324 contentsName = QStringLiteral(
"Read");
326 contentsName = QStringLiteral(
"Unread");
328 contentsName = QStringLiteral(
"New");
330 contentsName = QStringLiteral(
"Forwarded");
332 qCDebug(MAILCOMMON_LOG) <<
" contents for status not implemented " << contents;
334 }
else if (fieldName ==
"<size>") {
335 int value = contents.
toInt();
336 value = value * 1024;
338 }
else if (fieldName ==
"<date>") {
340 const QDate date = locale.toDate(contents, QStringLiteral(
"dd-MMM-yyyy"));
343 contentsName = contents;
347 filter->pattern()->append(rule);
379 actionName = QStringLiteral(
"transfer");
381 actionName = QStringLiteral(
"forward");
383 actionName = QStringLiteral(
"set status");
384 value = QStringLiteral(
"R");
386 actionName = QStringLiteral(
"set status");
387 value = QStringLiteral(
"U");
389 actionName = QStringLiteral(
"copy");
391 actionName = QStringLiteral(
"add tag");
393 actionName = QStringLiteral(
"delete");
395 actionName = QStringLiteral(
"Change priority");
402 actionName = QStringLiteral(
"set Reply-To");
404 filter->setStopProcessingHere(
true);
412 qCDebug(MAILCOMMON_LOG) << QStringLiteral(
" missing convert method: %1").arg(line);
419 const int value = line.
toInt();
421 filter->setApplyOnInbound(
true);
422 filter->setApplyOnExplicit(
false);
424 }
else if (value == 16) {
425 filter->setApplyOnInbound(
false);
426 filter->setApplyOnExplicit(
true);
428 }
else if (value == 17) {
429 filter->setApplyOnInbound(
true);
430 filter->setApplyOnExplicit(
true);
432 }
else if (value == 32) {
433 filter->setApplyOnExplicit(
false);
434 filter->setApplyOnOutbound(
true);
435 filter->setApplyOnInbound(
false);
437 }
else if (value == 48) {
438 filter->setApplyOnExplicit(
true);
439 filter->setApplyOnOutbound(
true);
440 filter->setApplyOnInbound(
false);
443 qCDebug(MAILCOMMON_LOG) <<
" type value is not valid :" << value;
451 str.
remove(QStringLiteral(
"\""));
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 path(const QString &relativePath)
bool isEmpty() const const
QString toString(QStringView format, QCalendar cal) const const
const_reference at(qsizetype i) const const
qsizetype count() const const
bool isEmpty() const const
qsizetype length() const const
QString number(double n, char format, int precision)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
int toInt(bool *ok, int base) const const
QString trimmed() const const
QString join(QChar separator) const const
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
QString readLine(qint64 maxlen)
QUrl fromLocalFile(const QString &localFile)
bool isValid() const const
QString path(ComponentFormattingOptions options) const const