Commit 91e79e77 authored by Laurent Montel's avatar Laurent Montel 😁

Try to improve comment support

parent 817a90a6
......@@ -2,6 +2,7 @@ require "imap4flags";
#SCRIPTNAME: Script part 0
#Script name: add flags
if size :under 1
{
addflag [ "\\Deleted", "\\Answered", "\\Flagged" ];
......
......@@ -3,6 +3,7 @@ require "imap4flags";
#SCRIPTNAME: Script part 0
#Script name: add-single-flag
if ihave "reject"
{
addflag [ "\\Seen" ];
......
......@@ -5,10 +5,11 @@ require "imap4flags";
#SCRIPTNAME: Script part 0
# Sieve filter
# Declare the extensions used by this script.
#
# Messages bigger than 100K will be rejected with an error message
#
if size :over 100K
{
reject text:
......
......@@ -2,6 +2,7 @@ require "foreverypart";
#SCRIPTNAME: Script part 0
#Script name: break
if true
{
break :name "optional name";
......
......@@ -2,6 +2,7 @@ require "convert";
#SCRIPTNAME: Script part 0
#Script name: convert action
if true
{
convert "image/png" "image/bmp" ["pix-x=250","pix-y=600"];
......
......@@ -2,6 +2,7 @@ require "editheader";
#SCRIPTNAME: Script part 0
#Script name: delete headers
if true
{
deleteheader :matches "header-str" "header-value";
......
......@@ -3,6 +3,7 @@ require "enclose";
#SCRIPTNAME: Script part 0
#Script name: enclose
if ihave "enclosz"
{
enclose :subject "subject" :headers "headers" text:
......
......@@ -2,6 +2,7 @@ require "extracttext";
#SCRIPTNAME: Script part 0
#Script name: extract-text
if true
{
extracttext :first 11 "voiture";
......
......@@ -4,6 +4,7 @@ require "mailbox";
#SCRIPTNAME: Script part 0
#Script name: scriptname
if header :is "Content-Type" "png"
{
fileinto :copy :create "INBOX";
......
......@@ -7,6 +7,7 @@ require "enclose";
#SCRIPTNAME: Script part 0
#Script name: include
include :personal "toto.siv";
global "global-variable";
set "test-variable" "25";
......
......@@ -3,6 +3,7 @@ require "include";
#SCRIPTNAME: Script part 0
#Script name: maiboxexist
if mailboxexists "INBOX2"
{
return;
......
......@@ -4,6 +4,7 @@ require "foreverypart";
#SCRIPTNAME: Script part 0
#Script name: not condition
if not envelope :localpart :is "Reply-To" "montel@kde.org"
{
break;
......
......@@ -3,6 +3,7 @@ require "foreverypart";
#SCRIPTNAME: Script part 0
#Script name: not condition
if allof (not header :is "Content-Type" "sdfsdf"
, ihave "xvwx"
)
......
......@@ -3,6 +3,7 @@ require "enotify";
#SCRIPTNAME: Script part 0
#Script name: notify
if convert "image/jpeg" "image/jpeg" ["pix-x=300","pix-y=200"]
{
notify :importance "2" :message "message !!!" "";
......
......@@ -3,6 +3,7 @@ require "copy";
#SCRIPTNAME: Script part 0
#Script name: redirect
if ihave "redirect"
{
redirect :copy "montel@kde.org";
......
......@@ -3,6 +3,7 @@ require "reject";
#SCRIPTNAME: Script part 0
#Script name: reject
if ihave "reject"
{
reject text:
......
......@@ -3,6 +3,7 @@ require "imap4flags";
#SCRIPTNAME: Script part 0
#Script name: remove flags
if ihave "reject"
{
removeflag [ "\\Answered", "\\Flagged", "\\Seen" ];
......
......@@ -2,6 +2,7 @@ require "replace";
#SCRIPTNAME: Script part 0
#Script name: replace
if true
{
replace :subject "subject" :from "montel@kde.org" text:
......
require "imapflags";
require "fileinto";
#SCRIPTNAME: test1
if header :is ""
{
/*Keep comment
Keep multi line*/
keep :flags [ "\\Answered", "\\Flagged" ];
} else {
#FileInto comment
#comment2
fileinto "";
}
require "imapflags";
require "fileinto";
#SCRIPTNAME: test1
if header :is ""
{
/*Keep comment
Keep multi line*/
keep :flags [ "\\Answered", "\\Flagged" ];
} else {
#FileInto comment
#comment2
fileinto "";
}
......@@ -3,6 +3,7 @@ require "imap4flags";
#SCRIPTNAME: test-date
#Script name: test-date
if allof (date :is "header" "day" "20"
, not date :matches "header" "hour" "08"
, not date :contains "header" "month" "08"
......
......@@ -3,6 +3,7 @@ require "subaddress";
#SCRIPTNAME: Script part 0
#Script name: test-envelop
if allof (envelope :user :is "to" "foo@example.com"
, not envelope :localpart :is "cc" "foo@example.com"
, not envelope :detail :matches "from" "foo@example.com"
......
......@@ -5,6 +5,7 @@ require "fileinto";
#SCRIPTNAME: Script part 0
# In this example the same user account receives mail for both
# "ken@example.com" and "postmaster@example.com"
# File all messages to postmaster into a single mailbox,
# ignoring the :detail part.
if envelope :user :is "to" "postmaster"
......
......@@ -3,6 +3,7 @@ require "imap4flags";
#SCRIPTNAME: Script part 0
#Script name: test environnement
if environment "PATH" "local folder"
{
keep;
......
#SCRIPTNAME: Script part 0
#Script name: test-exists
if allof (exists "Date"
, not exists "Reply-To"
)
......
......@@ -3,6 +3,7 @@ require "ihave";
#SCRIPTNAME: Script part 0
#Script name: test-foreach
foreverypart :name "foreach1" {
if ihave "value"
{
......
......@@ -7,9 +7,9 @@ require "imap4flags";
#SCRIPTNAME: Script part 0
# Sieve filter
# Declare the extensions used by this script.
#
# Messages bigger than 100K will be rejected with an error message
#
foreverypart :name "foo" {
if size :over 100K
{
......
......@@ -3,6 +3,7 @@ require "variables";
#SCRIPTNAME: Script part 0
#Script name: has flags
if allof (hasflag :is "test"
, not hasflag :is "variable" "test2"
, hasflag :contains "variable" "test3"
......
......@@ -2,6 +2,7 @@ require "imap4flags";
#SCRIPTNAME: Script part 0
#Script name: test-headers
if allof (header :contains "Content-Type" "value"
, not header :is "Date" "125"
, not header :contains "Subject" "sdfsdf"
......
......@@ -2,6 +2,7 @@ require "mboxmetadata";
#SCRIPTNAME: Script part 0
#Script name: test-metadata-exist
if metadataexists "INBOX" "ANNOTATION"
{
stop;
......
......@@ -3,6 +3,7 @@ require "imap4flags";
#SCRIPTNAME: Script part 0
#Script name: test-metadataexists
if servermetadataexists "ANNOTATION"
{
keep;
......
......@@ -5,6 +5,7 @@ require "spamtestplus";
#SCRIPTNAME: Script part 0
#Script name: test spam-plus
if allof (spamtest :percent :value "ne" :comparator "i;ascii-numeric" "4"
, spamtest :count "ge" :comparator "i;ascii-numeric" "3"
, spamtest :percent :value "ne" :comparator "i;ascii-numeric" "3"
......
......@@ -5,6 +5,7 @@ require "spamtestplus";
#SCRIPTNAME: Script part 0
#Script name: test spam
if allof (spamtest :count "lt" :comparator "i;ascii-numeric" "5"
, spamtest :value "ge" :comparator "i;ascii-numeric" "8"
, spamtest :count "lt" :comparator "i;ascii-numeric" "3"
......
......@@ -4,6 +4,7 @@ require "comparator-i;ascii-numeric";
#SCRIPTNAME: Script part 0
#Script name: test virus
if allof (virustest :count "ge" :comparator "i;ascii-numeric" "5"
, virustest :value "ne" :comparator "i;ascii-numeric" "5"
, virustest :count "lt" :comparator "i;ascii-numeric" "4"
......
......@@ -3,6 +3,7 @@ require "vacation";
#SCRIPTNAME: Script part 0
#Script name: vacation
if true
{
vacation :seconds 4 :subject "message" :addresses "foo@example.com" text:
......
......@@ -2,6 +2,7 @@ require "variables";
#SCRIPTNAME: Script part 0
#Script name: set variable example
if true
{
set :lowerfirst "25" "variable-lower";
......
......@@ -2,6 +2,7 @@ require "variables";
#SCRIPTNAME: Script part 0
#Script name: variables
if size :under 5
{
set "testvariable" "25";
......
......@@ -99,6 +99,7 @@ void SieveEditorGraphicalModeWidgetTest::shouldLoadScripts()
QEXPECT_FAIL("failed-1", "Expected failure on failed-1 file. anyof + allof.", Continue);
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);
QCOMPARE(proc.exitCode(), 0);
}
}
......@@ -184,6 +185,8 @@ void SieveEditorGraphicalModeWidgetTest::shouldLoadScripts_data()
QTest::newRow("failed-1") << QStringLiteral("failed-1") << true << true;
QTest::newRow("failed-2") << QStringLiteral("failed-2") << true << true;
QTest::newRow("failed-if-in-if") << QStringLiteral("failed-if-in-if") << true << true;
QTest::newRow("test-comment2") << QStringLiteral("test-comment2") << false << true;
}
QTEST_MAIN(SieveEditorGraphicalModeWidgetTest)
......@@ -95,8 +95,17 @@ void SieveActionWidget::generatedScript(QString &script, QStringList &requires,
indent += AutoCreateScriptUtil::indentation();
}
if (!comment.trimmed().isEmpty()) {
script += indent;
script += QLatin1Char('#') + comment.replace(QLatin1Char('\n'), QStringLiteral("\n%1#").arg(indent)) + QLatin1Char('\n');
//script += indent;
const QStringList commentList = comment.split(QLatin1Char('\n'));
for (const QString &str : commentList) {
if (str.isEmpty()) {
script += QLatin1Char('\n');
} else {
script += indent + QLatin1Char('#') + str + QLatin1Char('\n');
}
}
//script += QLatin1Char('#') + comment.replace(QLatin1Char('\n'), QStringLiteral("\n%1#").arg(indent)) + QLatin1Char('\n');
}
script += indent + widgetAction->code(currentWidget) + QLatin1Char('\n');
}
......
......@@ -80,10 +80,16 @@ void SieveScriptListItem::setScriptPage(SieveScriptPage *page)
QString SieveScriptListItem::generatedScript(QStringList &requires) const
{
QString script;
if (!mDescription.isEmpty()) {
script = QLatin1Char('#') + mDescription;
script.replace(QLatin1Char('\n'), QStringLiteral("\n#"));
script += QLatin1Char('\n');
if (!mDescription.trimmed().isEmpty()) {
const QStringList commentList = mDescription.split(QLatin1Char('\n'));
for (const QString &str : commentList) {
if (str.isEmpty()) {
script += QLatin1Char('\n');
} else {
script += QLatin1Char('#') + str + QLatin1Char('\n');
}
}
}
if (mScriptPage) {
mScriptPage->generatedScript(script, requires);
......@@ -394,12 +400,14 @@ void SieveScriptListBox::loadBlock(QDomNode &n, SieveScriptPage *currentPage, Pa
QString scriptName;
QString comment;
bool hasCreatedAIfBlock = false;
bool previousElementWasAComment = false;
while (!n.isNull()) {
QDomElement e = n.toElement();
if (!e.isNull()) {
const QString tagName = e.tagName();
//qCDebug(LIBKSIEVE_LOG)<<" tagName "<<tagName;
if (tagName == QLatin1String("control")) {
previousElementWasAComment = false;
//Create a new page when before it was "onlyactions"
if (typeBlock == TypeBlockAction) {
currentPage = nullptr;
......@@ -458,6 +466,12 @@ void SieveScriptListBox::loadBlock(QDomNode &n, SieveScriptPage *currentPage, Pa
}
}
} else if (tagName == QLatin1String("comment")) {
previousElementWasAComment = true;
if (e.hasAttribute(QStringLiteral("hash"))) {
//TODO
} else if (e.hasAttribute(QStringLiteral("bracket"))) {
//TODO
}
QString str(e.text());
if (str.contains(defaultScriptName())) {
scriptName = str.remove(defaultScriptName());
......@@ -468,6 +482,7 @@ void SieveScriptListBox::loadBlock(QDomNode &n, SieveScriptPage *currentPage, Pa
comment += e.text();
}
} else if (tagName == QLatin1String("action")) {
previousElementWasAComment = false;
if (e.hasAttribute(QStringLiteral("name"))) {
const QString actionName = e.attribute(QStringLiteral("name"));
if (actionName == QLatin1String("include")) {
......@@ -516,7 +531,10 @@ void SieveScriptListBox::loadBlock(QDomNode &n, SieveScriptPage *currentPage, Pa
}
}
} else if (tagName == QLatin1String("crlf")) {
//nothing
//If it was a comment previously you will create a \n
if (previousElementWasAComment) {
comment += QLatin1Char('\n');
}
} else {
qCDebug(LIBKSIEVE_LOG) << " unknown tagname" << tagName;
}
......
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