Commit 35156a5c authored by Laurent Montel's avatar Laurent Montel 😁

Implement comment support for condition

parent 7e371009
......@@ -212,3 +212,12 @@ AbstractRegexpEditorLineEdit *AutoCreateScriptUtil::createRegexpEditorLineEdit(Q
}
return edit;
}
QString AutoCreateScriptUtil::generateConditionComment(const QString &comment)
{
QString strComment;
if (!comment.trimmed().isEmpty()) {
strComment = QStringLiteral(" #") + comment;
}
return strComment;
}
......@@ -44,6 +44,7 @@ QString createFullWhatsThis(const QString &help, const QString &href);
QString protectSlash(QString str);
QString indentation();
AbstractRegexpEditorLineEdit *createRegexpEditorLineEdit(QWidget *parent = nullptr);
QString generateConditionComment(const QString &comment);
}
}
#endif // AUTOCREATESCRIPTUTIL_H
require "imapflags";
require "imap4flags";
require "fileinto";
#SCRIPTNAME: test1
if header :is "" #test header
{
keep :flags [ "\\Answered", "\\Flagged" ];
......@@ -16,4 +12,4 @@ if header :is "" #test header
#comment2
fileinto "";
}
}
\ No newline at end of file
......@@ -111,7 +111,6 @@ void SieveEditorGraphicalModeWidgetTest::shouldLoadScripts()
QEXPECT_FAIL("failed-2", "Expected failure on failed-2 file. Problem with body + text.", Continue);
QEXPECT_FAIL("failed-if-in-if", "Expected failure on failed-if-in-if file. Problem with if in another if.", Continue);
QEXPECT_FAIL("test-comment2", "Expected failure on test-comment2 file. Problem with # and /* .", Continue);
QEXPECT_FAIL("test-comment4", "Expected failure on test-comment4 file. Problem with comment after a condition .", Continue);
QCOMPARE(proc.exitCode(), 0);
}
}
......
......@@ -98,6 +98,7 @@ bool SieveActionRedirect::setParamWidgetValue(const QDomElement &element, QWidge
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
setComment(e.text());
//implement in the future ?
} else {
unknownTag(tagName, error);
......
......@@ -89,7 +89,12 @@ QString SieveConditionAddress::code(QWidget *w) const
const QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("editaddress"));
const QString addressStr = AutoCreateScriptUtil::createAddressList(edit->text().trimmed(), false);
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("address %1 %2 %3 %4").arg(selectAddressPartStr, matchTypeStr, selectHeaderTypeStr, addressStr);
QString strComment;
if (!comment().trimmed().isEmpty()) {
strComment = QLatin1Char('#') + comment();
}
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("address %1 %2 %3 %4").arg(selectAddressPartStr, matchTypeStr, selectHeaderTypeStr, addressStr)
+ AutoCreateScriptUtil::generateConditionComment(comment());
}
QStringList SieveConditionAddress::needRequires(QWidget *w) const
......@@ -144,7 +149,7 @@ bool SieveConditionAddress::setParamWidgetValue(const QDomElement &element, QWid
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionAddress::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -71,7 +71,8 @@ QString SieveConditionBody::code(QWidget *w) const
QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("edit"));
const QString editValue = AutoCreateScriptUtil::createAddressList(edit->text().trimmed(), false);
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("body %1 %2 %3").arg(bodyValue, matchValue, editValue);
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("body %1 %2 %3").arg(bodyValue, matchValue, editValue)
+ AutoCreateScriptUtil::generateConditionComment(comment());;
}
QStringList SieveConditionBody::needRequires(QWidget *) const
......@@ -125,7 +126,7 @@ bool SieveConditionBody::setParamWidgetValue(const QDomElement &element, QWidget
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else if (tagName == QLatin1String("list")) {
strValue << AutoCreateScriptUtil::listValueToStr(e);
wasListElement = true;
......
......@@ -83,7 +83,7 @@ QString SieveConditionConvert::code(QWidget *w) const
if (!paramsStr.isEmpty()) {
result += QStringLiteral("%1").arg(paramsStr);
}
return result;
return result + AutoCreateScriptUtil::generateConditionComment(comment());
}
QStringList SieveConditionConvert::needRequires(QWidget *) const
......@@ -132,7 +132,7 @@ bool SieveConditionConvert::setParamWidgetValue(const QDomElement &element, QWid
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << "SieveActionConvert::setParamWidgetValue unknown tag " << tagName;
......
......@@ -64,7 +64,8 @@ QString SieveConditionCurrentDate::code(QWidget *w) const
const SelectDateWidget *dateWidget = w->findChild<SelectDateWidget *>(QStringLiteral("datewidget"));
const QString dateWidgetStr = dateWidget->code();
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("currentdate %1 %2").arg(matchTypeStr, dateWidgetStr);
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("currentdate %1 %2").arg(matchTypeStr, dateWidgetStr)
+ AutoCreateScriptUtil::generateConditionComment(comment());
}
bool SieveConditionCurrentDate::needCheckIfServerHasCapability() const
......@@ -113,7 +114,7 @@ bool SieveConditionCurrentDate::setParamWidgetValue(const QDomElement &element,
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << "SieveConditionCurrentDate::setParamWidgetValue unknown tag " << tagName;
......
......@@ -79,7 +79,8 @@ QString SieveConditionDate::code(QWidget *w) const
const SelectDateWidget *dateWidget = w->findChild<SelectDateWidget *>(QStringLiteral("datewidget"));
const QString dateWidgetStr = dateWidget->code();
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("date %1 \"%2\" %3").arg(matchTypeStr, headerStr, dateWidgetStr);
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("date %1 \"%2\" %3").arg(matchTypeStr, headerStr, dateWidgetStr)
+ AutoCreateScriptUtil::generateConditionComment(comment());
}
bool SieveConditionDate::needCheckIfServerHasCapability() const
......@@ -131,7 +132,7 @@ bool SieveConditionDate::setParamWidgetValue(const QDomElement &element, QWidget
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << "SieveConditionDate::setParamWidgetValue unknown tag " << tagName;
......
......@@ -92,7 +92,8 @@ QString SieveConditionEnvelope::code(QWidget *w) const
const QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("editaddress"));
const QString addressStr = AutoCreateScriptUtil::createAddressList(edit->text().trimmed(), false);
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("envelope %1 %2 %3 %4").arg(selectAddressPartStr, matchTypeStr, selectHeaderTypeStr, addressStr);
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("envelope %1 %2 %3 %4").arg(selectAddressPartStr, matchTypeStr, selectHeaderTypeStr, addressStr)
+ AutoCreateScriptUtil::generateConditionComment(comment());
}
QStringList SieveConditionEnvelope::needRequires(QWidget *w) const
......@@ -168,7 +169,7 @@ bool SieveConditionEnvelope::setParamWidgetValue(const QDomElement &element, QWi
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionEnvelope::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -82,7 +82,7 @@ QString SieveConditionEnvironment::code(QWidget *w) const
const QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value"));
const QString valueStr = value->text();
return QStringLiteral("environment \"%1\" \"%2\"").arg(itemStr, valueStr);
return QStringLiteral("environment \"%1\" \"%2\"").arg(itemStr, valueStr) + AutoCreateScriptUtil::generateConditionComment(comment());
}
QStringList SieveConditionEnvironment::needRequires(QWidget *) const
......@@ -128,7 +128,7 @@ bool SieveConditionEnvironment::setParamWidgetValue(const QDomElement &element,
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveActionSetVariable::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -67,7 +67,7 @@ QString SieveConditionExists::code(QWidget *w) const
const QString comparaison = combo->itemData(combo->currentIndex()).toString();
const SelectHeaderTypeComboBox *value = w->findChild<SelectHeaderTypeComboBox *>(QStringLiteral("headervalue"));
return QStringLiteral("%1 %2").arg(comparaison, value->code());
return QStringLiteral("%1 %2").arg(comparaison, value->code()) + AutoCreateScriptUtil::generateConditionComment(comment());
}
QString SieveConditionExists::help() const
......@@ -95,7 +95,7 @@ bool SieveConditionExists::setParamWidgetValue(const QDomElement &element, QWidg
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionExists::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -94,7 +94,7 @@ QString SieveConditionHasFlag::code(QWidget *w) const
const QString valueStr = value->text();
result += QLatin1String(" \"") + valueStr + QLatin1Char('"');
}
return result;
return result + AutoCreateScriptUtil::generateConditionComment(comment());
}
QStringList SieveConditionHasFlag::needRequires(QWidget *) const
......@@ -151,7 +151,7 @@ bool SieveConditionHasFlag::setParamWidgetValue(const QDomElement &element, QWid
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionExists::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -79,7 +79,8 @@ QString SieveConditionHeader::code(QWidget *w) const
QString valueStr = value->text();
valueStr = AutoCreateScriptUtil::fixListValue(valueStr);
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("header %1 %2 %3").arg(matchString, headerStr, valueStr);
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("header %1 %2 %3").arg(matchString, headerStr, valueStr)
+ AutoCreateScriptUtil::generateConditionComment(comment());
}
QString SieveConditionHeader::help() const
......@@ -128,8 +129,7 @@ bool SieveConditionHeader::setParamWidgetValue(const QDomElement &element, QWidg
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
qDebug() << " Need to implement ";
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionHeader::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -55,7 +55,8 @@ QString SieveConditionIhave::code(QWidget *w) const
{
const QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("edit"));
const QString editValue = edit->text();
return QStringLiteral("ihave %1").arg(AutoCreateScriptUtil::createList(editValue, QLatin1Char(',')));
return QStringLiteral("ihave %1").arg(AutoCreateScriptUtil::createList(editValue, QLatin1Char(',')))
+ AutoCreateScriptUtil::generateConditionComment(comment());
}
QStringList SieveConditionIhave::needRequires(QWidget *) const
......@@ -92,7 +93,7 @@ bool SieveConditionIhave::setParamWidgetValue(const QDomElement &element, QWidge
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionIhave::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -53,7 +53,7 @@ QString SieveConditionMailboxExists::code(QWidget *w) const
{
const QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("edit"));
const QString editValue = edit->text();
return QStringLiteral("mailboxexists \"%1\"").arg(editValue);
return QStringLiteral("mailboxexists \"%1\"").arg(editValue) + AutoCreateScriptUtil::generateConditionComment(comment());
}
QStringList SieveConditionMailboxExists::needRequires(QWidget *) const
......@@ -91,7 +91,7 @@ bool SieveConditionMailboxExists::setParamWidgetValue(const QDomElement &element
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionMailboxExists::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -100,7 +100,7 @@ QString SieveConditionMetaData::code(QWidget *w) const
const QString valueStr = value->text();
result += QStringLiteral("\"%1\"").arg(valueStr);
return result;
return result + AutoCreateScriptUtil::generateConditionComment(comment());
}
QStringList SieveConditionMetaData::needRequires(QWidget *) const
......@@ -165,7 +165,7 @@ bool SieveConditionMetaData::setParamWidgetValue(const QDomElement &element, QWi
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionMetaData::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -66,7 +66,7 @@ QString SieveConditionMetaDataExists::code(QWidget *w) const
const QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value"));
const QString valueStr = value->text();
return QStringLiteral("metadataexists \"%1\" \"%2\"").arg(mailboxStr, valueStr);
return QStringLiteral("metadataexists \"%1\" \"%2\"").arg(mailboxStr, valueStr) + AutoCreateScriptUtil::generateConditionComment(comment());
}
QStringList SieveConditionMetaDataExists::needRequires(QWidget *) const
......@@ -113,7 +113,7 @@ bool SieveConditionMetaDataExists::setParamWidgetValue(const QDomElement &elemen
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionServerMetaDataExists::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -101,7 +101,7 @@ QString SieveConditionServerMetaData::code(QWidget *w) const
const QString valueStr = value->text();
result += QStringLiteral("\"%1\"").arg(valueStr);
return result;
return result + AutoCreateScriptUtil::generateConditionComment(comment());
}
QStringList SieveConditionServerMetaData::needRequires(QWidget *) const
......@@ -166,7 +166,7 @@ bool SieveConditionServerMetaData::setParamWidgetValue(const QDomElement &elemen
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionServerMetaData::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -18,6 +18,7 @@
*/
#include "sieveconditionservermetadataexists.h"
#include "editor/sieveeditorutil.h"
#include "autocreatescripts/autocreatescriptutil_p.h"
#include <KLocalizedString>
#include <QLineEdit>
......@@ -54,7 +55,7 @@ QString SieveConditionServerMetaDataExists::code(QWidget *w) const
{
const QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value"));
const QString valueStr = value->text();
return QStringLiteral("servermetadataexists \"%1\"").arg(valueStr);
return QStringLiteral("servermetadataexists \"%1\"").arg(valueStr) + AutoCreateScriptUtil::generateConditionComment(comment());
}
QStringList SieveConditionServerMetaDataExists::needRequires(QWidget *) const
......@@ -91,7 +92,7 @@ bool SieveConditionServerMetaDataExists::setParamWidgetValue(const QDomElement &
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionServerMetaDataExists::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -61,7 +61,7 @@ QString SieveConditionSize::code(QWidget *w) const
const QComboBox *combo = w->findChild<QComboBox *>(QStringLiteral("combosize"));
const QString comparaison = combo->itemData(combo->currentIndex()).toString();
const SelectSizeWidget *sizeWidget = w->findChild<SelectSizeWidget *>(QStringLiteral("sizewidget"));
return QStringLiteral("size %1 %2").arg(comparaison, sizeWidget->code());
return QStringLiteral("size %1 %2").arg(comparaison, sizeWidget->code()) + AutoCreateScriptUtil::generateConditionComment(comment());
}
QString SieveConditionSize::help() const
......@@ -94,7 +94,7 @@ bool SieveConditionSize::setParamWidgetValue(const QDomElement &element, QWidget
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionSize::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -89,7 +89,7 @@ QString SieveConditionSpamTest::code(QWidget *w) const
const QSpinBox *spinbox = w->findChild<QSpinBox *>(QStringLiteral("value"));
const QString value = QString::number(spinbox->value());
return QStringLiteral("spamtest %1 %2 %3 \"%4\"").arg(percentStr, relationStr, comparatorStr, value);
return QStringLiteral("spamtest %1 %2 %3 \"%4\"").arg(percentStr, relationStr, comparatorStr, value) + AutoCreateScriptUtil::generateConditionComment(comment());
}
bool SieveConditionSpamTest::needCheckIfServerHasCapability() const
......@@ -171,7 +171,7 @@ bool SieveConditionSpamTest::setParamWidgetValue(const QDomElement &element, QWi
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveSpamTest::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -73,7 +73,7 @@ QString SieveConditionVirusTest::code(QWidget *w) const
const QSpinBox *spinbox = w->findChild<QSpinBox *>(QStringLiteral("value"));
const QString value = QString::number(spinbox->value());
return QStringLiteral("virustest %1 %2 \"%3\"").arg(relationStr, comparatorStr, value);
return QStringLiteral("virustest %1 %2 \"%3\"").arg(relationStr, comparatorStr, value) + AutoCreateScriptUtil::generateConditionComment(comment());
}
bool SieveConditionVirusTest::needCheckIfServerHasCapability() const
......@@ -144,7 +144,7 @@ bool SieveConditionVirusTest::setParamWidgetValue(const QDomElement &element, QW
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
setComment(e.text());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionVirusTest::setParamWidgetValue unknown tagName " << tagName;
......
......@@ -406,6 +406,7 @@ void SieveConditionWidgetLister::loadScript(const QDomElement &e, bool uniqTest,
} else if (testTagName == QLatin1String("crlf")) {
//nothing
} else if (testTagName == QLatin1String("comment")) {
qDebug() << "Need to implement comment here ";
//nothing
//implement in the future ?
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment