diff --git a/CMakeLists.txt b/CMakeLists.txt index 79c0e2209..d71b59d11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,181 +1,180 @@ project(kdepimlibs) # where to look first for cmake modules. This line must be the first one or cmake will use the system's FindFoo.cmake set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules") ############### Build Options ############### option(KDEPIM_ONLY_KLEO "Only build the libraries needed by Kleopatra." FALSE) ############### The kdepimlibs version (used e.g. in KdepimLibsConfig.cmake) ############### set(KDEPIMLIBS_VERSION_MAJOR 4) set(KDEPIMLIBS_VERSION_MINOR 3) set(KDEPIMLIBS_VERSION_PATCH 60) set(KDEPIMLIBS_VERSION ${KDEPIMLIBS_VERSION_MAJOR}.${KDEPIMLIBS_VERSION_MINOR}.${KDEPIMLIBS_VERSION_PATCH}) ############### search packages used by KDE ############### find_package(KDE4 4.2.90 REQUIRED) include(KDE4Defaults) include(MacroLibrary) ############### Needed commands before building anything ############### add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES}) ############### Find the stuff we need ############### set(Boost_MINIMUM_VERSION "1.33.1") find_package(Boost) macro_log_feature(Boost_FOUND "Boost" "Boost C++ Libraries" "http://www.boost.org" TRUE "" "Required by several critical KDEPIM apps.") #FindGpgme.cmake already handles the log message but we must ensure it is required. find_package(Gpgme REQUIRED) # configure macros if (GPGME_FOUND) include (gpgme++/ConfigureChecks.cmake) endif (GPGME_FOUND) if (NOT KDEPIM_ONLY_KLEO) #FindAkonadi.cmake is only there for compatibility reasons, but we don't want to use that. find_package(Akonadi 1.1.91 QUIET NO_MODULE) macro_log_feature(Akonadi_FOUND "Akonadi" "Akonadi server libraries (from kdesupport)" "http://pim.kde.org/akonadi" TRUE "1.1.95" "Akonadi is required to build KdepimLibs.") find_package(Sasl2) macro_log_feature(SASL2_FOUND "cyrus-sasl" "Cyrus SASL API" "http://asg.web.cmu.edu/sasl/sasl-library.html" TRUE "" "Required to support authentication of logins in the IMAP and Sieve kioslaves.") include (ConfigureChecks.cmake) set(SHARED_MIME_INFO_MINIMUM_VERSION "0.30") find_package(SharedMimeInfo) macro_log_feature(SHARED_MIME_INFO_FOUND "SMI" "SharedMimeInfo" "http://freedesktop.org/wiki/Software/shared-mime-info" TRUE "0.30" "SharedMimeInfo is required.") endif (NOT KDEPIM_ONLY_KLEO) ############### Now, we add the KDEPIMLibs components ############### # These targets will always be built add_subdirectory(cmake) add_subdirectory(gpgme++) add_subdirectory(qgpgme) if (NOT KDEPIM_ONLY_KLEO) add_subdirectory(akonadi) add_subdirectory(kabc) add_subdirectory(kblog) add_subdirectory(kcal) add_subdirectory(kholidays) add_subdirectory(kimap) add_subdirectory(kioslave) add_subdirectory(kldap) add_subdirectory(kmime) add_subdirectory(kpimidentities) add_subdirectory(kpimutils) add_subdirectory(kpimtextedit) add_subdirectory(kresources) add_subdirectory(ktnef) add_subdirectory(kxmlrpcclient) add_subdirectory(mailtransport) add_subdirectory(microblog) - add_subdirectory(outboxinterface) add_subdirectory(syndication) # Build the CamelCase headers add_subdirectory(includes) endif (NOT KDEPIM_ONLY_KLEO) # doc must be a subdir of kdepimlibs macro_optional_add_subdirectory(doc) # All done, let's display what we found... macro_display_feature_log() ############### Here we install some extra stuff ############### if (NOT KDEPIM_ONLY_KLEO) install(FILES kdepimlibs-mime.xml DESTINATION ${XDG_MIME_INSTALL_DIR}) update_xdg_mimetypes(${XDG_MIME_INSTALL_DIR}) endif (NOT KDEPIM_ONLY_KLEO) # now create the KdepimLibsConfig.cmake file, which will be loaded by # kdelibs/cmake/modules/FindKdepimLibs.cmake and which has to contain all information # about the installed kdepimlibs anybody would like to have. Alex # we need the absolute directories where stuff will be installed too # but since the variables which contain the destinations can be relative # or absolute paths, we need this macro to make them all absoulte, Alex macro(MAKE_INSTALL_PATH_ABSOLUTE out in) if (IS_ABSOLUTE "${in}") # IS_ABSOLUTE is new since cmake 2.4.8 set(${out} "${in}") else (IS_ABSOLUTE "${in}") set(${out} "\${KDEPIMLIBS_INSTALL_DIR}/${in}") endif (IS_ABSOLUTE "${in}") endmacro(MAKE_INSTALL_PATH_ABSOLUTE out in) # all the following variables are put into KdepimLibsConfig.cmake, so # they are usable by projects using kdepimlibs. Alex make_install_path_absolute(KDEPIMLIBS_DATA_DIR ${DATA_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_DBUS_INTERFACES_DIR ${DBUS_INTERFACES_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_DBUS_SERVICES_DIR ${DBUS_SERVICES_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_INCLUDE_DIR ${INCLUDE_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_LIB_DIR ${LIB_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_BIN_DIR ${BIN_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_LIBEXEC_DIR ${LIBEXEC_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_SBIN_DIR ${SBIN_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_HTML_DIR ${HTML_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_CONFIG_DIR ${CONFIG_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_ICON_DIR ${ICON_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_KCFG_DIR ${KCFG_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_LOCALE_DIR ${LOCALE_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_MIME_DIR ${MIME_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_SOUND_DIR ${SOUND_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_TEMPLATES_DIR ${TEMPLATES_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_WALLPAPER_DIR ${WALLPAPER_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_KCONF_UPDATE_DIR ${KCONF_UPDATE_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_AUTOSTART_DIR ${AUTOSTART_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_XDG_APPS_DIR ${XDG_APPS_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_XDG_DIRECTORY_DIR ${XDG_DIRECTORY_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_SYSCONF_DIR ${SYSCONF_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_MAN_DIR ${MAN_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_INFO_DIR ${INFO_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_SERVICES_DIR ${SERVICES_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS_SERVICETYPES_DIR ${SERVICETYPES_INSTALL_DIR}) # Used in configure_file() and install(EXPORT) set(KDEPIMLIBS_TARGET_PREFIX KDEPIMLibs__) # this file is installed and contains all necessary information about the installed kdepimlibs, it also loads the file with the exported targets configure_file(KdepimLibsConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/KdepimLibsConfig.cmake" @ONLY) # this file will be installed too and will be used by cmake when searching for the Config.cmake file to check the version of kdepimlibs, Alex macro_write_basic_cmake_version_file(${CMAKE_CURRENT_BINARY_DIR}/KdepimLibsConfigVersion.cmake ${KDEPIMLIBS_VERSION_MAJOR} ${KDEPIMLIBS_VERSION_MINOR} ${KDEPIMLIBS_VERSION_PATCH}) set(_KdepimLibsConfig_INSTALL_DIR ${LIB_INSTALL_DIR}/KdepimLibs/cmake) # places where find_package() looks for FooConfig.cmake files: # CMake >= 2.6.0 looks in lib/Foo*/cmake/, CMake >= 2.6.3 also looks in # lib/cmake/Foo*/, which packagers prefer. So they can set the KDE4_USE_COMMON_CMAKE_PACKAGE_CONFIG_DIR # option to have kdepimlibs install its Config file there. Alex if(KDE4_USE_COMMON_CMAKE_PACKAGE_CONFIG_DIR) set(_KdepimLibsConfig_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/KdepimLibs) endif(KDE4_USE_COMMON_CMAKE_PACKAGE_CONFIG_DIR) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/KdepimLibsConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/KdepimLibsConfig.cmake DESTINATION ${_KdepimLibsConfig_INSTALL_DIR} ) # Install the file with the exported targets, use ${KDEPIMLIBS_TARGET_PREFIX} as prefix for the names of these targets, Alex install(EXPORT kdepimlibsLibraryTargets NAMESPACE ${KDEPIMLIBS_TARGET_PREFIX} DESTINATION ${_KdepimLibsConfig_INSTALL_DIR} FILE KDEPimLibsLibraryTargetsWithPrefix.cmake ) # Install a KDEPimLibsDependencies.cmake so people using kdepimlibs 4.2 with kdelibs < 4.2 get a useful error message, Alex file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/KDEPimLibsDependencies.cmake "\n message(FATAL_ERROR \"For using this version of kdepimlibs (${KDEPIMLIBS_VERSION}) you need a newer version of kdelibs, please update.\")\n") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/KDEPimLibsDependencies.cmake DESTINATION ${DATA_INSTALL_DIR}/cmake/modules) diff --git a/mailtransport/CMakeLists.txt b/mailtransport/CMakeLists.txt index 62d7abd95..27cef2ac7 100644 --- a/mailtransport/CMakeLists.txt +++ b/mailtransport/CMakeLists.txt @@ -1,81 +1,101 @@ set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" ) include_directories( ${Boost_INCLUDE_DIR} ) add_subdirectory( kconf_update ) add_subdirectory( tests ) add_definitions("-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII") add_definitions( -DKDE_DEFAULT_DEBUG_AREA=5324 ) +add_definitions( -DUSES_DEPRECATED_MAILTRANSPORT_API ) # for transportmanager set(mailtransport_lib_srcs transport.cpp transportmanager.cpp transporttype.cpp transportcombobox.cpp transportlistview.cpp transportmanagementwidget.cpp addtransportdialog.cpp transportconfigdialog.cpp transportconfigwidget.cpp sendmailconfigwidget.cpp smtpconfigwidget.cpp transportjob.cpp - akonadijob.cpp + resourcesendjob.cpp sendmailjob.cpp smtpjob.cpp precommandjob.cpp legacydecrypt.cpp socket.cpp servertest.cpp + + dispatcherinterface.cpp + messagequeuejob.cpp + outboxactions.cpp + + attributeregistrar.cpp + dispatchmodeattribute.cpp + errorattribute.cpp + sentbehaviourattribute.cpp + transportattribute.cpp ) kde4_add_ui_files(mailtransport_lib_srcs sendmailsettings.ui smtpsettings.ui addtransportdialog.ui transportmanagementwidget.ui ) kde4_add_kcfg_files(mailtransport_lib_srcs transportbase.kcfgc) kde4_add_library(mailtransport SHARED ${mailtransport_lib_srcs}) target_link_libraries(mailtransport ${KDE4_KIO_LIBS} akonadi-kde akonadi-kmime kmime ) set_target_properties(mailtransport PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) install(TARGETS mailtransport EXPORT kdepimlibsLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES mailtransport.kcfg DESTINATION ${KCFG_INSTALL_DIR}) set(mailtransport_kcm_srcs configmodule.cpp) kde4_add_plugin(kcm_mailtransport ${mailtransport_kcm_srcs}) target_link_libraries(kcm_mailtransport ${KDE4_KDEUI_LIBS} mailtransport) install(TARGETS kcm_mailtransport DESTINATION ${PLUGIN_INSTALL_DIR}) install(FILES kcm_mailtransport.desktop DESTINATION ${SERVICES_INSTALL_DIR}) install( FILES mailtransport_export.h transportjob.h - akonadijob.h + resourcesendjob.h sendmailjob.h smtpjob.h ${CMAKE_CURRENT_BINARY_DIR}/transportbase.h transport.h transportmanager.h transporttype.h servertest.h transportcombobox.h transportconfigdialog.h transportmanagementwidget.h + dispatcherinterface.h + messagequeuejob.h + outboxactions.h + + dispatchmodeattribute.h + errorattribute.h + sentbehaviourattribute.h + transportattribute.h + DESTINATION ${INCLUDE_INSTALL_DIR}/mailtransport COMPONENT Devel) diff --git a/mailtransport/DESIGN b/mailtransport/DESIGN new file mode 100644 index 000000000..e00f5299c --- /dev/null +++ b/mailtransport/DESIGN @@ -0,0 +1,22 @@ +Glossary: +New apps == apps using MessageQueueJob. +Old apps == apps using the MailTransport jobs directly. +Traditional transports == SMTP and Sendmail, which are handled by MailTransport. +Resource-based transports == Akonadi-based transports, which are handled by the MDA. +MDA == Mail Dispatcher Agent. + +Current situation: +* New apps, traditional transports: + App's composer -> MailTransport (MessageQueueJob) -> MDA -> MailTransport (SmtpJob or SendmailJob). +* New apps, resource-based transports: + App's composer -> MailTransport (MessageQueueJob) -> MDA -> specific resource. +* Old apps, traditional transports: + App's composer -> MailTransport (SmtpJob or SendmailJob). +* Old apps, resource-based transports: + App's composer -> MailTransport (ResourceSendJob) -> MailTransport (MessageQueueJob) -> MDA -> specific resource. + +Ideal situation (KDE5): +* Move SmtpJob and SendmailJob to the MDA, and let MailTransport handle only config stuff and putting things in the outbox. +* All apps: + App's composer -> MailTransport (MessageQueueJob) -> MDA (SMTP, Sendmail, or specific resource) + diff --git a/mailtransport/akonadijob.cpp b/mailtransport/akonadijob.cpp deleted file mode 100644 index 4e31fa47e..000000000 --- a/mailtransport/akonadijob.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/* - Copyright (c) 2009 Constantin Berzan - - 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 "akonadijob.h" -#include "transport.h" - -#include -#include -#include -#include - -#include - -#include - -#include -#include -#include -#include -#include - -using namespace Akonadi; -using namespace MailTransport; - -/** - * Private class that helps to provide binary compatibility between releases. - * @internal - */ -class AkonadiJobPrivate -{ - public: - AkonadiJob *q; - Item::Id itemId; - QDBusInterface *iface; - - // slots - void itemCreateResult( KJob *job ); - void itemFetchResult( KJob *job ); - - void doSend(); -}; - -void AkonadiJobPrivate::itemCreateResult( KJob *job ) -{ - if( job->error() ) { - // KCompositeJob takes care of the error. - return; - } - - Q_ASSERT( dynamic_cast( job ) ); - itemId = static_cast( job )->item().id(); - kDebug() << "Created item with id" << itemId; - doSend(); -} - -void AkonadiJobPrivate::itemFetchResult( KJob *job ) -{ - if( job->error() ) { - // KCompositeJob takes care of the error. - return; - } - - Q_ASSERT( dynamic_cast( job ) ); - const ItemFetchJob *fjob = static_cast( job ); - Q_ASSERT( fjob->items().count() == 1 ); - const Item item = fjob->items().first(); - if( !item.hasAttribute() ) { - kWarning() << "Item does not have AddressAttribute."; - q->setError( KJob::UserDefinedError ); - q->setErrorText( i18n( "Item does not have address information." ) ); - q->emitResult(); - } else { - kDebug() << "Good, item" << itemId << "has AddressAttribute."; - itemId = item.id(); - doSend(); - } -} - -void AkonadiJobPrivate::doSend() -{ - Q_ASSERT( itemId >= 0 ); - - iface = new QDBusInterface( - QLatin1String( "org.freedesktop.Akonadi.Resource." ) + q->transport()->host(), - QLatin1String( "/" ), QLatin1String( "org.freedesktop.Akonadi.Resource.Transport" ), - QDBusConnection::sessionBus(), q ); - if( !iface->isValid() ) { - q->setError( KJob::UserDefinedError ); - q->setErrorText( i18n( "Failed to get D-Bus interface of resource %1.", q->transport()->host() ) ); - q->emitResult(); - return; - } - - QObject::connect( iface, SIGNAL(transportResult(qlonglong,bool,QString)), - q, SLOT(resourceResult(qlonglong,bool,QString)) ); - - QDBusReply reply = iface->call( QLatin1String( "send" ), itemId ); - if( !reply.isValid() ) { - q->setError( KJob::UserDefinedError ); - q->setErrorText( i18n( "Invalid D-Bus reply from resource %1.", q->transport()->host() ) ); - q->emitResult(); - return; - } -} - -AkonadiJob::AkonadiJob( Transport *transport, QObject *parent ) - : TransportJob( transport, parent ), d( new AkonadiJobPrivate ) -{ - d->q = this; - d->itemId = -1; - d->iface = 0; -} - -AkonadiJob::~AkonadiJob() -{ - delete d; -} - -Akonadi::Item::Id AkonadiJob::itemId() const -{ - if( d->itemId < 0 ) { - kWarning() << "Invalid item."; - } - return d->itemId; -} - -void AkonadiJob::setItemId( Akonadi::Item::Id id ) -{ - Q_ASSERT( id >= 0 ); - d->itemId = id; -} - -void AkonadiJob::doStart() -{ - if( d->itemId < 0 ) { - // Create the item from TransportJob data. - using namespace KMime; - Item item; - item.setMimeType( QString::fromLatin1( "message/rfc822" ) ); - Message::Ptr msg = Message::Ptr( new Message ); - msg->setContent( data() ); - item.setPayload( msg ); - AddressAttribute *attr = new AddressAttribute( sender(), to(), cc(), bcc() ); - item.addAttribute( attr ); - // FIXME Where should this item be created??? - // And it should probably be deleted afterwards??? - ItemCreateJob *cjob = new ItemCreateJob( item, Collection::root(), this ); - connect( cjob, SIGNAL(result(KJob*)), this, SLOT(itemCreateResult(KJob*)) ); - addSubjob( cjob ); - } else { - // We have a ready-made item. Check that it has an AddressAttribute. - ItemFetchJob *fjob = new ItemFetchJob( Item( d->itemId ), this ); - fjob->fetchScope().fetchFullPayload( false ); - fjob->fetchScope().fetchAttribute(); - connect( fjob, SIGNAL(result(KJob*)), this, SLOT(itemFetchResult(KJob*)) ); - addSubjob( fjob ); - } -} - -void AkonadiJob::resourceResult( qlonglong itemId, bool success, const QString &message ) -{ - Q_ASSERT( itemId == d->itemId ); - if( !success ) { - setError( UserDefinedError ); - setErrorText( message ); - } - emitResult(); -} - -#include "akonadijob.moc" diff --git a/mailtransport/akonadijob.h b/mailtransport/akonadijob.h deleted file mode 100644 index 7bcb92afb..000000000 --- a/mailtransport/akonadijob.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - Copyright (c) 2009 Constantin Berzan - - 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 MAILTRANSPORT_AKONADIJOB_H -#define MAILTRANSPORT_AKONADIJOB_H - -#include - -#include - -class AkonadiJobPrivate; - -namespace MailTransport { - -/** - Mail transport job for an Akonadi-based transport. - - This job can be used in two ways: - 1) If you already have an Akonadi::Item containing the item you want to - send, use the setItem() method. Your item needs to have an - AddressAttribute. You do not need to call setData(), setSender(), - setTo() etc., in fact they are ignored. - 2) If you do not have a ready-made item, call the usual TransportJob methods - setData(), setSender(), setTo() etc. Then AkonadiJob will create a new - Akonadi::Item for you, and give it an AddressAttribute. - FIXME This does not work yet. See comments in doStart(). -*/ -class MAILTRANSPORT_EXPORT AkonadiJob : public TransportJob -{ - Q_OBJECT - public: - /** - Creates an AkonadiJob. - @param transport The transport object to use. - @param parent The parent object. - */ - explicit AkonadiJob( Transport *transport, QObject *parent = 0 ); - - /** - Destroys this job. - */ - virtual ~AkonadiJob(); - - /** - The id of the item to send. - */ - Akonadi::Item::Id itemId() const; - - /** - Set the id of the item to send. - @param itemId id of the item to send - */ - void setItemId( Akonadi::Item::Id id ); - - protected: - /** reimpl */ - virtual void doStart(); - - private Q_SLOTS: - void resourceResult( qlonglong itemId, bool success, const QString &message ); - - private: - friend class ::AkonadiJobPrivate; - AkonadiJobPrivate *const d; - - Q_PRIVATE_SLOT( d, void itemCreateResult( KJob* ) ) - Q_PRIVATE_SLOT( d, void itemFetchResult( KJob* ) ) - -}; - -} // namespace MailTransport - -#endif // MAILTRANSPORT_AKONADIJOB_H diff --git a/outboxinterface/attributeregistrar.cpp b/mailtransport/attributeregistrar.cpp similarity index 97% rename from outboxinterface/attributeregistrar.cpp rename to mailtransport/attributeregistrar.cpp index 6e89f02d1..b198074f9 100644 --- a/outboxinterface/attributeregistrar.cpp +++ b/mailtransport/attributeregistrar.cpp @@ -1,44 +1,44 @@ /* Copyright (c) 2009 Constantin Berzan 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 "dispatchmodeattribute.h" #include "errorattribute.h" #include "sentbehaviourattribute.h" #include "transportattribute.h" #include namespace { // Anonymous namespace; function is invisible outside this file. bool dummy() { using namespace Akonadi; - using namespace OutboxInterface; + using namespace MailTransport; AttributeFactory::registerAttribute(); AttributeFactory::registerAttribute(); AttributeFactory::registerAttribute(); AttributeFactory::registerAttribute(); return true; } // Called when this library is loaded. const bool registered = dummy(); } // namespace diff --git a/outboxinterface/dispatcherinterface.cpp b/mailtransport/dispatcherinterface.cpp similarity index 97% rename from outboxinterface/dispatcherinterface.cpp rename to mailtransport/dispatcherinterface.cpp index d85ddeb47..2965a8c4c 100644 --- a/outboxinterface/dispatcherinterface.cpp +++ b/mailtransport/dispatcherinterface.cpp @@ -1,118 +1,118 @@ /* Copyright (c) 2009 Constantin Berzan 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 "dispatcherinterface.h" #include "outboxactions.h" #include #include #include #include #include #include #include using namespace Akonadi; -using namespace OutboxInterface; +using namespace MailTransport; /** @internal */ -class OutboxInterface::DispatcherInterfacePrivate +class MailTransport::DispatcherInterfacePrivate { public: DispatcherInterfacePrivate(); ~DispatcherInterfacePrivate(); DispatcherInterface *instance; // slots void massModifyResult( KJob *job ); }; K_GLOBAL_STATIC( DispatcherInterfacePrivate, sInstance ) DispatcherInterfacePrivate::DispatcherInterfacePrivate() : instance( new DispatcherInterface( this ) ) { } DispatcherInterfacePrivate::~DispatcherInterfacePrivate() { delete instance; } void DispatcherInterfacePrivate::massModifyResult( KJob *job ) { // Nothing to do here, really. If the job fails, the user can retry it. if( job->error() ) { kDebug() << "failed" << job->errorString(); } else { kDebug() << "succeeded."; } } DispatcherInterface::DispatcherInterface( DispatcherInterfacePrivate *dd ) : QObject() , d( dd ) { } DispatcherInterface *DispatcherInterface::self() { return sInstance->instance; } AgentInstance DispatcherInterface::dispatcherInstance() const { AgentInstance a = AgentManager::self()->instance( QLatin1String( "akonadi_maildispatcher_agent" ) ); if( !a.isValid() ) { kWarning() << "Could not get MDA instance."; } return a; } void DispatcherInterface::dispatchManually() { if( !LocalFolders::self()->isReady() ) { kWarning() << "LocalFolders not ready."; return; } FilterActionJob *mjob = new FilterActionJob( LocalFolders::self()->outbox(), new SendQueuedAction, this ); connect( mjob, SIGNAL(result(KJob*)), this, SLOT(massModifyResult(KJob*)) ); } void DispatcherInterface::retryDispatching() { if( !LocalFolders::self()->isReady() ) { kWarning() << "LocalFolders not ready."; return; } FilterActionJob *mjob = new FilterActionJob( LocalFolders::self()->outbox(), new ClearErrorAction, this ); connect( mjob, SIGNAL(result(KJob*)), this, SLOT(massModifyResult(KJob*)) ); } #include "dispatcherinterface.moc" diff --git a/outboxinterface/dispatcherinterface.h b/mailtransport/dispatcherinterface.h similarity index 85% rename from outboxinterface/dispatcherinterface.h rename to mailtransport/dispatcherinterface.h index 5fe9d81e6..6b01dabbf 100644 --- a/outboxinterface/dispatcherinterface.h +++ b/mailtransport/dispatcherinterface.h @@ -1,87 +1,87 @@ /* Copyright (c) 2009 Constantin Berzan 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 OUTBOXINTERFACE_DISPATCHERINTERFACE_H -#define OUTBOXINTERFACE_DISPATCHERINTERFACE_H +#ifndef MAILTRANSPORT_DISPATCHERINTERFACE_H +#define MAILTRANSPORT_DISPATCHERINTERFACE_H -#include +#include #include #include -namespace OutboxInterface { +namespace MailTransport { class DispatcherInterfacePrivate; /** @short An interface for applications to interact with the dispatcher agent. This class provides methods such as send queued messages (@see dispatchManually) and retry sending (@see retryDispatching). This class also takes care of registering the attributes that the MDA and - OutboxInterface use. The attributes are registered the first time you call + MailTransport use. The attributes are registered the first time you call self(), so do that early in your application. @author Constantin Berzan @since 4.4 */ -class OUTBOXINTERFACE_EXPORT DispatcherInterface : public QObject +class MAILTRANSPORT_EXPORT DispatcherInterface : public QObject { Q_OBJECT public: /** Returns the DispatcherInterface instance. */ static DispatcherInterface *self(); /** Returns the current instance of the MDA. May return an invalid AgentInstance in case it cannot find the MDA. */ Akonadi::AgentInstance dispatcherInstance() const; /** Looks for messages in the outbox with DispatchMode::Never and marks them DispatchMode::Immediately for sending. */ void dispatchManually(); /** Looks for messages in the outbox with ErrorAttribute, and clears them and queues them again for sending. */ void retryDispatching(); private: friend class DispatcherInterfacePrivate; DispatcherInterfacePrivate *const d; // singleton class; the only instance resides in sInstance->instance DispatcherInterface( DispatcherInterfacePrivate *dd ); Q_PRIVATE_SLOT( d, void massModifyResult( KJob* ) ) }; -} // namespace OutboxInterface +} // namespace MailTransport -#endif // OUTBOXINTERFACE_DISPATCHERINTERFACE_H +#endif // MAILTRANSPORT_DISPATCHERINTERFACE_H diff --git a/outboxinterface/dispatchmodeattribute.cpp b/mailtransport/dispatchmodeattribute.cpp similarity index 95% rename from outboxinterface/dispatchmodeattribute.cpp rename to mailtransport/dispatchmodeattribute.cpp index 0d74e0cfa..e7320a268 100644 --- a/outboxinterface/dispatchmodeattribute.cpp +++ b/mailtransport/dispatchmodeattribute.cpp @@ -1,106 +1,106 @@ /* Copyright 2009 Constantin Berzan 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 "dispatchmodeattribute.h" #include #include "akonadi/attributefactory.h" using namespace Akonadi; -using namespace OutboxInterface; +using namespace MailTransport; class DispatchModeAttribute::Private { public: DispatchMode mMode; QDateTime mDueDate; }; DispatchModeAttribute::DispatchModeAttribute( DispatchMode mode, const QDateTime &date ) : d( new Private ) { d->mMode = mode; d->mDueDate = date; } DispatchModeAttribute::~DispatchModeAttribute() { delete d; } DispatchModeAttribute* DispatchModeAttribute::clone() const { return new DispatchModeAttribute( d->mMode, d->mDueDate ); } QByteArray DispatchModeAttribute::type() const { static const QByteArray sType( "DispatchModeAttribute" ); return sType; } QByteArray DispatchModeAttribute::serialized() const { switch( d->mMode ) { case Immediately: return "immediately"; case AfterDueDate: return "after" + d->mDueDate.toString(Qt::ISODate).toLatin1(); case Never: return "never"; } Q_ASSERT( false ); return QByteArray(); // suppress control-reaches-end-of-non-void-function warning } void DispatchModeAttribute::deserialize( const QByteArray &data ) { d->mDueDate = QDateTime(); if ( data == "immediately" ) { d->mMode = Immediately; } else if ( data == "never" ) { d->mMode = Never; } else if ( data.startsWith( QByteArray( "after" ) ) ) { d->mMode = AfterDueDate; - d->mDueDate = QDateTime::fromString( data.mid(5), Qt::ISODate ); + d->mDueDate = QDateTime::fromString( QString::fromLatin1( data.mid(5) ), Qt::ISODate ); // NOTE: 5 is the strlen of "after". } else { kWarning() << "Failed to deserialize data [" << data << "]"; } } DispatchModeAttribute::DispatchMode DispatchModeAttribute::dispatchMode() const { return d->mMode; } void DispatchModeAttribute::setDispatchMode( DispatchMode mode ) { d->mMode = mode; } QDateTime DispatchModeAttribute::dueDate() const { return d->mDueDate; } void DispatchModeAttribute::setDueDate( const QDateTime &date ) { d->mDueDate = date; } diff --git a/outboxinterface/dispatchmodeattribute.h b/mailtransport/dispatchmodeattribute.h similarity index 88% rename from outboxinterface/dispatchmodeattribute.h rename to mailtransport/dispatchmodeattribute.h index 11161c500..6bd9e636e 100644 --- a/outboxinterface/dispatchmodeattribute.h +++ b/mailtransport/dispatchmodeattribute.h @@ -1,101 +1,101 @@ /* Copyright 2009 Constantin Berzan 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 OUTBOXINTERFACE_DISPATCHMODEATTRIBUTE_H -#define OUTBOXINTERFACE_DISPATCHMODEATTRIBUTE_H +#ifndef MAILTRANSPORT_DISPATCHMODEATTRIBUTE_H +#define MAILTRANSPORT_DISPATCHMODEATTRIBUTE_H -#include +#include #include #include -namespace OutboxInterface { +namespace MailTransport { /** Attribute determining how and when a message from the outbox should be dispatched. Messages can be sent immediately, sent only when the user explicitly requests it, or sent automatically at a certain date and time. @author Constantin Berzan @since 4.4 */ -class OUTBOXINTERFACE_EXPORT DispatchModeAttribute : public Akonadi::Attribute +class MAILTRANSPORT_EXPORT DispatchModeAttribute : public Akonadi::Attribute { public: /** Determines how the message is sent. */ enum DispatchMode { Immediately, ///< Send message as soon as possible. AfterDueDate, ///< Send message at a certain date/time. Never ///< Send message only when the user requests so. }; /** Creates a new DispatchModeAttribute. */ explicit DispatchModeAttribute( DispatchMode mode = Immediately, const QDateTime &date = QDateTime() ); /** Destroys the DispatchModeAttribute. */ virtual ~DispatchModeAttribute(); /* reimpl */ virtual DispatchModeAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); /** Returns the dispatch mode for the message. @see DispatchMode. */ DispatchMode dispatchMode() const; /** Sets the dispatch mode for the message. @see DispatchMode. */ void setDispatchMode( DispatchMode mode ); /** Returns the date and time when the message should be sent. Only valid if dispatchMode() is AfterDueDate. */ QDateTime dueDate() const; /** Sets the date and time when the message should be sent. Make sure you set the DispatchMode to AfterDueDate first. @see setDispatchMode. */ void setDueDate( const QDateTime &date ); private: class Private; Private *const d; }; -} // namespace OutboxInterface +} // namespace MailTransport -#endif // OUTBOXINTERFACE_DISPATCHMODEATTRIBUTE_H +#endif // MAILTRANSPORT_DISPATCHMODEATTRIBUTE_H diff --git a/outboxinterface/errorattribute.cpp b/mailtransport/errorattribute.cpp similarity index 98% rename from outboxinterface/errorattribute.cpp rename to mailtransport/errorattribute.cpp index 2597541b2..e2393cd4d 100644 --- a/outboxinterface/errorattribute.cpp +++ b/mailtransport/errorattribute.cpp @@ -1,76 +1,76 @@ /* Copyright 2009 Constantin Berzan 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 "errorattribute.h" #include #include using namespace Akonadi; -using namespace OutboxInterface; +using namespace MailTransport; class ErrorAttribute::Private { public: QString mMessage; }; ErrorAttribute::ErrorAttribute( const QString &msg ) : d( new Private ) { d->mMessage = msg; } ErrorAttribute::~ErrorAttribute() { delete d; } ErrorAttribute* ErrorAttribute::clone() const { return new ErrorAttribute( d->mMessage ); } QByteArray ErrorAttribute::type() const { static const QByteArray sType( "ErrorAttribute" ); return sType; } QByteArray ErrorAttribute::serialized() const { return d->mMessage.toUtf8(); } void ErrorAttribute::deserialize( const QByteArray &data ) { d->mMessage = QString::fromUtf8( data ); } QString ErrorAttribute::message() const { return d->mMessage; } void ErrorAttribute::setMessage( const QString &msg ) { d->mMessage = msg; } diff --git a/outboxinterface/errorattribute.h b/mailtransport/errorattribute.h similarity index 84% rename from outboxinterface/errorattribute.h rename to mailtransport/errorattribute.h index b6310d2ed..26e42c510 100644 --- a/outboxinterface/errorattribute.h +++ b/mailtransport/errorattribute.h @@ -1,75 +1,75 @@ /* Copyright 2009 Constantin Berzan 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 OUTBOXINTERFACE_ERRORATTRIBUTE_H -#define OUTBOXINTERFACE_ERRORATTRIBUTE_H +#ifndef MAILTRANSPORT_ERRORATTRIBUTE_H +#define MAILTRANSPORT_ERRORATTRIBUTE_H -#include +#include #include #include -namespace OutboxInterface { +namespace MailTransport { /** Attribute given to the messages that failed to be sent. Contains the error message encountered. @author Constantin Berzan @since 4.4 */ -class OUTBOXINTERFACE_EXPORT ErrorAttribute : public Akonadi::Attribute +class MAILTRANSPORT_EXPORT ErrorAttribute : public Akonadi::Attribute { public: /** Creates a new ErrorAttribute. */ ErrorAttribute( const QString &msg = QString() ); /** Destroys this ErrorAttribute. */ virtual ~ErrorAttribute(); /* reimpl */ virtual ErrorAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); /** Returns the i18n'ed error message. */ QString message() const; /** Sets the error message. */ void setMessage( const QString &msg ); private: class Private; Private *const d; }; -} // namespace OutboxInterface +} // namespace MailTransport -#endif // OUTBOXINTERFACE_ERRORATTRIBUTE_H +#endif // MAILTRANSPORT_ERRORATTRIBUTE_H diff --git a/mailtransport/mailtransport_export.h b/mailtransport/mailtransport_export.h index cfd80d55e..49c366f58 100644 --- a/mailtransport/mailtransport_export.h +++ b/mailtransport/mailtransport_export.h @@ -1,39 +1,51 @@ /* Copyright (c) 2006 Volker Krause 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 MAILTRANSPORT_MAILTRANSPORT_EXPORT_H #define MAILTRANSPORT_MAILTRANSPORT_EXPORT_H #include #ifndef MAILTRANSPORT_EXPORT # if defined(MAKE_MAILTRANSPORT_LIB) /* We are building this library */ # define MAILTRANSPORT_EXPORT KDE_EXPORT # else /* We are using this library */ # define MAILTRANSPORT_EXPORT KDE_IMPORT # endif #endif +// TODO KDE5: Get rid of all this. +#ifndef MAILTRANSPORT_DEPRECATED +# if defined( USES_DEPRECATED_MAILTRANSPORT_API ) + /* Avoid deprecated warnings from ourselves and the MDA. */ +# define MAILTRANSPORT_DEPRECATED +# else + /* Show deprecated warnings for anyone else. */ +# define MAILTRANSPORT_DEPRECATED KDE_DEPRECATED +# endif +#endif + #ifndef MAILTRANSPORT_EXPORT_DEPRECATED -# define MAILTRANSPORT_EXPORT_DEPRECATED KDE_DEPRECATED MAILTRANSPORT_EXPORT +# define MAILTRANSPORT_EXPORT_DEPRECATED MAILTRANSPORT_DEPRECATED MAILTRANSPORT_EXPORT #endif + #endif diff --git a/outboxinterface/messagequeuejob.cpp b/mailtransport/messagequeuejob.cpp similarity index 97% rename from outboxinterface/messagequeuejob.cpp rename to mailtransport/messagequeuejob.cpp index 1b7cba438..0e4c5f733 100644 --- a/outboxinterface/messagequeuejob.cpp +++ b/mailtransport/messagequeuejob.cpp @@ -1,292 +1,290 @@ /* Copyright (c) 2009 Constantin Berzan 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 "messagequeuejob.h" +#include "transport.h" #include "transportattribute.h" +#include "transportmanager.h" #include #include #include #include #include #include #include -#include -#include - using namespace Akonadi; using namespace KMime; using namespace MailTransport; -using namespace OutboxInterface; /** @internal */ -class OutboxInterface::MessageQueueJob::Private +class MailTransport::MessageQueueJob::Private { public: Private( MessageQueueJob *qq ) : q( qq ) { transport = -1; dispatchMode = DispatchModeAttribute::Immediately; sentBehaviour = SentBehaviourAttribute::MoveToDefaultSentCollection; moveToCollection = -1; started = false; } MessageQueueJob *const q; Message::Ptr message; int transport; DispatchModeAttribute::DispatchMode dispatchMode; QDateTime dueDate; SentBehaviourAttribute::SentBehaviour sentBehaviour; Collection::Id moveToCollection; QString from; QStringList to; QStringList cc; QStringList bcc; bool started; /** Returns true if this message has everything it needs and is ready to be sent. */ bool validate(); // slot void doStart(); }; bool MessageQueueJob::Private::validate() { if( !message ) { q->setError( UserDefinedError ); q->setErrorText( i18n( "Empty message." ) ); q->emitResult(); return false; } if( to.count() + cc.count() + bcc.count() == 0 ) { q->setError( UserDefinedError ); q->setErrorText( i18n( "Message has no recipients." ) ); q->emitResult(); return false; } if( dispatchMode == DispatchModeAttribute::AfterDueDate && !dueDate.isValid() ) { q->setError( UserDefinedError ); q->setErrorText( i18n( "Message has invalid due date." ) ); q->emitResult(); return false; } if( TransportManager::self()->transportById( transport, false ) == 0 ) { q->setError( UserDefinedError ); q->setErrorText( i18n( "Message has invalid transport." ) ); q->emitResult(); return false; } if( sentBehaviour == SentBehaviourAttribute::MoveToCollection && moveToCollection < 0 ) { q->setError( UserDefinedError ); q->setErrorText( i18n( "Message has invalid sent-mail folder." ) ); q->emitResult(); return false; } else if( sentBehaviour == SentBehaviourAttribute::MoveToDefaultSentCollection ) { Q_ASSERT( LocalFolders::self()->isReady() ); Q_ASSERT( LocalFolders::self()->sentMail().isValid() ); } return true; // all ok } void MessageQueueJob::Private::doStart() { LocalFolders::self()->disconnect( q ); Q_ASSERT( !started ); started = true; if( !validate() ) { // The error has been set; the result has been emitted. return; } // Create item. Item item; - item.setMimeType( "message/rfc822" ); + item.setMimeType( QLatin1String( "message/rfc822" ) ); item.setPayload( message ); // Set attributes. AddressAttribute *addrA = new AddressAttribute( from, to, cc, bcc ); DispatchModeAttribute *dmA = new DispatchModeAttribute( dispatchMode, dueDate ); SentBehaviourAttribute *sA = new SentBehaviourAttribute( sentBehaviour, moveToCollection ); TransportAttribute *tA = new TransportAttribute( transport ); item.addAttribute( addrA ); item.addAttribute( dmA ); item.addAttribute( sA ); item.addAttribute( tA ); // Set flags. item.setFlag( "queued" ); // Store the item in the outbox. Q_ASSERT( LocalFolders::self()->isReady() ); Collection col = LocalFolders::self()->outbox(); ItemCreateJob *job = new ItemCreateJob( item, col ); // job autostarts q->addSubjob( job ); } MessageQueueJob::MessageQueueJob( QObject *parent ) : KCompositeJob( parent ) , d( new Private( this ) ) { } MessageQueueJob::~MessageQueueJob() { delete d; } Message::Ptr MessageQueueJob::message() const { return d->message; } int MessageQueueJob::transportId() const { return d->transport; } DispatchModeAttribute::DispatchMode MessageQueueJob::dispatchMode() const { return d->dispatchMode; } QDateTime MessageQueueJob::sendDueDate() const { if( d->dispatchMode != DispatchModeAttribute::AfterDueDate ) { kWarning() << "Called when dispatchMode is not AfterDueDate."; } return d->dueDate; } Collection::Id MessageQueueJob::moveToCollection() const { if( d->sentBehaviour != SentBehaviourAttribute::MoveToCollection ) { kWarning() << "Called when sentBehaviour is not MoveToCollection."; } return d->moveToCollection; } QString MessageQueueJob::from() const { return d->from; } QStringList MessageQueueJob::to() const { return d->to; } QStringList MessageQueueJob::cc() const { return d->cc; } QStringList MessageQueueJob::bcc() const { return d->bcc; } void MessageQueueJob::setMessage( Message::Ptr message ) { d->message = message; } void MessageQueueJob::setTransportId( int id ) { d->transport = id; } void MessageQueueJob::setDispatchMode( DispatchModeAttribute::DispatchMode mode ) { d->dispatchMode = mode; } void MessageQueueJob::setDueDate( const QDateTime &date ) { d->dueDate = date; } void MessageQueueJob::setSentBehaviour( SentBehaviourAttribute::SentBehaviour beh ) { d->sentBehaviour = beh; } void MessageQueueJob::setMoveToCollection( Collection::Id cid ) { d->moveToCollection = cid; } void MessageQueueJob::setFrom( const QString &from ) { d->from = from; } void MessageQueueJob::setTo( const QStringList &to ) { d->to = to; } void MessageQueueJob::setCc( const QStringList &cc ) { d->cc = cc; } void MessageQueueJob::setBcc( const QStringList &bcc ) { d->bcc = bcc; } void MessageQueueJob::start() { LocalFolders *folders = LocalFolders::self(); connect( folders, SIGNAL( foldersReady() ), this, SLOT( doStart() ) ); folders->fetch(); // will emit foldersReady() } void MessageQueueJob::slotResult( KJob *job ) { // error handling KCompositeJob::slotResult( job ); if( !error() ) { emitResult(); } } #include "messagequeuejob.moc" diff --git a/outboxinterface/messagequeuejob.h b/mailtransport/messagequeuejob.h similarity index 95% rename from outboxinterface/messagequeuejob.h rename to mailtransport/messagequeuejob.h index 9270b971a..ee337a44d 100644 --- a/outboxinterface/messagequeuejob.h +++ b/mailtransport/messagequeuejob.h @@ -1,255 +1,255 @@ /* Copyright (c) 2009 Constantin Berzan 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 OUTBOXINTERFACE_MESSAGEQUEUEJOB_H -#define OUTBOXINTERFACE_MESSAGEQUEUEJOB_H +#ifndef MAILTRANSPORT_MESSAGEQUEUEJOB_H +#define MAILTRANSPORT_MESSAGEQUEUEJOB_H -#include +#include #include "dispatchmodeattribute.h" #include "sentbehaviourattribute.h" #include #include #include #include #include #include #include -namespace OutboxInterface { +namespace MailTransport { /** @short Provides an interface for sending email. This class takes a KMime::Message and some related info such as sender and recipient addresses, and places the message in the outbox. The mail dispatcher agent will then take it from there and send it. This is the preferred way for applications to send email. This job requires some options to be set before being started. These are setMessage, setTransportId, setFrom, and one of setTo, setCc, or setBcc. Other settings are optional: setDispatchMode, setSentBehaviour. Example: @code MessageQueueJob *job = new MessageQueueJob( this ); job->setMessage( msg ); // msg is a Message::Ptr job->setTransportId( TransportManager::self()->defaultTransportId() ); // Use the default dispatch mode. // Use the default sent-behaviour. job->setFrom( from ); // from is a QString job->setTo( to ); // to is a QStringList connect( job, SIGNAL(result(KJob*)), this, SLOT(jobResult(KJob*)) ); job->start(); @endcode @see DispatchModeAttribute @see SentBehaviourAttribute @author Constantin Berzan @since 4.4 */ -class OUTBOXINTERFACE_EXPORT MessageQueueJob : public KCompositeJob +class MAILTRANSPORT_EXPORT MessageQueueJob : public KCompositeJob { Q_OBJECT public: /** Creates a new MessageQueueJob. This is not an autostarting job; you need to call start() yourself. */ explicit MessageQueueJob( QObject *parent = 0 ); /** Destroys the MessageQueueJob. This job deletes itself after finishing. */ virtual ~MessageQueueJob(); /** Returns the message to be sent. */ KMime::Message::Ptr message() const; /** Returns the transport id to use for sending the message. @see TransportManager. */ int transportId() const; /** Returns the dispatch mode for this message. @see DispatchModeAttribute. */ DispatchModeAttribute::DispatchMode dispatchMode() const; /** Returns the date and time when this message should be sent. Only valid if dispatchMode() is AfterDueDate. @see DispatchModeAttribute. */ QDateTime sendDueDate() const; /** Returns the sent-behaviour of this message. This determines what will happen to the message after it is sent. @see SentBehaviourAttribute. */ SentBehaviourAttribute::SentBehaviour sentBehaviour() const; /** Returns the collection to which the message will be moved after it is sent. Only valid if sentBehaviour() is MoveToCollection. @see SentBehaviourAttribute. */ Akonadi::Collection::Id moveToCollection() const; /** Returns the address of the sender. */ QString from() const; /** Returns the addresses of the "To:" receivers. */ QStringList to() const; /** Returns the addresses of the "Cc:" receivers. */ QStringList cc() const; /** Returns the addresses of the "Bcc:" receivers. */ QStringList bcc() const; /** Sets the message to be sent. */ void setMessage( KMime::Message::Ptr message ); /** Sets the transport id to use for sending the message. If you want to use the default transport, you must specify so explicitly: @code job->setTransportId( TransportManager::self()->defaultTransportId() ); @endcode @see TransportManager. */ void setTransportId( int id ); /** Sets the dispatch mode for this message. The default dispatch mode is Immediately (meaning the message will be sent as soon as possible). @see DispatchModeAttribute. */ void setDispatchMode( DispatchModeAttribute::DispatchMode mode ); /** Sets the date and time when this message should be sent. @code job->setDispatchMode( DispatchModeAttribute::AfterDueDate ); job->setDueDate( ... ); @endcode @see DispatchModeAttribute. */ void setDueDate( const QDateTime &date ); /** Sets the sent-behaviour of this message. This determines what will happen to the message after it is sent. The default sent-behaviour is MoveToDefaultSentCollection, which moves the message to the default sent-mail collection. @see SentBehaviourAttribute. */ void setSentBehaviour( SentBehaviourAttribute::SentBehaviour beh ); /** Sets the collection to which the message will be moved after it is sent. @code job->setSentBehaviour( SentBehaviourAttribute::MoveToCollection ); job->setMoveToCollection( ... ); @endcode @see SentBehaviourAttribute. */ void setMoveToCollection( Akonadi::Collection::Id cid ); /** Sets the address of the sender. */ void setFrom( const QString &from ); /** Sets the addresses of the "To:" receivers." */ void setTo( const QStringList &to ); /** Sets the addresses of the "Cc:" receivers." */ void setCc( const QStringList &cc ); /** Sets the addresses of the "Bcc:" receivers." */ void setBcc( const QStringList &bcc ); /** Creates the item and places it in the outbox. It is now queued for sending by the mail dispatcher agent. */ virtual void start(); protected Q_SLOTS: /** Called when the ItemCreateJob subjob finishes. (reimplemented from KCompositeJob) */ virtual void slotResult( KJob * ); private: class Private; friend class Private; Private *const d; Q_PRIVATE_SLOT( d, void doStart() ) }; -} // namespace OutboxInterface +} // namespace MailTransport -#endif // OUTBOXINTERFACE_MESSAGEQUEUEJOB_H +#endif // MAILTRANSPORT_MESSAGEQUEUEJOB_H diff --git a/outboxinterface/outboxactions.cpp b/mailtransport/outboxactions.cpp similarity index 98% rename from outboxinterface/outboxactions.cpp rename to mailtransport/outboxactions.cpp index f3898f756..a5240acd8 100644 --- a/outboxinterface/outboxactions.cpp +++ b/mailtransport/outboxactions.cpp @@ -1,78 +1,78 @@ /* Copyright (c) 2009 Constantin Berzan 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 "outboxactions.h" #include "dispatchmodeattribute.h" #include "errorattribute.h" #include using namespace Akonadi; -using namespace OutboxInterface; +using namespace MailTransport; ItemFetchScope SendQueuedAction::fetchScope() const { ItemFetchScope scope; scope.fetchFullPayload( false ); scope.fetchAttribute(); return scope; } bool SendQueuedAction::itemAccepted( const Item &item ) const { if( !item.hasAttribute() ) { kWarning() << "Item doesn't have DispatchModeAttribute."; return false; } return item.attribute()->dispatchMode() == DispatchModeAttribute::Never; } Job *SendQueuedAction::itemAction( const Item &item ) const { Item cp = item; cp.addAttribute( new DispatchModeAttribute ); // defaults to Immediately return new ItemModifyJob( cp ); } ItemFetchScope ClearErrorAction::fetchScope() const { ItemFetchScope scope; scope.fetchFullPayload( false ); scope.fetchAttribute(); return scope; } bool ClearErrorAction::itemAccepted( const Item &item ) const { return item.hasAttribute(); } Job *ClearErrorAction::itemAction( const Item &item ) const { Item cp = item; cp.removeAttribute(); cp.clearFlag( "error" ); cp.setFlag( "queued" ); return new ItemModifyJob( cp ); } diff --git a/outboxinterface/outboxactions.h b/mailtransport/outboxactions.h similarity index 83% rename from outboxinterface/outboxactions.h rename to mailtransport/outboxactions.h index 2bdbfa64c..a852b072d 100644 --- a/outboxinterface/outboxactions.h +++ b/mailtransport/outboxactions.h @@ -1,74 +1,74 @@ /* Copyright (c) 2009 Constantin Berzan 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 OUTBOXINTERFACE_OUTBOXACTIONS_H -#define OUTBOXINTERFACE_OUTBOXACTIONS_H +#ifndef MAILTRANSPORT_OUTBOXACTIONS_H +#define MAILTRANSPORT_OUTBOXACTIONS_H -#include +#include #include #include #include -namespace OutboxInterface { +namespace MailTransport { /** FilterAction that finds all messages with a DispatchMode of Never and assigns them a DispatchMode of Immediately. This is used to send "queued" messages on demand. @see FilterActionJob @author Constantin Berzan @since 4.4 */ -class OUTBOXINTERFACE_EXPORT SendQueuedAction : public Akonadi::FilterAction +class MAILTRANSPORT_EXPORT SendQueuedAction : public Akonadi::FilterAction { public: /* reimpl */ virtual Akonadi::ItemFetchScope fetchScope() const; virtual bool itemAccepted( const Akonadi::Item &item ) const; virtual Akonadi::Job *itemAction( const Akonadi::Item &item ) const; }; /** FilterAction that finds all messages with an ErrorAttribute, removes the attribute, and sets the "queued" flag. This is used to retry sending messages that failed. @see FilterActionJob @author Constantin Berzan @since 4.4 */ -class OUTBOXINTERFACE_EXPORT ClearErrorAction : public Akonadi::FilterAction +class MAILTRANSPORT_EXPORT ClearErrorAction : public Akonadi::FilterAction { public: /* reimpl */ virtual Akonadi::ItemFetchScope fetchScope() const; virtual bool itemAccepted( const Akonadi::Item &item ) const; virtual Akonadi::Job *itemAction( const Akonadi::Item &item ) const; }; -} // namespace OutboxInterface +} // namespace MailTransport -#endif // OUTBOXINTERFACE_OUTBOXACTIONS_H +#endif // MAILTRANSPORT_OUTBOXACTIONS_H diff --git a/mailtransport/resourcesendjob.cpp b/mailtransport/resourcesendjob.cpp new file mode 100644 index 000000000..192b8c77f --- /dev/null +++ b/mailtransport/resourcesendjob.cpp @@ -0,0 +1,96 @@ +/* + Copyright (c) 2009 Constantin Berzan + + 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 "resourcesendjob.h" +#include "messagequeuejob.h" +#include "transport.h" + +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include + + +using namespace Akonadi; +using namespace KMime; +using namespace MailTransport; + +/** + * Private class that helps to provide binary compatibility between releases. + * @internal + */ +class MailTransport::ResourceSendJobPrivate +{ + public: + ResourceSendJobPrivate( ResourceSendJob *qq ) + : q( qq ) + { + } + + void slotEmitResult(); // slot + + ResourceSendJob *const q; +}; + +void ResourceSendJobPrivate::slotEmitResult() +{ + // KCompositeJob took care of the error. + q->emitResult(); +} + +ResourceSendJob::ResourceSendJob( Transport *transport, QObject *parent ) + : TransportJob( transport, parent ), d( new ResourceSendJobPrivate( this ) ) +{ +} + +ResourceSendJob::~ResourceSendJob() +{ + delete d; +} + +void ResourceSendJob::doStart() +{ + Message::Ptr msg = Message::Ptr( new Message ); + msg->setContent( data() ); + MessageQueueJob *job = new MessageQueueJob; + job->setMessage( msg ); + job->setTransportId( transport()->id() ); + // Default dispatch mode (send now). + // Move to default sent-mail collection. + job->setFrom( sender() ); + job->setTo( to() ); + job->setCc( cc() ); + job->setBcc( bcc() ); + addSubjob( job ); + // Once the item is in the outbox, there is nothing more we can do. + connect( job, SIGNAL(result(KJob*)), this, SLOT(slotEmitResult()) ); + job->start(); +} + +#include "resourcesendjob.moc" diff --git a/mailtransport/resourcesendjob.h b/mailtransport/resourcesendjob.h new file mode 100644 index 000000000..d1dcbe60e --- /dev/null +++ b/mailtransport/resourcesendjob.h @@ -0,0 +1,74 @@ +/* + Copyright (c) 2009 Constantin Berzan + + 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 MAILTRANSPORT_RESOURCESENDJOB_H +#define MAILTRANSPORT_RESOURCESENDJOB_H + +#include + +#include + +namespace MailTransport { + +class ResourceSendJobPrivate; + +/** + Mail transport job for an Akonadi resource-based transport. + + This is a wrapper job that makes old applications work with resource-based + transports. It calls the appropriate methods in MessageQueueJob, and emits + result() as soon as the item is placed in the outbox, since there is no way + of monitoring the progress from here. + + @deprecated Use MessageQueueJob for placing messages in the outbox. + + @author Constantin Berzan + @since 4.4 +*/ +class MAILTRANSPORT_EXPORT_DEPRECATED ResourceSendJob : public TransportJob +{ + Q_OBJECT + public: + /** + Creates an ResourceSendJob. + @param transport The transport object to use. + @param parent The parent object. + */ + explicit ResourceSendJob( Transport *transport, QObject *parent = 0 ); + + /** + Destroys this job. + */ + virtual ~ResourceSendJob(); + + protected: + /** reimpl */ + virtual void doStart(); + + private: + friend class ResourceSendJobPrivate; + ResourceSendJobPrivate *const d; + + Q_PRIVATE_SLOT( d, void slotEmitResult() ) + +}; + +} // namespace MailTransport + +#endif // MAILTRANSPORT_RESOURCESENDJOB_H diff --git a/mailtransport/sendmailjob.h b/mailtransport/sendmailjob.h index 7826403a9..0c967bf2e 100644 --- a/mailtransport/sendmailjob.h +++ b/mailtransport/sendmailjob.h @@ -1,69 +1,71 @@ /* Copyright (c) 2007 Volker Krause Copyright (c) 2007 KovoKs Based on KMail code by: Copyright (c) 1996-1998 Stefan Taferner 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 MAILTRANSPORT_SENDMAILJOB_H #define MAILTRANSPORT_SENDMAILJOB_H #include #include class SendMailJobPrivate; namespace MailTransport { /** Mail transport job for sendmail. + + @deprecated Use MessageQueueJob for sending e-mail. */ -class MAILTRANSPORT_EXPORT SendmailJob : public TransportJob +class MAILTRANSPORT_EXPORT_DEPRECATED SendmailJob : public TransportJob { Q_OBJECT public: /** Creates a SendmailJob. @param transport The transport settings. @param parent The parent object. */ explicit SendmailJob( Transport *transport, QObject *parent = 0 ); /** Destroys this job. */ virtual ~SendmailJob(); protected: virtual void doStart(); virtual bool doKill(); private Q_SLOTS: void sendmailExited( int, QProcess::ExitStatus ); void receivedError(); void receivedStdErr(); private: SendMailJobPrivate *const d; }; } // namespace MailTransport #endif // MAILTRANSPORT_SENDMAILJOB_H diff --git a/outboxinterface/sentbehaviourattribute.cpp b/mailtransport/sentbehaviourattribute.cpp similarity index 98% rename from outboxinterface/sentbehaviourattribute.cpp rename to mailtransport/sentbehaviourattribute.cpp index 3c2726804..42e35e7de 100644 --- a/outboxinterface/sentbehaviourattribute.cpp +++ b/mailtransport/sentbehaviourattribute.cpp @@ -1,106 +1,106 @@ /* Copyright 2009 Constantin Berzan 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 "sentbehaviourattribute.h" #include #include using namespace Akonadi; -using namespace OutboxInterface; +using namespace MailTransport; class SentBehaviourAttribute::Private { public: SentBehaviour mBehaviour; Akonadi::Collection::Id mMoveToCollection; }; SentBehaviourAttribute::SentBehaviourAttribute( SentBehaviour beh, Collection::Id moveToCollection ) : d( new Private ) { d->mBehaviour = beh; d->mMoveToCollection = moveToCollection; } SentBehaviourAttribute::~SentBehaviourAttribute() { delete d; } SentBehaviourAttribute* SentBehaviourAttribute::clone() const { return new SentBehaviourAttribute( d->mBehaviour, d->mMoveToCollection ); } QByteArray SentBehaviourAttribute::type() const { static const QByteArray sType( "SentBehaviourAttribute" ); return sType; } QByteArray SentBehaviourAttribute::serialized() const { switch( d->mBehaviour ) { case Delete: return "delete"; case MoveToCollection: return "moveTo" + QByteArray::number( d->mMoveToCollection ); case MoveToDefaultSentCollection: return "moveToDefault"; } Q_ASSERT( false ); return QByteArray(); } void SentBehaviourAttribute::deserialize( const QByteArray &data ) { d->mMoveToCollection = -1; if ( data == "delete" ) { d->mBehaviour = Delete; } else if ( data == "moveToDefault" ) { d->mBehaviour = MoveToDefaultSentCollection; } else if ( data.startsWith( QByteArray( "moveTo" ) ) ) { d->mBehaviour = MoveToCollection; d->mMoveToCollection = data.mid(6).toLongLong(); // NOTE: 6 is the strlen of "moveTo". } else { Q_ASSERT( false ); } } SentBehaviourAttribute::SentBehaviour SentBehaviourAttribute::sentBehaviour() const { return d->mBehaviour; } void SentBehaviourAttribute::setSentBehaviour( SentBehaviour beh ) { d->mBehaviour = beh; } Collection::Id SentBehaviourAttribute::moveToCollection() const { return d->mMoveToCollection; } void SentBehaviourAttribute::setMoveToCollection( Collection::Id moveToCollection ) { d->mMoveToCollection = moveToCollection; } diff --git a/outboxinterface/sentbehaviourattribute.h b/mailtransport/sentbehaviourattribute.h similarity index 89% rename from outboxinterface/sentbehaviourattribute.h rename to mailtransport/sentbehaviourattribute.h index c2db8dcf6..3f784774d 100644 --- a/outboxinterface/sentbehaviourattribute.h +++ b/mailtransport/sentbehaviourattribute.h @@ -1,101 +1,101 @@ /* Copyright 2009 Constantin Berzan 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 OUTBOXINTERFACE_SENTBEHAVIOURATTRIBUTE_H -#define OUTBOXINTERFACE_SENTBEHAVIOURATTRIBUTE_H +#ifndef MAILTRANSPORT_SENTBEHAVIOURATTRIBUTE_H +#define MAILTRANSPORT_SENTBEHAVIOURATTRIBUTE_H -#include +#include #include #include -namespace OutboxInterface { +namespace MailTransport { /** Attribute determining what will happen to a message after it is sent. The message can be deleted from the Outbox, moved to the default sent-mail collection, or moved to a custom collection. @author Constantin Berzan @since 4.4 */ -class OUTBOXINTERFACE_EXPORT SentBehaviourAttribute : public Akonadi::Attribute +class MAILTRANSPORT_EXPORT SentBehaviourAttribute : public Akonadi::Attribute { public: /** What to do with the item in the outbox after it has been sent successfully. */ enum SentBehaviour { Delete, ///< Delete the item from the outbox. MoveToCollection, ///< Move the item to the default sent-mail collection. MoveToDefaultSentCollection ///< Move the item to a custom collection. }; /** Creates a new SentBehaviourAttribute. */ explicit SentBehaviourAttribute( SentBehaviour beh = MoveToDefaultSentCollection, Akonadi::Collection::Id moveToCollection = -1 ); /** Destroys the SentBehaviourAttribute. */ virtual ~SentBehaviourAttribute(); /* reimpl */ virtual SentBehaviourAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); /** Returns the sent-behaviour of the message. @see SentBehaviour. */ SentBehaviour sentBehaviour() const; /** Sets the sent-behaviour of the message. @see SentBehaviour. */ void setSentBehaviour( SentBehaviour beh ); /** Returns the collection to which the item should be moved after it is sent. Only valid if sentBehaviour() is MoveToCollection. */ Akonadi::Collection::Id moveToCollection() const; /** Sets the collection to which the item should be moved after it is sent. Make sure you set the SentBehaviour to MoveToCollection first. @see setSentBehaviour. */ void setMoveToCollection( Akonadi::Collection::Id moveToCollection ); private: class Private; Private *const d; }; -} // namespace OutboxInterface +} // namespace MailTransport -#endif // OUTBOXINTERFACE_SENTBEHAVIOURATTRIBUTE_H +#endif // MAILTRANSPORT_SENTBEHAVIOURATTRIBUTE_H diff --git a/mailtransport/smtpjob.h b/mailtransport/smtpjob.h index 0bd9e369f..f4c6e4e5b 100644 --- a/mailtransport/smtpjob.h +++ b/mailtransport/smtpjob.h @@ -1,83 +1,85 @@ /* Copyright (c) 2007 Volker Krause Based on KMail code by: Copyright (c) 1996-1998 Stefan Taferner 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 MAILTRANSPORT_SMTPJOB_H #define MAILTRANSPORT_SMTPJOB_H #include namespace KIO { class Job; class Slave; } class SmtpJobPrivate; namespace MailTransport { /** Mail transport job for SMTP. Internally, all jobs for a specific transport are queued to use the same KIO::Slave. This avoids multiple simultaneous connections to the server, which is not always allowed. Also, re-using an already existing connection avoids the login overhead and can improve performance. Precommands are automatically executed, once per opening a connection to the server (not necessarily once per message). + + @deprecated Use MessageQueueJob for sending e-mail. */ -class MAILTRANSPORT_EXPORT SmtpJob : public TransportJob +class MAILTRANSPORT_EXPORT_DEPRECATED SmtpJob : public TransportJob { Q_OBJECT public: /** Creates a SmtpJob. @param transport The transport settings. @param parent The parent object. */ explicit SmtpJob( Transport *transport, QObject *parent = 0 ); /** Deletes this job. */ virtual ~SmtpJob(); protected: virtual void doStart(); virtual bool doKill(); protected Q_SLOTS: virtual void slotResult( KJob *job ); void slaveError( KIO::Slave *slave, int errorCode, const QString &errorMsg ); private: void startSmtpJob(); private Q_SLOTS: void dataRequest( KIO::Job *job, QByteArray &data ); private: SmtpJobPrivate *const d; }; } // namespace MailTransport #endif // MAILTRANSPORT_SMTPJOB_H diff --git a/mailtransport/tests/CMakeLists.txt b/mailtransport/tests/CMakeLists.txt index 5660e72f7..60b94bb3d 100644 --- a/mailtransport/tests/CMakeLists.txt +++ b/mailtransport/tests/CMakeLists.txt @@ -1,6 +1,64 @@ set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) +macro(add_akonadi_isolated_test _source) + get_filename_component(_targetName ${_source} NAME_WE) + set(_srcList ${_source} ) + + kde4_add_executable(${_targetName} TEST ${_srcList}) + target_link_libraries(${_targetName} + ${QT_QTTEST_LIBRARY} + ${QT_QTGUI_LIBRARY} + ${KDE4_AKONADI_LIBS} + ${KDE4_AKONADI_KMIME_LIBS} + ${KDE4_KDECORE_LIBS} + mailtransport + ${KDE4_KMIME_LIBS} + ${QT_QTCORE_LIBRARY} + ${QT_QTDBUS_LIBRARY} + ) + + # based on kde4_add_unit_test + if (WIN32) + get_target_property( _loc ${_targetName} LOCATION ) + set(_executable ${_loc}.bat) + else (WIN32) + set(_executable ${EXECUTABLE_OUTPUT_PATH}/${_targetName}) + endif (WIN32) + if (UNIX) + set(_executable ${_executable}.shell) + endif (UNIX) + + find_program(_testrunner akonaditest) + + add_test( mailtransport-${_targetName} ${_testrunner} -c ${CMAKE_CURRENT_SOURCE_DIR}/unittestenv/config.xml ${_executable} ) +endmacro(add_akonadi_isolated_test) + + + +# Independent executables: + set(tm_srcs transportmgr.cpp) kde4_add_executable(transportmgr TEST ${tm_srcs}) target_link_libraries(transportmgr ${KDE4_KDEUI_LIBS} mailtransport) +set(queuer_srcs queuer.cpp) +kde4_add_executable(queuer TEST ${queuer_srcs}) +target_link_libraries(queuer ${KDE4_KDEUI_LIBS} ${KDE4_MAILTRANSPORT_LIBS} ${KDE4_KMIME_LIBS} mailtransport) + +set( sendqueued_srcs sendqueued.cpp ) +kde4_add_executable( sendqueued TEST ${sendqueued_srcs} ) +target_link_libraries( sendqueued mailtransport ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) + +set( clearerror_srcs clearerror.cpp ) +kde4_add_executable( clearerror TEST ${clearerror_srcs} ) +target_link_libraries( clearerror mailtransport ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) + +set( abort_srcs abort.cpp ) +kde4_add_executable( abort TEST ${abort_srcs} ) +target_link_libraries( abort mailtransport ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) + + +# Akonadi testrunner-based tests: + +add_akonadi_isolated_test( attributetest.cpp ) +add_akonadi_isolated_test( messagequeuejobtest.cpp ) diff --git a/mailtransport/tests/TODO b/mailtransport/tests/TODO new file mode 100644 index 000000000..37f78b4b7 --- /dev/null +++ b/mailtransport/tests/TODO @@ -0,0 +1,6 @@ +MessageQueueJob: +- see source + +Attributes: +- add test for common mistakes such as forgetting to setDueDate + diff --git a/outboxinterface/tests/abort.cpp b/mailtransport/tests/abort.cpp similarity index 95% rename from outboxinterface/tests/abort.cpp rename to mailtransport/tests/abort.cpp index 1b0db92ad..dba6e2a63 100644 --- a/outboxinterface/tests/abort.cpp +++ b/mailtransport/tests/abort.cpp @@ -1,68 +1,68 @@ /* Copyright (c) 2009 Constantin Berzan 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 "abort.h" #include #include #include #include #include -#include +#include using namespace Akonadi; -using namespace OutboxInterface; +using namespace MailTransport; Runner::Runner() { Control::start(); QTimer::singleShot( 0, this, SLOT(sendAbort()) ); } void Runner::sendAbort() { const AgentInstance mda = DispatcherInterface::self()->dispatcherInstance(); if( !mda.isValid() ) { kDebug() << "Invalid instance; waiting."; QTimer::singleShot( 1000, this, SLOT(sendAbort()) ); return; } mda.abort(); kDebug() << "Told the MDA to abort."; KApplication::exit( 0 ); } int main( int argc, char **argv ) { KCmdLineArgs::init( argc, argv, "abort", 0, ki18n( "abort" ), "0", ki18n( "An app that sends an abort signal to the MDA" ) ); KApplication app; new Runner(); return app.exec(); } #include "abort.moc" diff --git a/outboxinterface/tests/abort.h b/mailtransport/tests/abort.h similarity index 100% rename from outboxinterface/tests/abort.h rename to mailtransport/tests/abort.h diff --git a/outboxinterface/tests/attributetest.cpp b/mailtransport/tests/attributetest.cpp similarity index 94% rename from outboxinterface/tests/attributetest.cpp rename to mailtransport/tests/attributetest.cpp index 61ff5c00c..a1c29e59c 100644 --- a/outboxinterface/tests/attributetest.cpp +++ b/mailtransport/tests/attributetest.cpp @@ -1,139 +1,139 @@ /* Copyright 2009 Constantin Berzan 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 "attributetest.h" #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include using namespace Akonadi; -using namespace OutboxInterface; +using namespace MailTransport; void AttributeTest::initTestCase() { } void AttributeTest::testRegistrar() { // The attributes should have been registered without any effort on our part. { Attribute *a = AttributeFactory::createAttribute( "AddressAttribute" ); QVERIFY( dynamic_cast( a ) ); } { Attribute *a = AttributeFactory::createAttribute( "DispatchModeAttribute" ); QVERIFY( dynamic_cast( a ) ); } { Attribute *a = AttributeFactory::createAttribute( "ErrorAttribute" ); QVERIFY( dynamic_cast( a ) ); } { Attribute *a = AttributeFactory::createAttribute( "SentBehaviourAttribute" ); QVERIFY( dynamic_cast( a ) ); } { Attribute *a = AttributeFactory::createAttribute( "TransportAttribute" ); QVERIFY( dynamic_cast( a ) ); } } void AttributeTest::testSerialization() { { QString from( "from@me.org" ); QStringList to( "to1@me.org" ); to << "to2@me.org"; QStringList cc( "cc1@me.org" ); cc << "cc2@me.org"; QStringList bcc( "bcc1@me.org" ); bcc << "bcc2@me.org"; AddressAttribute *a = new AddressAttribute( from, to, cc, bcc ); QByteArray data = a->serialized(); delete a; a = new AddressAttribute; a->deserialize( data ); QCOMPARE( from, a->from() ); QCOMPARE( to, a->to() ); QCOMPARE( cc, a->cc() ); QCOMPARE( bcc, a->bcc() ); } { DispatchModeAttribute::DispatchMode mode = DispatchModeAttribute::AfterDueDate; QDateTime date = QDateTime::currentDateTime(); // The serializer does not keep track of milliseconds, so forget them. kDebug() << "ms" << date.toString( "z" ); int ms = date.toString( "z" ).toInt(); date = date.addMSecs( -ms ); DispatchModeAttribute *a = new DispatchModeAttribute( mode, date ); QByteArray data = a->serialized(); delete a; a = new DispatchModeAttribute; a->deserialize( data ); QCOMPARE( mode, a->dispatchMode() ); QCOMPARE( date, a->dueDate() ); } { QString msg( "The #!@$ing thing failed!" ); ErrorAttribute *a = new ErrorAttribute( msg ); QByteArray data = a->serialized(); delete a; a = new ErrorAttribute; a->deserialize( data ); QCOMPARE( msg, a->message() ); } { SentBehaviourAttribute::SentBehaviour beh = SentBehaviourAttribute::MoveToCollection; Collection::Id id = 123456789012345ll; SentBehaviourAttribute *a = new SentBehaviourAttribute( beh, id ); QByteArray data = a->serialized(); delete a; a = new SentBehaviourAttribute; a->deserialize( data ); QCOMPARE( beh, a->sentBehaviour() ); QCOMPARE( id, a->moveToCollection() ); } { int id = 3219; TransportAttribute *a = new TransportAttribute( id ); QByteArray data = a->serialized(); delete a; a = new TransportAttribute; a->deserialize( data ); QCOMPARE( id, a->transportId() ); } } QTEST_AKONADIMAIN( AttributeTest, NoGUI ) #include "attributetest.moc" diff --git a/outboxinterface/tests/attributetest.h b/mailtransport/tests/attributetest.h similarity index 100% rename from outboxinterface/tests/attributetest.h rename to mailtransport/tests/attributetest.h diff --git a/outboxinterface/tests/clearerror.cpp b/mailtransport/tests/clearerror.cpp similarity index 96% rename from outboxinterface/tests/clearerror.cpp rename to mailtransport/tests/clearerror.cpp index 7f81a57f1..9165fc0b9 100644 --- a/outboxinterface/tests/clearerror.cpp +++ b/mailtransport/tests/clearerror.cpp @@ -1,82 +1,82 @@ /* Copyright (c) 2009 Constantin Berzan 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 "clearerror.h" #include #include #include #include #include #include #include #include -#include +#include using namespace Akonadi; -using namespace OutboxInterface; +using namespace MailTransport; Runner::Runner() { Control::start(); connect( LocalFolders::self(), SIGNAL( foldersReady() ), this, SLOT( checkFolders() ) ); LocalFolders::self()->fetch(); } void Runner::checkFolders() { Collection outbox = LocalFolders::self()->outbox(); kDebug() << "Got outbox" << outbox.id(); if( !outbox.isValid() ) { KApplication::exit( 1 ); } FilterActionJob *fjob = new FilterActionJob( outbox, new ClearErrorAction, this ); connect( fjob, SIGNAL(result(KJob*)), this, SLOT(jobResult(KJob*)) ); } void Runner::jobResult( KJob *job ) { if( job->error() ) { kDebug() << "Job error:" << job->errorString(); KApplication::exit( 2 ); } else { kDebug() << "Job success."; KApplication::exit( 0 ); } } int main( int argc, char **argv ) { KCmdLineArgs::init( argc, argv, "clearerror", 0, ki18n( "clearerror" ), "0", ki18n( "An app that re-queues failed items from the outbox" ) ); KApplication app; new Runner(); return app.exec(); } #include "clearerror.moc" diff --git a/outboxinterface/tests/clearerror.h b/mailtransport/tests/clearerror.h similarity index 100% rename from outboxinterface/tests/clearerror.h rename to mailtransport/tests/clearerror.h diff --git a/outboxinterface/tests/messagequeuejobtest.cpp b/mailtransport/tests/messagequeuejobtest.cpp similarity index 95% rename from outboxinterface/tests/messagequeuejobtest.cpp rename to mailtransport/tests/messagequeuejobtest.cpp index 46608df07..275f32f27 100644 --- a/outboxinterface/tests/messagequeuejobtest.cpp +++ b/mailtransport/tests/messagequeuejobtest.cpp @@ -1,193 +1,191 @@ /* Copyright 2009 Constantin Berzan 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 "messagequeuejobtest.h" #include #include #include #include #include #include #include #include #include #include #include #include #include -#include -#include - #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #define SPAM_ADDRESS ( QStringList() << "idanoka@gmail.com" ) using namespace Akonadi; using namespace KMime; using namespace MailTransport; -using namespace OutboxInterface; void MessageQueueJobTest::initTestCase() { Control::start(); // HACK: Otherwise the MDA is not switched offline soon enough apparently... QTest::qWait( 1000 ); // Switch MDA offline to avoid spam. AgentInstance mda = AgentManager::self()->instance( "akonadi_maildispatcher_agent" ); QVERIFY( mda.isValid() ); mda.setIsOnline( false ); // check that outbox is empty LocalFolders::self()->fetch(); QTest::kWaitForSignal( LocalFolders::self(), SIGNAL( foldersReady() ) ); verifyOutboxContents( 0 ); } void MessageQueueJobTest::testValidMessages() { // check transport int tid = TransportManager::self()->defaultTransportId(); QVERIFY2( tid >= 0, "I need a default transport, but there is none." ); // send a valid message using the default transport MessageQueueJob *qjob = new MessageQueueJob; qjob->setTransportId( tid ); Message::Ptr msg = Message::Ptr( new Message ); msg->setContent( "\nThis is message #1 from the MessageQueueJobTest unit test.\n" ); qjob->setMessage( msg ); qjob->setTo( SPAM_ADDRESS ); verifyOutboxContents( 0 ); AKVERIFYEXEC( qjob ); // fetch the message and verify it QTest::qWait( 1000 ); verifyOutboxContents( 1 ); ItemFetchJob *fjob = new ItemFetchJob( LocalFolders::self()->outbox() ); fjob->fetchScope().fetchFullPayload(); fjob->fetchScope().fetchAllAttributes(); AKVERIFYEXEC( fjob ); QCOMPARE( fjob->items().count(), 1 ); Item item = fjob->items().first(); QVERIFY( !item.remoteId().isEmpty() ); // stored by the resource QVERIFY( item.hasPayload() ); AddressAttribute *addrA = item.attribute(); QVERIFY( addrA ); QVERIFY( addrA->from().isEmpty() ); QCOMPARE( addrA->to().count(), 1 ); QCOMPARE( addrA->to(), SPAM_ADDRESS ); QCOMPARE( addrA->cc().count(), 0 ); QCOMPARE( addrA->bcc().count(), 0 ); DispatchModeAttribute *dA = item.attribute(); QVERIFY( dA ); QCOMPARE( dA->dispatchMode(), DispatchModeAttribute::Immediately ); // default mode SentBehaviourAttribute *sA = item.attribute(); QVERIFY( sA ); QCOMPARE( sA->sentBehaviour(), SentBehaviourAttribute::MoveToDefaultSentCollection ); // default sent collection TransportAttribute *tA = item.attribute(); QVERIFY( tA ); QCOMPARE( tA->transportId(), tid ); ErrorAttribute *eA = item.attribute(); QVERIFY( !eA ); // no error QCOMPARE( item.flags().count(), 1 ); QVERIFY( item.flags().contains( "queued" ) ); // delete message, for further tests ItemDeleteJob *djob = new ItemDeleteJob( item ); AKVERIFYEXEC( djob ); verifyOutboxContents( 0 ); // TODO test with no To: but only BCC: // TODO test due-date sending // TODO test sending with custom sent-mail collections } void MessageQueueJobTest::testInvalidMessages() { MessageQueueJob *job = 0; Message::Ptr msg; // without message job = new MessageQueueJob; job->setTransportId( TransportManager::self()->defaultTransportId() ); job->setTo( SPAM_ADDRESS ); QVERIFY( !job->exec() ); // without recipients job = new MessageQueueJob; msg = Message::Ptr( new Message ); msg->setContent( "\nThis is a message sent from the MessageQueueJobTest unittest. This shouldn't have been sent.\n" ); job->setMessage( msg ); job->setTransportId( TransportManager::self()->defaultTransportId() ); QVERIFY( !job->exec() ); // without transport job = new MessageQueueJob; msg = Message::Ptr( new Message ); msg->setContent( "\nThis is a message sent from the MessageQueueJobTest unittest. This shouldn't have been sent.\n" ); job->setMessage( msg ); job->setTo( SPAM_ADDRESS ); QVERIFY( !job->exec() ); // with AfterDueDate and no due date job = new MessageQueueJob; msg = Message::Ptr( new Message ); msg->setContent( "\nThis is a message sent from the MessageQueueJobTest unittest. This shouldn't have been sent.\n" ); job->setMessage( msg ); job->setTo( SPAM_ADDRESS ); job->setDispatchMode( DispatchModeAttribute::AfterDueDate ); QVERIFY( !job->exec() ); // with MoveToCollection and no sent-mail folder job = new MessageQueueJob; msg = Message::Ptr( new Message ); msg->setContent( "\nThis is a message sent from the MessageQueueJobTest unittest. This shouldn't have been sent.\n" ); job->setMessage( msg ); job->setTo( SPAM_ADDRESS ); job->setSentBehaviour( SentBehaviourAttribute::MoveToCollection ); QVERIFY( !job->exec() ); } void MessageQueueJobTest::verifyOutboxContents( qlonglong count ) { QVERIFY( LocalFolders::self()->isReady() ); Collection outbox = LocalFolders::self()->outbox(); QVERIFY( outbox.isValid() ); CollectionStatisticsJob *job = new CollectionStatisticsJob( outbox ); AKVERIFYEXEC( job ); QCOMPARE( job->statistics().count(), count ); } QTEST_AKONADIMAIN( MessageQueueJobTest, NoGUI ) #include "messagequeuejobtest.moc" diff --git a/outboxinterface/tests/messagequeuejobtest.h b/mailtransport/tests/messagequeuejobtest.h similarity index 100% rename from outboxinterface/tests/messagequeuejobtest.h rename to mailtransport/tests/messagequeuejobtest.h diff --git a/outboxinterface/tests/queuer.cpp b/mailtransport/tests/queuer.cpp similarity index 97% rename from outboxinterface/tests/queuer.cpp rename to mailtransport/tests/queuer.cpp index c1f28334b..715fa07b9 100644 --- a/outboxinterface/tests/queuer.cpp +++ b/mailtransport/tests/queuer.cpp @@ -1,179 +1,176 @@ /* Copyright (c) 2006 - 2007 Volker Krause Copyright (c) 2009 Constantin Berzan 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 "queuer.h" #include #include #include #include #include #include #include #include #include #include #include +#include +#include #include #include -#include -#include - - using namespace KMime; using namespace MailTransport; -using namespace OutboxInterface; MessageQueuer::MessageQueuer() { if( !Akonadi::Control::start() ) { kFatal() << "Could not start Akonadi server."; } mComboBox = new TransportComboBox( this ); mComboBox->setEditable( true ); mSenderEdit = new KLineEdit( this ); mSenderEdit->setClickMessage( "Sender" ); mToEdit = new KLineEdit( this ); mToEdit->setText( "idanoka@gmail.com" ); mToEdit->setClickMessage( "To" ); mCcEdit = new KLineEdit( this ); mCcEdit->setClickMessage( "Cc" ); mBccEdit = new KLineEdit( this ); mBccEdit->setClickMessage( "Bcc" ); mMailEdit = new KTextEdit( this ); mMailEdit->setText( "test from queuer!" ); mMailEdit->setAcceptRichText( false ); mMailEdit->setLineWrapMode( QTextEdit::NoWrap ); QPushButton *b = new QPushButton( "&Send Now", this ); connect( b, SIGNAL(clicked(bool)), SLOT(sendNowClicked()) ); b = new QPushButton( "Send &Queued", this ); connect( b, SIGNAL(clicked(bool)), SLOT(sendQueuedClicked()) ); b = new QPushButton( "Send on &Date...", this ); connect( b, SIGNAL(clicked(bool)), SLOT(sendOnDateClicked()) ); } void MessageQueuer::sendNowClicked() { MessageQueueJob *qjob = createQueueJob(); kDebug() << "DispatchMode default (Immediately)."; qjob->start(); } void MessageQueuer::sendQueuedClicked() { MessageQueueJob *qjob = createQueueJob(); kDebug() << "DispatchMode Never."; qjob->setDispatchMode( DispatchModeAttribute::Never ); qjob->start(); } void MessageQueuer::sendOnDateClicked() { QPointer dialog = new KDialog( this ); KDateTimeWidget *dt = new KDateTimeWidget( dialog ); dt->setDateTime( QDateTime::currentDateTime() ); // HACK: QTimeEdit *te = dt->findChild(); Q_ASSERT( te ); te->setDisplayFormat( "hh:mm:ss" ); dialog->setMainWidget( dt ); dialog->enableButtonCancel( false ); dialog->exec(); if( !dialog ) { return; } kDebug() << "DispatchMode AfterDueDate" << dt->dateTime(); MessageQueueJob *qjob = createQueueJob(); qjob->setDispatchMode( DispatchModeAttribute::AfterDueDate ); qjob->setDueDate( dt->dateTime() ); qjob->start(); delete dialog; } MessageQueueJob *MessageQueuer::createQueueJob() { Message::Ptr msg = Message::Ptr( new Message ); // No headers; need a '\n' to separate headers from body. // TODO: use real headers msg->setContent( QByteArray("\n") + mMailEdit->document()->toPlainText().toLatin1() ); kDebug() << "msg:" << msg->encodedContent( true ); MessageQueueJob *job = new MessageQueueJob(); job->setMessage( msg ); job->setTransportId( mComboBox->currentTransportId() ); // default dispatch mode // default sent-mail collection job->setFrom( mSenderEdit->text() ); job->setTo( mToEdit->text().isEmpty() ? QStringList() : mToEdit->text().split( ',' ) ); job->setCc( mCcEdit->text().isEmpty() ? QStringList() : mCcEdit->text().split( ',' ) ); job->setBcc( mBccEdit->text().isEmpty() ? QStringList() : mBccEdit->text().split( ',' ) ); connect( job, SIGNAL(result(KJob*)), SLOT(jobResult(KJob*)) ); connect( job, SIGNAL(percent(KJob*,unsigned long)), SLOT(jobPercent(KJob*,unsigned long)) ); connect( job, SIGNAL(infoMessage(KJob*,QString,QString)), SLOT(jobInfoMessage(KJob*,QString,QString)) ); return job; } int main( int argc, char **argv ) { KCmdLineArgs::init( argc, argv, "messagequeuer", 0, ki18n( "messagequeuer" ), "0", ki18n( "MessageQueuerJob Demo" ) ); KApplication app; MessageQueuer *t = new MessageQueuer(); t->show(); app.exec(); delete t; } void MessageQueuer::jobResult( KJob *job ) { if( job->error() ) { kDebug() << "job error:" << job->errorText(); } else { kDebug() << "job success."; } } void MessageQueuer::jobPercent( KJob *job, unsigned long percent ) { Q_UNUSED( job ); kDebug() << percent << "%"; } void MessageQueuer::jobInfoMessage( KJob *job, const QString &info, const QString &info2 ) { Q_UNUSED( job ); kDebug() << info; kDebug() << info2; } #include "queuer.moc" diff --git a/outboxinterface/tests/queuer.h b/mailtransport/tests/queuer.h similarity index 91% rename from outboxinterface/tests/queuer.h rename to mailtransport/tests/queuer.h index 860b8082b..5e0076c6b 100644 --- a/outboxinterface/tests/queuer.h +++ b/mailtransport/tests/queuer.h @@ -1,64 +1,64 @@ /* Copyright (c) 2006 - 2007 Volker Krause Copyright (c) 2009 Constantin Berzan 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 MESSAGEQUEUER_H #define MESSAGEQUEUER_H #include #include class KJob; class KLineEdit; class KTextEdit; -namespace OutboxInterface { +namespace MailTransport { class MessageQueueJob; } /** - This is stolen from kdepimlibs/mailtransport/tests/transportmgr.{h,cpp} + Mostly stolen from transportmgr.{h,cpp} */ class MessageQueuer : public KVBox { Q_OBJECT public: MessageQueuer(); private slots: void sendNowClicked(); void sendQueuedClicked(); void sendOnDateClicked(); void jobResult( KJob *job ); void jobPercent( KJob *job, unsigned long percent ); void jobInfoMessage( KJob *job, const QString &info, const QString &info2 ); private: MailTransport::TransportComboBox *mComboBox; KLineEdit *mSenderEdit, *mToEdit, *mCcEdit, *mBccEdit; KTextEdit *mMailEdit; - OutboxInterface::MessageQueueJob *createQueueJob(); + MailTransport::MessageQueueJob *createQueueJob(); }; #endif diff --git a/outboxinterface/tests/sendqueued.cpp b/mailtransport/tests/sendqueued.cpp similarity index 96% rename from outboxinterface/tests/sendqueued.cpp rename to mailtransport/tests/sendqueued.cpp index 4396a6f2e..9038ecd20 100644 --- a/outboxinterface/tests/sendqueued.cpp +++ b/mailtransport/tests/sendqueued.cpp @@ -1,82 +1,82 @@ /* Copyright (c) 2009 Constantin Berzan 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 "sendqueued.h" #include #include #include #include #include #include #include #include -#include +#include using namespace Akonadi; -using namespace OutboxInterface; +using namespace MailTransport; Runner::Runner() { Control::start(); connect( LocalFolders::self(), SIGNAL( foldersReady() ), this, SLOT( checkFolders() ) ); LocalFolders::self()->fetch(); } void Runner::checkFolders() { Collection outbox = LocalFolders::self()->outbox(); kDebug() << "Got outbox" << outbox.id(); if( !outbox.isValid() ) { KApplication::exit( 1 ); } FilterActionJob *fjob = new FilterActionJob( outbox, new SendQueuedAction, this ); connect( fjob, SIGNAL(result(KJob*)), this, SLOT(jobResult(KJob*)) ); } void Runner::jobResult( KJob *job ) { if( job->error() ) { kDebug() << "Job error:" << job->errorString(); KApplication::exit( 2 ); } else { kDebug() << "Job success."; KApplication::exit( 0 ); } } int main( int argc, char **argv ) { KCmdLineArgs::init( argc, argv, "sendqueued", 0, ki18n( "sendqueued" ), "0", ki18n( "An app that sends all queued messages" ) ); KApplication app; new Runner(); return app.exec(); } #include "sendqueued.moc" diff --git a/outboxinterface/tests/sendqueued.h b/mailtransport/tests/sendqueued.h similarity index 100% rename from outboxinterface/tests/sendqueued.h rename to mailtransport/tests/sendqueued.h diff --git a/mailtransport/tests/transportmgr.h b/mailtransport/tests/transportmgr.h index f1dda1cc0..76591eb0d 100644 --- a/mailtransport/tests/transportmgr.h +++ b/mailtransport/tests/transportmgr.h @@ -1,53 +1,55 @@ /* Copyright (c) 2006 - 2007 Volker Krause 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 TRANSPORTMGR_H #define TRANSPORTMGR_H +#define USES_DEPRECATED_MAILTRANSPORT_API + #include #include class KJob; class KLineEdit; class KTextEdit; class TransportMgr : public KVBox { Q_OBJECT public: TransportMgr(); private slots: void removeAllBtnClicked(); void editBtnClicked(); void sendBtnClicked(); void cancelBtnClicked(); void jobResult( KJob *job ); void jobPercent( KJob *job, unsigned long percent ); void jobInfoMessage( KJob *job, const QString &info, const QString &info2 ); private: MailTransport::TransportComboBox *mComboBox; KLineEdit *mSenderEdit, *mToEdit, *mCcEdit, *mBccEdit; KTextEdit *mMailEdit; KJob *mCurrentJob; }; #endif diff --git a/outboxinterface/tests/unittestenv/config.xml b/mailtransport/tests/unittestenv/config.xml similarity index 100% rename from outboxinterface/tests/unittestenv/config.xml rename to mailtransport/tests/unittestenv/config.xml diff --git a/outboxinterface/tests/unittestenv/kdehome/share/config/akonadi-firstrunrc b/mailtransport/tests/unittestenv/kdehome/share/config/akonadi-firstrunrc similarity index 100% rename from outboxinterface/tests/unittestenv/kdehome/share/config/akonadi-firstrunrc rename to mailtransport/tests/unittestenv/kdehome/share/config/akonadi-firstrunrc diff --git a/outboxinterface/tests/unittestenv/kdehome/share/config/kdebugrc b/mailtransport/tests/unittestenv/kdehome/share/config/kdebugrc similarity index 100% rename from outboxinterface/tests/unittestenv/kdehome/share/config/kdebugrc rename to mailtransport/tests/unittestenv/kdehome/share/config/kdebugrc diff --git a/outboxinterface/tests/unittestenv/kdehome/share/config/kwalletrc b/mailtransport/tests/unittestenv/kdehome/share/config/kwalletrc similarity index 100% rename from outboxinterface/tests/unittestenv/kdehome/share/config/kwalletrc rename to mailtransport/tests/unittestenv/kdehome/share/config/kwalletrc diff --git a/outboxinterface/tests/unittestenv/kdehome/share/config/mailtransports b/mailtransport/tests/unittestenv/kdehome/share/config/mailtransports similarity index 100% rename from outboxinterface/tests/unittestenv/kdehome/share/config/mailtransports rename to mailtransport/tests/unittestenv/kdehome/share/config/mailtransports diff --git a/outboxinterface/tests/unittestenv/kdehome/share/config/qttestrc b/mailtransport/tests/unittestenv/kdehome/share/config/qttestrc similarity index 100% rename from outboxinterface/tests/unittestenv/kdehome/share/config/qttestrc rename to mailtransport/tests/unittestenv/kdehome/share/config/qttestrc diff --git a/outboxinterface/tests/unittestenv/xdgconfig/akonadi/akonadiserverrc b/mailtransport/tests/unittestenv/xdgconfig/akonadi/akonadiserverrc similarity index 100% rename from outboxinterface/tests/unittestenv/xdgconfig/akonadi/akonadiserverrc rename to mailtransport/tests/unittestenv/xdgconfig/akonadi/akonadiserverrc diff --git a/outboxinterface/transportattribute.cpp b/mailtransport/transportattribute.cpp similarity index 95% rename from outboxinterface/transportattribute.cpp rename to mailtransport/transportattribute.cpp index 8ea2cbdd1..1e738ba13 100644 --- a/outboxinterface/transportattribute.cpp +++ b/mailtransport/transportattribute.cpp @@ -1,82 +1,81 @@ /* Copyright 2009 Constantin Berzan 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 "transportattribute.h" -#include +#include "transportmanager.h" -#include "mailtransport/transportmanager.h" +#include using namespace Akonadi; using namespace MailTransport; -using namespace OutboxInterface; class TransportAttribute::Private { public: int mId; }; TransportAttribute::TransportAttribute( int id ) : d( new Private ) { d->mId = id; } TransportAttribute::~TransportAttribute() { delete d; } TransportAttribute* TransportAttribute::clone() const { return new TransportAttribute( d->mId ); } QByteArray TransportAttribute::type() const { static const QByteArray sType( "TransportAttribute" ); return sType; } QByteArray TransportAttribute::serialized() const { return QByteArray::number( d->mId ); } void TransportAttribute::deserialize( const QByteArray &data ) { d->mId = data.toInt(); } int TransportAttribute::transportId() const { return d->mId; } Transport* TransportAttribute::transport() const { return TransportManager::self()->transportById( d->mId, false ); } void TransportAttribute::setTransportId( int id ) { d->mId = id; } diff --git a/outboxinterface/transportattribute.h b/mailtransport/transportattribute.h similarity index 83% rename from outboxinterface/transportattribute.h rename to mailtransport/transportattribute.h index 0f16fdd67..93f613120 100644 --- a/outboxinterface/transportattribute.h +++ b/mailtransport/transportattribute.h @@ -1,87 +1,85 @@ /* Copyright 2009 Constantin Berzan 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 OUTBOXINTERFACE_TRANSPORTATTRIBUTE_H -#define OUTBOXINTERFACE_TRANSPORTATTRIBUTE_H +#ifndef MAILTRANSPORT_TRANSPORTATTRIBUTE_H +#define MAILTRANSPORT_TRANSPORTATTRIBUTE_H -#include +#include #include namespace MailTransport { - class Transport; -} -namespace OutboxInterface { +class Transport; /** Attribute determining which transport to use for sending a message. @see mailtransport @see TransportManager. @author Constantin Berzan @since 4.4 */ -class OUTBOXINTERFACE_EXPORT TransportAttribute : public Akonadi::Attribute +class MAILTRANSPORT_EXPORT TransportAttribute : public Akonadi::Attribute { public: /** Creates a new TransportAttribute. */ TransportAttribute( int id = -1 ); /** Destroys this TransportAttribute. */ virtual ~TransportAttribute(); /* reimpl */ virtual TransportAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); /** Returns the transport id to use for sending this message. @see TransportManager. */ int transportId() const; /** Returns the transport object corresponding to the transport id contained in this attribute. @see Transport. */ - MailTransport::Transport* transport() const; + Transport* transport() const; /** Sets the transport id to use for sending this message. */ void setTransportId( int id ); private: class Private; Private *const d; }; -} // namespace OutboxInterface +} // namespace MailTransport -#endif // OUTBOXINTERFACE_TRANSPORTATTRIBUTE_H +#endif // MAILTRANSPORT_TRANSPORTATTRIBUTE_H diff --git a/mailtransport/transportjob.h b/mailtransport/transportjob.h index 164dd88e2..c4aefd029 100644 --- a/mailtransport/transportjob.h +++ b/mailtransport/transportjob.h @@ -1,140 +1,142 @@ /* Copyright (c) 2007 Volker Krause 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 MAILTRANSPORT_TRANSPORTJOB_H #define MAILTRANSPORT_TRANSPORTJOB_H #include #include #include class QBuffer; namespace MailTransport { class Transport; /** Abstract base class for all mail transport jobs. This is a job that is supposed to send exactly one mail. + + @deprecated Use MessageQueueJob for sending e-mail. */ -class MAILTRANSPORT_EXPORT TransportJob : public KCompositeJob +class MAILTRANSPORT_EXPORT_DEPRECATED TransportJob : public KCompositeJob { friend class TransportManager; public: /** Deletes this transport job. */ virtual ~TransportJob(); /** Sets the sender of the mail. */ void setSender( const QString &sender ); /** Sets the "To" receiver(s) of the mail. */ void setTo( const QStringList &to ); /** Sets the "Cc" receiver(s) of the mail. */ void setCc( const QStringList &cc ); /** Sets the "Bcc" receiver(s) of the mail. */ void setBcc( const QStringList &bcc ); /** Sets the content of the mail. */ void setData( const QByteArray &data ); /** Starts this job. It is recommended to not call this method directly but use TransportManager::schedule() to execute the job instead. @see TransportManager::schedule() */ virtual void start(); /** Returns the Transport object containing the mail transport settings. */ Transport *transport() const; protected: /** Creates a new mail transport job. @param transport The transport configuration. This must be a deep copy of a Transport object, the job takes the ownership of this object. @param parent The parent object. @see TransportManager::createTransportJob() */ explicit TransportJob( Transport *transport, QObject *parent = 0 ); /** Returns the sender of the mail. */ QString sender() const; /** Returns the "To" receiver(s) of the mail. */ QStringList to() const; /** Returns the "Cc" receiver(s) of the mail. */ QStringList cc() const; /** Returns the "Bcc" receiver(s) of the mail. */ QStringList bcc() const; /** Returns the data of the mail. */ QByteArray data() const; /** Returns a QBuffer opened on the message data. This is useful for processing the data in smaller chunks. */ QBuffer *buffer(); /** Do the actual work, implement in your subclass. */ virtual void doStart() = 0; private: class Private; Private *const d; }; } // namespace MailTransport #endif // MAILTRANSPORT_TRANSPORTJOB_H diff --git a/mailtransport/transportmanager.cpp b/mailtransport/transportmanager.cpp index bc54bfa18..7311d9311 100644 --- a/mailtransport/transportmanager.cpp +++ b/mailtransport/transportmanager.cpp @@ -1,770 +1,771 @@ /* Copyright (c) 2006 - 2007 Volker Krause 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 "transportmanager.h" #include "addtransportdialog.h" -#include "akonadijob.h" +#include "resourcesendjob.h" #include "mailtransport_defs.h" #include "sendmailconfigwidget.h" #include "sendmailjob.h" #include "smtpconfigwidget.h" #include "smtpjob.h" #include "transport.h" #include "transportconfigwidget.h" #include "transportjob.h" #include "transporttype.h" #include "transporttype_p.h" #include "transportconfigdialog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace MailTransport; using namespace KWallet; /** * Private class that helps to provide binary compatibility between releases. * @internal */ class TransportManager::Private { public: Private() {} ~Private() { delete config; qDeleteAll( transports ); } KConfig *config; QList transports; TransportType::List types; bool myOwnChange; bool appliedChange; KWallet::Wallet *wallet; bool walletOpenFailed; bool walletAsyncOpen; int defaultTransportId; bool isMainInstance; QList walletQueue; }; class StaticTransportManager : public TransportManager { public: StaticTransportManager() : TransportManager() {} }; StaticTransportManager *sSelf = 0; static void destroyStaticTransportManager() { delete sSelf; } TransportManager::TransportManager() : QObject(), d( new Private ) { KGlobal::locale()->insertCatalog( QLatin1String( "libmailtransport" ) ); qAddPostRoutine( destroyStaticTransportManager ); d->myOwnChange = false; d->appliedChange = false; d->wallet = 0; d->walletOpenFailed = false; d->walletAsyncOpen = false; d->defaultTransportId = -1; d->config = new KConfig( QLatin1String( "mailtransports" ) ); QDBusConnection::sessionBus().registerObject( DBUS_OBJECT_PATH, this, QDBusConnection::ExportScriptableSlots | QDBusConnection::ExportScriptableSignals ); QDBusConnection::sessionBus().connect( QString(), QString(), DBUS_INTERFACE_NAME, DBUS_CHANGE_SIGNAL, this, SLOT(slotTransportsChanged()) ); d->isMainInstance = QDBusConnection::sessionBus().registerService( DBUS_SERVICE_NAME ); connect( QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)), SLOT(dbusServiceOwnerChanged(QString,QString,QString)) ); fillTypes(); } TransportManager::~TransportManager() { qRemovePostRoutine( destroyStaticTransportManager ); delete d; } TransportManager *TransportManager::self() { if ( !sSelf ) { sSelf = new StaticTransportManager; sSelf->readConfig(); } return sSelf; } Transport *TransportManager::transportById( int id, bool def ) const { foreach ( Transport *t, d->transports ) { if ( t->id() == id ) { return t; } } if ( def || ( id == 0 && d->defaultTransportId != id ) ) { return transportById( d->defaultTransportId, false ); } return 0; } Transport *TransportManager::transportByName( const QString &name, bool def ) const { foreach ( Transport *t, d->transports ) { if ( t->name() == name ) { return t; } } if ( def ) { return transportById( 0, false ); } return 0; } QList< Transport * > TransportManager::transports() const { return d->transports; } TransportType::List TransportManager::types() const { return d->types; } Transport *TransportManager::createTransport() const { int id = createId(); Transport *t = new Transport( QString::number( id ) ); t->setId( id ); return t; } void TransportManager::addTransport( Transport *transport ) { if ( d->transports.contains( transport ) ) { kDebug() << "Already have this transport."; return; } kDebug() << "Added transport" << transport; d->transports.append( transport ); validateDefault(); emitChangesCommitted(); } void TransportManager::schedule( TransportJob *job ) { connect( job, SIGNAL(result(KJob*)), SLOT(jobResult(KJob*)) ); // check if the job is waiting for the wallet if ( !job->transport()->isComplete() ) { kDebug() << "job waits for wallet:" << job; d->walletQueue << job; loadPasswordsAsync(); return; } job->start(); } void TransportManager::createDefaultTransport() { KEMailSettings kes; Transport *t = createTransport(); t->setName( i18n( "Default Transport" ) ); t->setHost( kes.getSetting( KEMailSettings::OutServer ) ); if ( t->isValid() ) { t->writeConfig(); addTransport( t ); } else { kWarning() << "KEMailSettings does not contain a valid transport."; } } bool TransportManager::showNewTransportDialog( QWidget *parent ) { QPointer dialog = new AddTransportDialog( parent ); bool accepted = ( dialog->exec() == QDialog::Accepted ); delete dialog; return accepted; } bool TransportManager::promptCreateTransportIfNoneExists( QWidget *parent ) { if ( !isEmpty() ) { return true; } const int response = KMessageBox::messageBox( parent, KMessageBox::WarningContinueCancel, i18n( "You must create an outgoing account before sending." ), i18n( "Create Account Now?" ), KGuiItem( i18n( "Create Account Now" ) ) ); if ( response == KMessageBox::Continue ) { return showNewTransportDialog( parent ); } return false; } bool TransportManager::configureTransport( Transport *transport, QWidget *parent ) { if( transport->type() == Transport::EnumType::Akonadi ) { using namespace Akonadi; AgentInstance instance = AgentManager::self()->instance( transport->host() ); if( !instance.isValid() ) { kWarning() << "Invalid resource instance" << transport->host(); } instance.configure( parent ); // Async... transport->writeConfig(); return true; // No way to know here if the user cancelled or not. } QPointer dialog = new KDialog( parent ); TransportConfigWidget *configWidget = 0; switch( transport->type() ) { case Transport::EnumType::SMTP: { configWidget = new SMTPConfigWidget( transport, dialog ); break; } case Transport::EnumType::Sendmail: { configWidget = new SendmailConfigWidget( transport, dialog ); break; } default: { Q_ASSERT( false ); delete dialog; return false; } } dialog->setMainWidget( configWidget ); dialog->setCaption( i18n( "Configure account" ) ); dialog->setButtons( KDialog::Ok | KDialog::Cancel ); bool okClicked = ( dialog->exec() == QDialog::Accepted ); if( okClicked ) { configWidget->apply(); // calls transport->writeConfig() } delete dialog; return okClicked; } TransportJob *TransportManager::createTransportJob( int transportId ) { Transport *t = transportById( transportId, false ); if ( !t ) { return 0; } t = t->clone(); // Jobs delete their transports. + t->updatePasswordState(); switch ( t->type() ) { case Transport::EnumType::SMTP: return new SmtpJob( t, this ); case Transport::EnumType::Sendmail: return new SendmailJob( t, this ); case Transport::EnumType::Akonadi: - return new AkonadiJob( t, this ); + return new ResourceSendJob( t, this ); } Q_ASSERT( false ); return 0; } TransportJob *TransportManager::createTransportJob( const QString &transport ) { bool ok = false; Transport *t = 0; int transportId = transport.toInt( &ok ); if ( ok ) { t = transportById( transportId ); } if ( !t ) { t = transportByName( transport, false ); } if ( t ) { return createTransportJob( t->id() ); } return 0; } bool TransportManager::isEmpty() const { return d->transports.isEmpty(); } QList TransportManager::transportIds() const { QList rv; foreach ( Transport *t, d->transports ) { rv << t->id(); } return rv; } QStringList TransportManager::transportNames() const { QStringList rv; foreach ( Transport *t, d->transports ) { rv << t->name(); } return rv; } QString TransportManager::defaultTransportName() const { Transport *t = transportById( d->defaultTransportId, false ); if ( t ) { return t->name(); } return QString(); } int TransportManager::defaultTransportId() const { return d->defaultTransportId; } void TransportManager::setDefaultTransport( int id ) { if ( id == d->defaultTransportId || !transportById( id, false ) ) { return; } d->defaultTransportId = id; writeConfig(); } void TransportManager::removeTransport( int id ) { Transport *t = transportById( id, false ); if ( !t ) { return; } emit transportRemoved( t->id(), t->name() ); // Kill the resource, if Akonadi-type transport. if( t->type() == Transport::EnumType::Akonadi ) { using namespace Akonadi; const AgentInstance instance = AgentManager::self()->instance( t->host() ); if( !instance.isValid() ) { kWarning() << "Could not find resource instance."; } AgentManager::self()->removeInstance( instance ); } d->transports.removeAll( t ); validateDefault(); QString group = t->currentGroup(); delete t; d->config->deleteGroup( group ); writeConfig(); } void TransportManager::readConfig() { QList oldTransports = d->transports; d->transports.clear(); QRegExp re( QLatin1String( "^Transport (.+)$" ) ); QStringList groups = d->config->groupList().filter( re ); foreach ( const QString &s, groups ) { re.indexIn( s ); Transport *t = 0; // see if we happen to have that one already foreach ( Transport *old, oldTransports ) { if ( old->currentGroup() == QLatin1String( "Transport " ) + re.cap( 1 ) ) { kDebug() << "reloading existing transport:" << s; t = old; t->readConfig(); oldTransports.removeAll( old ); break; } } if ( !t ) { t = new Transport( re.cap( 1 ) ); } if ( t->id() <= 0 ) { t->setId( createId() ); t->writeConfig(); } d->transports.append( t ); } qDeleteAll( oldTransports ); oldTransports.clear(); // read default transport KConfigGroup group( d->config, "General" ); d->defaultTransportId = group.readEntry( "default-transport", 0 ); if ( d->defaultTransportId == 0 ) { // migrated default transport contains the name instead QString name = group.readEntry( "default-transport", QString() ); if ( !name.isEmpty() ) { Transport *t = transportByName( name, false ); if ( t ) { d->defaultTransportId = t->id(); writeConfig(); } } } validateDefault(); migrateToWallet(); } void TransportManager::writeConfig() { KConfigGroup group( d->config, "General" ); group.writeEntry( "default-transport", d->defaultTransportId ); d->config->sync(); emitChangesCommitted(); } void TransportManager::fillTypes() { Q_ASSERT( d->types.isEmpty() ); // SMTP. { TransportType type; type.d->mType = Transport::EnumType::SMTP; type.d->mName = i18nc( "@option SMTP transport", "SMTP" ); type.d->mDescription = i18n( "An SMTP server on the internet" ); d->types << type; } // Sendmail. { TransportType type; type.d->mType = Transport::EnumType::Sendmail; type.d->mName = i18nc( "@option sendmail transport", "Sendmail" ); type.d->mDescription = i18n( "A local sendmail installation" ); d->types << type; } // All Akonadi resources with MailTransport capability. { using namespace Akonadi; foreach ( const AgentType &atype, AgentManager::self()->types() ) { // TODO probably the string "MailTransport" should be #defined somewhere // and used like that in the resources (?) if( atype.capabilities().contains( QLatin1String( "MailTransport" ) ) ) { TransportType type; type.d->mType = Transport::EnumType::Akonadi; type.d->mAgentType = atype; type.d->mName = atype.name(); type.d->mDescription = atype.description(); d->types << type; kDebug() << "Found Akonadi type" << atype.name(); } } // Watch for appearing and disappearing types. connect( AgentManager::self(), SIGNAL(typeAdded(Akonadi::AgentType)), this, SLOT(agentTypeAdded(Akonadi::AgentType)) ); connect( AgentManager::self(), SIGNAL(typeRemoved(Akonadi::AgentType)), this, SLOT(agentTypeRemoved(Akonadi::AgentType)) ); } kDebug() << "Have SMTP, Sendmail, and" << d->types.count() - 2 << "Akonadi types."; } void TransportManager::emitChangesCommitted() { d->myOwnChange = true; // prevent us from reading our changes again d->appliedChange = false; // but we have to read them at least once emit transportsChanged(); emit changesCommitted(); } void TransportManager::slotTransportsChanged() { if ( d->myOwnChange && d->appliedChange ) { d->myOwnChange = false; d->appliedChange = false; return; } kDebug(); d->config->reparseConfiguration(); // FIXME: this deletes existing transport objects! readConfig(); d->appliedChange = true; // to prevent recursion emit transportsChanged(); } int TransportManager::createId() const { QList usedIds; foreach ( Transport *t, d->transports ) { usedIds << t->id(); } usedIds << 0; // 0 is default for unknown int newId; do { newId = KRandom::random(); } while ( usedIds.contains( newId ) ); return newId; } KWallet::Wallet * TransportManager::wallet() { if ( d->wallet && d->wallet->isOpen() ) { return d->wallet; } if ( !Wallet::isEnabled() || d->walletOpenFailed ) { return 0; } WId window = 0; if ( qApp->activeWindow() ) { window = qApp->activeWindow()->winId(); } else if ( !QApplication::topLevelWidgets().isEmpty() ) { window = qApp->topLevelWidgets().first()->winId(); } delete d->wallet; d->wallet = Wallet::openWallet( Wallet::NetworkWallet(), window ); if ( !d->wallet ) { d->walletOpenFailed = true; return 0; } prepareWallet(); return d->wallet; } void TransportManager::prepareWallet() { if ( !d->wallet ) { return; } if ( !d->wallet->hasFolder( WALLET_FOLDER ) ) { d->wallet->createFolder( WALLET_FOLDER ); } d->wallet->setFolder( WALLET_FOLDER ); } void TransportManager::loadPasswords() { foreach ( Transport *t, d->transports ) { t->readPassword(); } // flush the wallet queue foreach ( TransportJob *job, d->walletQueue ) { job->start(); } d->walletQueue.clear(); emit passwordsChanged(); } void TransportManager::loadPasswordsAsync() { kDebug(); // check if there is anything to do at all bool found = false; foreach ( Transport *t, d->transports ) { if ( !t->isComplete() ) { found = true; break; } } if ( !found ) { return; } // async wallet opening if ( !d->wallet && !d->walletOpenFailed ) { WId window = 0; if ( qApp->activeWindow() ) { window = qApp->activeWindow()->winId(); } else if ( !QApplication::topLevelWidgets().isEmpty() ) { window = qApp->topLevelWidgets().first()->winId(); } d->wallet = Wallet::openWallet( Wallet::NetworkWallet(), window, Wallet::Asynchronous ); if ( d->wallet ) { connect( d->wallet, SIGNAL(walletOpened(bool)), SLOT(slotWalletOpened(bool)) ); d->walletAsyncOpen = true; } else { d->walletOpenFailed = true; loadPasswords(); } return; } if ( d->wallet && !d->walletAsyncOpen ) { loadPasswords(); } } void TransportManager::slotWalletOpened( bool success ) { kDebug(); d->walletAsyncOpen = false; if ( !success ) { d->walletOpenFailed = true; delete d->wallet; d->wallet = 0; } else { prepareWallet(); } loadPasswords(); } void TransportManager::validateDefault() { if ( !transportById( d->defaultTransportId, false ) ) { if ( isEmpty() ) { d->defaultTransportId = -1; } else { d->defaultTransportId = d->transports.first()->id(); writeConfig(); } } } void TransportManager::migrateToWallet() { // check if we tried this already static bool firstRun = true; if ( !firstRun ) { return; } firstRun = false; // check if we are the main instance if ( !d->isMainInstance ) { return; } // check if migration is needed QStringList names; foreach ( Transport *t, d->transports ) { if ( t->needsWalletMigration() ) { names << t->name(); } } if ( names.isEmpty() ) { return; } // ask user if he wants to migrate int result = KMessageBox::questionYesNoList( 0, i18n( "The following mail transports store their passwords in an " "unencrypted configuration file.\nFor security reasons, " "please consider migrating these passwords to KWallet, the " "KDE Wallet management tool,\nwhich stores sensitive data " "for you in a strongly encrypted file.\n" "Do you want to migrate your passwords to KWallet?" ), names, i18n( "Question" ), KGuiItem( i18n( "Migrate" ) ), KGuiItem( i18n( "Keep" ) ), QString::fromAscii( "WalletMigrate" ) ); if ( result != KMessageBox::Yes ) { return; } // perform migration foreach ( Transport *t, d->transports ) { if ( t->needsWalletMigration() ) { t->migrateToWallet(); } } } void TransportManager::dbusServiceOwnerChanged( const QString &service, const QString &oldOwner, const QString &newOwner ) { Q_UNUSED( oldOwner ); if ( service == DBUS_SERVICE_NAME && newOwner.isEmpty() ) { QDBusConnection::sessionBus().registerService( DBUS_SERVICE_NAME ); } } void TransportManager::agentTypeAdded( const Akonadi::AgentType &atype ) { using namespace Akonadi; if( atype.capabilities().contains( QLatin1String( "MailTransport" ) ) ) { TransportType type; type.d->mType = Transport::EnumType::Akonadi; type.d->mAgentType = atype; type.d->mName = atype.name(); type.d->mDescription = atype.description(); d->types << type; kDebug() << "Added new Akonadi type" << atype.name(); } } void TransportManager::agentTypeRemoved( const Akonadi::AgentType &atype ) { using namespace Akonadi; foreach ( const TransportType &type, d->types ) { if( type.type() == Transport::EnumType::Akonadi && type.agentType() == atype ) { d->types.removeAll( type ); kDebug() << "Removed Akonadi type" << atype.name(); } } } void TransportManager::jobResult( KJob *job ) { d->walletQueue.removeAll( static_cast( job ) ); } #include "transportmanager.moc" diff --git a/mailtransport/transportmanager.h b/mailtransport/transportmanager.h index ef960a007..452982e66 100644 --- a/mailtransport/transportmanager.h +++ b/mailtransport/transportmanager.h @@ -1,299 +1,312 @@ /* Copyright (c) 2006 - 2007 Volker Krause 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 MAILTRANSPORT_TRANSPORTMANAGER_H #define MAILTRANSPORT_TRANSPORTMANAGER_H #include #include #include #include #include class KJob; namespace KWallet { class Wallet; } namespace MailTransport { class Transport; class TransportConfigWidget; class TransportJob; /** @short Central transport management interface. This class manages the creation, configuration, and removal of mail - transports, as well as the loading and storing of mail transport settings, - and creation of transport jobs. + transports, as well as the loading and storing of mail transport settings. + + It also handles the creation of transport jobs, although that behaviour is + deprecated and you are encouraged to use MessageQueueJob. + + @see MessageQueueJob. */ class MAILTRANSPORT_EXPORT TransportManager : public QObject { Q_OBJECT Q_CLASSINFO( "D-Bus Interface", "org.kde.pim.TransportManager" ) friend class Transport; friend class Private; public: class Private; /** Destructor. */ virtual ~TransportManager(); /** Returns the TransportManager instance. */ static TransportManager *self(); /** Tries to load passwords asynchronously from KWallet if needed. The passwordsChanged() signal is emitted once the passwords have been loaded. Nothing happens if the passwords were already available. */ void loadPasswordsAsync(); /** Returns the Transport object with the given id. @param id The identifier of the Transport. @param def if set to true, the default transport will be returned if the specified Transport object could not be found, 0 otherwise. @returns A Transport object for immediate use. It might become invalid as soon as the event loop is entered again due to remote changes. If you need to store a Transport object, store the transport identifier instead. */ Transport *transportById( int id, bool def = true ) const; /** Returns the transport object with the given name. @param name The transport name. @param def if set to true, the default transport will be returned if the specified Transport object could not be found, 0 otherwise. @returns A Transport object for immediate use, see transportById() for limitations. */ Transport *transportByName( const QString &name, bool def = true ) const; /** Returns a list of all available transports. Note: The Transport objects become invalid as soon as a change occur, so they are only suitable for immediate use. */ QListtransports() const; /** Returns a list of all available transport types. */ TransportType::List types() const; /** Creates a new, empty Transport object. The object is owned by the caller. If you want to add the Transport permanently (eg. after configuring it) call addTransport(). */ Transport *createTransport() const; /** Adds the given transport. The object ownership is transferred to TransportMananger, ie. you must not delete @p transport. @param transport The Transport object to add. */ void addTransport( Transport *transport ); /** Creates a mail transport job for the given transport identifier. Returns 0 if the specified transport is invalid. @param transportId The transport identifier. + + @deprecated use MessageQueueJob to queue messages + and rely on the Dispatcher Agent to send them. */ - TransportJob *createTransportJob( int transportId ); + MAILTRANSPORT_DEPRECATED TransportJob *createTransportJob( int transportId ); /** Creates a mail transport job for the given transport identifer, or transport name. Returns 0 if the specified transport is invalid. @param transport A string defining a mail transport. + + @deprecated use MessageQueueJob to queue messages + and rely on the Dispatcher Agent to send them. */ - TransportJob *createTransportJob( const QString &transport ); + MAILTRANSPORT_DEPRECATED TransportJob *createTransportJob( const QString &transport ); /** Executes the given transport job. This is the preferred way to start transport jobs. It takes care of asynchronously loading passwords from KWallet if necessary. @param job The completely configured transport job to execute. + + @deprecated use MessageQueueJob to queue messages + and rely on the Dispatcher Agent to send them. */ - void schedule( TransportJob *job ); + MAILTRANSPORT_DEPRECATED void schedule( TransportJob *job ); /** Tries to create a transport based on KEMailSettings. If the data in KEMailSettings is incomplete, no transport is created. */ void createDefaultTransport(); /** Shows a dialog for creating and configuring a new transport. @param parent Parent widget of the dialog. @return True if a new transport has been created and configured. @since 4.4 */ bool showNewTransportDialog( QWidget *parent ); /** If no transport exists, asks the user to create and configure one. Returns true if a transport exists or the user created one. Otherwise returns false. @param parent Parent widget of the dialog. @since 4.4 */ bool promptCreateTransportIfNoneExists( QWidget *parent ); /** Open a configuration dialog for an existing transport. @param transport The transport to configure. It can be a new transport, or one already managed by TransportManager. @param parent The parent widget for the dialog. @return True if the user clicked Ok, false if the user cancelled. @since 4.4 */ bool configureTransport( Transport *transport, QWidget *parent ); public Q_SLOTS: /** Returns true if there are no mail transports at all. */ Q_SCRIPTABLE bool isEmpty() const; /** Returns a list of transport identifiers. */ Q_SCRIPTABLE QList transportIds() const; /** Returns a list of transport names. */ Q_SCRIPTABLE QStringList transportNames() const; /** Returns the default transport name. */ Q_SCRIPTABLE QString defaultTransportName() const; /** Returns the default transport identifier. Invalid if there are no transports at all. */ Q_SCRIPTABLE int defaultTransportId() const; /** Sets the default transport. The change will be in effect immediately. @param id The identifier of the new default transport. */ Q_SCRIPTABLE void setDefaultTransport( int id ); /** Deletes the specified transport. @param id The identifier of the mail transport to remove. */ Q_SCRIPTABLE void removeTransport( int id ); Q_SIGNALS: /** Emitted when transport settings have changed (by this or any other TransportManager instance). */ Q_SCRIPTABLE void transportsChanged(); /** Internal signal to synchronize all TransportManager instances. This signal is emitted by the instance writing the changes. You probably want to use transportsChanged() instead. */ Q_SCRIPTABLE void changesCommitted(); /** Emitted when passwords have been loaded from the wallet. If you made a deep copy of a transport, you should call updatePasswordState() for the cloned transport to ensure its password is updated as well. */ void passwordsChanged(); /** Emitted when a transport is deleted. @param id The identifier of the deleted transport. @param name The name of the deleted transport. */ void transportRemoved( int id, const QString &name ); /** Emitted when a transport has been renamed. @param id The identifier of the renamed transport. @param oldName The old name. @param newName The new name. */ void transportRenamed( int id, const QString &oldName, const QString &newName ); protected: /** Returns a pointer to an open wallet if available, 0 otherwise. The wallet is opened synchronously if necessary. */ KWallet::Wallet *wallet(); /** Loads all passwords synchronously. */ void loadPasswords(); /** Singleton class, the only instance resides in the static object sSelf. */ TransportManager(); private: void readConfig(); void writeConfig(); void fillTypes(); void emitChangesCommitted(); int createId() const; void prepareWallet(); void validateDefault(); void migrateToWallet(); private Q_SLOTS: void slotTransportsChanged(); void slotWalletOpened( bool success ); void dbusServiceOwnerChanged( const QString &service, const QString &oldOwner, const QString &newOwner ); void agentTypeAdded( const Akonadi::AgentType &atype ); void agentTypeRemoved( const Akonadi::AgentType &atype ); void jobResult( KJob *job ); private: Private *const d; }; } // namespace MailTransport #endif // MAILTRANSPORT_TRANSPORTMANAGER_H diff --git a/outboxinterface/CMakeLists.txt b/outboxinterface/CMakeLists.txt deleted file mode 100644 index 7702a951e..000000000 --- a/outboxinterface/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -add_definitions( -DKDE_DEFAULT_DEBUG_AREA=5324 ) - -include_directories( - ${Boost_INCLUDE_DIR} -) - -set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" ) - -add_subdirectory( tests ) - -set( outboxinterface_lib_srcs - dispatcherinterface.cpp - messagequeuejob.cpp - outboxactions.cpp - - dispatchmodeattribute.cpp - errorattribute.cpp - sentbehaviourattribute.cpp - transportattribute.cpp - attributeregistrar.cpp -) - -kde4_add_library( outboxinterface SHARED ${outboxinterface_lib_srcs} ) -target_link_libraries( outboxinterface ${KDE4_KIO_LIBS} akonadi-kde akonadi-kmime kmime mailtransport ) -set_target_properties( outboxinterface PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) - -install( TARGETS outboxinterface ${INSTALL_TARGETS_DEFAULT_ARGS} ) - -install( FILES - outboxinterface_export.h - - dispatcherinterface.h - messagequeuejob.h - outboxactions.h - - dispatchmodeattribute.h - errorattribute.h - sentbehaviourattribute.h - transportattribute.h - - DESTINATION ${INCLUDE_INSTALL_DIR}/outboxinterface COMPONENT Devel ) - diff --git a/outboxinterface/TODO b/outboxinterface/TODO deleted file mode 100644 index d1dae8409..000000000 --- a/outboxinterface/TODO +++ /dev/null @@ -1,9 +0,0 @@ -Design: - -Future: -* Support volatile outbox (not stored on disk). -* Support optional default folders (e.g. no sent-mail for IMAP users). - -Build: -* Get our own debug area. - diff --git a/outboxinterface/outboxinterface_export.h b/outboxinterface/outboxinterface_export.h deleted file mode 100644 index b95bb011d..000000000 --- a/outboxinterface/outboxinterface_export.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright (c) 2009 Constantin Berzan - - 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 OUTBOXINTERFACE_OUTBOXINTERFACE_EXPORT_H -#define OUTBOXINTERFACE_OUTBOXINTERFACE_EXPORT_H - -#include - -#ifndef OUTBOXINTERFACE_EXPORT -# if defined(MAKE_OUTBOXINTERFACE_LIB) - /* We are building this library */ -# define OUTBOXINTERFACE_EXPORT KDE_EXPORT -# else - /* We are using this library */ -# define OUTBOXINTERFACE_EXPORT KDE_IMPORT -# endif -#endif - -#endif diff --git a/outboxinterface/tests/CMakeLists.txt b/outboxinterface/tests/CMakeLists.txt deleted file mode 100644 index df36baa42..000000000 --- a/outboxinterface/tests/CMakeLists.txt +++ /dev/null @@ -1,60 +0,0 @@ -set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) - - -set(queuer_srcs queuer.cpp) -kde4_add_executable(queuer TEST ${queuer_srcs}) -target_link_libraries(queuer ${KDE4_KDEUI_LIBS} ${KDE4_MAILTRANSPORT_LIBS} ${KDE4_KMIME_LIBS} outboxinterface) - -set( sendqueued_srcs sendqueued.cpp ) -kde4_add_executable( sendqueued TEST ${sendqueued_srcs} ) -target_link_libraries( sendqueued outboxinterface ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) - -set( clearerror_srcs clearerror.cpp ) -kde4_add_executable( clearerror TEST ${clearerror_srcs} ) -target_link_libraries( clearerror outboxinterface ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) - -set( abort_srcs abort.cpp ) -kde4_add_executable( abort TEST ${abort_srcs} ) -target_link_libraries( abort outboxinterface ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) - - -# Stolen from kdepimlibs/akonadi/tests -macro(add_akonadi_isolated_test _source) - get_filename_component(_targetName ${_source} NAME_WE) - set(_srcList ${_source} ) - - kde4_add_executable(${_targetName} TEST ${_srcList}) - target_link_libraries(${_targetName} - ${QT_QTTEST_LIBRARY} - ${QT_QTGUI_LIBRARY} - ${KDE4_AKONADI_LIBS} - ${KDE4_KDECORE_LIBS} - ${KDE4_MAILTRANSPORT_LIBS} - ${KDE4_KMIME_LIBS} - ${QT_QTCORE_LIBRARY} - ${QT_QTDBUS_LIBRARY} - outboxinterface - ) - - # based on kde4_add_unit_test - if (WIN32) - get_target_property( _loc ${_targetName} LOCATION ) - set(_executable ${_loc}.bat) - else (WIN32) - set(_executable ${EXECUTABLE_OUTPUT_PATH}/${_targetName}) - endif (WIN32) - if (UNIX) - set(_executable ${_executable}.shell) - endif (UNIX) - - find_program(_testrunner akonaditest) - - add_test( outboxinterface-${_targetName} ${_testrunner} -c ${CMAKE_CURRENT_SOURCE_DIR}/unittestenv/config.xml ${_executable} ) -endmacro(add_akonadi_isolated_test) - - - - -add_akonadi_isolated_test( attributetest.cpp ) -add_akonadi_isolated_test( messagequeuejobtest.cpp ) - diff --git a/outboxinterface/tests/TODO b/outboxinterface/tests/TODO deleted file mode 100644 index 04bb421ba..000000000 --- a/outboxinterface/tests/TODO +++ /dev/null @@ -1,6 +0,0 @@ -MessageQueueJob: -- see source - -Attributes: -- add test for serialization and common mistakes such as forgetting to setDueDate -