[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/pim/mailody
From: Tom Albers <tomalbers () kde ! nl>
Date: 2008-01-03 18:55:36
Message-ID: 1199386536.432763.29191.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 756774 by toma:
Implement the first funtions. It now connects to the server, does the login and \
retrieves the mailboxes/collections when you press synchronise.
M +1 -1 akonadi_resource/CMakeLists.txt
M +194 -3 akonadi_resource/imaplibresource.cpp
M +13 -0 akonadi_resource/imaplibresource.h
M +1 -1 src/CMakeLists.txt
--- trunk/playground/pim/mailody/akonadi_resource/CMakeLists.txt #756773:756774
@@ -28,7 +28,7 @@
kde4_add_executable(akonadi_imaplib_resource RUN_UNINSTALLED \
${imaplibresource_SRCS})
-target_link_libraries(akonadi_imaplib_resource akonadi ${QT_QTDBUS_LIBRARIES})
+target_link_libraries(akonadi_imaplib_resource akonadi ${QT_QTDBUS_LIBRARIES} imap)
install(TARGETS akonadi_imaplib_resource DESTINATION ${BIN_INSTALL_DIR})
--- trunk/playground/pim/mailody/akonadi_resource/imaplibresource.cpp #756773:756774
@@ -19,12 +19,19 @@
*/
#include "imaplibresource.h"
+#include "imaplib.h"
#include <QtCore/QDebug>
#include <QtDBus/QDBusConnection>
#include <kdebug.h>
#include <klocale.h>
+#include <kconfiggroup.h>
+#include <kstandarddirs.h>
+#include <kpassworddialog.h>
+#include <kmessagebox.h>
+#include <kwallet.h>
+using KWallet::Wallet;
#include <libakonadi/collectionlistjob.h>
#include <libakonadi/collectionmodifyjob.h>
@@ -40,12 +47,34 @@
ImaplibResource::ImaplibResource( const QString &id )
:ResourceBase( id )
{
- kDebug(50002) << "Implement me!";
+ // For now, read the mailody settings. Need to figure out how to set mailody up \
for settings(). + KConfig* tempConfig = new \
KConfig(KStandardDirs::locate("config", "mailodyrc")); + KConfigGroup config = \
tempConfig->group("General"); + const QString imapServer = \
config.readEntry("imapServer"); + int safe = config.readEntry("safeImap",3);
+
+ QString server = imapServer.section(":",0,0);
+ int port = imapServer.section(":",1,1).toInt();
+
+ m_imap = new Imaplib(0,"serverconnection");
+
+ /* TODO: copy cryptoConnectionSupport or do this somewhere else ?
+ if ((safe == 1 || safe == 2) && !Global::cryptoConnectionSupported())
+ {
+ kDebug(50002) << "Crypto not supported!" << endl;
+ slotError(i18n("You requested TLS/SSL, but your "
+ "system does not seem to be set up for that."));
+ return;
+ }
+ */
+
+ m_imap->startConnection(server, port, safe);
+ connections();
}
ImaplibResource::~ImaplibResource()
{
- kDebug(50002) << "Implement me!";
+ delete m_imap;
}
bool ImaplibResource::retrieveItem( const Akonadi::Item &item, const QStringList \
&parts ) @@ -88,9 +117,27 @@
void ImaplibResource::retrieveCollections()
{
- kDebug(50002) << "Implement me!";
+ m_imap->getMailBoxList();
}
+void ImaplibResource::slotGetMailBoxList(const QStringList& list)
+{
+ Collection::List collections;
+
+ QStringList::ConstIterator it = list.begin();
+ while (it != list.end())
+ {
+ Collection c;
+ c.setName( *it );
+ c.setRemoteId( *it );
+ kDebug(50002) << "ADDING: " << (*it) << endl;
+ collections << c;
+ ++it;
+ }
+
+ collectionsRetrieved( collections );
+}
+
void ImaplibResource::retrieveItems(const Akonadi::Collection & col, const \
QStringList &parts) {
kDebug(50002) << "Implement me!";
@@ -111,4 +158,148 @@
qDebug() << "Implement me!";
}
+/******************* Slots ***********************************************/
+
+void ImaplibResource::slotLogin( Imaplib* connection)
+{
+ // kDebug(50002) << endl;
+
+ // For now, read the mailody settings. Need to figure out how to set mailody up \
for settings(). + KConfig* tempConfig = new \
KConfig(KStandardDirs::locate("config", "mailodyrc")); + KConfigGroup config = \
tempConfig->group("General"); + QString login = config.readEntry("userName");
+ QString pass;
+
+ Wallet* wallet = Wallet::openWallet(Wallet::NetworkWallet(), 0 /* TODO: anything \
more intelligent possible?*/); + if (wallet && wallet->isOpen() && \
wallet->hasFolder("mailody")) + {
+ wallet->setFolder( "mailody" );
+ wallet->readPassword("account1", pass);
+ }
+ delete wallet;
+
+ if (pass.isEmpty())
+ {
+ manualAuth( connection, login);
+ }
+ else
+ {
+ connection->login(login, pass);
+ }
+}
+
+void ImaplibResource::slotLoginFailed(Imaplib* connection)
+{
+ // the credentials where not ok....
+ int i = KMessageBox::questionYesNoCancel(0,
+ i18n("The server refused the supplied username and password. "
+ "Do you want to go to the settings, re-enter it for one "
+ "time or do nothing?"),
+ i18n("Could Not Log In"),
+ KGuiItem(i18n("Settings")), KGuiItem(i18n("Single Input")));
+ if (i == KMessageBox::Yes)
+ configure();
+ else if (i == KMessageBox::No)
+ {
+ // For now, read the mailody settings. Need to figure out how to set mailody \
up for settings(). + KConfig* tempConfig = new \
KConfig(KStandardDirs::locate("config", "mailodyrc")); + KConfigGroup config = \
tempConfig->group("General"); + QString username = \
config.readEntry("userName"); + manualAuth(connection, username);
+ }
+ else
+ connection->logout();
+}
+
+void ImaplibResource::slotAlert(Imaplib*, const QString& message)
+{
+ KMessageBox::information(0, i18n("Server reported: %1",message));
+}
+
+/******************* Private ***********************************************/
+
+void ImaplibResource::connections()
+{
+ connect(m_imap,
+ SIGNAL(login( Imaplib* )),
+ SLOT( slotLogin( Imaplib* ) ));
+ connect(m_imap,
+ SIGNAL(loginOk( Imaplib* )),
+ SIGNAL( loginOk() ));
+ connect(m_imap,
+ SIGNAL(status( const QString& )),
+ SIGNAL(status( const QString& )));
+ connect(m_imap,
+ SIGNAL(statusReady()),
+ SIGNAL(statusReady()));
+ connect(m_imap,
+ SIGNAL(statusError( const QString& )),
+ SIGNAL(statusError( const QString& )));
+ connect(m_imap,
+ SIGNAL(saveDone()),
+ SIGNAL(saveDone()));
+ connect(m_imap,
+ SIGNAL(error(const QString&)),
+ SLOT(slotError(const QString&)));
+ connect(m_imap,
+ SIGNAL(unexpectedDisconnect()),
+ SLOT(slotDisconnected()));
+ connect(m_imap,
+ SIGNAL(disconnected()),
+ SIGNAL(disconnected()));
+ connect(m_imap,
+ SIGNAL(loginFailed( Imaplib* )),
+ SLOT( slotLoginFailed( Imaplib* ) ));
+ connect(m_imap,
+ SIGNAL(alert( Imaplib*, const QString& )),
+ SLOT( slotAlert( Imaplib*, const QString& ) ));
+ connect(m_imap,
+ SIGNAL(mailBoxList(const QStringList&)),
+ SLOT( slotGetMailBoxList(const QStringList& ) ));
+ connect(m_imap,
+ SIGNAL(mailBox( Imaplib*, const QString&, const QStringList& )),
+ SLOT( slotGetMailBox( Imaplib*, const QString&, const QStringList& ) ));
+ connect(m_imap,
+ SIGNAL(message( Imaplib*, const QString&, int, const QString& )),
+ SLOT( slotGetMessage( Imaplib*, const QString&, int, const QString& ) \
)); + connect(m_imap,
+ SIGNAL(messageCount(Imaplib*, const QString&, int)),
+ SLOT(slotMessagesInMailbox(Imaplib*, const QString&, int) ));
+ connect(m_imap,
+ SIGNAL(unseenCount(Imaplib*, const QString&, int)),
+ SLOT(slotUnseenMessagesInMailbox(Imaplib*, const QString& , int ) ));
+ connect(m_imap,
+ SIGNAL(mailBoxAdded(const QString&)),
+ SLOT(slotMailBoxAdded(const QString&)));
+ connect(m_imap,
+ SIGNAL(mailBoxDeleted(const QString&)),
+ SLOT(slotMailBoxRemoved(const QString&)));
+ connect(m_imap,
+ SIGNAL(mailBoxRenamed(const QString&, const QString&)),
+ SLOT(slotMailBoxRenamed(const QString&, const QString&)));
+ connect(m_imap,
+ SIGNAL(expungeCompleted(Imaplib*, const QString&)),
+ SLOT(slotMailBoxExpunged(Imaplib*, const QString&)));
+ connect(m_imap,
+ SIGNAL(itemsInMailBox(Imaplib*,const QString&,const QStringList&)),
+ SLOT(slotMailBoxItems(Imaplib*,const QString&,const QStringList&)));
+ connect(m_imap,
+ SIGNAL(integrity(const QString&, int, const QString&,
+ const QString&)),
+ SLOT(slotIntegrity(const QString&, int, const QString&,
+ const QString&)));
+}
+
+void ImaplibResource::manualAuth(Imaplib* connection, const QString& username)
+{
+ // kDebug(50002) << endl;
+
+ KPasswordDialog dlg( 0 /* todo: sane? */);
+ dlg.setPrompt( i18n("Could not find a valid password, please enter it here") );
+ if (dlg.exec() == QDialog::Accepted && !dlg.password().isEmpty())
+ connection->login(username, QString(dlg.password()));
+ else
+ connection->logout();
+}
+
#include "imaplibresource.moc"
--- trunk/playground/pim/mailody/akonadi_resource/imaplibresource.h #756773:756774
@@ -21,6 +21,8 @@
#ifndef __IMAPLIB_RESOURCE_H__
#define __IMAPLIB_RESOURCE_H__
+class Imaplib;
+
#include <resourcebase.h>
class ImaplibResource : public Akonadi::ResourceBase
@@ -47,6 +49,17 @@
virtual void collectionAdded( const Akonadi::Collection &collection, const \
Akonadi::Collection &parent );
virtual void collectionChanged( const Akonadi::Collection &collection );
virtual void collectionRemoved( int id, const QString &remoteId );
+
+ private Q_SLOTS:
+ void slotLogin( Imaplib* connection);
+ void slotLoginFailed(Imaplib* connection);
+ void slotAlert(Imaplib*, const QString& message);
+ void slotGetMailBoxList(const QStringList& list);
+
+ private:
+ Imaplib* m_imap;
+ void connections();
+ void manualAuth(Imaplib* connection, const QString& username);
};
#endif
--- trunk/playground/pim/mailody/src/CMakeLists.txt #756773:756774
@@ -40,7 +40,7 @@
KDE4_ADD_EXECUTABLE(mailody ${mailody_SRCS})
-TARGET_LINK_LIBRARIES(mailody imap akonadicomponents kmimeakonadi \
${QT_AND_KDECORE_LIBS} ${KDE4_KHTML_LIBS} kabc ${KDE4_KPIMUTILS_LIBS} \
${KDE4_KIMAP_LIBS} kmime ${KDE4_MAILTRANSPORT_LIBS} ${KDE4_KPIMIDENTITIES_LIBS} \
${KDE4_KNOTIFYCONFIG_LIBS} ${KDE4_KFILE_LIBS} ${KDE4_KUTILS_LIBS} ) \
+TARGET_LINK_LIBRARIES(mailody akonadicomponents kmimeakonadi ${QT_AND_KDECORE_LIBS} \
${KDE4_KHTML_LIBS} kabc ${KDE4_KPIMUTILS_LIBS} ${KDE4_KIMAP_LIBS} kmime \
${KDE4_MAILTRANSPORT_LIBS} ${KDE4_KPIMIDENTITIES_LIBS} ${KDE4_KNOTIFYCONFIG_LIBS} \
${KDE4_KFILE_LIBS} ${KDE4_KUTILS_LIBS} )
INSTALL(TARGETS mailody DESTINATION ${BIN_INSTALL_DIR})
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic