Commit 1eac8d95 authored by Laurent Montel's avatar Laurent Montel 😁

Start to create seamonkey plugin

parent ab2b7b95
set(seamonkeyimporter_SRCS
seamonkeyimportdata.cpp
../thunderbird/thunderbirdaddressbook.cpp
../thunderbird/thunderbirdsettings.cpp
../thunderbird/addressbook/MorkParser.cpp
)
ecm_qt_declare_logging_category(seamonkeyimporter_SRCS HEADER thunderbirdplugin_debug.h
IDENTIFIER THUNDERBIRDPLUGIN_LOG CATEGORY_NAME org.kde.pim.importwizard.thunderbirdplugin)
kcoreaddons_add_plugin(seamonkeyimporterplugin JSON seamonkeyimporter.json SOURCES
${seamonkeyimporter_SRCS} INSTALL_NAMESPACE importwizard)
target_link_libraries(seamonkeyimporterplugin
KPim::ImportWizard
KF5::XmlGui
KF5::I18n
KF5::Contacts
KF5::MailImporterAkonadi
KF5::MailTransport
KF5::IdentityManagement
KF5::MailCommon
)
/*
Copyright (C) 2012-2017 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "seamonkeyimportdata.h"
#include "abstractdisplayinfo.h"
#include "../thunderbird/thunderbirdsettings.h"
#include "../thunderbird/thunderbirdaddressbook.h"
#include "mailimporter/filterthunderbird.h"
#include "mailimporter/filterinfo.h"
#include "MailCommon/FilterImporterExporter"
#include <KLocalizedString>
#include <kpluginfactory.h>
#include <KConfig>
#include <QDir>
SeaMonkeyImportData::SeaMonkeyImportData(QObject *parent, const QList<QVariant> &)
: LibImportWizard::AbstractImporter(parent)
{
mPath = MailImporter::FilterSeaMonkey::defaultSettingsPath();
}
SeaMonkeyImportData::~SeaMonkeyImportData()
{
}
QString SeaMonkeyImportData::defaultProfile()
{
if (mDefaultProfile.isEmpty()) {
mDefaultProfile = MailImporter::FilterThunderbird::defaultProfile(mPath, mAbstractDisplayInfo->parentWidget());
}
return mDefaultProfile;
}
bool SeaMonkeyImportData::foundMailer() const
{
QDir directory(mPath);
if (directory.exists()) {
return true;
}
return false;
}
bool SeaMonkeyImportData::importAddressBook()
{
const QDir addressbookDir(mPath + defaultProfile());
ThunderBirdAddressBook account(addressbookDir);
account.setAbstractDisplayInfo(mAbstractDisplayInfo);
account.importAddressBook();
return true;
}
QString SeaMonkeyImportData::name() const
{
return QStringLiteral("SeaMonkey");
}
bool SeaMonkeyImportData::importSettings()
{
const QString accountFile = mPath + defaultProfile() + QLatin1String("/prefs.js");
if (QFileInfo::exists(accountFile)) {
ThunderbirdSettings account(accountFile);
account.setAbstractDisplayInfo(mAbstractDisplayInfo);
account.importSettings();
} else {
addImportSettingsInfo(i18n("SeaMonkey settings not found."));
}
return true;
}
bool SeaMonkeyImportData::importMails()
{
//* This should be usually ~/.SeaMonkey/xxxx.default/Mail/Local Folders/
MailImporter::FilterThunderbird thunderbird;
initializeFilter(thunderbird);
thunderbird.filterInfo()->setStatusMessage(i18n("Import in progress"));
const QString mailsPath = mPath + defaultProfile() + QLatin1String("/Mail/Local Folders/");
QDir directory(mailsPath);
if (directory.exists()) {
thunderbird.importMails(mailsPath);
} else {
thunderbird.import();
}
thunderbird.filterInfo()->setStatusMessage(i18n("Import finished"));
return true;
}
bool SeaMonkeyImportData::importFilters()
{
const QString path(mPath + defaultProfile());
QDir dir(path);
bool filtersAdded = false;
const QStringList subDir = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name);
if (subDir.isEmpty()) {
return true;
}
for (const QString &mailPath : subDir) {
const QString subMailPath(path + QLatin1Char('/') + mailPath);
QDir dirMail(subMailPath);
const QStringList subDirMail = dirMail.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name);
bool foundFilterFile = false;
for (const QString &file : subDirMail) {
const QString filterFile(subMailPath + QLatin1Char('/') + file + QLatin1String("/msgFilterRules.dat"));
if (QFileInfo::exists(filterFile)) {
foundFilterFile = true;
const bool added = addFilters(filterFile, MailCommon::FilterImporterExporter::SeaMonkeyFilter);
if (!filtersAdded && added) {
filtersAdded = true;
}
}
}
if (!foundFilterFile) {
return true;
}
}
return filtersAdded;
}
LibImportWizard::AbstractImporter::TypeSupportedOptions SeaMonkeyImportData::supportedOption()
{
TypeSupportedOptions options;
options |= LibImportWizard::AbstractImporter::Mails;
options |= LibImportWizard::AbstractImporter::Filters;
options |= LibImportWizard::AbstractImporter::Settings;
options |= LibImportWizard::AbstractImporter::AddressBooks;
return options;
}
/*
Copyright (C) 2017 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef SeaMonkeyImportData_H
#define SeaMonkeyImportData_H
#include <ImportWizard/AbstractImporter>
class SeaMonkeyImportData : public LibImportWizard::AbstractImporter
{
public:
explicit SeaMonkeyImportData(QObject *parent, const QList<QVariant> & = QList<QVariant>());
~SeaMonkeyImportData();
TypeSupportedOptions supportedOption() Q_DECL_OVERRIDE;
bool foundMailer() const Q_DECL_OVERRIDE;
bool importSettings() Q_DECL_OVERRIDE;
bool importMails() Q_DECL_OVERRIDE;
bool importFilters() Q_DECL_OVERRIDE;
bool importAddressBook() Q_DECL_OVERRIDE;
QString name() const Q_DECL_OVERRIDE;
private:
QString defaultProfile();
QString mDefaultProfile;
};
#endif /* SeaMonkeyImportData_H */
{
"KPlugin": {
"Id": "seamonkeyimporter",
"Name": "SeaMonkey Importer",
"ServiceTypes": [
"ImportWizard/PluginMailImporter"
],
"Version": "1.0"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment