File indexing completed on 2024-11-10 04:50:05

0001 /*
0002   SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "filterconverttosieve.h"
0008 #include "filter/mailfilter.h"
0009 #include "filterconverttosieveresultdialog.h"
0010 
0011 #include <QPointer>
0012 
0013 using namespace MailCommon;
0014 
0015 FilterConvertToSieve::FilterConvertToSieve(const QList<MailFilter *> &filters)
0016     : mListFilters(filters)
0017 {
0018 }
0019 
0020 FilterConvertToSieve::~FilterConvertToSieve() = default;
0021 
0022 void FilterConvertToSieve::convert()
0023 {
0024     QString result;
0025     if (!mListFilters.isEmpty()) {
0026         QStringList requiresModule;
0027         QString code;
0028         for (MailFilter *filter : std::as_const(mListFilters)) {
0029             filter->generateSieveScript(requiresModule, code);
0030             code += QLatin1Char('\n');
0031         }
0032         QString requireStr;
0033         for (const QString &require : std::as_const(requiresModule)) {
0034             requireStr += QStringLiteral("require \"%1\";").arg(require);
0035             requireStr += QLatin1Char('\n');
0036         }
0037         result = requireStr + code;
0038     }
0039     FilterConvertToSieveResultDialog dlg;
0040     dlg.setCode(result);
0041     dlg.exec();
0042 }