From 9b5bfc14c4753b3e80e45309fda45ca491c90c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Lanzend=C3=B6rfer?= Date: Wed, 3 Nov 2021 23:47:35 +0000 Subject: [PATCH] Starting pEp identity search Adding some filtering stuff for digging for pEp messages --- .gitignore | 3 ++ akonadi_pep_agent/CMakeLists.txt | 2 + akonadi_pep_agent/pepagent.cpp | 86 +++++++++++++++----------------- akonadi_pep_agent/pepagent.h | 46 ++++++++++++++--- akonadi_pep_agent/syncthread.cpp | 11 ++++ 5 files changed, 95 insertions(+), 53 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66866dc --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build +CMakeLists.txt.user +.clang-format diff --git a/akonadi_pep_agent/CMakeLists.txt b/akonadi_pep_agent/CMakeLists.txt index 263a785..481dda8 100644 --- a/akonadi_pep_agent/CMakeLists.txt +++ b/akonadi_pep_agent/CMakeLists.txt @@ -53,6 +53,8 @@ target_link_libraries(akonadi_pep_agent sequoia_openpgp_ffi ) +set_property(TARGET akonadi_pep_agent PROPERTY CXX_STANDARD 17) + configure_file(pepagent.service.in ${CMAKE_CURRENT_BINARY_DIR}/pepagent.service) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pepagent.service DESTINATION ${KDE_INSTALL_DBUSSERVICEDIR}) diff --git a/akonadi_pep_agent/pepagent.cpp b/akonadi_pep_agent/pepagent.cpp index f84a68a..9e95ad4 100644 --- a/akonadi_pep_agent/pepagent.cpp +++ b/akonadi_pep_agent/pepagent.cpp @@ -9,27 +9,6 @@ #include "pepagent_debug.h" #include "pep-introspectadaptor.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include - -#include - using namespace Akonadi; PEP_STATUS pEpAgent::messageToSend(::message* msg) @@ -38,16 +17,6 @@ PEP_STATUS pEpAgent::messageToSend(::message* msg) return PEP_STATUS_OK; } -notifyHandshake_t pEpAgent::notifyHandshake() -{ - return 1; -} - -retrieve_next_sync_event_t pEpAgent::retrieve_next_sync_event() -{ - return 1; -} - pEpAgent::pEpAgent(const QString &id) : ResourceBase(id) { @@ -67,6 +36,9 @@ pEpAgent::pEpAgent(const QString &id) dbus.registerService(service); /* --------------------- Done ------------------------------- */ + // pEp management + m_syncThread = new pEpSyncThread(this); + // This here is just bureaucracy: auto *collectionMonitor = new Akonadi::Monitor(this); collectionMonitor->setObjectName(QStringLiteral("pEpCollectionMonitor")); @@ -86,7 +58,7 @@ pEpAgent::pEpAgent(const QString &id) mProgressCounter = 0; mProgressTimer = new QTimer(this); - auto *itemMonitor = new Akonadi::Monitor(this); + itemMonitor = new Akonadi::Monitor(this); itemMonitor->setObjectName(QStringLiteral("pEpItemMonitor")); itemMonitor->itemFetchScope().setFetchRemoteIdentification(true); itemMonitor->itemFetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent); @@ -133,7 +105,6 @@ void pEpAgent::emitProgressMessage(const QString &message) void pEpAgent::itemsReceiviedForFiltering(const Akonadi::Item::List &items) { - qCDebug(PEPAGENT_LOG) << __FUNCTION__ << " Test"; qDebug() << __FUNCTION__ << " Test"; if (items.isEmpty()) { @@ -175,11 +146,11 @@ void pEpAgent::emitStatusReady() bool pEpAgent::isFilterableCollection(const Akonadi::Collection &collection) const { // TODO: Do this smarter - if(QStringLiteral("INBOX")==collection.name()) { + if(QStringLiteral( "INBOX" ) == collection.name()) { qDebug() << __FUNCTION__ << "Found an INBOX folder"; return true; } - if(QStringLiteral("inbox")==collection.name()) { + if( QStringLiteral("inbox") == collection.name() ) { qDebug() << __FUNCTION__ << "Found an INBOX folder"; return true; } @@ -188,6 +159,10 @@ bool pEpAgent::isFilterableCollection(const Akonadi::Collection &collection) con return false; } +void pEpAgent::scanCollection(const Akonadi::Collection &collection) +{ +} + void pEpAgent::initialCollectionFetchingDone(KJob *job) { qDebug() << __FUNCTION__ << " Test"; @@ -202,9 +177,10 @@ void pEpAgent::initialCollectionFetchingDone(KJob *job) const auto lstCols = fetchJob->collections(); for (const Akonadi::Collection &collection : lstCols) { // All the folders of all the accounts - if(isFilterableCollection(collection)) { + if(isFilterableCollection(collection)) { + qDebug() << "Checking for keys in collection: " << collection.name(); changeRecorder()->setCollectionMonitored(collection, true); - } + } } Q_EMIT status(AgentBase::Idle, i18n("Ready")); @@ -214,29 +190,44 @@ void pEpAgent::initialCollectionFetchingDone(KJob *job) void pEpAgent::slotItemChanged(const Akonadi::Item &item) { - qCDebug(PEPAGENT_LOG) << __FUNCTION__ << " Test"; qDebug() << __FUNCTION__ << " Test"; - /*if (item.remoteId().isEmpty()) { + if (item.remoteId().isEmpty()) { return; } // now we have the remoteId itemMonitor->setItemMonitored(item, false); - filterItem(item, item.parentCollection());*/ + filterItem(item, item.parentCollection()); +} + +void pEpAgent::filterItem(const Akonadi::Item &item, const Akonadi::Collection &collection) +{ + qDebug() << __FUNCTION__; + auto job = new Akonadi::ItemFetchJob(item); + connect(job, &Akonadi::ItemFetchJob::itemsReceived, this, &pEpAgent::itemsReceiviedForFiltering); + job->fetchScope().fetchFullPayload(); + job->fetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent); + job->fetchScope().fetchAttribute(); + job->setProperty("resource", collection.resource()); + + // TODO: Error handling? } void pEpAgent::mailCollectionRemoved(const Akonadi::Collection &collection) { + qDebug() << __FUNCTION__; changeRecorder()->setCollectionMonitored(collection, false); } void pEpAgent::mailCollectionChanged(const Akonadi::Collection &collection) { + qDebug() << __FUNCTION__; changeRecorder()->setCollectionMonitored(collection, isFilterableCollection(collection)); } void pEpAgent::mailCollectionAdded(const Akonadi::Collection &collection, const Akonadi::Collection &) { + qDebug() << __FUNCTION__; if (isFilterableCollection(collection)) { changeRecorder()->setCollectionMonitored(collection, true); } @@ -244,24 +235,26 @@ void pEpAgent::mailCollectionAdded(const Akonadi::Collection &collection, const void pEpAgent::slotInstanceRemoved(const Akonadi::AgentInstance &instance) { + qDebug() << __FUNCTION__; //m_filterManager->agentRemoved(instance.identifier()); } void pEpAgent::itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection) { + qDebug() << __FUNCTION__; /* The monitor mimetype filter would override the collection filter, therefor we have to check * for the mimetype of the item here. */ - /*if (item.mimeType() != KMime::Message::mimeType()) { - qCDebug(MAILFILTERAGENT_LOG) << "MailFilterAgent::itemAdded called for a non-message item!"; + if (item.mimeType() != KMime::Message::mimeType()) { return; } if (item.remoteId().isEmpty()) { itemMonitor->setItemMonitored(item); } else { + qDebug() << __FUNCTION__ << ": Filter this\n"; filterItem(item, collection); - }*/ + } } void pEpAgent::configure(WId windowId) @@ -271,8 +264,7 @@ void pEpAgent::configure(WId windowId) void pEpAgent::retrieveCollections() { - qDebug() << __FUNCTION__ << "Test"; - + // TODO: Put information here, like person table content and so: Akonadi::Collection::List collections; Akonadi::Collection topLevel; topLevel.setName(identifier()); @@ -293,8 +285,8 @@ int pEpAgent::decrypt_message(const QString &src, QString &dst, QStringList &key qDebug() << "pEpAgent: Decrypting"; char *ms = src.toLatin1().data(); ::message *m = NULL; - ::message *md = malloc(sizeof(::message)); - stringlist_t *kl = malloc(sizeof(stringlist_t)); + ::message *md = new_message(PEP_dir_incoming); + stringlist_t *kl = new_stringlist(""); PEP_decrypt_flags_t fl = 0; bool might_be_pep = true; ::mime_decode_message( ms, src.toLatin1().size(), &m, &might_be_pep ); diff --git a/akonadi_pep_agent/pepagent.h b/akonadi_pep_agent/pepagent.h index c45fe4c..7fbe5d9 100644 --- a/akonadi_pep_agent/pepagent.h +++ b/akonadi_pep_agent/pepagent.h @@ -4,13 +4,37 @@ #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 "pepagent_p.h" +#include "syncthread.h" #include #include @@ -22,12 +46,17 @@ class PepAdaptor; class pEpAgent : public Akonadi::ResourceBase, - public Akonadi::AgentBase::Observer + public Akonadi::AgentBase::ObserverV3 { Q_OBJECT public: explicit pEpAgent(const QString &id); + + void filterItem(qint64 item, int filterSet, const QString &resourceId); + void filter(qint64 item, const QString &filterIdentifier, const QString &resourceId); + void filterCollections(const QList &collections, int filterSet); + ~pEpAgent() = default; protected Q_SLOTS: @@ -42,6 +71,9 @@ protected: void mailCollectionRemoved(const Akonadi::Collection &collection); void mailCollectionChanged(const Akonadi::Collection &collection); + void scanCollection(const Akonadi::Collection &collection); + + private Q_SLOTS: void slotInstanceRemoved(const Akonadi::AgentInstance &instance); void slotItemChanged(const Akonadi::Item &item); @@ -51,6 +83,10 @@ public Q_SLOTS: // pEp methods private: Q_DECLARE_PRIVATE(pEpAgent) + pEpSyncThread *m_syncThread = nullptr; + Akonadi::Monitor *itemMonitor = nullptr; + + void filterItem(const Akonadi::Item &item, const Akonadi::Collection &collection); void initialCollectionFetchingDone(KJob *job); void initializeCollections(); @@ -71,8 +107,6 @@ private: PEP_SESSION m_session; static PEP_STATUS messageToSend(::message* msg); inject_sync_event_t inject_sync_event = nullptr; - static notifyHandshake_t notifyHandshake(); - static retrieve_next_sync_event_t retrieve_next_sync_event(); }; diff --git a/akonadi_pep_agent/syncthread.cpp b/akonadi_pep_agent/syncthread.cpp index 72398ff..2395db6 100644 --- a/akonadi_pep_agent/syncthread.cpp +++ b/akonadi_pep_agent/syncthread.cpp @@ -1,5 +1,16 @@ #include "syncthread.h" +/*notifyHandshake_t notifyHandshake() +{ + return 1; +} + +retrieve_next_sync_event_t retrieve_next_sync_event() +{ + return 1; +}*/ + + pEpSyncThread::pEpSyncThread(QObject *parent) : QThread(parent) {