summaryrefslogtreecommitdiff
path: root/lib/kolabaccount.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-10-26 15:04:15 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-10-26 15:04:15 (GMT)
commit49273576d059c21a3aba58ee4f371b40f12eaf14 (patch)
tree8ef3b1029eab38f62d1c48b68daf956070142638 /lib/kolabaccount.cpp
parente21838326486e1a382ecd214e1052b75493ea453 (diff)
downloadkolab-utils-49273576d059c21a3aba58ee4f371b40f12eaf14.tar.gz
Moved the writing to the kolabaccount class which frees the way for writing kolabv2 as well.
Diffstat (limited to 'lib/kolabaccount.cpp')
-rw-r--r--lib/kolabaccount.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/lib/kolabaccount.cpp b/lib/kolabaccount.cpp
index 0d98ede..8d744a1 100644
--- a/lib/kolabaccount.cpp
+++ b/lib/kolabaccount.cpp
@@ -34,6 +34,7 @@
#include <kolab/errorhandler.h>
#include <kolab/kolabdefinitions.h>
#include <formathelpers.h>
+#include <kolabobject.h>
KolabAccount::KolabAccount(QObject* parent)
@@ -115,6 +116,30 @@ bool KolabAccount::init()
const char* FlagRecent2 = "\\Recent";
+
+
+KMime::Message::Ptr writeObject(const Object &obj)
+{
+ KMime::Message::Ptr msg;
+ if (obj.object.canConvert<KMime::Message::Ptr>()) {
+ msg = obj.object.value<KMime::Message::Ptr>();
+ } else if (obj.object.canConvert<KCalCore::Incidence::Ptr>()) {
+ msg = Kolab::KolabObjectWriter::writeIncidence(obj.object.value<KCalCore::Incidence::Ptr>());
+ } else if (obj.object.canConvert<KABC::Addressee>()) {
+ msg = Kolab::KolabObjectWriter::writeContact(obj.object.value<KABC::Addressee>());
+ } else if (obj.object.canConvert<KABC::ContactGroup>()) {
+ msg = Kolab::KolabObjectWriter::writeDistlist(obj.object.value<KABC::ContactGroup>());
+ } else if (obj.object.canConvert<Note>()) {
+ msg = Kolab::KolabObjectWriter::writeNote(obj.object.value<Note>().msg);
+ } else if (obj.object.canConvert<Dictionary>()) {
+ const Dictionary dict = obj.object.value<Dictionary>();
+ msg = Kolab::KolabObjectWriter::writeDictionary(dict.dict, dict.lang);
+ } else {
+ Error() << "Type not handled";
+ }
+ return msg;
+}
+
void KolabAccount::appendObject(Object obj, const QString& folder)
{
if (mDryRun) {
@@ -122,14 +147,16 @@ void KolabAccount::appendObject(Object obj, const QString& folder)
return;
}
Q_ASSERT(mFolders.contains(folder));
- if (!obj.message) {
+
+ KMime::Message::Ptr message = writeObject(obj);
+
+ if (!message) {
Error() << "got empty message";
return;
}
- Q_ASSERT(obj.message.get());
KIMAP::AppendJob *job = new KIMAP::AppendJob( mSession );
job->setMailBox( folder );
- job->setContent( obj.message->encodedContent( true ) );
+ job->setContent( 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 );
@@ -321,7 +348,7 @@ QList<Object> KolabAccount::getObjects(const QString& folder)
QList<Object> messages;
foreach (const KMime::Message::Ptr &msg, fetchJob->getMessages()) {
Object obj;
- obj.message = msg;
+ obj.object = QVariant::fromValue(msg);
obj.flags = fetchJob->getFlags(msg);
messages.append(obj);
}