Commit 8602b015 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add more impl class

parent f1a19ccc
......@@ -14,7 +14,7 @@ set(pimdataexporter_addressbook_SRCS
)
set(pimdataexporter_mail_SRCS
mail/exportmailjobinterface.cpp
mail/exportmailjobinterfaceimpl.cpp
mail/importmailjobinterface.cpp
mail/importexportmailutil.cpp
)
......@@ -33,6 +33,7 @@ set(pimdataexporter_interfaces_SRCS
addressbook/importaddressbookjobinterface.cpp
alarm/importalarmjobinterface.cpp
alarm/exportalarmjobinterface.cpp
mail/exportmailjobinterface.cpp
)
set(pimdataexporter_notes_SRCS
......
......@@ -24,9 +24,7 @@
#include <MailCommon/FilterManager>
#include <MailCommon/FilterImporterExporter>
#include "importexportprogressindicatorbase.h"
#include <AkonadiCore/AgentManager>
#include <AkonadiCore/Collection>
#include "exportresourcearchivejob.h"
#include <MailTransport/TransportManager>
......@@ -40,7 +38,6 @@
#include <QDir>
#include <QTimer>
#include <QStandardPaths>
#include <exportresourcearchivejob.h>
#include <QRegularExpression>
#include "resourceconverterimpl.h"
......@@ -130,76 +127,6 @@ void ExportMailJobInterface::slotCheckBackupMails()
QTimer::singleShot(0, this, &ExportMailJobInterface::slotCheckBackupResources);
}
void ExportMailJobInterface::slotMailsJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
exportArchiveResource();
}
void ExportMailJobInterface::exportArchiveResource()
{
QTimer::singleShot(0, this, &ExportMailJobInterface::slotWriteNextArchiveResource);
}
void ExportMailJobInterface::slotWriteNextArchiveResource()
{
Akonadi::AgentManager *manager = Akonadi::AgentManager::self();
const Akonadi::AgentInstance::List list = manager->instances();
if (mIndexIdentifier < list.count()) {
const Akonadi::AgentInstance agent = list.at(mIndexIdentifier);
const QStringList capabilities(agent.type().capabilities());
if (agent.type().mimeTypes().contains(KMime::Message::mimeType())) {
if (capabilities.contains(QLatin1String("Resource"))
&& !capabilities.contains(QLatin1String("Virtual"))
&& !capabilities.contains(QLatin1String("MailTransport"))) {
const QString identifier = agent.identifier();
if (identifier.contains(QLatin1String("akonadi_maildir_resource_"))
|| identifier.contains(QLatin1String("akonadi_mixedmaildir_resource_"))) {
const QString archivePath = Utils::mailsPath() + identifier + QLatin1Char('/');
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url)) {
mAgentPaths << url;
if (!url.isEmpty()) {
ExportResourceArchiveJob *resourceJob = new ExportResourceArchiveJob(this);
resourceJob->setArchivePath(archivePath);
resourceJob->setUrl(url);
resourceJob->setIdentifier(identifier);
resourceJob->setArchive(archive());
resourceJob->setArchiveName(QStringLiteral("mail.zip"));
connect(resourceJob, &ExportResourceArchiveJob::error, this, &ExportMailJobInterface::error);
connect(resourceJob, &ExportResourceArchiveJob::info, this, &ExportMailJobInterface::info);
connect(resourceJob, &ExportResourceArchiveJob::terminated, this, &ExportMailJobInterface::slotMailsJobTerminated);
connect(this, &ExportMailJobInterface::taskCanceled, resourceJob, &ExportResourceArchiveJob::slotTaskCanceled);
resourceJob->start();
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << "Url is empty for " << identifier;
QTimer::singleShot(0, this, &ExportMailJobInterface::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterface::slotMailsJobTerminated);
}
} else if (identifier.contains(QLatin1String("akonadi_mbox_resource_"))) {
backupResourceFile(agent, Utils::addressbookPath());
QTimer::singleShot(0, this, &ExportMailJobInterface::slotMailsJobTerminated);
} else {
QTimer::singleShot(0, this, &ExportMailJobInterface::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterface::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterface::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterface::slotCheckBackupResources);
}
}
void ExportMailJobInterface::backupTransports()
{
setProgressDialogLabel(i18n("Backing up transports..."));
......@@ -239,36 +166,6 @@ void ExportMailJobInterface::slotCheckBackupResources()
Q_EMIT jobFinished();
}
void ExportMailJobInterface::backupResources()
{
setProgressDialogLabel(i18n("Backing up resources..."));
Akonadi::AgentManager *manager = Akonadi::AgentManager::self();
const Akonadi::AgentInstance::List list = manager->instances();
for (const Akonadi::AgentInstance &agent : list) {
const QStringList capabilities(agent.type().capabilities());
if (agent.type().mimeTypes().contains(KMime::Message::mimeType())) {
if (capabilities.contains(QLatin1String("Resource"))
&& !capabilities.contains(QLatin1String("Virtual"))
&& !capabilities.contains(QLatin1String("MailTransport"))) {
const QString identifier = agent.identifier();
//Store just pop3/imap/kolab/gmail account. Store other config when we copy data.
if (identifier.contains(QLatin1String("pop3")) || identifier.contains(QLatin1String("imap"))
|| identifier.contains(QLatin1String("_kolab_")) || identifier.contains(QLatin1String("_gmail_"))) {
const QString errorStr = Utils::storeResources(archive(), identifier, Utils::resourcesPath());
if (!errorStr.isEmpty()) {
Q_EMIT error(errorStr);
}
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << " resource \"" << identifier << "\" will not store";
}
}
}
}
Q_EMIT info(i18n("Resources backup done."));
}
void ExportMailJobInterface::backupConfig()
{
setProgressDialogLabel(i18n("Backing up config..."));
......@@ -684,20 +581,3 @@ void ExportMailJobInterface::backupIdentity()
}
}
void ExportMailJobInterface::convertCollectionIdsToRealPath(KConfigGroup &group, const QString &currentKey, const QString &prefixCollection)
{
ResourceConverterImpl converter;
converter.convertCollectionIdsToRealPath(group, currentKey, prefixCollection);
}
void ExportMailJobInterface::convertCollectionToRealPath(KConfigGroup &group, const QString &currentKey)
{
ResourceConverterImpl converter;
converter.convertCollectionToRealPath(group, currentKey);
}
void ExportMailJobInterface::convertCollectionListToRealPath(KConfigGroup &group, const QString &currentKey)
{
ResourceConverterImpl converter;
converter.convertCollectionListToRealPath(group, currentKey);
}
......@@ -40,26 +40,22 @@ Q_SIGNALS:
void taskCanceled();
protected:
virtual void convertCollectionIdsToRealPath(KConfigGroup &group, const QString &currentKey, const QString &prefixCollection = QString());
virtual void convertCollectionToRealPath(KConfigGroup &group, const QString &currentKey);
virtual void convertCollectionListToRealPath(KConfigGroup &group, const QString &currentKey);
virtual void exportArchiveResource();
virtual void convertCollectionIdsToRealPath(KConfigGroup &group, const QString &currentKey, const QString &prefixCollection = QString()) = 0;
virtual void convertCollectionToRealPath(KConfigGroup &group, const QString &currentKey) = 0;
virtual void convertCollectionListToRealPath(KConfigGroup &group, const QString &currentKey) = 0;
virtual void exportArchiveResource() = 0;
virtual void backupResources() = 0;
void slotCheckBackupResources();
private:
void slotCheckBackupIdentity();
void slotCheckBackupMailTransport();
void slotCheckBackupConfig();
void slotCheckBackupMails();
void slotCheckBackupResources();
void slotMailsJobTerminated();
void slotWriteNextArchiveResource();
Q_REQUIRED_RESULT bool checkBackupType(Utils::StoredType type) const;
void backupTransports();
void backupResources();
void backupConfig();
void backupIdentity();
QDateTime mArchiveTime = QDateTime::currentDateTime();
int mIndexIdentifier = 0;
};
#endif // ExportMailJob_H
/*
Copyright (C) 2020 Laurent Montel <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 "exportmailjobinterfaceimpl.h"
#include "importexportmailutil.h"
#include <MailCommon/MailUtil>
#include <MailCommon/FilterManager>
#include <MailCommon/FilterImporterExporter>
#include "importexportprogressindicatorbase.h"
#include <AkonadiCore/AgentManager>
#include <AkonadiCore/Collection>
#include <MailTransport/TransportManager>
#include <KZip>
#include <KLocalizedString>
#include <QTemporaryFile>
#include "pimdataexportcore_debug.h"
#include <QFile>
#include <QDir>
#include <QTimer>
#include <QStandardPaths>
#include <exportresourcearchivejob.h>
#include <QRegularExpression>
#include "resourceconverterimpl.h"
#include <KIdentityManagement/IdentityManager>
#include <KIdentityManagement/Identity>
ExportMailJobInterfaceImpl::ExportMailJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: ExportMailJobInterface(parent, typeSelected, archiveStorage, numberOfStep)
{
}
ExportMailJobInterfaceImpl::~ExportMailJobInterfaceImpl()
{
}
void ExportMailJobInterfaceImpl::slotMailsJobTerminated()
{
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
mIndexIdentifier++;
exportArchiveResource();
}
void ExportMailJobInterfaceImpl::exportArchiveResource()
{
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotWriteNextArchiveResource);
}
void ExportMailJobInterfaceImpl::slotWriteNextArchiveResource()
{
Akonadi::AgentManager *manager = Akonadi::AgentManager::self();
const Akonadi::AgentInstance::List list = manager->instances();
if (mIndexIdentifier < list.count()) {
const Akonadi::AgentInstance agent = list.at(mIndexIdentifier);
const QStringList capabilities(agent.type().capabilities());
if (agent.type().mimeTypes().contains(KMime::Message::mimeType())) {
if (capabilities.contains(QLatin1String("Resource"))
&& !capabilities.contains(QLatin1String("Virtual"))
&& !capabilities.contains(QLatin1String("MailTransport"))) {
const QString identifier = agent.identifier();
if (identifier.contains(QLatin1String("akonadi_maildir_resource_"))
|| identifier.contains(QLatin1String("akonadi_mixedmaildir_resource_"))) {
const QString archivePath = Utils::mailsPath() + identifier + QLatin1Char('/');
ResourceConverterImpl converter;
const QString url = converter.resourcePath(identifier);
if (!mAgentPaths.contains(url)) {
mAgentPaths << url;
if (!url.isEmpty()) {
ExportResourceArchiveJob *resourceJob = new ExportResourceArchiveJob(this);
resourceJob->setArchivePath(archivePath);
resourceJob->setUrl(url);
resourceJob->setIdentifier(identifier);
resourceJob->setArchive(archive());
resourceJob->setArchiveName(QStringLiteral("mail.zip"));
connect(resourceJob, &ExportResourceArchiveJob::error, this, &ExportMailJobInterfaceImpl::error);
connect(resourceJob, &ExportResourceArchiveJob::info, this, &ExportMailJobInterfaceImpl::info);
connect(resourceJob, &ExportResourceArchiveJob::terminated, this, &ExportMailJobInterfaceImpl::slotMailsJobTerminated);
connect(this, &ExportMailJobInterfaceImpl::taskCanceled, resourceJob, &ExportResourceArchiveJob::slotTaskCanceled);
resourceJob->start();
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << "Url is empty for " << identifier;
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotMailsJobTerminated);
}
} else if (identifier.contains(QLatin1String("akonadi_mbox_resource_"))) {
backupResourceFile(agent, Utils::addressbookPath());
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotMailsJobTerminated);
} else {
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotMailsJobTerminated);
}
} else {
QTimer::singleShot(0, this, &ExportMailJobInterfaceImpl::slotCheckBackupResources);
}
}
void ExportMailJobInterfaceImpl::backupResources()
{
setProgressDialogLabel(i18n("Backing up resources..."));
Akonadi::AgentManager *manager = Akonadi::AgentManager::self();
const Akonadi::AgentInstance::List list = manager->instances();
for (const Akonadi::AgentInstance &agent : list) {
const QStringList capabilities(agent.type().capabilities());
if (agent.type().mimeTypes().contains(KMime::Message::mimeType())) {
if (capabilities.contains(QLatin1String("Resource"))
&& !capabilities.contains(QLatin1String("Virtual"))
&& !capabilities.contains(QLatin1String("MailTransport"))) {
const QString identifier = agent.identifier();
//Store just pop3/imap/kolab/gmail account. Store other config when we copy data.
if (identifier.contains(QLatin1String("pop3")) || identifier.contains(QLatin1String("imap"))
|| identifier.contains(QLatin1String("_kolab_")) || identifier.contains(QLatin1String("_gmail_"))) {
const QString errorStr = Utils::storeResources(archive(), identifier, Utils::resourcesPath());
if (!errorStr.isEmpty()) {
Q_EMIT error(errorStr);
}
} else {
qCDebug(PIMDATAEXPORTERCORE_LOG) << " resource \"" << identifier << "\" will not store";
}
}
}
}
Q_EMIT info(i18n("Resources backup done."));
}
void ExportMailJobInterfaceImpl::convertCollectionIdsToRealPath(KConfigGroup &group, const QString &currentKey, const QString &prefixCollection)
{
ResourceConverterImpl converter;
converter.convertCollectionIdsToRealPath(group, currentKey, prefixCollection);
}
void ExportMailJobInterfaceImpl::convertCollectionToRealPath(KConfigGroup &group, const QString &currentKey)
{
ResourceConverterImpl converter;
converter.convertCollectionToRealPath(group, currentKey);
}
void ExportMailJobInterfaceImpl::convertCollectionListToRealPath(KConfigGroup &group, const QString &currentKey)
{
ResourceConverterImpl converter;
converter.convertCollectionListToRealPath(group, currentKey);
}
/*
Copyright (C) 2020 Laurent Montel <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 EXPORTMAILJOBINTERFACEIMPL_H
#define EXPORTMAILJOBINTERFACEIMPL_H
#include "exportmailjobinterface.h"
#include "pimdataexportercore_private_export.h"
#include <KSharedConfig>
#include <QDateTime>
#include <time.h>
class ArchiveStorage;
class PIMDATAEXPORTER_TESTS_EXPORT ExportMailJobInterfaceImpl : public ExportMailJobInterface
{
Q_OBJECT
public:
explicit ExportMailJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep);
~ExportMailJobInterfaceImpl() override;
protected:
void convertCollectionIdsToRealPath(KConfigGroup &group, const QString &currentKey, const QString &prefixCollection = QString()) override;
void convertCollectionToRealPath(KConfigGroup &group, const QString &currentKey) override;
void convertCollectionListToRealPath(KConfigGroup &group, const QString &currentKey) override;
void exportArchiveResource() override;
void backupResources() override;
private:
void slotCheckBackupMails();
void slotWriteNextArchiveResource();
void slotMailsJobTerminated();
QDateTime mArchiveTime = QDateTime::currentDateTime();
int mIndexIdentifier = 0;
};
#endif // ExportMailJob_H
This diff is collapsed.
/*
Copyright (C) 2020 Laurent Montel <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 ImportMailJobINTERFACE_H
#define ImportMailJobINTERFACE_H
#include "abstractimportexportjob.h"
#include "pimdataexportercore_private_export.h"
#include <AkonadiCore/Collection>
#include <Akonadi/KMime/SpecialMailCollections>
#include <QStringList>
#include <QHash>
#include <KArchive>
class KArchiveDirectory;
class KArchiveFile;
class ArchiveStorage;
namespace MailTransport {
class Transport;
}
class PIMDATAEXPORTER_TESTS_EXPORT ImportMailJobInterfaceImpl : public AbstractImportExportJob
{
Q_OBJECT
public:
explicit ImportMailJobInterfaceImpl(QObject *widget, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep);
~ImportMailJobInterfaceImpl() override;
void start() override;
//For debugging
void importMailTransport(const QString &tempDirName);
protected:
void slotNextStep() override;
void restoreResources() override;
private:
void registerSpecialCollection(Akonadi::SpecialMailCollections::Type type, qint64 colId);
void restoreTransports();
void restoreMails();
void restoreConfig();
void restoreIdentity();
void importTemplatesConfig(const KArchiveFile *templatesconfiguration, const QString &templatesconfigurationrc, const QString &filename, const QString &prefix);
void importKmailConfig(const KArchiveFile *kmailsnippet, const QString &kmail2rc, const QString &filename, const QString &prefix);
void importArchiveConfig(const KArchiveFile *archiveconfiguration, const QString &archiveconfigurationrc, const QString &filename, const QString &prefix);
void importFolderArchiveConfig(const KArchiveFile *archiveconfiguration, const QString &archiveconfigurationrc, const QString &filename, const QString &prefix);
void searchAllMailsFiles(const KArchiveDirectory *dir, const QString &prefix);
void storeMailArchiveResource(const KArchiveDirectory *dir, const QString &prefix);
void importMailArchiveConfig(const KArchiveFile *archiveconfiguration, const QString &archiveconfigurationrc, const QString &filename, const QString &prefix);
void mergeLdapConfig(const KArchiveFile *archivefile, const QString &filename, const QString &prefix);
void mergeKmailSnippetConfig(const KArchiveFile *archivefile, const QString &filename, const QString &prefix);
void mergeArchiveMailAgentConfig(const KArchiveFile *archivefile, const QString &filename, const QString &prefix);
void copyArchiveMailAgentConfigGroup(const KSharedConfig::Ptr &archiveConfigOrigin, const KSharedConfig::Ptr &archiveConfigDestination);
void copyMailArchiveConfig(const KSharedConfig::Ptr &archiveConfigOrigin, const KSharedConfig::Ptr &archiveConfigDestination);
void mergeMailArchiveConfig(const KArchiveFile *archivefile, const QString &filename, const QString &prefix);
void mergeSieveTemplate(const KArchiveFile *archivefile, const QString &filename, const QString &prefix);
void importSimpleFilesInDirectory(const QString &relativePath);
void addMailTransport(MailTransport::Transport *mt, int defaultTransport, int transportId);
Q_REQUIRED_RESULT QString uniqueIdentityName(const QString &name);
QHash<int, uint> mHashIdentity;
QHash<int, int> mHashTransport;
QHash<QString, QString> mHashResources;
QStringList mFileList;
};
#endif // ImportMailJob_H
......@@ -21,7 +21,7 @@
#include "archivestorage.h"
#include "importexportprogressindicatorbase.h"
#include "mail/exportmailjobinterface.h"
#include "mail/exportmailjobinterfaceimpl.h"
#include "mail/importmailjobinterface.h"
#include "addressbook/exportaddressbookjobinterfaceimpl.h"
......@@ -46,6 +46,7 @@
#include <QDateTime>
#include <QLocale>
PimDataBackupRestore::PimDataBackupRestore(QObject *parent)
: QObject(parent)
{
......@@ -134,7 +135,7 @@ void PimDataBackupRestore::backupNextStep()
switch (mStoreIterator.key()) {
case Utils::KMail:
if (mStoreIterator.value().numberSteps != 0) {
mImportExportData = new ExportMailJobInterface(this, mStoreIterator.value().types, mArchiveStorage, mStoreIterator.value().numberSteps);
mImportExportData = new ExportMailJobInterfaceImpl(this, mStoreIterator.value().types, mArchiveStorage, mStoreIterator.value().numberSteps);
executeJob();
}
break;
......
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