diff --git a/kimap/CMakeLists.txt b/kimap/CMakeLists.txt index 957011681..535042e9f 100644 --- a/kimap/CMakeLists.txt +++ b/kimap/CMakeLists.txt @@ -1,28 +1,29 @@ project(kimap) add_definitions( -DKDE_DEFAULT_DEBUG_AREA=5327 ) add_subdirectory( tests ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}") set(kimap_LIB_SRCS imapstreamparser.cpp job.cpp + capabilitiesjob.cpp loginjob.cpp logoutjob.cpp rfccodecs.cpp session.cpp sessionthread.cpp ) kde4_add_library(kimap SHARED ${kimap_LIB_SRCS}) target_link_libraries(kimap ${KDE4_KDECORE_LIBS} ${QT_QTNETWORK_LIBRARY}) set_target_properties(kimap PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) install(TARGETS kimap EXPORT kdepimlibsLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) ########### install files ############### install( FILES kimap_export.h job.h loginjob.h logoutjob.h rfccodecs.h session.h DESTINATION ${INCLUDE_INSTALL_DIR}/kimap COMPONENT Devel) diff --git a/kimap/capabilitiesjob.cpp b/kimap/capabilitiesjob.cpp new file mode 100644 index 000000000..e44f7aa5a --- /dev/null +++ b/kimap/capabilitiesjob.cpp @@ -0,0 +1,96 @@ +/* + Copyright (c) 2009 Kevin Ottens + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "capabilitiesjob.h" + +#include + +#include "job_p.h" +#include "message_p.h" +#include "session_p.h" + +namespace KIMAP +{ + class CapabilitiesJobPrivate : public JobPrivate + { + public: + CapabilitiesJobPrivate( Session *session ) : JobPrivate(session) { } + ~CapabilitiesJobPrivate() { } + + QStringList capabilities; + QByteArray tag; + }; +} + +using namespace KIMAP; + +CapabilitiesJob::CapabilitiesJob( Session *session ) + : Job( *new CapabilitiesJobPrivate(session) ) +{ + +} + +CapabilitiesJob::~CapabilitiesJob() +{ +} + +QStringList CapabilitiesJob::capabilities() const +{ + Q_D(const CapabilitiesJob); + return d->capabilities; +} + +void CapabilitiesJob::doStart() +{ + Q_D(CapabilitiesJob); + d->tag = d->sessionInternal()->sendCommand( "CAPABILITY" ); +} + +void CapabilitiesJob::doHandleResponse( const Message &response ) +{ + Q_D(CapabilitiesJob); + + if ( !response.content.isEmpty() + && response.content.first().toString()==d->tag ) { + if ( response.content.size() < 2 ) { + setErrorText( i18n("Capabilities query failed, malformed reply from the server") ); + } else if ( response.content[1].toString()!="OK" ) { + QString status; + for ( QList::ConstIterator it = response.content.begin()+1; + it!=response.content.end(); ++it ) { + if (it!=response.content.begin()+1) { + status+=' '; + } + status+=(*it).toString(); + } + setError( UserDefinedError ); + setErrorText( i18n("Capabilities query failed, server replied: %1", status) ); + } + + emitResult(); + } else if ( response.content.size() >= 2 + && response.content[1].toString()=="CAPABILITY" ) { + for (int i=2; icapabilities << response.content[i].toString(); + } + emit capabilitiesReceived(d->capabilities); + } +} + +#include "capabilitiesjob.moc" diff --git a/kimap/capabilitiesjob.h b/kimap/capabilitiesjob.h new file mode 100644 index 000000000..767b2ca3e --- /dev/null +++ b/kimap/capabilitiesjob.h @@ -0,0 +1,56 @@ +/* + Copyright (c) 2009 Kevin Ottens + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef KIMAP_CAPABILITIESJOB_H +#define KIMAP_CAPABILITIESJOB_H + +#include "kimap_export.h" + +#include "job.h" + +namespace KIMAP { + +class Session; +class Message; +class CapabilitiesJobPrivate; + +class KIMAP_EXPORT CapabilitiesJob : public Job +{ + Q_OBJECT + Q_DECLARE_PRIVATE(CapabilitiesJob) + + friend class SessionPrivate; + + public: + CapabilitiesJob( Session *session ); + virtual ~CapabilitiesJob(); + + QStringList capabilities() const; + + Q_SIGNALS: + void capabilitiesReceived( const QStringList &capabilities ); + + protected: + virtual void doStart(); + virtual void doHandleResponse( const Message &response ); +}; + +} + +#endif diff --git a/kimap/tests/testimapserver.cpp b/kimap/tests/testimapserver.cpp index 4bbbae4ad..d72e29629 100644 --- a/kimap/tests/testimapserver.cpp +++ b/kimap/tests/testimapserver.cpp @@ -1,44 +1,55 @@ #include #include #include #include #include +#include #include "kimap/session.h" +#include "kimap/capabilitiesjob.h" #include "kimap/loginjob.h" #include "kimap/logoutjob.h" using namespace KIMAP; int main( int argc, char **argv ) { KAboutData about("TestImapServer", 0, ki18n("TestImapServer"), "version"); KComponentData cData(&about); if (argc < 4) { kError() << "Not enough parameters, expecting: "; } QString server = QString::fromLocal8Bit(argv[1]); QString user = QString::fromLocal8Bit(argv[2]); QString password = QString::fromLocal8Bit(argv[3]); kDebug() << "Querying:" << server << user << password; QCoreApplication app(argc, argv); Session session(server, 143); + kDebug() << "Logging in..."; LoginJob *login = new LoginJob(&session); login->setUserName(user); login->setPassword(password); login->exec(); Q_ASSERT_X(login->error()==0, "LoginJob", login->errorString().toLocal8Bit()); Q_ASSERT(session.state()==Session::Authenticated); + kDebug() << "Asking for capabilities:"; + CapabilitiesJob *capabilities = new CapabilitiesJob(&session); + capabilities->exec(); + Q_ASSERT_X(capabilities->error()==0, "CapabilitiesJob", capabilities->errorString().toLocal8Bit()); + Q_ASSERT(session.state()==Session::Authenticated); + kDebug() << capabilities->capabilities(); + + kDebug() << "Logging out..."; LogoutJob *logout = new LogoutJob(&session); logout->exec(); Q_ASSERT_X(logout->error()==0, "LogoutJob", logout->errorString().toLocal8Bit()); Q_ASSERT(session.state()==Session::Disconnected); return 0; }