File indexing completed on 2025-02-23 04:58:15

0001 /*
0002    SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "parsingutil.h"
0008 #include "parser.h"
0009 #include "xmlprintingscriptbuilder.h"
0010 using KSieve::Parser;
0011 
0012 #include "scriptbuilder.h"
0013 
0014 #include "libksievecore_debug.h"
0015 
0016 using namespace KSieveCore;
0017 
0018 QString ParsingUtil::parseScript(const QString &scriptStr, bool &result)
0019 {
0020     const QByteArray script = scriptStr.toUtf8();
0021 
0022     KSieve::Parser parser(script.begin(), script.begin() + script.length());
0023     KSieveCore::XMLPrintingScriptBuilder psb;
0024     parser.setScriptBuilder(&psb);
0025     if (parser.parse()) {
0026         result = true;
0027         return psb.result();
0028     } else {
0029         qCDebug(LIBKSIEVECORE_LOG) << "Impossible to parse file";
0030         result = false;
0031     }
0032     return {};
0033 }