diff --git a/core/autotests/mail/data/export/identitiesandconfigandmailtransportandresources/list.txt b/core/autotests/mail/data/export/identitiesandconfigandmailtransportandresources/list.txt index 9126b84..ff2a7b4 100644 --- a/core/autotests/mail/data/export/identitiesandconfigandmailtransportandresources/list.txt +++ b/core/autotests/mail/data/export/identitiesandconfigandmailtransportandresources/list.txt @@ -1,17 +1,19 @@ information/VERSION_2 information/exportdatatype.xml identities/emailidentities configs/akonadi_archivemail_agentrc configs/foldermailarchiverc configs/kabldaprc configs/kmail2rc configs/templatesconfigurationrc transports/mailtransports configs/filters mails/akonadi_mbox_resource_1/agent_config_akonadi_mbox_resource_1 mails/akonadi_mbox_resource_1/akonadi_mbox_resource_1.mbox mails/akonadi_mbox_resource_1/akonadi_mbox_resource_1rc mails/akonadi_mixedmaildir_resource_1/agent_config_akonadi_mixedmaildir_resource_1 mails/akonadi_mixedmaildir_resource_1/akonadi_mixedmaildir_resource_1rc mails/akonadi_mixedmaildir_resource_1/mail.zip mails/akonadi_maildir_resource_1/mail.zip +mails/akonadi_maildir_resource_1/agent_config_akonadi_maildir_resource_1 +mails/akonadi_maildir_resource_1/akonadi_maildir_resource_1rc diff --git a/core/autotests/mail/data/export/identitiesandconfigandmailtransportandresources/references/mails/akonadi_maildir_resource_1/agent_config_akonadi_maildir_resource_1 b/core/autotests/mail/data/export/identitiesandconfigandmailtransportandresources/references/mails/akonadi_maildir_resource_1/agent_config_akonadi_maildir_resource_1 new file mode 100644 index 0000000..483097f --- /dev/null +++ b/core/autotests/mail/data/export/identitiesandconfigandmailtransportandresources/references/mails/akonadi_maildir_resource_1/agent_config_akonadi_maildir_resource_1 @@ -0,0 +1,3 @@ +[Agent] +DesiredOnlineState=true +Name=maildir 1 diff --git a/core/autotests/mail/data/export/identitiesandconfigandmailtransportandresources/references/mails/akonadi_maildir_resource_1/akonadi_maildir_resource_1rc b/core/autotests/mail/data/export/identitiesandconfigandmailtransportandresources/references/mails/akonadi_maildir_resource_1/akonadi_maildir_resource_1rc new file mode 100644 index 0000000..fa2885d --- /dev/null +++ b/core/autotests/mail/data/export/identitiesandconfigandmailtransportandresources/references/mails/akonadi_maildir_resource_1/akonadi_maildir_resource_1rc @@ -0,0 +1,3 @@ +[General] +Path[$e]=$[TEST_PATH]/resources/akonadi_maildir_resource_1/ +TopLevelIsContainer=true diff --git a/core/autotests/mail/data/export/identitiesandconfigandmailtransportandresources/references/mails/akonadi_maildir_resource_1/mail.zip b/core/autotests/mail/data/export/identitiesandconfigandmailtransportandresources/references/mails/akonadi_maildir_resource_1/mail.zip new file mode 100644 index 0000000..e69de29 diff --git a/core/autotests/mail/data/import/identitiesandconfigandmailtransportandresources/archive.zip b/core/autotests/mail/data/import/identitiesandconfigandmailtransportandresources/archive.zip index be03938..48e4994 100644 Binary files a/core/autotests/mail/data/import/identitiesandconfigandmailtransportandresources/archive.zip and b/core/autotests/mail/data/import/identitiesandconfigandmailtransportandresources/archive.zip differ diff --git a/core/autotests/mail/data/import/identitiesandconfigandmailtransportandresources/list.txt b/core/autotests/mail/data/import/identitiesandconfigandmailtransportandresources/list.txt index 6b95706..3c9ee52 100644 --- a/core/autotests/mail/data/import/identitiesandconfigandmailtransportandresources/list.txt +++ b/core/autotests/mail/data/import/identitiesandconfigandmailtransportandresources/list.txt @@ -1,10 +1,19 @@ -identities/emailidentities -information/VERSION_2 -information/exportdatatype.xml configs/akonadi_archivemail_agentrc +configs/filters configs/foldermailarchiverc configs/kabldaprc configs/kmail2rc configs/templatesconfigurationrc +identities/emailidentities +information/VERSION_2 +information/exportdatatype.xml +mails/akonadi_maildir_resource_1/agent_config_akonadi_maildir_resource_1 +mails/akonadi_maildir_resource_1/akonadi_maildir_resource_1rc +mails/akonadi_maildir_resource_1/mail.zip +mails/akonadi_mbox_resource_1/agent_config_akonadi_mbox_resource_1 +mails/akonadi_mbox_resource_1/akonadi_mbox_resource_1.mbox +mails/akonadi_mbox_resource_1/akonadi_mbox_resource_1rc +mails/akonadi_mixedmaildir_resource_1/agent_config_akonadi_mixedmaildir_resource_1 +mails/akonadi_mixedmaildir_resource_1/akonadi_mixedmaildir_resource_1rc +mails/akonadi_mixedmaildir_resource_1/mail.zip transports/mailtransports -configs/filters diff --git a/core/autotests/resourceconvertertest.cpp b/core/autotests/resourceconvertertest.cpp index ccaed96..d621634 100644 --- a/core/autotests/resourceconvertertest.cpp +++ b/core/autotests/resourceconvertertest.cpp @@ -1,85 +1,84 @@ /* 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 "resourceconvertertest.h" #include #include ResourceConverterTest::ResourceConverterTest() { } ResourceConverterTest::~ResourceConverterTest() { } QString ResourceConverterTest::prefixStr() const { return QStringLiteral("foo/bla bla/bli"); } QString ResourceConverterTest::convertToFullCollectionPath(const qlonglong collectionValue) { return prefixStr() + QString::number(collectionValue); } Akonadi::Collection::Id ResourceConverterTest::convertFolderPathToCollectionId(const QString &path) { QString str = path; str.remove(prefixStr()); auto result = str.toLongLong(); //Make sure that we use another number. if (result != -1) { result += 10; } return result; } QString ResourceConverterTest::changeResourcePath(QString url) const { - qDebug() << " need to fix " << url << " mTestPath " << mTestPath; + //qDebug() << " need to fix " << url << " mTestPath " << mTestPath; if (!url.isEmpty()) { url.replace(QLatin1String("[TEST_PATH]"), mTestPath); } - qDebug() <<" FIXED " << url; - //TODO FIXME + //qDebug() <<" FIXED " << url; return url; } void ResourceConverterTest::setTestPath(const QString &testPath) { mTestPath = testPath; } //TODO use another one ? QString ResourceConverterTest::installDefaultDirectory() { return QDir::tempPath(); } QString ResourceConverterTest::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) { QString newUrl; if (overwriteResources) { newUrl = resourcePath(resourceConfig); } else { newUrl = adaptResourcePath(resourceConfig, storePath); } return newUrl; } diff --git a/core/autotests/saveresourceconfigtest.cpp b/core/autotests/saveresourceconfigtest.cpp index 7bcbde8..48d3764 100644 --- a/core/autotests/saveresourceconfigtest.cpp +++ b/core/autotests/saveresourceconfigtest.cpp @@ -1,70 +1,70 @@ /* 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 "saveresourceconfigtest.h" #include "resourceconvertertest.h" #include #include SaveResourceConfigTest::SaveResourceConfigTest() { } KZip *SaveResourceConfigTest::archive() const { return mArchive; } void SaveResourceConfigTest::setArchive(KZip *archive) { mArchive = archive; } void SaveResourceConfigTest::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier, const QString &resourceArchiveName, const QStringList &resourceIdentifierTypes) { QVERIFY(mArchive); bool typeIdentifierFound = false; for (const QString &resourceType: resourceIdentifierTypes) { typeIdentifierFound = identifier.startsWith(resourceType); if (typeIdentifierFound) { break; } } QVERIFY(typeIdentifierFound); if (QFileInfo(url).isFile()) { QVERIFY(mArchive->addLocalFile(url, archivePath + resourceArchiveName)); } else { const QString zipFile = url + identifier + QLatin1String(".zip"); const bool success = mArchive->addLocalFile(zipFile, archivePath + resourceArchiveName); if (!success) { qDebug() << " zip file " << zipFile; } QVERIFY(success); } ResourceConverterTest converter; const QString errorStr = converter.storeResources(mArchive, identifier, archivePath); QVERIFY(errorStr.isEmpty()); const QString urlAgentConfig = Akonadi::ServerManager::agentConfigFilePath(identifier); QVERIFY(!urlAgentConfig.isEmpty()); const QFileInfo fi(urlAgentConfig); const QString filename = fi.fileName(); - qDebug() << "urlAgentConfig " << urlAgentConfig; + //qDebug() << "urlAgentConfig " << urlAgentConfig; QVERIFY(mArchive->addLocalFile(urlAgentConfig, archivePath + filename)); } diff --git a/core/resourceconverterbase.cpp b/core/resourceconverterbase.cpp index d79730b..7e7f9de 100644 --- a/core/resourceconverterbase.cpp +++ b/core/resourceconverterbase.cpp @@ -1,221 +1,221 @@ /* 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 "resourceconverterbase.h" #include "utils.h" #include #include #include #include #include #include #include ResourceConverterBase::ResourceConverterBase() { } ResourceConverterBase::~ResourceConverterBase() { } QString ResourceConverterBase::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) { QString newUrl = ResourceConverterBase::resourcePath(resourceConfig); if (!newUrl.contains(installDefaultDirectory())) { QFileInfo fileInfo(newUrl); fileInfo.fileName(); //qCDebug(PIMDATAEXPORTERCORE_LOG)<<" url "<group(QStringLiteral("General")); QString url = group.readEntry(QStringLiteral("Path"), defaultPath); if (!url.isEmpty()) { url.replace(QLatin1String("$HOME"), QDir::homePath()); } url = changeResourcePath(url); return url; } QString ResourceConverterBase::resourcePath(const QString &agentIdentifier, const QString &defaultPath) { const QString agentFileName = agentIdentifier + QStringLiteral("rc"); const QString configFileName = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + agentFileName; - qDebug() << "configFileName " << configFileName; + //qDebug() << "configFileName " << configFileName; KSharedConfigPtr resourceConfig = KSharedConfig::openConfig(configFileName); const QString url = resourcePath(resourceConfig, defaultPath); - qDebug() << " resourcePath " << url; + //qDebug() << " resourcePath " << url; return url; } QString ResourceConverterBase::changeResourcePath(QString url) const { return url; } //Merge two methods I think void ResourceConverterBase::convertCollectionIdsToRealPath(KConfigGroup &group, const QString ¤tKey, const QString &prefixCollection) { if (group.hasKey(currentKey)) { const QStringList value = group.readEntry(currentKey, QStringList()); QStringList newValue; for (QString str : value) { bool found = false; if (!prefixCollection.isEmpty() && str.startsWith(prefixCollection)) { str.remove(0, prefixCollection.length()); } const qlonglong collectionId = str.toLongLong(&found); if (found) { const QString realPath = convertToFullCollectionPath(collectionId); if (!realPath.isEmpty()) { newValue << realPath; } } } if (newValue.isEmpty()) { group.deleteEntry(currentKey); } else { group.writeEntry(currentKey, newValue); } } } void ResourceConverterBase::convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey) { if (group.hasKey(currentKey)) { const QStringList listExpension = group.readEntry(currentKey, QStringList()); if (listExpension.isEmpty()) { group.deleteEntry(currentKey); } else { QStringList result; for (QString collection : listExpension) { collection.remove(QLatin1Char('c')); bool found = false; const qlonglong collectionValue = collection.toLongLong(&found); if (found && collectionValue != -1) { const QString realPath = convertToFullCollectionPath(collectionValue); if (!realPath.isEmpty()) { result << realPath; } } } if (result.isEmpty()) { group.deleteEntry(currentKey); } else { group.writeEntry(currentKey, result); } } } } void ResourceConverterBase::convertCollectionToRealPath(KConfigGroup &group, const QString ¤tKey) { if (group.hasKey(currentKey)) { QString collectionId = group.readEntry(currentKey); if (collectionId.isEmpty()) { group.deleteEntry(currentKey); } else { collectionId.remove(QLatin1Char('c')); bool found = false; const qlonglong collectionValue = collectionId.toLongLong(&found); if (found && collectionValue != -1) { const QString realPath = convertToFullCollectionPath(collectionValue); group.writeEntry(currentKey, realPath); } else { group.deleteEntry(currentKey); } } } } QString ResourceConverterBase::agentFileName(const QString &filename) { QString agentFileConfigName = filename; agentFileConfigName.remove(Utils::resourcesPath()); agentFileConfigName.remove(agentFileConfigName.length() - 2, 2); //Remove "rc" agentFileConfigName = Utils::resourcesPath() + Utils::prefixAkonadiConfigFile() + agentFileConfigName; return agentFileConfigName; } QString ResourceConverterBase::storeResources(KZip *archive, const QString &identifier, const QString &path) { const QString agentFileName = identifier + QStringLiteral("rc"); const QString configFileName = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + agentFileName; qCDebug(PIMDATAEXPORTERCORE_LOG) << "configFileName " << configFileName << "agentFileName " << configFileName; KSharedConfigPtr resourceConfig = KSharedConfig::openConfig(configFileName); QTemporaryFile tmp; tmp.open(); KConfig *config = resourceConfig->copyTo(tmp.fileName()); if (identifier.contains(POP3_RESOURCE_IDENTIFIER)) { const QString targetCollection = QStringLiteral("targetCollection"); KConfigGroup group = config->group("General"); if (group.hasKey(targetCollection)) { group.writeEntry(targetCollection, convertToFullCollectionPath(group.readEntry(targetCollection).toLongLong())); } } else if (PimCommon::Util::isImapResource(identifier)) { const QString trash = QStringLiteral("TrashCollection"); KConfigGroup group = config->group("cache"); if (group.hasKey(trash)) { group.writeEntry(trash, convertToFullCollectionPath(group.readEntry(trash).toLongLong())); } } //Customize resource if necessary here. config->sync(); bool fileAdded = archive->addLocalFile(tmp.fileName(), path + agentFileName); delete config; if (!fileAdded) { return i18n("Resource file \"%1\" cannot be added to backup file.", agentFileName); } const QString agentConfigFileName = Utils::prefixAkonadiConfigFile() + identifier; const QString agentConfigFileNamePath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1String("/akonadi/") + agentConfigFileName; if (QFileInfo::exists(agentConfigFileNamePath)) { fileAdded = archive->addLocalFile(agentConfigFileNamePath, path + agentConfigFileName); if (!fileAdded) { return i18n("Resource file \"%1\" cannot be added to backup file.", agentFileName); } } return QString(); }