File indexing completed on 2024-12-22 04:52:49
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 "seamonkeyimportdata.h" 0008 0009 #include "../thunderbird/thunderbirdaddressbook.h" 0010 #include "../thunderbird/thunderbirdsettings.h" 0011 #include "abstractdisplayinfo.h" 0012 0013 #include <MailCommon/FilterImporterExporter> 0014 #include <MailImporter/FilterInfo> 0015 #include <MailImporter/FilterSeaMonkey> 0016 0017 #include <KLocalizedString> 0018 #include <KPluginFactory> 0019 0020 #include <QDir> 0021 0022 SeaMonkeyImportData::SeaMonkeyImportData(QObject *parent, const QList<QVariant> &) 0023 : LibImportWizard::AbstractImporter(parent) 0024 { 0025 mPath = MailImporter::FilterSeaMonkey::defaultSettingsPath(); 0026 } 0027 0028 SeaMonkeyImportData::~SeaMonkeyImportData() = default; 0029 0030 QString SeaMonkeyImportData::defaultProfile() 0031 { 0032 if (mDefaultProfile.isEmpty()) { 0033 mDefaultProfile = MailImporter::FilterThunderbird::defaultProfile(mPath, mAbstractDisplayInfo->parentWidget()); 0034 } 0035 return mDefaultProfile; 0036 } 0037 0038 bool SeaMonkeyImportData::foundMailer() const 0039 { 0040 QDir directory(mPath); 0041 if (directory.exists()) { 0042 return true; 0043 } 0044 return false; 0045 } 0046 0047 bool SeaMonkeyImportData::importAddressBook() 0048 { 0049 const QDir addressbookDir(mPath + defaultProfile()); 0050 ThunderBirdAddressBook account(addressbookDir); 0051 account.setAbstractDisplayInfo(mAbstractDisplayInfo); 0052 account.importAddressBook(); 0053 return true; 0054 } 0055 0056 QString SeaMonkeyImportData::name() const 0057 { 0058 return QStringLiteral("SeaMonkey"); 0059 } 0060 0061 bool SeaMonkeyImportData::importSettings() 0062 { 0063 const QString accountFile = mPath + defaultProfile() + QLatin1StringView("/prefs.js"); 0064 if (QFileInfo::exists(accountFile)) { 0065 ThunderbirdSettings account(accountFile); 0066 account.setAbstractDisplayInfo(mAbstractDisplayInfo); 0067 account.importSettings(); 0068 } else { 0069 addImportSettingsInfo(i18n("SeaMonkey settings not found.")); 0070 } 0071 return true; 0072 } 0073 0074 bool SeaMonkeyImportData::importMails() 0075 { 0076 //* This should be usually ~/.mozilla/seamonkey/xxxx.default/Mail/Local Folders/ 0077 MailImporter::FilterThunderbird thunderbird; 0078 initializeFilter(thunderbird); 0079 thunderbird.filterInfo()->setStatusMessage(i18n("Import in progress")); 0080 const QString mailsPath = mPath + defaultProfile() + QLatin1StringView("/Mail/Local Folders/"); 0081 QDir directory(mailsPath); 0082 if (directory.exists()) { 0083 thunderbird.importMails(mailsPath); 0084 } else { 0085 thunderbird.import(); 0086 } 0087 thunderbird.filterInfo()->setStatusMessage(i18n("Import finished")); 0088 return true; 0089 } 0090 0091 bool SeaMonkeyImportData::importFilters() 0092 { 0093 const QString path(mPath + defaultProfile()); 0094 QDir dir(path); 0095 bool filtersAdded = false; 0096 const QStringList subDir = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name); 0097 if (subDir.isEmpty()) { 0098 return true; 0099 } 0100 0101 for (const QString &mailPath : subDir) { 0102 const QString subMailPath(path + QLatin1Char('/') + mailPath); 0103 QDir dirMail(subMailPath); 0104 const QStringList subDirMail = dirMail.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name); 0105 bool foundFilterFile = false; 0106 for (const QString &file : subDirMail) { 0107 const QString filterFile(subMailPath + QLatin1Char('/') + file + QLatin1StringView("/msgFilterRules.dat")); 0108 if (QFileInfo::exists(filterFile)) { 0109 foundFilterFile = true; 0110 const bool added = addFilters(filterFile, MailCommon::FilterImporterExporter::SeaMonkeyFilter); 0111 if (!filtersAdded && added) { 0112 filtersAdded = true; 0113 } 0114 } 0115 } 0116 if (!foundFilterFile) { 0117 return true; 0118 } 0119 } 0120 return filtersAdded; 0121 } 0122 0123 LibImportWizard::AbstractImporter::TypeSupportedOptions SeaMonkeyImportData::supportedOption() 0124 { 0125 TypeSupportedOptions options; 0126 options |= LibImportWizard::AbstractImporter::Mails; 0127 options |= LibImportWizard::AbstractImporter::Filters; 0128 options |= LibImportWizard::AbstractImporter::Settings; 0129 options |= LibImportWizard::AbstractImporter::AddressBooks; 0130 return options; 0131 }