summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-10-01 11:02:51 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-10-01 11:02:51 (GMT)
commit1d544eb3af8fbb26611cfc3023ab90709760c9bc (patch)
tree3b0c336991c863393054e9e439e4497e90f01d10
parent7bd55debd99d15da8316dce7721550c2516016bc (diff)
downloadkolab-utils-1d544eb3af8fbb26611cfc3023ab90709760c9bc.tar.gz
Copy message flags
-rw-r--r--migrationutility/kolabaccount.cpp26
-rw-r--r--migrationutility/kolabaccount.h3
-rw-r--r--migrationutility/migratefolderjob.cpp6
-rw-r--r--migrationutility/object.h29
-rw-r--r--migrationutility/sourceaccount.cpp25
-rw-r--r--migrationutility/sourceaccount.h7
6 files changed, 67 insertions, 29 deletions
diff --git a/migrationutility/kolabaccount.cpp b/migrationutility/kolabaccount.cpp
index c269d19..ea32799 100644
--- a/migrationutility/kolabaccount.cpp
+++ b/migrationutility/kolabaccount.cpp
@@ -99,14 +99,17 @@ void KolabAccount::init()
}
}
-void KolabAccount::appendObject(KMime::Message::Ptr obj, const QString& folder)
+const char* FlagRecent2 = "\\Recent";
+
+void KolabAccount::appendObject(Object obj, const QString& folder)
{
Q_ASSERT(mFolders.contains(folder));
KIMAP::AppendJob *job = new KIMAP::AppendJob( mSession );
job->setMailBox( folder );
- job->setContent( obj->encodedContent( true ) );
- //TODO copy flags over
-// job->setFlags( m_flags );
+ job->setContent( obj.message->encodedContent( true ) );
+ //The Recent flag is a special case which is not allowed in the append command
+ obj.flags.removeAll(QByteArray(FlagRecent2));
+ job->setFlags( obj.flags );
job->exec();
Debug() << "appended object in folder: " << folder;
if (job->error()) {
@@ -182,13 +185,13 @@ void KolabAccount::mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &desc
mMailboxes.append(descriptors);
}
+//TODO move to formathelpers.h or kolabdefinitions.h
#define KOLAB_FOLDER_TYPE_DRAFT_SUFFIX ".draft"
#define KOLAB_FOLDER_TYPE_SENT_SUFFIX ".sentitems"
#define KOLAB_FOLDER_TYPE_OUTBOX_SUFFIX ".outbox"
#define KOLAB_FOLDER_TYPE_TRASH_SUFFIX ".wastebasket"
#define KOLAB_FOLDER_TYPE_JUNK_SUFFIX ".junkemail"
-//TODO setup drafts/sent/
void KolabAccount::createFolder(const QString &name, const QByteArray &annotation)
{
if (mFolders.contains(name, Qt::CaseInsensitive)) {
@@ -206,15 +209,15 @@ void KolabAccount::createFolder(const QString &name, const QByteArray &annotatio
KIMAP::SetMetaDataJob *setMetadataJob = new KIMAP::SetMetaDataJob(mSession);
setMetadataJob->setMailBox(createJob->mailBox());
-// if ( m_serverCapabilities.contains( "METADATA" ) ) {
-// setMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Metadata );
-// setMetadataJob->setEntry( KOLAB_FOLDER_TYPE_ANNOTATION );
-// setMetadataJob->addMetaData( KOLAB_FOLDER_TYPE_ANNOTATION, QString::fromStdString(Kolab::folderAnnotation(folderType, true)).toLatin1() );
-// } else {
+ if ( mCapabilities.contains( "METADATA" ) ) {
+ setMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Metadata );
+ setMetadataJob->setEntry( KOLAB_FOLDER_TYPE_ANNOTATION );
+ setMetadataJob->addMetaData( KOLAB_FOLDER_TYPE_ANNOTATION, annotation );
+ } else {
setMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Annotatemore );
setMetadataJob->setEntry( KOLAB_FOLDER_TYPE_ANNOTATION );
setMetadataJob->addMetaData( "value.shared", annotation );
-// }
+ }
mFolders.append(name);
}
@@ -235,6 +238,7 @@ void KolabAccount::setupFolders()
}
KIMAP::SelectJob *selectJob = new KIMAP::SelectJob(mSession);
selectJob->setMailBox(QString());
+ //TODO internationalize folder names
createFolder("Drafts", KOLAB_FOLDER_TYPE_MAIL KOLAB_FOLDER_TYPE_DRAFT_SUFFIX);
createFolder("Sent", KOLAB_FOLDER_TYPE_MAIL KOLAB_FOLDER_TYPE_SENT_SUFFIX);
createFolder("Trash", KOLAB_FOLDER_TYPE_MAIL KOLAB_FOLDER_TYPE_TRASH_SUFFIX);
diff --git a/migrationutility/kolabaccount.h b/migrationutility/kolabaccount.h
index 512716f..7b93325 100644
--- a/migrationutility/kolabaccount.h
+++ b/migrationutility/kolabaccount.h
@@ -22,6 +22,7 @@
#include <kimap/loginjob.h>
#include <kimap/listjob.h>
#include <kmime/kmime_message.h>
+#include "object.h"
namespace KIMAP {
class Session;
@@ -38,7 +39,7 @@ public:
void cleanAccount();
void setupFolders();
- void appendObject(KMime::Message::Ptr obj, const QString &folder);
+ void appendObject(Object obj, const QString &folder);
void createFolder(const QString &name, Kolab::FolderType folderType);
void createFolder(const QString &name, const QByteArray &annotation);
diff --git a/migrationutility/migratefolderjob.cpp b/migrationutility/migratefolderjob.cpp
index 09d3d1e..e3b05b6 100644
--- a/migrationutility/migratefolderjob.cpp
+++ b/migrationutility/migratefolderjob.cpp
@@ -32,9 +32,9 @@ void MigrateFolderJob::start()
{
const QPair<Kolab::FolderType, QString> &targetFolder = mSourceAccount->translateFolder(mFolder);
mKolabAccount->createFolder(targetFolder.second, targetFolder.first);
- QList<KMime::Message::Ptr> messages = mSourceAccount->getObjects(mFolder);
- foreach (const KMime::Message::Ptr &msg, messages) {
- mKolabAccount->appendObject(msg, targetFolder.second);
+ QList<Object> messages = mSourceAccount->getObjects(mFolder);
+ foreach (const Object &obj, messages) {
+ mKolabAccount->appendObject(obj, targetFolder.second);
}
emitResult();
} \ No newline at end of file
diff --git a/migrationutility/object.h b/migrationutility/object.h
new file mode 100644
index 0000000..1d34e1a
--- /dev/null
+++ b/migrationutility/object.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef OBJECT_H
+#define OBJECT_H
+#include <kmime/kmime_message.h>
+
+class Object
+{
+public:
+ KMime::Message::Ptr message;
+ QList<QByteArray> flags;
+};
+
+#endif // OBJECT_H
diff --git a/migrationutility/sourceaccount.cpp b/migrationutility/sourceaccount.cpp
index fa52ad8..5d8a20c 100644
--- a/migrationutility/sourceaccount.cpp
+++ b/migrationutility/sourceaccount.cpp
@@ -38,9 +38,9 @@ QStringList SourceAccount::lookupFolderList()
return QStringList();
}
-QList<KMime::Message::Ptr> SourceAccount::getObjects(const QString& folder)
+QList<Object> SourceAccount::getObjects(const QString& folder)
{
- return QList<KMime::Message::Ptr>();
+ return QList<Object>();
}
void SourceAccount::logout()
@@ -67,11 +67,11 @@ QStringList TestAccount::lookupFolderList()
return mFolderList;
}
-QList<KMime::Message::Ptr> TestAccount::getObjects(const QString& folder)
+QList<Object> TestAccount::getObjects(const QString& folder)
{
Debug() << folder;
Q_ASSERT(mFolderList.removeAll(folder) == 1);
- return QList<KMime::Message::Ptr>();
+ return QList<Object>();
}
//--------------------------------------------------------------
@@ -201,24 +201,27 @@ KMime::Message::Ptr upgradeMessage(KMime::Message::Ptr msg, Kolab::ObjectType ov
return KMime::Message::Ptr();
}
-QList<KMime::Message::Ptr> KolabSourceAccount::getObjects(const QString& folder)
+QList<Object> KolabSourceAccount::getObjects(const QString& folder)
{
- Kolab::ObjectType type = Kolab::InvalidObject;
+ bool isKolabType = false;
if (mKolabFolders.values().contains(folder)) {
- type = Kolab::DictionaryConfigurationObject;//Some random, we use the autodetection afterwards //TODO use the detected type instead
+ isKolabType = true;
}
Debug() << folder;
FetchMessagesJob *fetchJob = new FetchMessagesJob(folder, mSession, this);
fetchJob->exec();
Debug() << fetchJob->getMessages().size();
- QList<KMime::Message::Ptr> messages;
+ QList<Object> messages;
foreach (const KMime::Message::Ptr &msg, fetchJob->getMessages()) {
//TODO writing the message again would rather belong to the KolabAccount, but for that we'd need some Kolab object container to pass around (aka QPair<Type,Object>)
- if (type != Kolab::InvalidObject) {
- messages.append(upgradeMessage(msg, Kolab::InvalidObject));
+ Object obj;
+ if (isKolabType) {
+ obj.message = upgradeMessage(msg, Kolab::InvalidObject);
} else {
- messages.append(msg);
+ obj.message = msg;
}
+ obj.flags = fetchJob->getFlags(msg);
+ messages.append(obj);
}
return messages;
}
diff --git a/migrationutility/sourceaccount.h b/migrationutility/sourceaccount.h
index 50f6095..51ec3fa 100644
--- a/migrationutility/sourceaccount.h
+++ b/migrationutility/sourceaccount.h
@@ -24,6 +24,7 @@
#include <kimap/loginjob.h>
#include <kimap/listjob.h>
#include <kmime/kmime_message.h>
+#include "object.h"
class SourceAccount: public QObject
{
@@ -32,7 +33,7 @@ public:
explicit SourceAccount(QObject* parent = 0);
virtual QStringList lookupFolderList();
- virtual QList<KMime::Message::Ptr> getObjects(const QString &folder);
+ virtual QList<Object> getObjects(const QString &folder);
virtual void logout();
virtual QPair<Kolab::FolderType, QString> translateFolder(const QString& folder);
signals:
@@ -49,7 +50,7 @@ class TestAccount: public SourceAccount
public:
explicit TestAccount(QObject* parent = 0);
virtual QStringList lookupFolderList();
- virtual QList<KMime::Message::Ptr> getObjects(const QString &folder);
+ virtual QList<Object> getObjects(const QString &folder);
QStringList mFolderList;
};
@@ -60,7 +61,7 @@ class KolabSourceAccount: public SourceAccount
public:
explicit KolabSourceAccount(QObject* parent = 0);
virtual QStringList lookupFolderList();
- virtual QList<KMime::Message::Ptr> getObjects(const QString &folder);
+ virtual QList<Object> getObjects(const QString &folder);
virtual QPair<Kolab::FolderType, QString> translateFolder(const QString& folder);
void setHost(const QString &host, qint16 port);