Browse Source

Starting pEp identity search

Adding some filtering stuff for digging for pEp messages
master
David Lanzendörfer 1 month ago
parent
commit
9b5bfc14c4
5 changed files with 95 additions and 53 deletions
  1. +3
    -0
      .gitignore
  2. +2
    -0
      akonadi_pep_agent/CMakeLists.txt
  3. +39
    -47
      akonadi_pep_agent/pepagent.cpp
  4. +40
    -6
      akonadi_pep_agent/pepagent.h
  5. +11
    -0
      akonadi_pep_agent/syncthread.cpp

+ 3
- 0
.gitignore View File

@ -0,0 +1,3 @@
build
CMakeLists.txt.user
.clang-format

+ 2
- 0
akonadi_pep_agent/CMakeLists.txt View File

@ -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})


+ 39
- 47
akonadi_pep_agent/pepagent.cpp View File

@ -9,27 +9,6 @@
#include "pepagent_debug.h"
#include "pep-introspectadaptor.h"
#include <Akonadi/KMime/Pop3ResourceAttribute>
#include <AkonadiCore/ServerManager>
#include <AkonadiCore/CollectionFetchJob>
#include <AkonadiCore/CollectionFetchScope>
#include <AkonadiCore/AgentManager>
#include <AkonadiCore/AttributeFactory>
#include <AkonadiCore/Monitor>
#include <AkonadiCore/Session>
#include <AkonadiCore/ItemFetchScope>
#include <AkonadiCore/ChangeRecorder>
#include <AkonadiAgentBase/ResourceBase>
#include <AkonadiCore/EntityDisplayAttribute>
#include <MailCommon/MailKernel>
#include <KI18n/KLocalizedString>
#include <GrantleeTheme/GrantleeKi18nLocalizer>
#include <QDBusInterface>
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<Akonadi::Pop3ResourceAttribute>();
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 );


+ 40
- 6
akonadi_pep_agent/pepagent.h View File

@ -4,13 +4,37 @@
#include <ResourceBase>
#include <KMime/Message>
#include <KJob>
#include <AkonadiCore/AgentInstance>
#include <Akonadi/KMime/Pop3ResourceAttribute>
#include <AkonadiCore/ServerManager>
#include <AkonadiCore/CollectionFetchJob>
#include <AkonadiCore/CollectionFetchScope>
#include <AkonadiCore/AgentManager>
#include <AkonadiCore/AttributeFactory>
#include <AkonadiCore/Monitor>
#include <AkonadiCore/Session>
#include <AkonadiCore/ItemFetchScope>
#include <AkonadiCore/ChangeRecorder>
#include <AkonadiAgentBase/ResourceBase>
#include <AkonadiCore/EntityDisplayAttribute>
#include <AkonadiCore/ItemFetchJob>
#include <AkonadiCore/PartFetcher>
#include <Akonadi/KMime/MessageParts>
#include <MailCommon/MailKernel>
#include <MailCommon/SearchRule>
#include <KI18n/KLocalizedString>
#include <GrantleeTheme/GrantleeKi18nLocalizer>
#include <QDBusInterface>
#include <QSet>
#include <QTimer>
#include <QDBusInterface>
#include <AkonadiCore/AgentInstance>
#include "pepagent_p.h"
#include "syncthread.h"
#include <pEp/pEpEngine.h>
#include <pEp/Adapter.hh>
@ -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<qint64> &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();
};


+ 11
- 0
akonadi_pep_agent/syncthread.cpp View File

@ -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)
{


Loading…
Cancel
Save