summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-08-15 09:47:26 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-08-15 09:47:26 (GMT)
commit454ce87264c26acfaca410ed0000113a71067bcb (patch)
tree585bc52d5061dfd53be84e3434659a06ff6d3bf3
parent8229cd20b5800a37833a710706844330ce68b66b (diff)
downloadkolab-utils-454ce87264c26acfaca410ed0000113a71067bcb.tar.gz
Option to force the type and upgrade only a single folder
-rw-r--r--upgradetool/imapupgradejob.cpp27
-rw-r--r--upgradetool/imapupgradejob.h7
-rw-r--r--upgradetool/kolabformatupgradejob.cpp10
-rw-r--r--upgradetool/kolabformatupgradejob.h6
-rw-r--r--upgradetool/upgradetool.cpp33
-rw-r--r--upgradetool/upgradeutilities.cpp9
-rw-r--r--upgradetool/upgradeutilities.h5
7 files changed, 84 insertions, 13 deletions
diff --git a/upgradetool/imapupgradejob.cpp b/upgradetool/imapupgradejob.cpp
index 1d17354..2193a8f 100644
--- a/upgradetool/imapupgradejob.cpp
+++ b/upgradetool/imapupgradejob.cpp
@@ -54,6 +54,17 @@ ImapUpgradeJob::~ImapUpgradeJob()
}
+void ImapUpgradeJob::setOverrideObjectType(const Kolab::ObjectType type)
+{
+ m_overrideObjectType = type;
+}
+
+void ImapUpgradeJob::setFolderToUpgrade(const QString &folder)
+{
+ m_folderToUpgrade = folder;
+}
+
+
void ImapUpgradeJob::connectToAccount(const QString &hostName, qint16 port, const QString &username, const QString &proxyauth, const QString &pw, KIMAP::LoginJob::EncryptionMode encryptionMode, KIMAP::LoginJob::AuthenticationMode authenticationMode)
{
Debug() << "connecting to: " << hostName << port << username << pw;
@@ -110,9 +121,19 @@ void ImapUpgradeJob::onLoginDone( KJob *job )
return;
}
- ProbeKolabServerJob *probeJob = new ProbeKolabServerJob(m_session, this);
- connect(probeJob, SIGNAL(result(KJob*)), this, SLOT(onProbeDone(KJob*)));
- probeJob->start();
+ if (m_folderToUpgrade.isEmpty()) {
+ ProbeKolabServerJob *probeJob = new ProbeKolabServerJob(m_session, this);
+ connect(probeJob, SIGNAL(result(KJob*)), this, SLOT(onProbeDone(KJob*)));
+ probeJob->start();
+ } else {
+ SequentialCompositeJob *seqJob = new SequentialCompositeJob(this);
+ KolabFormatUpgradeJob *upgradeJob = new KolabFormatUpgradeJob(m_folderToUpgrade, m_session, this);
+ upgradeJob->setOverrideObjectType(m_overrideObjectType);
+ seqJob->addSubjob(upgradeJob);
+ seqJob->addSubjob(new KIMAP::LogoutJob(m_session));
+ connect(seqJob, SIGNAL(result(KJob*)), this, SLOT(modifyDone(KJob*)));
+ seqJob->start();
+ }
}
void ImapUpgradeJob::onProbeDone(KJob* job)
diff --git a/upgradetool/imapupgradejob.h b/upgradetool/imapupgradejob.h
index 18a10d8..df3945c 100644
--- a/upgradetool/imapupgradejob.h
+++ b/upgradetool/imapupgradejob.h
@@ -23,6 +23,7 @@
#include <QObject>
#include <QStringList>
#include <kjob.h>
+#include <kolabobject.h>
#include <kimap/session.h>
#include <kimap/loginjob.h>
@@ -36,7 +37,9 @@ class ImapUpgradeJob: public KJob
public:
explicit ImapUpgradeJob(QObject* parent = 0);
virtual ~ImapUpgradeJob();
-
+
+ void setOverrideObjectType(const Kolab::ObjectType type);
+ void setFolderToUpgrade(const QString &);
void connectToAccount(const QString &hostName, qint16 port, const QString &username, const QString &proxyauth, const QString &pw, KIMAP::LoginJob::EncryptionMode, KIMAP::LoginJob::AuthenticationMode);
virtual void start(){};
@@ -49,6 +52,8 @@ private:
KIMAP::Session *m_session;
bool m_requireEncryption;
+ QString m_folderToUpgrade;
+ Kolab::ObjectType m_overrideObjectType;
};
#endif // IMAPUPGRADER_H
diff --git a/upgradetool/kolabformatupgradejob.cpp b/upgradetool/kolabformatupgradejob.cpp
index 4d5bc6d..b3c94a2 100644
--- a/upgradetool/kolabformatupgradejob.cpp
+++ b/upgradetool/kolabformatupgradejob.cpp
@@ -35,11 +35,17 @@ KolabFormatUpgradeJob::KolabFormatUpgradeJob(const QString& folder, KIMAP::Sessi
: KJob(parent),
m_session(session),
m_folder(folder),
- seqJob(new SequentialCompositeJob(this))
+ seqJob(new SequentialCompositeJob(this)),
+ m_overrideObjectType(Kolab::InvalidObject)
{
}
+void KolabFormatUpgradeJob::setOverrideObjectType(Kolab::ObjectType type)
+{
+ m_overrideObjectType = type;
+}
+
void KolabFormatUpgradeJob::start()
{
Debug() << "Processing Mailbox....... " << m_folder;
@@ -94,7 +100,7 @@ void KolabFormatUpgradeJob::onHeadersReceived( const QString &mailBox,
// Debug() << "preparing for upgrade " << uids[number];
const KMime::Message::Ptr &message = messages[number];
//TODO implement different target folder
- KMime::Message::Ptr msg = Kolab::Upgrade::upgradeMessage(message);
+ KMime::Message::Ptr msg = Kolab::Upgrade::upgradeMessage(message, m_overrideObjectType);
if (!msg.get()) {
Error() << "failed to convert message with uid " << QString::number(uids[number]);
continue;
diff --git a/upgradetool/kolabformatupgradejob.h b/upgradetool/kolabformatupgradejob.h
index 87c199e..d905802 100644
--- a/upgradetool/kolabformatupgradejob.h
+++ b/upgradetool/kolabformatupgradejob.h
@@ -22,6 +22,7 @@
#define KOLABFORMATUPGRADEJOB_H
#include <kjob.h>
+#include <kolabobject.h>
#include <kimap/fetchjob.h>
class SequentialCompositeJob;
@@ -34,6 +35,10 @@ class KolabFormatUpgradeJob : public KJob
Q_OBJECT
public:
explicit KolabFormatUpgradeJob(const QString &folder, KIMAP::Session *session, QObject* parent = 0);
+ /**
+ * Override the objectType
+ */
+ void setOverrideObjectType(Kolab::ObjectType);
virtual void start();
private slots:
void onSelectDone(KJob*);
@@ -47,6 +52,7 @@ private:
KIMAP::Session *m_session;
QString m_folder;
SequentialCompositeJob *seqJob;
+ Kolab::ObjectType m_overrideObjectType;
};
#endif // KOLABFORMATUPGRADEJOB_H
diff --git a/upgradetool/upgradetool.cpp b/upgradetool/upgradetool.cpp
index 15e8b5a..52263d3 100644
--- a/upgradetool/upgradetool.cpp
+++ b/upgradetool/upgradetool.cpp
@@ -50,18 +50,47 @@ int main(int argc, char *argv[])
options.add("p").add("password <password>", ki18n("Password for IMAP Account"));
options.add("P").add("port <port>", ki18n("Port to be used on IMAP Server"), "143");
options.add("e").add("encrypt <mode>", ki18n("Encryption mode to be used (NONE, TLS, SSL)"), "TLS");
+ options.add("f").add("folder <folder>", ki18n("Upgrade only the specified folder"));
+ options.add("t").add("type <type>", ki18n("force the type (EVENT, TODO, JOURNAL, CONTACT). Applies only when upgrading a single file or a specific folder."));
+
options.add("a").add("auth <mode>", ki18n("Authentication mode to be used (PLAIN, LOGIN, CRAMMD5, DIGESTMD5, NTLM, GSSAPI, ANONYMOUS, CLEARTEXT)"), "PLAIN");
+// options.add("f").add
options.add("+[server/file]", ki18n("IMAP Server/File"));
KCmdLineArgs::addCmdLineOptions( options );
QCoreApplication app(argc, argv);
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ Kolab::ObjectType overrideType = Kolab::InvalidObject;
+ if (args->isSet("type")) {
+ const QString &type = args->getOption("type");
+ if (type == "EVENT") {
+ overrideType = Kolab::EventObject;
+ } else if (type == "TODO") {
+ overrideType = Kolab::TodoObject;
+ } else if (type == "JOURNAL") {
+ overrideType = Kolab::JournalObject;
+ } else if (type == "CONTACT") {
+ overrideType = Kolab::ContactObject;
+ } else {
+ kWarning() << "unknown type mode";
+ return -1;
+ }
+ }
+
+ QString folderToUpgrade;
+ if (args->isSet("folder")) {
+ folderToUpgrade = args->getOption("folder");
+ }
+
if (!args->isSet("mime")) {
if (args->count() == 0) {
kWarning() << "specify imap server";
return -1;
}
ImapUpgradeJob *upgrader = new ImapUpgradeJob(&app);
+ upgrader->setOverrideObjectType(overrideType);
+ upgrader->setFolderToUpgrade(folderToUpgrade);
QObject::connect(upgrader, SIGNAL(result(KJob*)), &app, SLOT(quit()));
KIMAP::LoginJob::EncryptionMode encryptionMode = KIMAP::LoginJob::TlsV1;
@@ -118,9 +147,9 @@ int main(int argc, char *argv[])
file.open( QFile::ReadOnly );
const QByteArray data = file.readAll();
Q_ASSERT( !data.isEmpty() );
- s << Kolab::Upgrade::upgradeMime(data);
+ s << Kolab::Upgrade::upgradeMime(data, overrideType);
} else {
- s << Kolab::Upgrade::upgradeMime(stream.readAll().toLatin1());
+ s << Kolab::Upgrade::upgradeMime(stream.readAll().toLatin1(), overrideType);
}
}
if (Kolab::ErrorHandler::instance().error() >= Kolab::ErrorHandler::Error) {
diff --git a/upgradetool/upgradeutilities.cpp b/upgradetool/upgradeutilities.cpp
index 3074c6a..0bf6c6a 100644
--- a/upgradetool/upgradeutilities.cpp
+++ b/upgradetool/upgradeutilities.cpp
@@ -28,9 +28,12 @@
namespace Kolab {
namespace Upgrade {
-KMime::Message::Ptr upgradeMessage(KMime::Message::Ptr msg)
+KMime::Message::Ptr upgradeMessage(KMime::Message::Ptr msg, Kolab::ObjectType overrideObjectType)
{
Kolab::KolabObjectReader reader;
+ if (overrideObjectType != Kolab::InvalidObject) {
+ reader.setObjectType(overrideObjectType);
+ }
switch (reader.parseMimeMessage(msg)) {
case Kolab::EventObject:
return Kolab::KolabObjectWriter::writeEvent(reader.getEvent());
@@ -59,14 +62,14 @@ KMime::Message::Ptr upgradeMessage(KMime::Message::Ptr msg)
/**
* Upgrades the format of a complete mime message containing a kolab object
*/
-QString upgradeMime(const QByteArray &input)
+QString upgradeMime(const QByteArray &input, Kolab::ObjectType overrideObjectType)
{
KMime::Message::Ptr msg = KMime::Message::Ptr(new KMime::Message);
msg->setContent( KMime::CRLFtoLF(input) );
msg->parse();
msg->content(KMime::ContentIndex());
- KMime::Message::Ptr message = upgradeMessage(msg);
+ KMime::Message::Ptr message = upgradeMessage(msg, overrideObjectType);
if (!message) {
return QString();
}
diff --git a/upgradetool/upgradeutilities.h b/upgradetool/upgradeutilities.h
index 37d539b..c2efd9e 100644
--- a/upgradetool/upgradeutilities.h
+++ b/upgradetool/upgradeutilities.h
@@ -18,6 +18,7 @@
#ifndef UPGRADEUTILITIES_H
#define UPGRADEUTILITIES_H
#include <QString>
+#include <kolabobject.h>
#include <kmime/kmime_message.h>
namespace Kolab {
@@ -30,8 +31,8 @@ namespace Kolab {
/**
* Takes a v2 mime message and returns a v3 version
*/
-KMime::Message::Ptr upgradeMessage(KMime::Message::Ptr msg);
-QString upgradeMime(const QByteArray &);
+KMime::Message::Ptr upgradeMessage(KMime::Message::Ptr msg, Kolab::ObjectType overrideObjectType = Kolab::InvalidObject);
+QString upgradeMime(const QByteArray &, Kolab::ObjectType overrideObjectType = Kolab::InvalidObject);