diff --git a/core/autotests/mail/importmailjobinterfacetestimpl.cpp b/core/autotests/mail/importmailjobinterfacetestimpl.cpp index 6996a1b..c4b324a 100644 --- a/core/autotests/mail/importmailjobinterfacetestimpl.cpp +++ b/core/autotests/mail/importmailjobinterfacetestimpl.cpp @@ -1,123 +1,138 @@ /* Copyright (C) 2020 Laurent Montel 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 "importmailjobinterfacetestimpl.h" #include "archivestorage.h" #include "resourceconvertertest.h" #include "testimportfile.h" #include "utils.h" #include "mail/smtpmailtransport.h" #include #include #include ImportMailJobInterfaceTestImpl::ImportMailJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : ImportMailJobInterface(parent, typeSelected, archiveStorage, numberOfStep) { } ImportMailJobInterfaceTestImpl::~ImportMailJobInterfaceTestImpl() { //Clean up temp repo. FIXME ! QVERIFY(QDir(extractPath()).removeRecursively()); } void ImportMailJobInterfaceTestImpl::start() { QDir().mkpath(extractPath()); //Create temporary file for identities ImportMailJobInterface::start(); } Akonadi::Collection::Id ImportMailJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.convertFolderPathToCollectionId(path); } void ImportMailJobInterfaceTestImpl::synchronizeResource(const QStringList &lst) { mLogCreateResource->logSynchronizeResource(lst); slotNextStep(); } QString ImportMailJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) { return mLogCreateResource->logCreateResource(resources, name, settings, synchronizeTree); } void ImportMailJobInterfaceTestImpl::registerSpecialCollection(Akonadi::SpecialMailCollections::Type type, qint64 colId) { mLogCreateResource->logRegisterSpecialCollection(type, colId); } void ImportMailJobInterfaceTestImpl::importFilters(const QVector &filters) { qDebug() << " void ImportMailJobInterfaceTestImpl::importFilters(const QVector &filters)"; } QString ImportMailJobInterfaceTestImpl::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptResourcePath(resourceConfig, storedData); } QString ImportMailJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); } void ImportMailJobInterfaceTestImpl::addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) { + const QString uniqueName = uniqueIdentityName(name); qDebug() << " void ImportMailJobInterfaceTestImpl::addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) not implemented yet" << oldUid << " name " << name; KIdentityManagement::Identity identity; identity.setUoid(mIdentityUoid++); - group.writeEntry(QStringLiteral("Name"), name); + group.writeEntry(QStringLiteral("Name"), uniqueName); group.sync(); identity.readConfig(group); if (oldUid != -1) { mHashIdentity.insert(oldUid, identity.uoid()); if (oldUid == defaultIdentities) { //TODO //mIdentityManager->setAsDefault(identity->uoid()); } } // identity.writeConfig(); //TODO write identity ? //TODO log it. //mIdentityManager->commit(); } +QString ImportMailJobInterfaceTestImpl::uniqueIdentityName(const QString &name) +{ + QString newName(name); + int i = 0; + + const QStringList existingIdentityNames{QStringLiteral("identity1"), QStringLiteral("identity2")}; + + while (!existingIdentityNames.contains(newName)) { + newName = QStringLiteral("%1_%2").arg(name).arg(i); + ++i; + } + return newName; +} + void ImportMailJobInterfaceTestImpl::importCustomMailTransport(const QString &identifierValue, const KConfigGroup &group, int defaultTransport, int transportId) { qDebug() << "importCustomMailTransport(const QString &identifierValue, const KConfigGroup &group, int defaultTransport, int transportId) not implemented yet"; } void ImportMailJobInterfaceTestImpl::importSmtpMailTransport(const KConfigGroup &group, int defaultTransport, int transportId) { SmtpMailTransport smtpMailTransport(group); qDebug() << "ImportMailJobInterfaceTestImpl::importSmtpMailTransport(const KConfigGroup &group, int defaultTransport, int transportId) not implement yet"; qDebug() << " defaultTransport " << defaultTransport << " transportId " << transportId; } diff --git a/core/autotests/mail/importmailjobinterfacetestimpl.h b/core/autotests/mail/importmailjobinterfacetestimpl.h index 6be0f7c..34f855e 100644 --- a/core/autotests/mail/importmailjobinterfacetestimpl.h +++ b/core/autotests/mail/importmailjobinterfacetestimpl.h @@ -1,52 +1,53 @@ /* Copyright (C) 2020 Laurent Montel 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 IMPORTMAILJOBINTERFACETESTIMPL_H #define IMPORTMAILJOBINTERFACETESTIMPL_H #include "exportimportutil.h" #include "mail/importmailjobinterface.h" class ImportMailJobInterfaceTestImpl : public ImportMailJobInterface, public ExportImportUtil { Q_OBJECT public: explicit ImportMailJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); ~ImportMailJobInterfaceTestImpl(); void start() override; protected: Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; void synchronizeResource(const QStringList &lst) override; Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree = false) override; void registerSpecialCollection(Akonadi::SpecialMailCollections::Type type, qint64 colId) override; void importFilters(const QVector &filters) override; Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) override; Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; void addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) override; void importCustomMailTransport(const QString &identifierValue, const KConfigGroup &group, int defaultTransport, int transportId) override; void importSmtpMailTransport(const KConfigGroup &group, int defaultTransport, int transportId) override; private: + Q_REQUIRED_RESULT QString uniqueIdentityName(const QString &name); uint mIdentityUoid = 1; }; #endif // IMPORTMAILJOBINTERFACETESTIMPL_H