diff --git a/lib/jobs/findkolabfoldersjob.cpp b/lib/jobs/findkolabfoldersjob.cpp index 8c50032..ae99a2d 100644 --- a/lib/jobs/findkolabfoldersjob.cpp +++ b/lib/jobs/findkolabfoldersjob.cpp @@ -1,167 +1,167 @@ /* Copyright (C) 2012 Christian Mollekopf This library 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 2.1 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "findkolabfoldersjob.h" #include #include #include #include #include #include -FindKolabFoldersJob::FindKolabFoldersJob(const QStringList &serverCapabilities, const QList &pN, const QList &excluded, KIMAP::Session* session, QObject* parent) +FindKolabFoldersJob::FindKolabFoldersJob(const QStringList &serverCapabilities, const QList &fetchedNamespaces, const QList &excluded, KIMAP::Session* session, QObject* parent) : KJob(parent), m_session(session), m_metadataRetrieveJobs(0), m_mailBoxReceiveDone(false), -m_personalNamespaces(pN), +m_fetchedNamespaces(fetchedNamespaces), m_serverCapabilities(serverCapabilities) { foreach (const KIMAP::MailBoxDescriptor &desc, excluded) { m_excludedNamespaces.append(desc.name); } } void FindKolabFoldersJob::start() { // foreach (const KIMAP::MailBoxDescriptor &desc, m_personalNamespaces) { // Debug() << desc.name; // } KIMAP::ListJob *fullListJob = new KIMAP::ListJob( m_session ); fullListJob->setOption( KIMAP::ListJob::IncludeUnsubscribed ); - fullListJob->setQueriedNamespaces( m_personalNamespaces ); + fullListJob->setQueriedNamespaces( m_fetchedNamespaces ); connect( fullListJob, SIGNAL(mailBoxesReceived(QList,QList >)), this, SLOT(onMailBoxesReceived(QList,QList >)) ); connect( fullListJob, SIGNAL(result(KJob*)), SLOT(onMailBoxesReceiveDone(KJob*)) ); fullListJob->start(); } QMultiHash FindKolabFoldersJob::getKolabFolders() { return m_kolabFolders; } QMultiHash FindKolabFoldersJob::getAllFolders() { return m_allFolders; } void FindKolabFoldersJob::onMailBoxesReceived( const QList< KIMAP::MailBoxDescriptor > &descriptors, const QList< QList > &/* flags */ ) { for ( int i=0; isetMailBox( descriptor.name ); if ( m_serverCapabilities.contains( "METADATA" ) ) { meta->setServerCapability( KIMAP::MetaDataJobBase::Metadata ); //TODO support shared/private meta->addEntry( "/shared" KOLAB_FOLDER_TYPE_ANNOTATION ); } else if ( m_serverCapabilities.contains( "ANNOTATEMORE" ) ) { meta->setServerCapability( KIMAP::MetaDataJobBase::Annotatemore ); meta->addEntry( KOLAB_FOLDER_TYPE_ANNOTATION, "value.shared" ); } else { Warning() << "Server does not support annotations"; emitResult(); return; } connect( meta, SIGNAL(result(KJob*)), SLOT(onGetMetaDataDone(KJob*)) ); m_metadataRetrieveJobs++; meta->start(); } } void FindKolabFoldersJob::onMailBoxesReceiveDone( KJob* job ) { if ( job->error() ) { Warning() << job->errorString(); } m_mailBoxReceiveDone = true; if (m_metadataRetrieveJobs == 0) { emitResult(); } } void FindKolabFoldersJob::onGetMetaDataDone( KJob *job ) { m_metadataRetrieveJobs--; if ( job->error() ) { Warning() << job->errorString(); setError(KJob::UserDefinedError); if (m_mailBoxReceiveDone && (m_metadataRetrieveJobs <= 0)) { emitResult(); } return; // Well, no metadata for us then... } KIMAP::GetMetaDataJob *meta = qobject_cast( job ); QMap > rawAnnotations = meta->allMetaData( meta->mailBox() ); QByteArray attribute = ""; QByteArray annotation = KOLAB_FOLDER_TYPE_ANNOTATION; if ( meta->serverCapability()==KIMAP::MetaDataJobBase::Annotatemore ) { attribute = "value.shared"; } if ( meta->serverCapability()==KIMAP::MetaDataJobBase::Metadata ) { annotation = "/shared" KOLAB_FOLDER_TYPE_ANNOTATION; } //TODO default flag? const QByteArray &kolabType = rawAnnotations[annotation][attribute]; // Debug() << meta->mailBox() << kolabType; m_allFolders.insertMulti(kolabType, meta->mailBox()); if (!kolabType.isEmpty()) { if (kolabType.contains(KOLAB_FOLDER_TYPE_CONTACT)) { m_kolabFolders.insertMulti(KOLAB_FOLDER_TYPE_CONTACT, meta->mailBox()); } else if (kolabType.contains(KOLAB_FOLDER_TYPE_EVENT)) { m_kolabFolders.insertMulti(KOLAB_FOLDER_TYPE_EVENT, meta->mailBox()); } else if (kolabType.contains(KOLAB_FOLDER_TYPE_TASK)) { m_kolabFolders.insertMulti(KOLAB_FOLDER_TYPE_TASK, meta->mailBox()); } else if (kolabType.contains(KOLAB_FOLDER_TYPE_JOURNAL)) { m_kolabFolders.insertMulti(KOLAB_FOLDER_TYPE_JOURNAL, meta->mailBox()); } else if (kolabType.contains(KOLAB_FOLDER_TYPE_NOTE)) { m_kolabFolders.insertMulti(KOLAB_FOLDER_TYPE_NOTE, meta->mailBox()); } else if (kolabType.contains(KOLAB_FOLDER_TYPE_FREEBUSY)) { m_kolabFolders.insertMulti(KOLAB_FOLDER_TYPE_FREEBUSY, meta->mailBox()); } else if (kolabType.contains("mail") || kolabType.contains("configuration") || kolabType.contains("file") || kolabType == "NIL") { //ignore silently } else { Warning() << "invalid/unhandled folder-type " << kolabType; } } if (m_mailBoxReceiveDone && (m_metadataRetrieveJobs <= 0)) { emitResult(); } } diff --git a/lib/jobs/findkolabfoldersjob.h b/lib/jobs/findkolabfoldersjob.h index aae2746..454800f 100644 --- a/lib/jobs/findkolabfoldersjob.h +++ b/lib/jobs/findkolabfoldersjob.h @@ -1,61 +1,61 @@ /* Copyright (C) 2012 Christian Mollekopf This library 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 2.1 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef FINDKOLABFOLDERSJOB_H #define FINDKOLABFOLDERSJOB_H #include #include #include #include #include namespace KIMAP { class Session; } class FindKolabFoldersJob : public KJob { Q_OBJECT public: - explicit FindKolabFoldersJob(const QStringList &serverCapabilities, const QList &personalNamespaces, const QList &excluded, KIMAP::Session *session, QObject* parent = 0); + explicit FindKolabFoldersJob(const QStringList &serverCapabilities, const QList &fetchedNamespaces, const QList &excluded, KIMAP::Session *session, QObject* parent = 0); virtual void start(); QMultiHash getKolabFolders(); QMultiHash getAllFolders(); private slots: void onMailBoxesReceived( const QList< KIMAP::MailBoxDescriptor > &descriptors, const QList< QList > &flags ); void onMailBoxesReceiveDone( KJob* job ); void onGetMetaDataDone( KJob *job ); private: KIMAP::Session *m_session; QList m_mailboxes; QHash m_kolabFolders; QHash m_allFolders; int m_metadataRetrieveJobs; bool m_mailBoxReceiveDone; - QList m_personalNamespaces; + QList m_fetchedNamespaces; QStringList m_excludedNamespaces; QStringList m_serverCapabilities; }; #endif // FINDKOLABFOLDERSJOB_H diff --git a/lib/jobs/probeimapserverjob.cpp b/lib/jobs/probeimapserverjob.cpp index 512a77e..2bdf2ef 100644 --- a/lib/jobs/probeimapserverjob.cpp +++ b/lib/jobs/probeimapserverjob.cpp @@ -1,93 +1,99 @@ /* * Copyright (C) 2012 Christian Mollekopf * * 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 . */ #include "probeimapserverjob.h" #include #include #include ProbeIMAPServerJob::ProbeIMAPServerJob(KIMAP::Session *session, QObject* parent) : KJob(parent), mSession(session) { } ProbeIMAPServerJob::~ProbeIMAPServerJob() { } void ProbeIMAPServerJob::start() { KIMAP::CapabilitiesJob *capabilities = new KIMAP::CapabilitiesJob(mSession); connect(capabilities, SIGNAL(result(KJob*)), this, SLOT(onCapabilitiesTestDone(KJob*))); capabilities->start(); } void ProbeIMAPServerJob::onCapabilitiesTestDone(KJob* job) { if ( job->error() ) { Warning() << job->errorString(); setError(KJob::UserDefinedError); emitResult(); return; } KIMAP::CapabilitiesJob *capabilitiesJob = qobject_cast( job ); Q_ASSERT(capabilitiesJob); mCapabilities = capabilitiesJob->capabilities(); if ( mCapabilities.contains( "NAMESPACE" ) ) { KIMAP::NamespaceJob *nsJob = new KIMAP::NamespaceJob( mSession ); QObject::connect( nsJob, SIGNAL(result(KJob*)), SLOT(onNamespacesTestDone(KJob*)) ); nsJob->start(); return; } else { emitResult(); } } void ProbeIMAPServerJob::onNamespacesTestDone( KJob *job ) { if ( job->error() ) { Warning() << job->errorString(); setError(KJob::UserDefinedError); emitResult(); return; } KIMAP::NamespaceJob *nsJob = qobject_cast( job ); Q_ASSERT(nsJob); mPersonalNamespace = nsJob->personalNamespaces(); - mExcludedNamespace = nsJob->userNamespaces()+nsJob->sharedNamespaces(); + mExcludedNamespace = nsJob->userNamespaces() + nsJob->sharedNamespaces(); + mSharedNamespace = nsJob->sharedNamespaces(); emitResult(); } QStringList ProbeIMAPServerJob::capabilities() const { return mCapabilities; } QList< KIMAP::MailBoxDescriptor > ProbeIMAPServerJob::personalNamespace() const { return mPersonalNamespace; } QList< KIMAP::MailBoxDescriptor > ProbeIMAPServerJob::excludedNamespaces() const { return mExcludedNamespace; } + +QList< KIMAP::MailBoxDescriptor > ProbeIMAPServerJob::sharedNamespaces() const +{ + return mSharedNamespace; +} diff --git a/lib/jobs/probeimapserverjob.h b/lib/jobs/probeimapserverjob.h index 6cf0197..9e42f3f 100644 --- a/lib/jobs/probeimapserverjob.h +++ b/lib/jobs/probeimapserverjob.h @@ -1,53 +1,55 @@ /* * Copyright (C) 2013 Christian Mollekopf * * 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 . */ #ifndef PROBEIMAPSERVERJOB_H #define PROBEIMAPSERVERJOB_H #include #include #include #include #include /** * Probeserver for supported IMAP features */ class ProbeIMAPServerJob: public KJob { Q_OBJECT public: explicit ProbeIMAPServerJob(KIMAP::Session *, QObject* parent = 0); virtual ~ProbeIMAPServerJob(); virtual void start(); QList personalNamespace() const; QList excludedNamespaces() const; + QList sharedNamespaces() const; QStringList capabilities() const; protected Q_SLOTS: void onCapabilitiesTestDone(KJob *); void onNamespacesTestDone(KJob *); private: KIMAP::Session *mSession; QStringList mCapabilities; QList mPersonalNamespace; QList mExcludedNamespace; + QList mSharedNamespace; }; #endif diff --git a/lib/jobs/probekolabserverjob.cpp b/lib/jobs/probekolabserverjob.cpp index 6d118d7..3afb34e 100644 --- a/lib/jobs/probekolabserverjob.cpp +++ b/lib/jobs/probekolabserverjob.cpp @@ -1,98 +1,109 @@ /* * Copyright (C) 2012 Christian Mollekopf * * 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 . */ #include "probekolabserverjob.h" #include "findkolabfoldersjob.h" #include "setupkolabfoldersjob.h" #include "probeimapserverjob.h" #include ProbeKolabServerJob::ProbeKolabServerJob(KIMAP::Session *session, QObject* parent) : KJob(parent), mSession(session) { } ProbeKolabServerJob::~ProbeKolabServerJob() { } void ProbeKolabServerJob::start() { ProbeIMAPServerJob *probeJob = new ProbeIMAPServerJob(mSession, this); connect(probeJob, SIGNAL(result(KJob*)), this, SLOT(onProbeJobDone(KJob*))); probeJob->start(); } +void ProbeKolabServerJob::fetchSharedFolders(bool fetch) +{ + mFetchSharedFolders = fetch; +} + void ProbeKolabServerJob::onProbeJobDone(KJob* job) { if (job->error()) { Warning() << job->errorString(); setError(KJob::UserDefinedError); emitResult(); return; } ProbeIMAPServerJob *probeJob = static_cast(job); mCapabilities = probeJob->capabilities(); mPersonalNamespace = probeJob->personalNamespace(); mExcludedNamespace = probeJob->excludedNamespaces(); - FindKolabFoldersJob *findJob = new FindKolabFoldersJob(mCapabilities, mPersonalNamespace, mExcludedNamespace, mSession, this); + QList sharedNamespaces = probeJob->sharedNamespaces(); + FindKolabFoldersJob *findJob; + if (mFetchSharedFolders) { + findJob = new FindKolabFoldersJob(mCapabilities, probeJob->sharedNamespaces(), QList(), mSession, this); + } else { + findJob = new FindKolabFoldersJob(mCapabilities, probeJob->personalNamespace(), mExcludedNamespace, mSession, this); + } connect(findJob, SIGNAL(result(KJob*)), this, SLOT(findKolabFoldersDone(KJob*))); findJob->start(); } void ProbeKolabServerJob::findKolabFoldersDone(KJob *job) { if (job->error()) { Warning() << job->errorString(); setError(KJob::UserDefinedError); emitResult(); return; } FindKolabFoldersJob *findJob = static_cast(job); // qDebug() << "Found kolab folders: " << findJob->getKolabFolders(); mKolabFolders = findJob->getKolabFolders(); mAllFolders = findJob->getAllFolders(); emitResult(); } QMultiHash ProbeKolabServerJob::kolabFolders() const { return mKolabFolders; } QMultiHash ProbeKolabServerJob::allFolders() const { return mAllFolders; } QStringList ProbeKolabServerJob::capabilities() const { return mCapabilities; } QList< KIMAP::MailBoxDescriptor > ProbeKolabServerJob::personalNamespace() const { return mPersonalNamespace; } QList< KIMAP::MailBoxDescriptor > ProbeKolabServerJob::excludedNamespaces() const { return mExcludedNamespace; } diff --git a/lib/jobs/probekolabserverjob.h b/lib/jobs/probekolabserverjob.h index ef23b53..92bba34 100644 --- a/lib/jobs/probekolabserverjob.h +++ b/lib/jobs/probekolabserverjob.h @@ -1,55 +1,58 @@ /* * Copyright (C) 2012 Christian Mollekopf * * 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 . */ #ifndef PROBEKOLABSERVERJOB_H #define PROBEKOLABSERVERJOB_H #include #include #include #include /** * Probeserver for supported IMAP features and existing kolab folders */ class ProbeKolabServerJob: public KJob { Q_OBJECT public: explicit ProbeKolabServerJob(KIMAP::Session *, QObject* parent = 0); virtual ~ProbeKolabServerJob(); virtual void start(); QList personalNamespace() const; QList excludedNamespaces() const; QStringList capabilities() const; QMultiHash kolabFolders() const; QMultiHash allFolders() const; + void fetchSharedFolders(bool fetch); + protected Q_SLOTS: void onProbeJobDone(KJob *job); void findKolabFoldersDone(KJob*); private: KIMAP::Session *mSession; QStringList mCapabilities; QList mPersonalNamespace; QList mExcludedNamespace; QMultiHash mKolabFolders; QMultiHash mAllFolders; + bool mFetchSharedFolders; }; #endif // PROBEKOLABSERVERJOB_H diff --git a/upgradetool/imapupgradejob.cpp b/upgradetool/imapupgradejob.cpp index 0194dd0..fe82b15 100644 --- a/upgradetool/imapupgradejob.cpp +++ b/upgradetool/imapupgradejob.cpp @@ -1,186 +1,182 @@ /* Copyright (C) 2012 Christian Mollekopf This library 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 2.1 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "imapupgradejob.h" #include "kolabformatupgradejob.h" #include "jobs/probekolabserverjob.h" #include "jobs/sequentialcompositejob.h" #include #include #include #include #include #include #include #include #include #include #include class UiProxy: public KIMAP::SessionUiProxy { public: bool ignoreSslError(const KSslErrorUiData& /*errorData*/) { return true; //Necessary due to the untrusted certificate } }; ImapUpgradeJob::ImapUpgradeJob(QObject* parent): KJob(parent), m_session(0) { } ImapUpgradeJob::~ImapUpgradeJob() { } void ImapUpgradeJob::setUpgradeOptions(const Kolab::Upgrade::UpgradeOptions &options) { m_upgradeOptions = options; } 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; m_session = new KIMAP::Session( hostName, port, this ); m_session->setUiProxy( KIMAP::SessionUiProxy::Ptr(new UiProxy()) ); QObject::connect( m_session, SIGNAL(stateChanged(KIMAP::Session::State,KIMAP::Session::State)), this, SLOT(onSessionStateChanged(KIMAP::Session::State,KIMAP::Session::State)) ); KIMAP::LoginJob *loginJob = new KIMAP::LoginJob( m_session ); if (!proxyauth.isEmpty()) { loginJob->setAuthorizationName(proxyauth); } loginJob->setUserName( username ); loginJob->setPassword( pw ); loginJob->setEncryptionMode( encryptionMode ); if (encryptionMode != KIMAP::LoginJob::Unencrypted) { m_requireEncryption = true; } else { m_requireEncryption = false; } loginJob->setAuthenticationMode( authenticationMode ); QObject::connect( loginJob, SIGNAL(result(KJob*)), this, SLOT(onLoginDone(KJob*)) ); loginJob->start(); } void ImapUpgradeJob::onSessionStateChanged(KIMAP::Session::State newState, KIMAP::Session::State oldState) { Debug() << newState; if (newState == KIMAP::Session::Disconnected && oldState != KIMAP::Session::Disconnected) { Warning() << "lost connection"; } } void ImapUpgradeJob::onLoginDone( KJob *job ) { KIMAP::LoginJob *login = static_cast( job ); if ( job->error() ) { Error() << job->errorString(); Error() << "Login failed, job aborted"; emitResult(); return; } if (m_requireEncryption && login->encryptionMode() == KIMAP::LoginJob::Unencrypted) { setError(KJob::UserDefinedError); setErrorText("failed to encrypt communication"); Error() << errorString(); emitResult(); return; } ProbeKolabServerJob *probeJob = new ProbeKolabServerJob(m_session, this); + probeJob->fetchSharedFolders(m_upgradeOptions.fetchSharedFolders); connect(probeJob, SIGNAL(result(KJob*)), this, SLOT(onProbeDone(KJob*))); probeJob->start(); } void ImapUpgradeJob::onProbeDone(KJob* job) { if ( job->error() ) { Error() << job->errorString(); emitResult(); return; } ProbeKolabServerJob *capabilitiesJob = qobject_cast( job ); Q_ASSERT(capabilitiesJob); SequentialCompositeJob *seqJob = new SequentialCompositeJob(this); - QMultiHash folders; - if (!m_upgradeOptions.validateMode) { - folders = capabilitiesJob->kolabFolders(); - } else { - folders = capabilitiesJob->allFolders(); - } + QMultiHash folders = capabilitiesJob->kolabFolders(); QMultiHash::const_iterator it; QMultiHash::const_iterator end = folders.constEnd(); for (it = folders.constBegin(); it != end; ++it) { if (!m_upgradeOptions.validateMode && it.key() == QLatin1String(KOLAB_FOLDER_TYPE_FREEBUSY)) { continue; } if (!m_folderToUpgrade.isEmpty() && it.value() != m_folderToUpgrade) { continue; } KolabFormatUpgradeJob *upgradeJob = new KolabFormatUpgradeJob(it.value(), m_session, this); upgradeJob->setUpgradeOptions(m_upgradeOptions); upgradeJob->setFolderType(it.key()); seqJob->addSubjob(upgradeJob); } connect(seqJob, SIGNAL(result(KJob*)), this, SLOT(modifyDone(KJob*))); seqJob->start(); } void ImapUpgradeJob::modifyDone( KJob *job ) { Debug() << "all done, logging out"; if ( job->error() ) { Error() << job->errorString(); } //Logout after we're done if (m_session->state() != KIMAP::Session::Disconnected) { KIMAP::LogoutJob *logoutJob = new KIMAP::LogoutJob(m_session); connect(logoutJob, SIGNAL(result(KJob*)), this, SLOT(logoutDone(KJob*))); logoutJob->start(); } else { Debug() << "session is down, not logging out."; emitResult(); } } void ImapUpgradeJob::logoutDone( KJob *job ) { emitResult(); } diff --git a/upgradetool/upgradetool.cpp b/upgradetool/upgradetool.cpp index 83d2ef6..f5fa5a9 100644 --- a/upgradetool/upgradetool.cpp +++ b/upgradetool/upgradetool.cpp @@ -1,214 +1,222 @@ /* * Copyright (C) 2012 Christian Mollekopf * * 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 . */ #include #include #include #include #include #include #include #include #include #include "upgradeutilities.h" #include "imapupgradejob.h" #include "kolabutils-version.h" #include /** * Usage: * * IMAP: * ./upgradetool -u username -p password imap.server.com * * Read mimefile: * ./upgradetool -mime complex.ics.mime * * Read mimemessage from stdin: * cat complex.ics.mime | ./upgradetool -mime * */ int main(int argc, char *argv[]) { KComponentData componentData("upgradetool"); KCmdLineArgs::init(argc, argv, "upgradetool", "upgradetool",ki18n("upgradetool"), KOLABUTILS_VERSION); KCmdLineOptions options; options.add("mime", ki18n("Read mime from stdin or file")); options.add("u").add("user ", ki18n("Username for IMAP Account")); options.add("y").add("proxyauth ", ki18n("Username to be used for authentication together with password (optional, works with PLAIN/SASL authentication)")); options.add("p").add("password ", ki18n("Password for IMAP Account")); options.add("P").add("port ", ki18n("Port to be used on IMAP Server"), "143"); options.add("e").add("encrypt ", ki18n("Encryption mode to be used (NONE, TLS, SSL)"), "TLS"); options.add("f").add("folder ", ki18n("Upgrade only the specified folder")); options.add("t").add("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 ", ki18n("Authentication mode to be used (PLAIN, LOGIN, CRAMMD5, DIGESTMD5, NTLM, GSSAPI, ANONYMOUS, CLEARTEXT)"), "PLAIN"); options.add("fix-utc-incidences", ki18n("Converts all incidences from UTC to floating time.")); // options.add("f").add options.add("fix-utc-incidences-offset ", ki18n("Uses a UTC offset to convert the times. If not provided the local timezone get's used instead. The offset is in seconds."), "0"); options.add("fix-utc-incidences-timezone ", ki18n("Uses the specified timezone to convert the times. If not provided the local timezone get's used instead. Timezones are read from zone.tab")); options.add("validate", ki18n("Validate all kolab-objects and mails, and delete the ones that are invalid.")); options.add("delete", ki18n("Delete invalid objects from the server. Applies to validate mode.")); + options.add("shared", ki18n("Validate shared folders (This requires login with an admin account). Applies to validate mode.")); options.add("save-to ", ki18n("Store invalid objects under the given path. Applies to validate mode.")); 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; } } const bool fixUtcIncidencesWithOffset = args->isSet("fix-utc-incidences-offset"); const bool fixUtcIncidencesWithTimezone = args->isSet("fix-utc-incidences-timezone"); const bool fixUtcIncidences = args->isSet("fix-utc-incidences") || fixUtcIncidencesWithOffset || fixUtcIncidencesWithTimezone; Kolab::Upgrade::UpgradeOptions upgradeOptions; upgradeOptions.fixUtcIncidences = fixUtcIncidences; upgradeOptions.fixUtcIncidencesWithOffset = fixUtcIncidencesWithOffset; upgradeOptions.fixUtcIncidencesOffset = args->getOption("fix-utc-incidences-offset").toInt(); if (fixUtcIncidencesWithTimezone) { upgradeOptions.fixUtcIncidencesTimezone = KSystemTimeZones::readZone(args->getOption("fix-utc-incidences-timezone")); } upgradeOptions.overrideObjectType = overrideType; QString folderToUpgrade; if (args->isSet("folder")) { folderToUpgrade = args->getOption("folder"); } if (args->isSet("validate")) { kDebug() << "Running in validation mode."; upgradeOptions.validateMode = true; Q_ASSERT(upgradeOptions.validateMode); } if (!args->isSet("delete")) { kDebug() << "Running in no-delete mode."; upgradeOptions.noDelete = true; } else { kDebug() << "Running in delete mode."; upgradeOptions.noDelete = false; } + if (!args->isSet("shared")) { + kDebug() << "Fetching user folders."; + upgradeOptions.fetchSharedFolders = false; + } else { + kDebug() << "Fetching shared folders."; + upgradeOptions.fetchSharedFolders = true; + } if (args->isSet("save-to")) { kDebug() << "Saving faulty messages to: " << args->getOption("save-to"); upgradeOptions.saveTo = args->getOption("save-to"); QDir dir; if (!dir.mkpath(upgradeOptions.saveTo)) { kWarning() << "Failed to create the given folder: " << upgradeOptions.saveTo; return -1; } } const bool operatingOnMimeFile = args->isSet("mime"); if (!operatingOnMimeFile) { if (args->count() == 0) { kWarning() << "specify imap server"; return -1; } ImapUpgradeJob *upgrader = new ImapUpgradeJob(&app); upgrader->setUpgradeOptions(upgradeOptions); upgrader->setFolderToUpgrade(folderToUpgrade); QObject::connect(upgrader, SIGNAL(result(KJob*)), &app, SLOT(quit())); KIMAP::LoginJob::EncryptionMode encryptionMode = KIMAP::LoginJob::TlsV1; const QString &encrypt = args->getOption("encrypt"); if (encrypt == "NONE") { encryptionMode = KIMAP::LoginJob::Unencrypted; } else if (encrypt == "SSL") { encryptionMode = KIMAP::LoginJob::AnySslVersion; } else if (encrypt == "TLS") { encryptionMode = KIMAP::LoginJob::TlsV1; } else { kWarning() << "unknown encryption mode"; return -1; } KIMAP::LoginJob::AuthenticationMode authenticationMode = KIMAP::LoginJob::Plain; const QString &auth = args->getOption("auth"); if (auth == "PLAIN") { authenticationMode = KIMAP::LoginJob::Plain; } else if (auth == "LOGIN") { authenticationMode = KIMAP::LoginJob::Login; } else if (auth == "CRAMMD5") { authenticationMode = KIMAP::LoginJob::CramMD5; } else if (auth == "DIGESTMD5") { authenticationMode = KIMAP::LoginJob::DigestMD5; } else if (auth == "NTLM") { authenticationMode = KIMAP::LoginJob::NTLM; } else if (auth == "GSSAPI") { authenticationMode = KIMAP::LoginJob::GSSAPI; } else if (auth == "ANONYMOUS") { authenticationMode = KIMAP::LoginJob::Anonymous; } else if (auth == "CLEARTEXT") { authenticationMode = KIMAP::LoginJob::ClearText; } else { kWarning() << "unknown authentication mode"; return -1; } upgrader->connectToAccount(args->arg(0), args->getOption("port").toInt(), args->getOption("user"), args->getOption("proxyauth"), args->getOption("password"), encryptionMode, authenticationMode); args->clear(); if (app.exec() || Kolab::ErrorHandler::instance().error() >= Kolab::ErrorHandler::Error) { return -1; } } else { QTextStream s(stdout); s.setCodec( "UTF-8" ); QTextStream stream(stdin); stream.setCodec( "UTF-8" ); if (operatingOnMimeFile) { if (args->count() > 0) { const QString &filename = args->arg(0); QFile file( filename ); if (!file.open( QFile::ReadOnly )) { kWarning() << "failed to open the file: " << filename; return -1; } const QByteArray data = file.readAll(); Q_ASSERT( !data.isEmpty() ); s << Kolab::Upgrade::upgradeMime(data, upgradeOptions); } else { s << Kolab::Upgrade::upgradeMime(stream.readAll().toUtf8(), upgradeOptions); } } if (Kolab::ErrorHandler::instance().error() >= Kolab::ErrorHandler::Error) { return -1; } } return 0; } diff --git a/upgradetool/upgradeutilities.h b/upgradetool/upgradeutilities.h index 0308f63..6572ab4 100644 --- a/upgradetool/upgradeutilities.h +++ b/upgradetool/upgradeutilities.h @@ -1,67 +1,69 @@ /* * Copyright (C) 2012 Christian Mollekopf * * 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 . */ #ifndef UPGRADEUTILITIES_H #define UPGRADEUTILITIES_H #include #include #include #include namespace Kolab { namespace Upgrade { /** * Takes a v2 xml document and returns a v3 version */ // QString upgradeEventXML(const QByteArray &xmlData); struct UpgradeOptions { UpgradeOptions() :overrideObjectType(Kolab::InvalidObject), fixUtcIncidences(false), fixUtcIncidencesWithOffset(false), fixUtcIncidencesOffset(0), validateMode(false), - noDelete(false) + noDelete(false), + fetchSharedFolders(false) { } Kolab::ObjectType overrideObjectType; bool fixUtcIncidences; bool fixUtcIncidencesWithOffset; int fixUtcIncidencesOffset; KTimeZone fixUtcIncidencesTimezone; bool validateMode; bool noDelete; + bool fetchSharedFolders; QString saveTo; }; /** * Takes a v2 mime message and returns a v3 version */ KMime::Message::Ptr upgradeMessage(KMime::Message::Ptr msg, UpgradeOptions upgradeOptions = UpgradeOptions()); bool validateMessage(KMime::Message::Ptr msg, const QList &expectedType); QString upgradeMime(const QByteArray &, UpgradeOptions upgradeOptions = UpgradeOptions()); } } #endif