7#include "filterimporterclawsmail.h"
8#include "filter/mailfilter.h"
9#include "mailcommon_debug.h"
16FilterImporterClawsMails::FilterImporterClawsMails(
QFile *file)
17 : FilterImporterAbstract()
23FilterImporterClawsMails::FilterImporterClawsMails(
QString string)
24 : FilterImporterAbstract()
30FilterImporterClawsMails::FilterImporterClawsMails(
bool interactive)
31 : FilterImporterAbstract(interactive)
35FilterImporterClawsMails::~FilterImporterClawsMails() =
default;
37void FilterImporterClawsMails::readStream(
QTextStream &stream)
39 MailFilter *
filter =
nullptr;
40 while (!stream.
atEnd()) {
42 qCDebug(MAILCOMMON_LOG) <<
" line :" << line <<
" filter " <<
filter;
56QString FilterImporterClawsMails::defaultFiltersSettingsPath()
58 return QStringLiteral(
"%1/.claws-mail/matcherrc").arg(
QDir::homePath());
61MailFilter *FilterImporterClawsMails::parseLine(
const QString &line)
63 auto filter =
new MailFilter();
66 if (tmp.
startsWith(QLatin1StringView(
"enabled"))) {
68 tmp.
remove(QStringLiteral(
"enabled "));
72 if (tmp.
startsWith(QLatin1StringView(
"rulename"))) {
73 tmp.
remove(QStringLiteral(
"rulename "));
75 const QString
name = extractString(tmp, pos);
76 filter->pattern()->setName(name);
77 filter->setToolbarName(name);
79 tmp = tmp.
mid(pos + 2);
80 qCDebug(MAILCOMMON_LOG) <<
" new tmp" << tmp;
83 tmp = extractConditions(tmp, filter);
85 tmp = extractActions(tmp, filter);
90QString FilterImporterClawsMails::extractActions(
const QString &line,
MailFilter *filter)
96QString FilterImporterClawsMails::extractConditions(
const QString &line,
MailFilter *filter)
100 if (line.
startsWith(QLatin1StringView(
"subject"))) {
101 fieldName =
"subject";
102 }
else if (line.
startsWith(QLatin1StringView(
"age_lower"))) {
104 filter->pattern()->setOp(SearchPattern::OpAnd);
109QString FilterImporterClawsMails::extractString(
const QString &tmp,
int &pos)
114 for (; i < tmp.
length(); ++i) {
115 const QChar currentChar = tmp.
at(i);
116 if (i == 0 && (currentChar.
isSpace() || currentChar == QLatin1Char(
'"'))) {
118 if (currentChar != QLatin1Char(
'"')) {
119 if (currentChar != QLatin1Char(
'\\')) {
123 if (previousChar == QLatin1Char(
'\\')) {
129 previousChar = currentChar;
133 qCDebug(MAILCOMMON_LOG) <<
" name " <<
name;
QString name(StandardAction id)
bool isSpace(char32_t ucs4)
const QChar at(qsizetype position) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
QString readLine(qint64 maxlen)