File indexing completed on 2024-12-29 04:44:29

0001 /*
0002    SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "sylpheedimportdata.h"
0008 #include <MailImporter/FilterInfo>
0009 #include <MailImporter/FilterSylpheed>
0010 
0011 #include <MailCommon/FilterImporterExporter>
0012 
0013 #include "sylpheedaddressbook.h"
0014 #include "sylpheedsettings.h"
0015 
0016 #include <KLocalizedString>
0017 #include <KPluginFactory>
0018 #include <QDir>
0019 
0020 K_PLUGIN_CLASS_WITH_JSON(SylpheedImportData, "sylpheedimporter.json")
0021 SylpheedImportData::SylpheedImportData(QObject *parent, const QList<QVariant> &)
0022     : LibImportWizard::AbstractImporter(parent)
0023 {
0024     mPath = MailImporter::FilterSylpheed::defaultSettingsPath();
0025 }
0026 
0027 SylpheedImportData::~SylpheedImportData() = default;
0028 
0029 bool SylpheedImportData::foundMailer() const
0030 {
0031     QDir directory(mPath);
0032     if (directory.exists()) {
0033         return true;
0034     }
0035     return false;
0036 }
0037 
0038 QString SylpheedImportData::name() const
0039 {
0040     return QStringLiteral("Sylpheed");
0041 }
0042 
0043 bool SylpheedImportData::importSettings()
0044 {
0045     const QString accountFile = mPath + QLatin1StringView("/accountrc");
0046     if (QFileInfo::exists(accountFile)) {
0047         SylpheedSettings account;
0048         account.setAbstractDisplayInfo(mAbstractDisplayInfo);
0049         account.importSettings(accountFile, mPath);
0050     } else {
0051         addImportSettingsInfo(i18n("Sylpheed settings not found."));
0052     }
0053     return true;
0054 }
0055 
0056 bool SylpheedImportData::importMails()
0057 {
0058     MailImporter::FilterSylpheed sylpheed;
0059     initializeFilter(sylpheed);
0060     sylpheed.filterInfo()->setStatusMessage(i18n("Import in progress"));
0061     const QString mailsPath = sylpheed.localMailDirPath();
0062     QDir directory(mailsPath);
0063     if (directory.exists()) {
0064         sylpheed.importMails(mailsPath);
0065     } else {
0066         sylpheed.import();
0067     }
0068     sylpheed.filterInfo()->setStatusMessage(i18n("Import finished"));
0069     return true;
0070 }
0071 
0072 bool SylpheedImportData::importFilters()
0073 {
0074     const QString filterPath = mPath + QLatin1StringView("/filter.xml");
0075     return addFilters(filterPath, MailCommon::FilterImporterExporter::SylpheedFilter);
0076 }
0077 
0078 bool SylpheedImportData::importAddressBook()
0079 {
0080     const QDir addressbookDir(mPath);
0081     SylpheedAddressBook account(addressbookDir);
0082     account.setAbstractDisplayInfo(mAbstractDisplayInfo);
0083     account.importAddressBook();
0084     return true;
0085 }
0086 
0087 LibImportWizard::AbstractImporter::TypeSupportedOptions SylpheedImportData::supportedOption()
0088 {
0089     TypeSupportedOptions options;
0090     options |= LibImportWizard::AbstractImporter::Mails;
0091     options |= LibImportWizard::AbstractImporter::Filters;
0092     options |= LibImportWizard::AbstractImporter::Settings;
0093     options |= LibImportWizard::AbstractImporter::AddressBooks;
0094     return options;
0095 }
0096 
0097 #include "sylpheedimportdata.moc"