summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-11-05 00:30:42 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-11-05 00:30:42 (GMT)
commit4a1168e8e666689e0ecff22f366c79a8d2be36ad (patch)
treef29e3f8c8fbad32c6c04aaed708deb8777301619
parent49c3bd44e25636dad61955cc64ea11a33bfae746 (diff)
downloadkolab-utils-4a1168e8e666689e0ecff22f366c79a8d2be36ad.tar.gz
Fix metadata if missing during foldersetup.
-rw-r--r--lib/jobs/setupkolabfoldersjob.cpp46
1 files changed, 29 insertions, 17 deletions
diff --git a/lib/jobs/setupkolabfoldersjob.cpp b/lib/jobs/setupkolabfoldersjob.cpp
index f719721..295658d 100644
--- a/lib/jobs/setupkolabfoldersjob.cpp
+++ b/lib/jobs/setupkolabfoldersjob.cpp
@@ -68,6 +68,21 @@ void SetupKolabFoldersJob::onSelectDone(KJob *job)
createMailbox();
}
+static QString getFolderName(Kolab::FolderType type)
+{
+ return QString::fromStdString(Kolab::nameForFolderType(type));
+}
+
+static Kolab::FolderType getFolderType(const QString &typeString)
+{
+ Kolab::FolderType folderType = Kolab::folderTypeFromString(typeString.toStdString());
+ //FIXME: this is only required for libkolab < 0.4.0. Afterwards folderTypeFromString should do the job
+ if (!typeString.compare(QLatin1String("freebusy"), Qt::CaseInsensitive)) {
+ folderType = Kolab::FreebusyType;
+ }
+ return folderType;
+}
+
void SetupKolabFoldersJob::createMailbox()
{
if (m_folderTypes.isEmpty()) {
@@ -75,11 +90,7 @@ void SetupKolabFoldersJob::createMailbox()
return;
}
m_currentFolderType = m_folderTypes.takeFirst();
- Kolab::FolderType folderType = Kolab::folderTypeFromString(m_currentFolderType.toStdString());
- //FIXME: this is only required for libkolab < 0.4.0. Afterwards folderTypeFromString should do the job
- if (!m_currentFolderType.compare(QLatin1String("freebusy"), Qt::CaseInsensitive)) {
- folderType = Kolab::FreebusyType;
- }
+ Kolab::FolderType folderType = getFolderType(m_currentFolderType);
if (folderType == Kolab::MailType) {
Warning() << "unknown kolab type: " << m_currentFolderType;
setError(KJob::UserDefinedError);
@@ -87,26 +98,26 @@ void SetupKolabFoldersJob::createMailbox()
return;
}
KIMAP::CreateJob *createJob = new KIMAP::CreateJob(m_session);
- createJob->setMailBox(QString::fromStdString(Kolab::nameForFolderType(folderType)));
+ createJob->setMailBox(getFolderName(folderType));
connect(createJob, SIGNAL(result(KJob*)), this, SLOT(onCreateDone(KJob*)));
createJob->start();
}
void SetupKolabFoldersJob::onCreateDone(KJob *job)
{
- if ( job->error() ) {
- Warning() << job->errorString() << job->error();
- setError(KJob::UserDefinedError);
- createMailbox();
- //TODO also check metadata in case this fails because the folder is already existing but doesn't contain the annotation
- return;
- }
- KIMAP::CreateJob *createJob = static_cast<KIMAP::CreateJob*>(job);
- Debug() << "Created folder " << m_rootFolder << createJob->mailBox();
- m_createdFolders.insert(m_currentFolderType, createJob->mailBox());
+ QString mailbox;
+ if (job->error()) {
+ Warning() << job->errorString() << "Trying to fix the metadata";
+ mailbox = getFolderName(getFolderType(m_currentFolderType));
+ } else {
+ KIMAP::CreateJob *createJob = static_cast<KIMAP::CreateJob*>(job);
+ mailbox = createJob->mailBox();
+ Debug() << "Created folder " << m_rootFolder << createJob->mailBox();
+ }
+ m_createdFolders.insert(m_currentFolderType, mailbox);
KIMAP::SetMetaDataJob *setMetadataJob = new KIMAP::SetMetaDataJob(m_session);
- setMetadataJob->setMailBox(createJob->mailBox());
+ setMetadataJob->setMailBox(mailbox);
Kolab::FolderType folderType = Kolab::folderTypeFromString(m_currentFolderType.toStdString());
if ( m_serverCapabilities.contains( "METADATA" ) ) {
setMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Metadata );
@@ -125,6 +136,7 @@ void SetupKolabFoldersJob::onMetadataSetDone(KJob *job)
{
if ( job->error() ) {
Warning() << job->errorString();
+ setErrorText("Failed to create the folder for type: " + m_currentFolderType);
setError(KJob::UserDefinedError);
}
createMailbox();