File indexing completed on 2024-12-22 04:52:48

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 "clawsmailimportdata.h"
0008 #include "clawsmailaddressbook.h"
0009 #include "clawsmailsettings.h"
0010 #include <MailCommon/FilterImporterClawsMail>
0011 #include <MailImporter/FilterClawsMail>
0012 #include <MailImporter/FilterInfo>
0013 
0014 #include <KLocalizedString>
0015 #include <KPluginFactory>
0016 
0017 #include <QDir>
0018 
0019 K_PLUGIN_CLASS_WITH_JSON(ClawsMailImportData, "clawsmailimporter.json")
0020 
0021 ClawsMailImportData::ClawsMailImportData(QObject *parent, const QList<QVariant> &)
0022     : LibImportWizard::AbstractImporter(parent)
0023 {
0024     mPath = MailImporter::FilterClawsMail::defaultSettingsPath();
0025 }
0026 
0027 ClawsMailImportData::~ClawsMailImportData() = default;
0028 
0029 bool ClawsMailImportData::foundMailer() const
0030 {
0031     QDir directory(mPath);
0032     if (directory.exists()) {
0033         return true;
0034     }
0035     return false;
0036 }
0037 
0038 QString ClawsMailImportData::name() const
0039 {
0040     return QStringLiteral("Claws Mails");
0041 }
0042 
0043 bool ClawsMailImportData::importMails()
0044 {
0045     MailImporter::FilterClawsMail clawsMail;
0046     initializeFilter(clawsMail);
0047     clawsMail.filterInfo()->setStatusMessage(i18n("Import in progress"));
0048     const QString mailsPath = clawsMail.localMailDirPath();
0049     QDir directory(mailsPath);
0050     if (directory.exists()) {
0051         clawsMail.importMails(mailsPath);
0052     } else {
0053         clawsMail.import();
0054     }
0055     clawsMail.filterInfo()->setStatusMessage(i18n("Import finished"));
0056     return true;
0057 }
0058 
0059 bool ClawsMailImportData::importAddressBook()
0060 {
0061     const QDir addressbookDir(mPath + QLatin1StringView("addrbook/"));
0062     ClawsMailAddressBook account(addressbookDir);
0063     account.setAbstractDisplayInfo(mAbstractDisplayInfo);
0064     account.importAddressBook();
0065     return true;
0066 }
0067 
0068 bool ClawsMailImportData::importSettings()
0069 {
0070     const QString accountFile = mPath + QLatin1StringView("accountrc");
0071     if (QFileInfo::exists(accountFile)) {
0072         ClawsMailSettings account;
0073         account.setAbstractDisplayInfo(mAbstractDisplayInfo);
0074         account.importSettings(accountFile, mPath);
0075     } else {
0076         addImportSettingsInfo(i18n("Claws Mail settings not found."));
0077     }
0078     return true;
0079 }
0080 
0081 bool ClawsMailImportData::importFilters()
0082 {
0083     const QString filterPath(mPath + QLatin1StringView("matcherrc"));
0084     return addFilters(filterPath, MailCommon::FilterImporterExporter::ClawsMailFilter);
0085 }
0086 
0087 LibImportWizard::AbstractImporter::TypeSupportedOptions ClawsMailImportData::supportedOption()
0088 {
0089     TypeSupportedOptions options;
0090     options |= LibImportWizard::AbstractImporter::Mails;
0091     options |= LibImportWizard::AbstractImporter::AddressBooks;
0092     options |= LibImportWizard::AbstractImporter::Settings;
0093     options |= LibImportWizard::AbstractImporter::Filters;
0094     return options;
0095 }
0096 
0097 #include "clawsmailimportdata.moc"