Branch 'dev/sieve_kep14' - 4 commits - libksieve/ksieveui libksieve/parser
Sandro Knauß
knauss at kolabsys.com
Tue Mar 24 15:31:29 CET 2015
libksieve/ksieveui/managescriptsjob/parseuserscriptjob.cpp | 1
libksieve/ksieveui/managescriptsjob/parseuserscriptjob.h | 2
libksieve/ksieveui/managescriptsjob/tests/parseuserjobtest.cpp | 23 -
libksieve/ksieveui/managescriptsjob/tests/parseuserjobtest.h | 6
libksieve/ksieveui/vacation/tests/CMakeLists.txt | 24 +
libksieve/ksieveui/vacation/tests/data/vacation-complex.siv | 8
libksieve/ksieveui/vacation/tests/data/vacation-deactivate-complex.siv | 8
libksieve/ksieveui/vacation/tests/data/vacation-deactivate-multiple.siv | 19 +
libksieve/ksieveui/vacation/tests/data/vacation-deactivate.siv | 9
libksieve/ksieveui/vacation/tests/data/vacation-multiple.siv | 16 +
libksieve/ksieveui/vacation/tests/data/vacation-notfound.siv | 15
libksieve/ksieveui/vacation/tests/data/vacation-simple.siv | 6
libksieve/ksieveui/vacation/tests/vacationutilstest.cpp | 152 ++++++++++
libksieve/ksieveui/vacation/tests/vacationutilstest.h | 37 ++
libksieve/ksieveui/vacation/vacation.cpp | 8
libksieve/ksieveui/vacation/vacationpagewidget.cpp | 7
libksieve/ksieveui/vacation/vacationscriptextractor.cpp | 47 +++
libksieve/ksieveui/vacation/vacationscriptextractor.h | 133 ++++----
libksieve/ksieveui/vacation/vacationutils.cpp | 34 +-
libksieve/ksieveui/vacation/vacationutils.h | 2
libksieve/parser/lexer.cpp | 20 -
libksieve/parser/parser.cpp | 22 -
22 files changed, 485 insertions(+), 114 deletions(-)
New commits:
commit b13aab602147524f7bb2fd543ea05ba6277d49c1
Author: Sandro Knauà <knauss at kolabsys.com>
Date: Tue Mar 24 15:12:12 2015 +0100
parse new vacation script
diff --git a/libksieve/ksieveui/vacation/vacationscriptextractor.cpp b/libksieve/ksieveui/vacation/vacationscriptextractor.cpp
index 42b5c6d..4648058 100644
--- a/libksieve/ksieveui/vacation/vacationscriptextractor.cpp
+++ b/libksieve/ksieveui/vacation/vacationscriptextractor.cpp
@@ -22,6 +22,9 @@ VacationDataExtractor::VacationDataExtractor()
: KSieve::ScriptBuilder(),
mContext( None ),
mNotificationInterval( 0 )
+ , mActive(true)
+ , mInIfBlock(false)
+ , mBlockLevel(0)
{
kDebug();
}
@@ -33,6 +36,9 @@ VacationDataExtractor::~VacationDataExtractor()
void VacationDataExtractor::commandStart( const QString & identifier ) {
kDebug() << "( \"" << identifier <<"\" )";
+ if (identifier == QLatin1String("if") && mContext == None) {
+ mContext = IfBlock;
+ }
if ( identifier != QLatin1String("vacation") )
return;
reset();
@@ -41,7 +47,9 @@ void VacationDataExtractor::commandStart( const QString & identifier ) {
void VacationDataExtractor::commandEnd() {
kDebug();
- mContext = None;
+ if ( mContext != None && mContext != IfBlock ) {
+ mContext = VacationEnd;
+ }
}
void VacationDataExtractor::error( const KSieve::Error & e )
@@ -54,6 +62,43 @@ void VacationDataExtractor::finished()
}
+void VacationDataExtractor::testStart(const QString &test)
+{
+ if (mContext == IfBlock) {
+ if (test == QLatin1String("true") || test == QLatin1String("false")) {
+ mActive = (test == QLatin1String("true"));
+ mIfComment = QString();
+ kDebug() << "set active level to" << mActive;
+ }
+ }
+}
+
+void VacationDataExtractor::hashComment(const QString &comment)
+{
+ if (mContext == IfBlock) {
+ mIfComment += comment;
+ }
+}
+
+
+void VacationDataExtractor::blockStart()
+{
+ if (mContext == IfBlock) {
+ mContext = None;
+ }
+ mBlockLevel++;
+}
+
+void VacationDataExtractor::blockEnd()
+{
+ mBlockLevel--;
+ if(mBlockLevel == 0 && !commandFound()) { //We are in main level again, and didn't found vacation in block
+ mActive = true;
+ mIfComment = QString();
+ kDebug() << "Reset active level";
+ }
+}
+
void VacationDataExtractor::taggedArgument( const QString & tag )
{
kDebug() << "( \"" << tag <<"\" )";
diff --git a/libksieve/ksieveui/vacation/vacationscriptextractor.h b/libksieve/ksieveui/vacation/vacationscriptextractor.h
index fc03e05..d5f1a5d 100644
--- a/libksieve/ksieveui/vacation/vacationscriptextractor.h
+++ b/libksieve/ksieveui/vacation/vacationscriptextractor.h
@@ -180,9 +180,9 @@ private:
doProcess( method, string );
}
}
- void commandStart( const QString & identifier ) { kDebug() ; process( CommandStart, identifier ); }
+ void commandStart( const QString & identifier ) { kDebug() << identifier ; process( CommandStart, identifier ); }
void commandEnd() { kDebug() ; process( CommandEnd ); }
- void testStart( const QString & identifier ) { kDebug() ; process( TestStart, identifier ); }
+ void testStart( const QString & identifier ) { kDebug() << identifier ; process( TestStart, identifier ); }
void testEnd() { kDebug() ; process( TestEnd ); }
void testListStart() { kDebug() ; process( TestListStart ); }
void testListEnd() { kDebug() ; process( TestListEnd ); }
@@ -208,34 +208,38 @@ private:
typedef GenericInformationExtractor GIE;
static const GenericInformationExtractor::StateNode spamNodes[] = {
{ 0, GIE::CommandStart, "if", 1, 0, 0 }, // 0
- { 0, GIE::TestStart, "header", 2, 0, 0 }, // 1
- { 0, GIE::TaggedArgument, "contains", 3, 0, 0 }, // 2
+ { 0, GIE::TestStart, "allof", 2, 3, 0 }, // 1
+ { 0, GIE::TestListStart, 0, 3, 0, 0 }, // 2
+ { 0, GIE::TestStart, "not", 4, 3, 0 }, // 3
+ { 0, GIE::TestStart, "header", 5, 3, 0 }, // 4
+ { 0, GIE::TaggedArgument, "contains", 6, 0, 0 }, // 5
// accept both string and string-list:
- { 0, GIE::StringArgument, "x-spam-flag", 9, 4, "x-spam-flag" }, // 3
- { 0, GIE::StringListArgumentStart, 0, 5, 0, 0 }, // 4
- { 0, GIE::StringListEntry, "x-spam-flag", 6, 7, "x-spam-flag" }, // 5
- { 0, GIE::StringListEntry, 0, 6, 8, 0 }, // 6
- { 0, GIE::StringListArgumentEnd, 0, 0, 5, 0 }, // 7
- { 0, GIE::StringListArgumentEnd, 0, 9, 0, 0 }, // 8
+ { 0, GIE::StringArgument, "x-spam-flag", 12, 7, "x-spam-flag" }, // 6
+ { 0, GIE::StringListArgumentStart, 0, 8, 0, 0 }, // 7
+ { 0, GIE::StringListEntry, "x-spam-flag", 9, 10, "x-spam-flag" }, // 8
+ { 0, GIE::StringListEntry, 0, 9, 11, 0 }, // 9
+ { 0, GIE::StringListArgumentEnd, 0, 0, 8, 0 }, // 10
+ { 0, GIE::StringListArgumentEnd, 0, 12, 0, 0 }, // 11
// accept both string and string-list:
- { 0, GIE::StringArgument, "yes", 15, 10, "spam-flag-yes" }, // 9
- { 0, GIE::StringListArgumentStart, 0, 11, 0, 0 }, // 10
- { 0, GIE::StringListEntry, "yes", 12, 13, "spam-flag-yes" }, // 11
- { 0, GIE::StringListEntry, 0, 12, 14, 0 }, // 12
- { 0, GIE::StringListArgumentEnd, 0, 0, 11, 0 }, // 13
- { 0, GIE::StringListArgumentEnd, 0, 15, 0, 0 }, // 14
+ { 0, GIE::StringArgument, "yes", 18, 13, "spam-flag-yes" }, // 12
+ { 0, GIE::StringListArgumentStart, 0, 14, 0, 0 }, // 13
+ { 0, GIE::StringListEntry, "yes", 15, 16, "spam-flag-yes" }, // 14
+ { 0, GIE::StringListEntry, 0, 15, 17, 0 }, // 15
+ { 0, GIE::StringListArgumentEnd, 0, 0, 14, 0 }, // 16
+ { 0, GIE::StringListArgumentEnd, 0, 18, 0, 0 }, // 17
- { 0, GIE::TestEnd, 0, 16, 0, 0 }, // 15
+ { 0, GIE::TestEnd, 0, 20, 19, 0 }, // 18
+ { 0, GIE::TestListEnd, 0, 20, 0, 0 }, // 19
// block of command, find "stop", take nested if's into account:
- { 0, GIE::BlockStart, 0, 17, 0, 0 }, // 16
- { 1, GIE::CommandStart, "stop", 20, 19, "stop" }, // 17
- { -1, GIE::Any, 0, 17, 0, 0 }, // 18
- { 0, GIE::BlockEnd, 0, 0, 18, 0 }, // 19
+ { 0, GIE::BlockStart, 0, 21, 18, 0 }, // 20
+ { 1, GIE::CommandStart, "vacation", 24, 24, "vacation" }, // 21
+ { -1, GIE::Any, 0, 21, 0, 0 }, // 22
+ { 0, GIE::BlockEnd, 0, 0, 18, 0 }, // 23
- { -1, GIE::Any, 0, 20, 20, 0 }, // 20 end state
+ { -1, GIE::Any, 0, 24, 24, 0 }, // 24 end state
};
static const unsigned int numSpamNodes = sizeof spamNodes / sizeof *spamNodes ;
@@ -250,7 +254,7 @@ public:
bool found() const {
return mResults.count( QLatin1String("x-spam-flag") ) &&
mResults.count( QLatin1String("spam-flag-yes") ) &&
- mResults.count( QLatin1String("stop") ) ;
+ mResults.count( QLatin1String("vacation") ) ;
}
};
@@ -313,42 +317,44 @@ public:
// currentfate :value "le" date "YYYY-MM-DD) { keep; stop; }
static const GenericInformationExtractor::StateNode datesNodes[] = {
{ 0, GIE::CommandStart, "if", 1, 0, 0 }, // 0
- { 0, GIE::TestStart, "not", 2, 0, 0 }, // 1
- { 0, GIE::TestStart, "allof", 3, 0, 0 }, // 2
+ { 0, GIE::TestStart, "allof", 2, 0, 0 }, // 1
// handle startDate and endDate in arbitrary order
- { 0, GIE::TestListStart, 0, 4, 0, 0 }, // 3
- { 0, GIE::TestStart, "currentdate", 5, 0, 0 }, // 4
- { 0, GIE::TaggedArgument, "value", 6, 0, 0 }, // 5
- { 0, GIE::StringArgument, "ge", 7, 9, 0 }, // 6
- { 0, GIE::StringArgument, "date", 8, 0, 0 }, // 7
- { 0, GIE::StringArgument, 0, 12, 0, "startDate" }, // 8
- { 0, GIE::StringArgument, "le", 10, 0, 0 }, // 9
- { 0, GIE::StringArgument, "date", 11, 0, 0 }, // 10
- { 0, GIE::StringArgument, 0, 12, 0, "endDate" }, // 11
- { 0, GIE::TestEnd, 0, 13, 0, 0 }, // 12
-
- { 0, GIE::TestStart, "currentdate", 14, 0, 0 }, // 13
- { 0, GIE::TaggedArgument, "value", 15, 0, 0 }, // 14
- { 0, GIE::StringArgument, "le", 16, 18, 0 }, // 15
- { 0, GIE::StringArgument, "date", 17, 0, 0 }, // 16
- { 0, GIE::StringArgument, 0, 21, 0, "endDate" }, // 17
- { 0, GIE::StringArgument, "ge", 19, 0, 0 }, // 18
- { 0, GIE::StringArgument, "date", 20, 0, 0 }, // 19
- { 0, GIE::StringArgument, 0, 21, 0, "startDate" }, // 20
- { 0, GIE::TestEnd, 0, 22, 0, 0 }, // 21
- { 0, GIE::TestListEnd, 0, 23, 0, 0 }, // 22
-
- { 0, GIE::TestEnd, 0, 24, 0, 0 }, // 23
- { 0, GIE::TestEnd, 0, 25, 0, 0 }, // 24
+ { 0, GIE::TestListStart, 0, 3, 0, 0 }, // 2
+ { 0, GIE::TestStart, "currentdate", 4, 0, 0 }, // 3
+ { 0, GIE::TaggedArgument, "value", 5, 4, 0 }, // 4
+ { 0, GIE::StringArgument, "ge", 6, 8, 0 }, // 5
+ { 0, GIE::StringArgument, "date", 7, 0, 0 }, // 6
+ { 0, GIE::StringArgument, 0, 11, 0, "startDate" }, // 7
+ { 0, GIE::StringArgument, "le", 9, 0, 0 }, // 8
+ { 0, GIE::StringArgument, "date", 10, 0, 0 }, // 9
+ { 0, GIE::StringArgument, 0, 11, 0, "endDate" }, // 10
+ { 0, GIE::TestEnd, 0, 12, 0, 0 }, // 11
+
+ { 0, GIE::TestStart, "currentdate", 13, 0, 0 }, // 12
+ { 0, GIE::TaggedArgument, "value", 14, 13, 0 }, // 13
+ { 0, GIE::StringArgument, "le", 15, 17, 0 }, // 14
+ { 0, GIE::StringArgument, "date", 16, 0, 0 }, // 15
+ { 0, GIE::StringArgument, 0, 20, 0, "endDate" }, // 16
+ { 0, GIE::StringArgument, "ge", 18, 0, 0 }, // 17
+ { 0, GIE::StringArgument, "date", 19, 0, 0 }, // 18
+ { 0, GIE::StringArgument, 0, 20, 0, "startDate" }, // 19
+ { 0, GIE::TestEnd, 0, 24, 0, 0 }, // 20
+ { 0, GIE::TestStart, 0, 23, 22, 0 }, // 21
+ { -1, GIE::Any, 0, 24, 0, 0 }, // 22
+ { 0, GIE::TestEnd, 0, 24, 22, 0 }, // 23
+ { 0, GIE::TestListEnd, 0, 25, 21, 0 }, // 24
+
+ { 0, GIE::TestEnd, 0, 26, 0, 0 }, // 25
// block of commands, find "stop", take nested if's into account:
- { 0, GIE::BlockStart, 0, 26, 0, 0 }, // 25
- { 1, GIE::CommandStart, "stop", 29, 28, "stop" }, // 26
- { -1, GIE::Any, 0, 26, 0, 0 }, // 27
- { 0, GIE::BlockEnd, 0, 0, 27, 0 }, // 28
+ { 0, GIE::BlockStart, 0, 28, 25, 0 }, // 26
+ { -1, GIE::Any, 0, 28, 0, 0 }, // 27
+ { 1, GIE::CommandStart, "vacation", 30, 27, "vacation" }, // 28
+ { -1, GIE::Any, 0, 30, 0, 0 }, // 29
+ { 0, GIE::BlockEnd, 0, 31, 29, 0 }, // 30
- { -1, GIE::Any, 0, 27, 27, 0 } // 29 end state
+ { -1, GIE::Any, 0, 31, 31, 0 } // 31 end state
};
static const unsigned int numDatesNodes = sizeof datesNodes / sizeof *datesNodes;
@@ -387,15 +393,20 @@ class VacationDataExtractor : public KSieve::ScriptBuilder {
// command itself:
VacationCommand,
// tagged args:
- Days, Addresses, Subject
+ Days, Addresses, Subject,
+ VacationEnd,
+ IfBlock
};
public:
VacationDataExtractor();
virtual ~VacationDataExtractor();
+ bool commandFound() const { return mContext == VacationEnd; }
+ bool active() const { return mActive; }
int notificationInterval() const { return mNotificationInterval; }
const QString & messageText() const { return mMessageText; }
const QStringList & aliases() const { return mAliases; }
+ const QString &ifComment() const { return mIfComment; }
const QString &subject() const
{
@@ -407,13 +418,13 @@ private:
void commandEnd();
- void testStart( const QString & ) {}
+ void testStart( const QString &);
void testEnd() {}
void testListStart() {}
void testListEnd() {}
- void blockStart() {}
- void blockEnd() {}
- void hashComment( const QString & ) {}
+ void blockStart();
+ void blockEnd();
+ void hashComment( const QString & );
void bracketComment( const QString & ) {}
void lineFeed() {}
void error( const KSieve::Error & e );
@@ -435,6 +446,10 @@ private:
QString mMessageText;
QString mSubject;
QStringList mAliases;
+ bool mActive;
+ bool mInIfBlock;
+ int mBlockLevel;
+ QString mIfComment;
void reset();
};
diff --git a/libksieve/ksieveui/vacation/vacationutils.cpp b/libksieve/ksieveui/vacation/vacationutils.cpp
index 0604e12..a6b69ac 100644
--- a/libksieve/ksieveui/vacation/vacationutils.cpp
+++ b/libksieve/ksieveui/vacation/vacationutils.cpp
@@ -98,13 +98,14 @@ QDate KSieveUi::VacationUtils::defaultEndDate()
}
-bool KSieveUi::VacationUtils::parseScript( const QString &script, QString &messageText,
+bool KSieveUi::VacationUtils::parseScript( const QString &script, bool &active, QString &messageText,
QString &subject,
int & notificationInterval, QStringList &aliases,
bool & sendForSpam, QString &domainName,
QDate & startDate, QDate & endDate )
{
if ( script.trimmed().isEmpty() ) {
+ active = false;
messageText = VacationUtils::defaultMessageText();
subject = VacationUtils::defaultSubject();
notificationInterval = VacationUtils::defaultNotificationInterval();
@@ -125,20 +126,33 @@ bool KSieveUi::VacationUtils::parseScript( const QString &script, QString &messa
SpamDataExtractor sdx;
DomainRestrictionDataExtractor drdx;
DateExtractor dx;
- KSieveExt::MultiScriptBuilder tsb( &vdx, &sdx, &drdx, &dx );
+ KSieveExt::MultiScriptBuilder tsb( &vdx , &sdx, &drdx, &dx );
parser.setScriptBuilder( &tsb );
- if ( !parser.parse() )
+ if ( !parser.parse() || !vdx.commandFound() ) {
+ active = false;
return false;
+ }
+ active = vdx.active();
messageText = vdx.messageText().trimmed();
if (!vdx.subject().isEmpty()) {
subject = vdx.subject().trimmed();
}
notificationInterval = vdx.notificationInterval();
aliases = vdx.aliases();
- if ( !VacationSettings::allowOutOfOfficeUploadButNoSettings() ) {
- sendForSpam = !sdx.found();
- domainName = drdx.domainName();
+
+ if (!active && !vdx.ifComment().isEmpty()) {
+ const QByteArray newScript = QString::fromAscii("if ").toUtf8() + vdx.ifComment().toUtf8() + QString::fromLatin1("{vacation;}").toUtf8();
+ tsb = KSieveExt::MultiScriptBuilder( &sdx, &drdx, &dx );
+ KSieve::Parser parser( newScript.begin(),
+ newScript.begin() + newScript.length() );
+ parser.setScriptBuilder( &tsb );
+ if ( !parser.parse() ) {
+ return false;
+ }
}
+
+ sendForSpam = !sdx.found();
+ domainName = drdx.domainName();
startDate = dx.startDate();
endDate = dx.endDate();
return true;
@@ -156,12 +170,8 @@ bool KSieveUi::VacationUtils::foundVacationScript(const QString &script)
KSieve::Parser parser( scriptUTF8.begin(),
scriptUTF8.begin() + scriptUTF8.length() );
VacationDataExtractor vdx;
- SpamDataExtractor sdx;
- DomainRestrictionDataExtractor drdx;
- DateExtractor dx;
- KSieveExt::MultiScriptBuilder tsb( &vdx, &sdx, &drdx, &dx );
- parser.setScriptBuilder( &tsb );
- return parser.parse();
+ parser.setScriptBuilder(&vdx);
+ return parser.parse() && vdx.commandFound();
}
QString KSieveUi::VacationUtils::composeScript( const QString & messageText,
diff --git a/libksieve/ksieveui/vacation/vacationutils.h b/libksieve/ksieveui/vacation/vacationutils.h
index 21965a8..53248c8 100644
--- a/libksieve/ksieveui/vacation/vacationutils.h
+++ b/libksieve/ksieveui/vacation/vacationutils.h
@@ -45,7 +45,7 @@ QString composeScript( const QString & messageText, const QString &subject,
const KMime::Types::AddrSpecList & aliases,
bool sendForSpam, const QString & excludeDomain,
const QDate & startDate, const QDate & endDate );
-bool parseScript( const QString & script, QString & messageText,
+bool parseScript( const QString & script, bool &active, QString & messageText,
QString &subject,
int & notificationInterval, QStringList & aliases,
bool & sendForSpam, QString & domainName,
commit 39f0f3120a6af9f6206b614fd780502474060e0d
Author: Sandro Knauà <knauss at kolabsys.com>
Date: Tue Mar 24 15:10:13 2015 +0100
Get tests running again
diff --git a/libksieve/ksieveui/managescriptsjob/parseuserscriptjob.cpp b/libksieve/ksieveui/managescriptsjob/parseuserscriptjob.cpp
index da664e5..6e48743 100644
--- a/libksieve/ksieveui/managescriptsjob/parseuserscriptjob.cpp
+++ b/libksieve/ksieveui/managescriptsjob/parseuserscriptjob.cpp
@@ -85,7 +85,6 @@ void ParseUserScriptJob::emitSuccess(const QStringList &activeScriptList)
emit finished(this);
}
-
QStringList ParseUserScriptJob::parsescript(const QString &script, bool &result)
{
QStringList lst;
diff --git a/libksieve/ksieveui/managescriptsjob/parseuserscriptjob.h b/libksieve/ksieveui/managescriptsjob/parseuserscriptjob.h
index 595ef66..3fc5053 100644
--- a/libksieve/ksieveui/managescriptsjob/parseuserscriptjob.h
+++ b/libksieve/ksieveui/managescriptsjob/parseuserscriptjob.h
@@ -32,6 +32,8 @@ namespace KSieveUi {
class KSIEVEUI_EXPORT ParseUserScriptJob : public QObject
{
Q_OBJECT
+
+ friend class ParseUserJobTest;
public:
explicit ParseUserScriptJob(const KUrl &url,QObject *parent=0);
~ParseUserScriptJob();
diff --git a/libksieve/ksieveui/managescriptsjob/tests/parseuserjobtest.cpp b/libksieve/ksieveui/managescriptsjob/tests/parseuserjobtest.cpp
index 2f39ffa..c699e93 100644
--- a/libksieve/ksieveui/managescriptsjob/tests/parseuserjobtest.cpp
+++ b/libksieve/ksieveui/managescriptsjob/tests/parseuserjobtest.cpp
@@ -18,19 +18,20 @@
#include "ksieveui/managescriptsjob/parseuserscriptjob.h"
#include <qtest_kde.h>
+using namespace KSieveUi;
-QTEST_KDEMAIN( ParseUserTest, NoGUI )
+QTEST_KDEMAIN( ParseUserJobTest, NoGUI )
-void ParseUserTest::testParseEmptyUserJob()
+void ParseUserJobTest::testParseEmptyUserJob()
{
const QString script;
bool result;
- const QStringList lst = KSieveUi::ParseUserScriptJob::parsescript(script, result);
+ const QStringList lst = ParseUserScriptJob::parsescript(script, result);
QCOMPARE(lst.count(), 0);
QCOMPARE(result, true);
}
-void ParseUserTest::testParseUserTwoActiveScriptJob()
+void ParseUserJobTest::testParseUserTwoActiveScriptJob()
{
const QString script = QLatin1String("# USER Management Script\n"
"#\n"
@@ -44,12 +45,12 @@ void ParseUserTest::testParseUserTwoActiveScriptJob()
"include :personal \"file1\";\n"
"include :personal \"file2\";\n");
bool result;
- const QStringList lst = KSieveUi::ParseUserScriptJob::parsescript(script, result);
+ const QStringList lst = ParseUserScriptJob::parsescript(script, result);
QCOMPARE(lst.count(), 2);
QCOMPARE(result, true);
}
-void ParseUserTest::testParseUserNoActiveScriptJob()
+void ParseUserJobTest::testParseUserNoActiveScriptJob()
{
const QString script = QLatin1String("# USER Management Script\n"
"#\n"
@@ -61,12 +62,12 @@ void ParseUserTest::testParseUserNoActiveScriptJob()
"\n"
"require [\"include\"];\n");
bool result;
- const QStringList lst = KSieveUi::ParseUserScriptJob::parsescript(script, result);
+ const QStringList lst = ParseUserScriptJob::parsescript(script, result);
QCOMPARE(lst.count(), 0);
QCOMPARE(result, true);
}
-void ParseUserTest::testParseUserDuplicateActiveScriptJob()
+void ParseUserJobTest::testParseUserDuplicateActiveScriptJob()
{
const QString script = QLatin1String("# USER Management Script\n"
"#\n"
@@ -80,12 +81,12 @@ void ParseUserTest::testParseUserDuplicateActiveScriptJob()
"include :personal \"file1\";\n"
"include :personal \"file1\";\n");
bool result;
- const QStringList lst = KSieveUi::ParseUserScriptJob::parsescript(script, result);
+ const QStringList lst = ParseUserScriptJob::parsescript(script, result);
QCOMPARE(lst.count(), 1);
QCOMPARE(result, true);
}
-void ParseUserTest::testParseUserErrorScriptJob()
+void ParseUserJobTest::testParseUserErrorScriptJob()
{
const QString script = QLatin1String("# USER Management Script\n"
"#\n"
@@ -97,7 +98,7 @@ void ParseUserTest::testParseUserErrorScriptJob()
"\n"
"errorscript\n");
bool result;
- const QStringList lst = KSieveUi::ParseUserScriptJob::parsescript(script, result);
+ const QStringList lst = ParseUserScriptJob::parsescript(script, result);
QCOMPARE(lst.count(), 0);
QCOMPARE(result, false);
}
diff --git a/libksieve/ksieveui/managescriptsjob/tests/parseuserjobtest.h b/libksieve/ksieveui/managescriptsjob/tests/parseuserjobtest.h
index 3a62665..7806c21 100644
--- a/libksieve/ksieveui/managescriptsjob/tests/parseuserjobtest.h
+++ b/libksieve/ksieveui/managescriptsjob/tests/parseuserjobtest.h
@@ -19,7 +19,9 @@
#define PARSEUSERJOBTEST_H
#include <QObject>
-class ParseUserTest : public QObject
+
+namespace KSieveUi {
+class ParseUserJobTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
@@ -29,5 +31,5 @@ private Q_SLOTS:
void testParseUserDuplicateActiveScriptJob();
void testParseUserErrorScriptJob();
};
-
+}
#endif // PARSEUSERJOBTEST_H
commit 174b145429bc9f8c645fea751e6c000b24392a2f
Author: Sandro Knauà <knauss at kolabsys.com>
Date: Tue Mar 24 15:06:50 2015 +0100
Added tests for VacationParser
diff --git a/libksieve/ksieveui/vacation/tests/CMakeLists.txt b/libksieve/ksieveui/vacation/tests/CMakeLists.txt
index 546a63f..200e679 100644
--- a/libksieve/ksieveui/vacation/tests/CMakeLists.txt
+++ b/libksieve/ksieveui/vacation/tests/CMakeLists.txt
@@ -1,5 +1,7 @@
include_directories(${CMAKE_SOURCE_DIR}/libksieve
${CMAKE_SOURCE_DIR}/libksieve/ksieveui
+ ${CMAKE_BINARY_DIR}/libksieve
+ ${CMAKE_BINARY_DIR}/libksieve/ksieveui
)
@@ -10,3 +12,25 @@ set(vacation_multi_server_SRCS
KDE4_ADD_EXECUTABLE(vacationmultiservertest ${vacation_multi_server_SRCS} )
TARGET_LINK_LIBRARIES(vacationmultiservertest ${KDE4_KDEUI_LIBS} ksieveui ksieve)
+set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
+
+macro( add_vacation_test _source )
+ set( _test ${_source}test.cpp
+ ../${_source}.cpp
+ ../vacationscriptextractor.cpp
+ ${CMAKE_BINARY_DIR}/libksieve/ksieveui/sieve-vacation.cpp
+ ${CMAKE_SOURCE_DIR}/libksieve/parser/lexer.cpp
+ ${CMAKE_SOURCE_DIR}/libksieve/parser/parser.cpp
+ ${CMAKE_SOURCE_DIR}/libksieve/parser/utf8validator.cpp
+ )
+ get_filename_component( _name ${_source} NAME_WE )
+ kde4_add_unit_test( ${_name} TESTNAME vacation-${_name} ${_test} )
+ set_target_properties(${_name} PROPERTIES COMPILE_FLAGS -DVACATIONTESTDATADIR="\\"${CMAKE_CURRENT_SOURCE_DIR}/data/\\"")
+ target_link_libraries( ${_name}
+ ksieveui
+ kmanagesieve
+ ksieve
+ ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDEPIMLIBS_KMIME_LIBS} ${KDEPIMLIBS_KPIMIDENTITIES_LIBS})
+endmacro()
+
+add_vacation_test( vacationutils )
\ No newline at end of file
diff --git a/libksieve/ksieveui/vacation/tests/data/vacation-complex.siv b/libksieve/ksieveui/vacation/tests/data/vacation-complex.siv
new file mode 100644
index 0000000..b7b4140
--- /dev/null
+++ b/libksieve/ksieveui/vacation/tests/data/vacation-complex.siv
@@ -0,0 +1,8 @@
+require ["date","relational","vacation"];
+# EDITOR Roundcube (Managesieve)
+# EDITOR_VERSION 8.2
+# rule:[Urlaub]
+if allof (currentdate :zone "+0100" :value "ge" "date" "2015-01-02", currentdate :zone "+0100" :value "le" "date" "2015-03-04", not header :contains "X-Spam-Flag" "YES")
+{
+ vacation :days 7 :addresses "test at test.de" :subject "XXX" "dsfgsdfgsdfg";
+}
\ No newline at end of file
diff --git a/libksieve/ksieveui/vacation/tests/data/vacation-deactivate-complex.siv b/libksieve/ksieveui/vacation/tests/data/vacation-deactivate-complex.siv
new file mode 100644
index 0000000..bbd94ab
--- /dev/null
+++ b/libksieve/ksieveui/vacation/tests/data/vacation-deactivate-complex.siv
@@ -0,0 +1,8 @@
+require ["date","relational","vacation"];
+# EDITOR Roundcube (Managesieve)
+# EDITOR_VERSION 8.2
+# rule:[Urlaub]
+if false # allof (currentdate :zone "+0100" :value "ge" "date" "2015-01-02", currentdate :zone "+0100" :value "le" "date" "2015-03-04", not header :contains "X-Spam-Flag" "YES")
+{
+ vacation :days 7 :addresses "test at test.de" :subject "XXX" "dsfgsdfgsdfg";
+}
\ No newline at end of file
diff --git a/libksieve/ksieveui/vacation/tests/data/vacation-deactivate-multiple.siv b/libksieve/ksieveui/vacation/tests/data/vacation-deactivate-multiple.siv
new file mode 100644
index 0000000..1889dc2
--- /dev/null
+++ b/libksieve/ksieveui/vacation/tests/data/vacation-deactivate-multiple.siv
@@ -0,0 +1,19 @@
+require ["vacation"];
+
+if true
+{
+ testcommand;
+}
+
+# EDITOR Roundcube (Managesieve)
+# EDITOR_VERSION 8.2
+# rule:[Urlaub]
+if false # true
+{
+ vacation :subject "XXX" "dsfgsdfgsdfg";
+}
+
+if true
+{
+ testcommand;
+}
\ No newline at end of file
diff --git a/libksieve/ksieveui/vacation/tests/data/vacation-deactivate.siv b/libksieve/ksieveui/vacation/tests/data/vacation-deactivate.siv
new file mode 100644
index 0000000..c2b15a2
--- /dev/null
+++ b/libksieve/ksieveui/vacation/tests/data/vacation-deactivate.siv
@@ -0,0 +1,9 @@
+require ["vacation"];
+
+# EDITOR Roundcube (Managesieve)
+# EDITOR_VERSION 8.2
+# rule:[Urlaub]
+if false # true
+{
+ vacation :subject "XXX" "dsfgsdfgsdfg";
+}
\ No newline at end of file
diff --git a/libksieve/ksieveui/vacation/tests/data/vacation-multiple.siv b/libksieve/ksieveui/vacation/tests/data/vacation-multiple.siv
new file mode 100644
index 0000000..7737faf
--- /dev/null
+++ b/libksieve/ksieveui/vacation/tests/data/vacation-multiple.siv
@@ -0,0 +1,16 @@
+require ["vacation"];
+
+if false
+{
+ testcommand;
+}
+
+# EDITOR Roundcube (Managesieve)
+# EDITOR_VERSION 8.2
+# rule:[Urlaub]
+vacation :subject "XXX" "dsfgsdfgsdfg";
+
+if false
+{
+ testcommand;
+}
diff --git a/libksieve/ksieveui/vacation/tests/data/vacation-notfound.siv b/libksieve/ksieveui/vacation/tests/data/vacation-notfound.siv
new file mode 100644
index 0000000..ce93aee
--- /dev/null
+++ b/libksieve/ksieveui/vacation/tests/data/vacation-notfound.siv
@@ -0,0 +1,15 @@
+#blabla
+
+testcommand;
+
+if true {
+ testcmd2;
+}
+
+if false {
+ testcmd3;
+}
+
+if true {
+ testcmd4;
+}
\ No newline at end of file
diff --git a/libksieve/ksieveui/vacation/tests/data/vacation-simple.siv b/libksieve/ksieveui/vacation/tests/data/vacation-simple.siv
new file mode 100644
index 0000000..ab6c321
--- /dev/null
+++ b/libksieve/ksieveui/vacation/tests/data/vacation-simple.siv
@@ -0,0 +1,6 @@
+require ["vacation"];
+
+# EDITOR Roundcube (Managesieve)
+# EDITOR_VERSION 8.2
+# rule:[Urlaub]
+vacation :subject "XXX" "dsfgsdfgsdfg";
\ No newline at end of file
diff --git a/libksieve/ksieveui/vacation/tests/vacationutilstest.cpp b/libksieve/ksieveui/vacation/tests/vacationutilstest.cpp
new file mode 100644
index 0000000..876fcb5
--- /dev/null
+++ b/libksieve/ksieveui/vacation/tests/vacationutilstest.cpp
@@ -0,0 +1,152 @@
+/*
+ Copyright (c) 2015 Sandro Knauà <knauss at kolabsys.com>
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License, version 2, as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+#include "vacationutilstest.h"
+#include "vacation/vacationutils.h"
+
+#include <QFile>
+#include <qtest_kde.h>
+#include <KDebug>
+
+using namespace KSieveUi;
+
+QTEST_KDEMAIN( VacationUtilsTest, NoGUI )
+
+void VacationUtilsTest::testParseEmptyScript()
+{
+ const QString script;
+ QCOMPARE(VacationUtils::foundVacationScript(script), false);
+}
+
+void VacationUtilsTest::testParseOnlyComment()
+{
+ QString script(QLatin1String("#comment"));
+ QCOMPARE(VacationUtils::foundVacationScript(script), false);
+ script = QLatin1String("#comment\n\n#comment\n");
+ QCOMPARE(VacationUtils::foundVacationScript(script), false);
+}
+
+void VacationUtilsTest::testParseActivate_data()
+{
+ QTest::addColumn<QString>("filename");
+ QTest::addColumn<bool>("found");
+ QTest::addColumn<bool>("active");
+
+ QTest::newRow("notfound") << QString::fromLatin1("vacation-notfound.siv") << false << false;
+ QTest::newRow("simple") << QString::fromLatin1("vacation-simple.siv") << true << true;
+ QTest::newRow("multile if") << QString::fromLatin1("vacation-multiple.siv") << true << true;
+ QTest::newRow("deactivate") << QString::fromLatin1("vacation-deactivate.siv") << true << false;
+ QTest::newRow("deactivate-multiple if") << QString::fromLatin1("vacation-deactivate-multiple.siv") << true << false;
+ QTest::newRow("deactivate-complex") << QString::fromLatin1("vacation-deactivate-complex.siv") << true << false;
+}
+
+
+void VacationUtilsTest::testParseActivate()
+{
+ QFETCH(QString, filename);
+ QFETCH(bool, found);
+ QFETCH(bool, active);
+
+ QFile file(QLatin1String(VACATIONTESTDATADIR)+filename);
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QString script = QString::fromUtf8(file.readAll());
+ QCOMPARE(VacationUtils::foundVacationScript(script), found);
+
+ QString messageText;
+ QString subject;
+ int notificationInterval;
+ QStringList aliases;
+ bool sendForSpam;
+ QString domainName;
+ QDate startDate;
+ QDate endDate;
+ bool scriptActive = !active;
+
+ bool ret = VacationUtils::parseScript(script, scriptActive, messageText, subject, notificationInterval, aliases, sendForSpam, domainName, startDate, endDate);
+ QCOMPARE(ret, found);
+ QCOMPARE(scriptActive, active);
+}
+
+void VacationUtilsTest::testParseScript_data()
+{
+ QTest::addColumn<QString>("activate");
+ QTest::addColumn<QString>("deactivate");
+
+ QTest::newRow("simple") << QString::fromLatin1("vacation-simple.siv") << QString::fromLatin1("vacation-deactivate.siv");
+ QTest::newRow("complex") << QString::fromLatin1("vacation-complex.siv") << QString::fromLatin1("vacation-deactivate-complex.siv");
+}
+
+
+void VacationUtilsTest::testParseScript()
+{
+ QFETCH(QString, activate);
+ QFETCH(QString, deactivate);
+ QFile fileA(QLatin1String(VACATIONTESTDATADIR) + activate);
+ QVERIFY(fileA.open(QIODevice::ReadOnly));
+ QString scriptA = QString::fromUtf8(fileA.readAll());
+ QFile fileD(QLatin1String(VACATIONTESTDATADIR) + deactivate);
+ QVERIFY(fileD.open(QIODevice::ReadOnly));
+ QString scriptD = QString::fromUtf8(fileD.readAll());
+
+ QString messageTextA, messageTextD;
+ QString subjectA, subjectD;
+ int notificationIntervalA, notificationIntervalD;
+ QStringList aliasesA, aliasesD;
+ bool sendForSpamA, sendForSpamD;
+ QString domainNameA, domainNameD;
+ QDate startDateA, startDateD;
+ QDate endDateA, endDateD;
+ bool scriptActiveA, scriptActiveD;
+ VacationUtils::parseScript(scriptA, scriptActiveA, messageTextA, subjectA, notificationIntervalA, aliasesA, sendForSpamA, domainNameA, startDateA, endDateA);
+ VacationUtils::parseScript(scriptD, scriptActiveD, messageTextD, subjectD, notificationIntervalD, aliasesD, sendForSpamD, domainNameD, startDateD, endDateD);
+ QCOMPARE(scriptActiveA, true);
+ QCOMPARE(scriptActiveD, false);
+ QCOMPARE(messageTextD, messageTextA);
+ QCOMPARE(subjectD, subjectA);
+ QCOMPARE(notificationIntervalD, notificationIntervalA);
+ QCOMPARE(aliasesD, aliasesA);
+ QCOMPARE(sendForSpamD, sendForSpamA);
+ QCOMPARE(domainNameD, domainNameA);
+ QCOMPARE(startDateD, startDateA);
+ QCOMPARE(endDateD, endDateA);
+}
+
+void VacationUtilsTest::testParseScriptComplex()
+{
+ QFile file(QLatin1String(VACATIONTESTDATADIR "vacation-complex.siv"));
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QString script = QString::fromUtf8(file.readAll());
+
+ QString messageText;
+ QString subject;
+ int notificationInterval;
+ QStringList aliases;
+ bool sendForSpam;
+ QString domainName;
+ QDate startDate;
+ QDate endDate;
+ bool scriptActive;
+ VacationUtils::parseScript(script, scriptActive, messageText, subject, notificationInterval, aliases, sendForSpam, domainName, startDate, endDate);
+ QCOMPARE(scriptActive, true);
+ QCOMPARE(messageText, QLatin1String("dsfgsdfgsdfg"));
+ QCOMPARE(subject, QLatin1String("XXX"));
+ QCOMPARE(notificationInterval, 7);
+ QCOMPARE(aliases, QStringList() << QLatin1String("test at test.de"));
+ QCOMPARE(sendForSpam, false);
+ QCOMPARE(domainName, QString());
+ QCOMPARE(startDate, QDate(2015, 01, 02));
+ QCOMPARE(endDate, QDate(2015,03,04));
+}
\ No newline at end of file
diff --git a/libksieve/ksieveui/vacation/tests/vacationutilstest.h b/libksieve/ksieveui/vacation/tests/vacationutilstest.h
new file mode 100644
index 0000000..eac4378
--- /dev/null
+++ b/libksieve/ksieveui/vacation/tests/vacationutilstest.h
@@ -0,0 +1,37 @@
+/*
+ Copyright (c) 2015 Sandro Knauà <knauss at kolabsys.com>
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License, version 2, as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef VACATIONUTILSTEST_H
+#define VACATIONUTILSTEST_H
+
+#include <QObject>
+
+namespace KSieveUi {
+class VacationUtilsTest : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void testParseEmptyScript();
+ void testParseOnlyComment();
+ void testParseActivate_data();
+ void testParseActivate();
+ void testParseScript_data();
+ void testParseScript();
+ void testParseScriptComplex();
+};
+}
+#endif // VACATIONUTILSTEST_H
diff --git a/libksieve/ksieveui/vacation/vacation.cpp b/libksieve/ksieveui/vacation/vacation.cpp
index 96689fa..a886fcf 100644
--- a/libksieve/ksieveui/vacation/vacation.cpp
+++ b/libksieve/ksieveui/vacation/vacation.cpp
@@ -115,18 +115,20 @@ void Vacation::slotGetResult( KManageSieve::SieveJob * job, bool success,
QString domainName = VacationUtils::defaultDomainName();
QDate startDate = VacationUtils::defaultStartDate();
QDate endDate = VacationUtils::defaultEndDate();
+ bool sActive = true;
+
if ( !success ) active = false; // default to inactive
- if ( !mCheckOnly && ( !success || !KSieveUi::VacationUtils::parseScript( script, messageText, subject, notificationInterval, aliases, sendForSpam, domainName, startDate, endDate ) ) )
+ if ( !mCheckOnly && ( !success || !KSieveUi::VacationUtils::parseScript( script, sActive, messageText, subject, notificationInterval, aliases, sendForSpam, domainName, startDate, endDate ) ) )
KMessageBox::information( 0, i18n("Someone (probably you) changed the "
"vacation script on the server.\n"
"KMail is no longer able to determine "
"the parameters for the autoreplies.\n"
"Default values will be used." ) );
- mWasActive = active;
+ mWasActive = active && sActive;
if ( mDialog ) {
- mDialog->setActivateVacation( active );
+ mDialog->setActivateVacation( active && sActive );
mDialog->setSubject(subject);
mDialog->setMessageText( messageText );
mDialog->setNotificationInterval( notificationInterval );
diff --git a/libksieve/ksieveui/vacation/vacationpagewidget.cpp b/libksieve/ksieveui/vacation/vacationpagewidget.cpp
index 784b9a4..cbdc4c0 100644
--- a/libksieve/ksieveui/vacation/vacationpagewidget.cpp
+++ b/libksieve/ksieveui/vacation/vacationpagewidget.cpp
@@ -129,16 +129,17 @@ void VacationPageWidget::slotGetResult(const QString &serverName, const QStringL
QString domainName = VacationUtils::defaultDomainName();
QDate startDate = VacationUtils::defaultStartDate();
QDate endDate = VacationUtils::defaultEndDate();
+ bool scriptActive = true;
- const bool bParse = KSieveUi::VacationUtils::parseScript(script, messageText, subject, notificationInterval, aliases, sendForSpam, domainName, startDate, endDate);
+ const bool bParse = KSieveUi::VacationUtils::parseScript(script, scriptActive, messageText, subject, notificationInterval, aliases, sendForSpam, domainName, startDate, endDate);
if (!bParse) {
mVacationWarningWidget->setVisible(true);
}
- mWasActive = active;
+ mWasActive = active && scriptActive;
mVacationEditWidget->setEnabled(true);
- mVacationEditWidget->setActivateVacation( active );
+ mVacationEditWidget->setActivateVacation( active && scriptActive );
mVacationEditWidget->setMessageText( messageText );
mVacationEditWidget->setSubject( subject );
mVacationEditWidget->setNotificationInterval( notificationInterval );
commit df667c6c51e6a1e9e25dd925096f7009bf308281
Author: Sandro Knauà <knauss at kolabsys.com>
Date: Tue Mar 24 15:04:52 2015 +0100
char* -> QLatin1String
diff --git a/libksieve/parser/lexer.cpp b/libksieve/parser/lexer.cpp
index 1dfc848..653c154 100644
--- a/libksieve/parser/lexer.cpp
+++ b/libksieve/parser/lexer.cpp
@@ -161,7 +161,7 @@ static inline bool is8Bit( signed char ch ) {
#endif
static QString removeCRLF( const QString & s ) {
const bool CRLF = s.endsWith( QLatin1String("\r\n") );
- const bool LF = !CRLF && s.endsWith( '\n' );
+ const bool LF = !CRLF && s.endsWith( QLatin1Char('\n') );
const int e = CRLF ? 2 : LF ? 1 : 0 ; // what to chop off at the end
@@ -255,7 +255,7 @@ Lexer::Token Lexer::Impl::nextToken( QString & result ) {
case ')':
case ';':
case ',': // Special
- result = *mState.cursor++;
+ result = QLatin1Char(*mState.cursor++);
return Special;
case '0':
case '1':
@@ -401,7 +401,7 @@ bool Lexer::Impl::parseBracketComment( QString & result, bool reallySave ) {
}
if ( reallySave ) {
QString tmp = QString::fromUtf8( commentStart, commentLength );
- result += tmp.remove( '\r' ); // get rid of CR in CRLF pairs
+ result += tmp.remove( QLatin1Char('\r') ); // get rid of CR in CRLF pairs
}
}
@@ -505,7 +505,7 @@ bool Lexer::Impl::parseNumber( QString & result ) {
assert( isdigit( *mState.cursor ) );
while ( !atEnd() && isdigit( *mState.cursor ) )
- result += *mState.cursor++;
+ result += QLatin1Char(*mState.cursor++);
if ( atEnd() || isDelim( *mState.cursor ) )
return true;
@@ -517,7 +517,7 @@ bool Lexer::Impl::parseNumber( QString & result ) {
case 'm':
case 'K':
case 'k':
- result += *mState.cursor++;
+ result += QLatin1Char(*mState.cursor++);
break;
default:
makeIllegalCharError();
@@ -589,21 +589,21 @@ MultiLineStart:
}
const QString line = removeCRLF( QString::fromUtf8( oldBeginOfLine, lineLength ) );
lines.push_back( removeDotStuff( line ) );
- if ( line == "." )
+ if ( line == QLatin1String(".") )
break;
} else {
lines.push_back( QString() );
}
}
- if ( lines.back() != "." ) {
+ if ( lines.back() != QLatin1String(".") ) {
makeError( Error::PrematureEndOfMultiLine, mlBeginLine, mlBeginCol );
return false;
}
assert( !lines.empty() );
lines.erase( --lines.end() ); // don't include the lone dot.
- result = lines.join("\n");
+ result = lines.join(QLatin1String("\n"));
return true;
}
@@ -630,7 +630,7 @@ bool Lexer::Impl::parseQuotedString( QString & result ) {
case '\n':
if ( !eatCRLF() )
return false;
- result += '\n';
+ result += QLatin1Char('\n');
break;
case '\\':
++mState.cursor;
@@ -639,7 +639,7 @@ bool Lexer::Impl::parseQuotedString( QString & result ) {
// else fall through:
default:
if ( !is8Bit( *mState.cursor ) )
- result += *mState.cursor++;
+ result += QLatin1Char(*mState.cursor++);
else { // probably UTF-8
const char * const eightBitBegin = mState.cursor;
skipTo8BitEnd();
diff --git a/libksieve/parser/parser.cpp b/libksieve/parser/parser.cpp
index 2192e68..3562452 100644
--- a/libksieve/parser/parser.cpp
+++ b/libksieve/parser/parser.cpp
@@ -130,7 +130,7 @@ bool Parser::Impl::isArgumentToken() const {
return isStringToken() ||
token() == Lexer::Number ||
token() == Lexer::Tag ||
- ( token() == Lexer::Special && mTokenValue == "[" );
+ ( token() == Lexer::Special && mTokenValue == QLatin1String("[")) ;
}
bool Parser::Impl::obtainToken() {
@@ -251,7 +251,7 @@ bool Parser::Impl::parseCommand() {
return false;
}
- if ( token() == Lexer::Special && tokenValue() == "(" ) { // test-list
+ if ( token() == Lexer::Special && tokenValue() == QLatin1String ("(")) { // test-list
if ( !parseTestList() ) {
assert( error() );
return false;
@@ -280,9 +280,9 @@ bool Parser::Impl::parseCommand() {
return false;
}
- if ( tokenValue() == ";" )
+ if ( tokenValue() == QLatin1String (";"))
consumeToken();
- else if ( tokenValue() == "{" ) { // block
+ else if ( tokenValue() == QLatin1String ("{")) { // block
if ( !parseBlock() )
return false; // it's an error since we saw '{'
} else {
@@ -334,7 +334,7 @@ bool Parser::Impl::parseArgument() {
scriptBuilder()->stringArgument( tokenValue(), token() == Lexer::MultiLineString, QString() );
consumeToken();
return true;
- } else if ( token() == Lexer::Special && tokenValue() == "[" ) {
+ } else if ( token() == Lexer::Special && tokenValue() == QLatin1String("[")) {
if ( !parseStringList() ) {
assert( error() );
return false;
@@ -352,7 +352,7 @@ bool Parser::Impl::parseTestList() {
if ( !obtainToken() || atEnd() )
return false;
- if ( token() != Lexer::Special || tokenValue() != "(" )
+ if ( token() != Lexer::Special || tokenValue() != QLatin1String("("))
return false;
if ( scriptBuilder() )
scriptBuilder()->testListStart();
@@ -462,7 +462,7 @@ bool Parser::Impl::parseTest() {
if ( atEnd() ) // a test w/o nested tests
goto TestEnd;
- if ( token() == Lexer::Special && tokenValue() == "(" ) { // test-list
+ if ( token() == Lexer::Special && tokenValue() == QLatin1String("(")) { // test-list
if ( !parseTestList() ) {
assert( error() );
return false;
@@ -488,7 +488,7 @@ bool Parser::Impl::parseBlock() {
if ( !obtainToken() || atEnd() )
return false;
- if ( token() != Lexer::Special || tokenValue() != "{" )
+ if ( token() != Lexer::Special || tokenValue() != QLatin1String("{"))
return false;
if ( scriptBuilder() )
scriptBuilder()->blockStart();
@@ -517,7 +517,7 @@ bool Parser::Impl::parseBlock() {
return false;
}
- if ( token() != Lexer::Special || tokenValue() != "}" ) {
+ if ( token() != Lexer::Special || tokenValue() != QLatin1String("}")) {
makeError( Error::NonCommandInCommandList );
return false;
}
@@ -538,7 +538,7 @@ bool Parser::Impl::parseStringList() {
if ( !obtainToken() || atEnd() )
return false;
- if ( token() != Lexer::Special || tokenValue() != "[" )
+ if ( token() != Lexer::Special || tokenValue() != QLatin1String("[") )
return false;
if ( scriptBuilder() )
@@ -619,7 +619,7 @@ bool Parser::Impl::parseNumber() {
int i = 0;
const QByteArray s = tokenValue().toLatin1();
for ( const int len = s.length() ; i < len && isdigit( s[i] ) ; ++i ) {
- const unsigned long digitValue = s[i] - '0' ;
+ const unsigned long digitValue = s[i] - QLatin1Char('0').toLatin1() ;
if ( willOverflowULong( result, digitValue ) ) {
makeError( Error::NumberOutOfRange );
return false;
More information about the commits
mailing list