Commit 25d962c7 authored by Volker Krause's avatar Volker Krause
Browse files

Ininitial work on the mixed mbox/maildir tree conversion. It can walk

arbitrarily mixed trees, but doesn't do any conversion yet. Thus,
migration will only succeed for pure maildir trees so far.

svn path=/trunk/KDE/kdepim/runtime/; revision=1074704
parent 47e0ae5a
set(kmail-migrator_srcs
main.cpp
kmailmigrator.cpp
mixedtreeconverter.cpp
${MIGRATION_AKONADI_SHARED_SOURCES}
)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../../resources/maildir
${CMAKE_CURRENT_SOURCE_DIR}/../../resources/mbox
)
macro(add_resource_iface _kcfgFile _ifaceName _className)
kcfg_generate_dbus_interface(${kdepim-runtime_SOURCE_DIR}/resources/${_kcfgFile} ${_ifaceName})
string(TOLOWER ${_className} _codeFile)
......@@ -27,6 +33,8 @@ kde4_add_executable(kmail-migrator ${kmail-migrator_srcs})
target_link_libraries(kmail-migrator
${KDEPIMLIBS_AKONADI_LIBS}
${KDE4_KDEUI_LIBS}
maildir
mbox
)
install(TARGETS kmail-migrator ${INSTALL_TARGETS_DEFAULT_ARGS})
......
/*
Copyright (c) 2009 Jonathan Armond <jon.armond@gmail.com>
Copyright (c) 2010 Volker Krause <vkrause@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
......@@ -18,6 +19,7 @@
*/
#include "kmailmigrator.h"
#include "mixedtreeconverter.h"
#include "imapsettings.h"
#include "pop3settings.h"
......@@ -65,7 +67,8 @@ static void migratePassword( const QString &idString, const AgentInstance &insta
KMailMigrator::KMailMigrator() :
KMigratorBase(),
mConfig( 0 )
mConfig( 0 ),
mConverter( 0 )
{
}
......@@ -122,10 +125,10 @@ void KMailMigrator::migrateLocalFolders()
const QString localMaildirPath = cfgGroup.readPathEntry( "folders", QString() );
kDebug() << localMaildirPath;
// TODO convert mbox files in a mixed-mode tree
emit message( Info, i18n( "Migrating local folders in '%1'...", localMaildirPath ) );
createAgentInstance( "akonadi_maildir_resource", this, SLOT(localMaildirCreated(KJob*)) );
mConverter = new MixedTreeConverter( this );
connect( mConverter, SIGNAL(conversionDone(QString)), SLOT(localFoldersConverted(QString)) );
mConverter->convert( localMaildirPath );
}
void KMailMigrator::migrationDone()
......@@ -401,10 +404,24 @@ void KMailMigrator::maildirAccountCreated( KJob *job )
migrationCompleted( instance );
}
void KMailMigrator::localFoldersConverted(const QString& errorMsg)
{
disconnect( mConverter, SIGNAL(conversionDone(QString)), this, SLOT(localFoldersConverted(QString)) );
if ( !errorMsg.isEmpty() ) {
emit message( Error, i18n( "Failed to convert local folder tree: %1", errorMsg ) );
deleteLater();
return;
}
emit message( Success, i18n( "Converted local mixed-mode folder tree." ) );
createAgentInstance( "akonadi_maildir_resource", this, SLOT(localMaildirCreated(KJob*)) );
}
void KMailMigrator::localMaildirCreated(KJob* job)
{
if ( job->error() ) {
migrationFailed( i18n( "Failed to resource for local folders: %1", job->errorText() ) );
emit message( Error, i18n( "Failed to resource for local folders: %1", job->errorText() ) );
deleteLater();
return;
}
emit message( Info, i18n( "Created local maildir resource." ) );
......
......@@ -24,6 +24,7 @@
#include <QStringList>
class MixedTreeConverter;
class KConfig;
class KJob;
......@@ -54,6 +55,7 @@ class KMailMigrator : public KMigratorBase
void mboxAccountCreated( KJob *job );
void maildirAccountCreated( KJob *job );
void localMaildirCreated( KJob *job );
void localFoldersConverted( const QString &errorMsg );
private:
void migrateImapAccount( KJob *job, bool disconnected );
......@@ -68,6 +70,7 @@ class KMailMigrator : public KMigratorBase
QStringList mAccounts;
typedef QStringList::iterator AccountIterator;
AccountIterator mIt;
MixedTreeConverter *mConverter;
};
} // namespace KMail
......
/*
Copyright (c) 2010 Volker Krause <vkrause@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "mixedtreeconverter.h"
#include <libmaildir/maildir.h>
#include <KDebug>
#include <KLocalizedString>
#include <QtCore/QDir>
MixedTreeConverter::MixedTreeConverter(QObject* parent): QObject(parent)
{
}
void MixedTreeConverter::convert(const QString& basePath)
{
const KPIM::Maildir md( basePath, true );
if ( !md.isValid() ) {
emit conversionDone( i18n( "'%1' is not a valid maildir folder.", basePath ) );
return;
}
convert( md );
emit conversionDone( QString() );
}
void MixedTreeConverter::convert(const KPIM::Maildir& md)
{
kDebug() << md.path();
if ( !md.isValid() )
return;
// recurse into maildirs, nothing to do there
foreach ( const QString &subFolder, md.subFolderList() ) {
kDebug() << subFolder;
convert( md.subFolder( subFolder ) );
}
// code from Maildir::subFolder minus the safety checks
QDir dir( md.path() );
if ( !md.isRoot() ) {
dir.cdUp();
const QString subDirPath = QString::fromLatin1( ".%1.directory" ).arg( md.name() );
if ( dir.exists( subDirPath ) ) {
dir.cd( subDirPath );
} else {
return;
}
}
// look for mboxes
dir.setFilter( QDir::Files );
foreach ( const QString &file, dir.entryList() ) {
convertMbox( dir.absolutePath() + QDir::separator() + file );
// recurse into mbox sub-folders
QDir subDir( dir );
const QString subDirPath = QString::fromLatin1( ".%1.directory" ).arg( file );
if ( subDir.exists( subDirPath ) )
subDir.cd( subDirPath );
else
continue;
convert( KPIM::Maildir( subDir.path(), true ) );
}
}
void MixedTreeConverter::convertMbox(const QString& path)
{
kDebug() << path;
emit conversionDone( i18n( "Mbox conversion not yet implemented: '%1'", path ) );
}
#include "mixedtreeconverter.moc"
/*
Copyright (c) 2010 Volker Krause <vkrause@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef MIXEDTREECONVERTER_H
#define MIXEDTREECONVERTER_H
#include <qobject.h>
namespace KPIM {
class Maildir;
}
/**
Converts a mixed mbox/maildir tree to pure maildir
*/
class MixedTreeConverter : public QObject
{
Q_OBJECT
public:
explicit MixedTreeConverter( QObject *parent = 0 );
void convert( const QString &basePath );
signals:
void conversionDone( const QString &error );
private:
void convert( const KPIM::Maildir &md );
void convertMbox( const QString &path );
};
#endif
......@@ -213,6 +213,10 @@ bool Maildir::isValid( QString &error ) const
return false;
}
bool Maildir::isRoot() const
{
return d->isRoot;
}
bool Maildir::create()
{
......
......@@ -60,6 +60,11 @@ public:
*/
bool isValid( QString &error ) const;
/**
* Returns wether this is a normal maildir or a container containing maildirs.
*/
bool isRoot() const;
/**
* Make a valid maildir at the path of this Maildir object. This involves
* creating the necessary subdirs, etc. Note that an empty Maildir is
......
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