Initial spinup

It now properly shoves over the email content over DBus, and the
akonadi agent spins up the pEp engine and processes the stuff.
Now we just have to put a bit more logic into it and also make sure
it properly syncs with other pEp users.
master
David Lanzendörfer 1 year ago
parent 62fd3c4dff
commit 36b6e828a1
  1. 5
      CMakeLists.txt
  2. 12
      akonadi_pep_agent/CMakeLists.txt
  3. 11
      akonadi_pep_agent/org.freedesktop.Akonadi.pEpAgent.xml
  4. 134
      akonadi_pep_agent/pepagent.cpp
  5. 25
      akonadi_pep_agent/pepagent.h
  6. 3
      akonadi_pep_agent/pepagent.service.in
  7. 5
      akonadi_pep_agent/pepmessage.h
  8. 53
      messageviewerplugin/pephelpers.cpp
  9. 2
      messageviewerplugin/viewerpluginpep.cpp
  10. 74
      messageviewerplugin/viewerpluginpepinterface.cpp
  11. 8
      messageviewerplugin/viewerpluginpepinterface.h
  12. 2
      pEpDBusAdapter

@ -1,5 +1,10 @@
project(pEpForKDE)
string( REPLACE "fno-exceptions" "fexceptions" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string( REPLACE "fno-exceptions" "fexceptions" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string( REGEX REPLACE "\\-DNDEBUG" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string( REGEX REPLACE "\\-DNDEBUG" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# setting the version of this viewer:
set(PROJECT_VERSION_STRING "alpha")
set(PEP_MESSAGEVIEWER_VERSION_STRING ${PROJECT_VERSION_STRING})

@ -8,7 +8,7 @@ set(pepagent_SRCS
kcfg_generate_dbus_interface(${CMAKE_CURRENT_SOURCE_DIR}/pepagent.kcfg org.kde.Akonadi.pEpAgent.Settings)
qt5_add_dbus_adaptor(pepagent_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.Akonadi.pEpAgent.xml pepagent.h pEpAgent
${PROJECT_SOURCE_DIR}/pEpDBusAdapter/pep-introspect.xml pepagent.h pEpAgent
)
ecm_qt_declare_logging_category(pepagent_SRCS HEADER pepagent_debug.h IDENTIFIER PEPAGENT_LOG CATEGORY_NAME org.kde.pim.pepagent
@ -32,7 +32,6 @@ target_link_libraries(akonadi_pep_agent
Grantlee5::Templates
KF5::MailCommon
Qt5::Core
Qt5::DBus
Qt5::Network
KF5::AkonadiCore
KF5::IMAP
@ -46,8 +45,17 @@ target_link_libraries(akonadi_pep_agent
KF5::WindowSystem
KF5::PimCommon
KF5::Libkdepim
pEpEngine
pEpMIME
pEpAdapter
sequoia_ffi
sequoia_openpgp_ffi
)
configure_file(pepagent.service.in ${CMAKE_CURRENT_BINARY_DIR}/pepagent.service)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pepagent.service
DESTINATION ${KDE_INSTALL_DBUSSERVICEDIR})
install( TARGETS akonadi_pep_agent ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} )
install( FILES pepagent.desktop DESTINATION "${KDE_INSTALL_DATAROOTDIR}/akonadi/agents" )
install( FILES akonadi_pep_agent.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFY5RCDIR} )

@ -1,11 +0,0 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.Akonadi.Agent.pEpAgent">
<method name="decryptMessage" >
<arg direction="in" type="ay" name="message" />
<arg direction="out" type="(iiii)" name="message" />
<!--<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="const KMime::Message::Ptr &amp;"/>-->
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="pEpMessage*"/>
</method>
</interface>
</node>

@ -7,7 +7,7 @@
#include "pepagent.h"
#include "pepagent_debug.h"
#include "pepagentadaptor.h"
#include "pep-introspectadaptor.h"
#include <Akonadi/KMime/Pop3ResourceAttribute>
#include <AkonadiCore/ServerManager>
@ -28,32 +28,46 @@
#include <GrantleeTheme/GrantleeKi18nLocalizer>
#include <QDBusInterface>
using namespace Akonadi;
PEP_STATUS pEpAgent::messageToSend(::message* msg)
{
qDebug() << "pEp wants to send a message";
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)
{
Q_D(pEpAgent);
new PEpAgentAdaptor(this);
//d->scheduler = new pEpScheduler(this);
PEP_STATUS status;
QDBusConnection dbus = QDBusConnection::sessionBus();
const QString service = Akonadi::ServerManager::self()->agentServiceName(Akonadi::ServerManager::Agent, QStringLiteral("pEpAgent"));
QDBusConnection::sessionBus().registerService(service);
qDebug() << __FUNCTION__ << "Registered as " << service;
//Akonadi::AttributeFactory::registerAttribute<Akonadi::Pop3ResourceAttribute>();
//mTheKernel = new DummyKernel(this);
//CommonKernel->registerKernelIf(mMailFilterKernel); //register KernelIf early, it is used by the Filter classes
//CommonKernel->registerSettingsIf(mMailFilterKernel); //SettingsIf is used in FolderTreeWidget
/* -------------- Starting the pEp Engine ------------------- */
status = ::init(&m_session, NULL, NULL, NULL);
/* --------------------- Done ------------------------------- */
/*m_filterManager = new FilterManager(this);
connect(m_filterManager, &FilterManager::percent, this, &pEpAgent::emitProgress);
connect(m_filterManager, &FilterManager::progressMessage, this, &pEpAgent::emitProgressMessage);*/
/* ------------- Extending DBus functions ------------------- */
m_pEpadaptor = new PepAdaptor(this);
dbus.registerObject(QStringLiteral("/security/pep"), QStringLiteral("security.pep"), this);
dbus.registerService(service);
/* --------------------- Done ------------------------------- */
// This here is just bureaucracy:
auto *collectionMonitor = new Akonadi::Monitor(this);
collectionMonitor->setObjectName(QStringLiteral("pEpCollectionMonitor"));
collectionMonitor->fetchCollection(true);
@ -69,35 +83,8 @@ pEpAgent::pEpAgent(const QString &id)
QTimer::singleShot(0, this, &pEpAgent::initializeCollections);
qDBusRegisterMetaType<QList<qint64> >();
QDBusConnection::sessionBus().registerObject(QStringLiteral("/pEpAgent"), this, QDBusConnection::ExportAdaptors);
/*
//Enabled or not filterlogdialog
KSharedConfig::Ptr config = KSharedConfig::openConfig();
if (config->hasGroup("FilterLog")) {
KConfigGroup group(config, "FilterLog");
if (group.readEntry("Enabled", false)) {
KNotification *notify = new KNotification(QStringLiteral("mailfilterlogenabled"));
notify->setComponentName(QApplication::applicationDisplayName());
notify->setIconName(QStringLiteral("view-filter"));
notify->setText(i18nc("Notification when the filter log was enabled", "Mail Filter Log Enabled"));
notify->sendEvent();
}
}
changeRecorder()->itemFetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent);
changeRecorder()->itemFetchScope().setCacheOnly(true);
changeRecorder()->fetchCollection(true);
changeRecorder()->setChangeRecordingEnabled(false);
*/
mProgressCounter = 0;
mProgressTimer = new QTimer(this);
//connect(mProgressTimer, &QTimer::timeout, this, [this]() {
// emitProgress();
//});
auto *itemMonitor = new Akonadi::Monitor(this);
itemMonitor->setObjectName(QStringLiteral("pEpItemMonitor"));
@ -105,21 +92,8 @@ pEpAgent::pEpAgent(const QString &id)
itemMonitor->itemFetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent);
connect(itemMonitor, &Akonadi::Monitor::itemChanged, this, &pEpAgent::slotItemChanged);
//new pEpSelectJob(identifier());
// Here we spin up and connect to the pEp engine DBus service
m_pEpEngine = new QDBusInterface(
QStringLiteral("security.pep"),
QStringLiteral("/security/pep"),
QStringLiteral("security.pep"),
QDBusConnection::sessionBus()
);
}
//pEpAgent::~pEpAgent()
//{}
void pEpAgent::initializeCollections()
{
@ -173,12 +147,6 @@ void pEpAgent::itemsReceiviedForFiltering(const Akonadi::Item::List &items)
return;
}
/*Akonadi::MessageStatus status;
status.setStatusFromFlags(item.flags());
if (status.isRead() || status.isSpam() || status.isIgnored()) {
return;
}*/
QString resource = sender()->property("resource").toString();
const Akonadi::Pop3ResourceAttribute *pop3ResourceAttribute = item.attribute<Akonadi::Pop3ResourceAttribute>();
if (pop3ResourceAttribute) {
@ -186,9 +154,6 @@ void pEpAgent::itemsReceiviedForFiltering(const Akonadi::Item::List &items)
}
emitProgressMessage(i18n("Filtering in %1", Akonadi::AgentManager::self()->instance(resource).name()));
/*if (!m_filterManager->process(item, m_filterManager->requiredPart(resource), FilterManager::Inbound, true, resource)) {
qCWarning(PEPAGENT_LOG) << "Impossible to process mails";
}*/
emitProgress(++mProgressCounter);
@ -197,9 +162,6 @@ void pEpAgent::itemsReceiviedForFiltering(const Akonadi::Item::List &items)
void pEpAgent::clearMessage()
{
qCDebug(PEPAGENT_LOG) << __FUNCTION__ << " Test";
qDebug() << __FUNCTION__ << " Test";
//Q_EMIT status(AgentBase::Idle, QString("p≡p engine ready"));
}
void pEpAgent::emitStatusReady()
@ -325,20 +287,30 @@ void pEpAgent::retrieveCollections()
collectionsRetrieved(std::move(collections));
}
void pEpAgent::test(){
qDebug() << __FUNCTION__ << "Test";
}
//pEpMessage pEpAgent::decryptMessage(const KMime::Message::Ptr &value){
//pEpMessage pEpAgent::decryptMessage(QString s){
//pEpMessage* pEpAgent::decryptMessage(const KMime::Message::Ptr &value){
pEpMessage* pEpAgent::decryptMessage(const QByteArray &content)
{;
qDebug() << __FUNCTION__ << "\n" << content;
//qDebug() << m_pEpEngine->call(QStringLiteral("decrypt_message"), content);
qDebug() << m_pEpEngine->call(QStringLiteral("hello"));
pEpMessage *ret = new pEpMessage();
return ret;
int pEpAgent::decrypt_message(const QString &src, QString &dst, QStringList &keylist, int &flags)
{
qDebug() << "pEpAgent: Decrypting";
char *ms = src.toLatin1().data();
::message *m = NULL;
::message *md = malloc(sizeof(::message));
stringlist_t *kl = malloc(sizeof(stringlist_t));
PEP_decrypt_flags_t fl = 0;
bool might_be_pep = true;
::mime_decode_message( ms, src.toLatin1().size(), &m, &might_be_pep );
::decrypt_message(m_session, m, &md, &kl, &fl);
if(md) {
::mime_encode_message(md, true, &ms, true);
}
flags = fl;
dst = QLatin1String(ms);
keylist.clear();
while(kl) {
keylist << QLatin1String(kl->value);
kl = kl->next;
}
return 0;
}
AKONADI_RESOURCE_MAIN(pEpAgent)

@ -5,12 +5,20 @@
#include <KMime/Message>
#include <KJob>
#include <QSet>
#include <QTimer>
#include <QDBusInterface>
#include <AkonadiCore/AgentInstance>
#include "pepagent_p.h"
#include "pepmessage.h"
#include <pEp/pEpEngine.h>
#include <pEp/Adapter.hh>
#include <pEp/message.h>
#include <pEp/message_api.h>
#include <pEp/mime.h>
class PepAdaptor;
class pEpAgent :
public Akonadi::ResourceBase,
@ -22,10 +30,6 @@ public:
explicit pEpAgent(const QString &id);
~pEpAgent() = default;
void test();
//pEpMessage* decryptMessage(const KMime::Message::Ptr &value);
pEpMessage* decryptMessage(const QByteArray &content);
protected Q_SLOTS:
void retrieveCollections() override;
void retrieveItems(const Akonadi::Collection &col) override {};
@ -42,6 +46,9 @@ private Q_SLOTS:
void slotInstanceRemoved(const Akonadi::AgentInstance &instance);
void slotItemChanged(const Akonadi::Item &item);
public Q_SLOTS: // pEp methods
int decrypt_message(const QString &src, QString &dst, QStringList &keylist, int &flags);
private:
Q_DECLARE_PRIVATE(pEpAgent)
@ -57,8 +64,16 @@ private:
bool isFilterableCollection(const Akonadi::Collection &collection) const;
QTimer *mProgressTimer;
PepAdaptor *m_pEpadaptor;
QDBusInterface *m_pEpEngine;
int mProgressCounter;
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();
};
#endif

@ -0,0 +1,3 @@
[D-BUS Service]
Name=org.freedesktop.Akonadi.Agent.pEpAgent
Exec=/usr/bin/akonadi_pep_agent

@ -1,5 +0,0 @@
#ifndef PEP_MESSAGE_H
#define PEP_MESSAGE_H
class pEpMessage {
};
#endif

@ -1,21 +1,52 @@
#include "viewerpluginpepinterface.h"
#include <MimeTreeParser/NodeHelper>
#include <QStringLiteral>
#include <QByteArray>
#include <pEp/message.h>
using namespace MessageViewer;
void pEpViewerInterface::convert_pEpMessage_to_mMessage(message m)
void pEpViewerInterface::convert_pEpMessage_to_mMessage(message *m)
{
if(!m)
return;
mMessage->from()->from7BitString( QByteArray(m->from->address) );
mMessage->to()->from7BitString( QByteArray(m->to->ident->address) );
foreach ( KMime::Content *attachment, mMessage->contents() ) {
attachment->setContent(QByteArray("pEp"));
attachment->contentType()->setMimeType(QByteArray("text/plain"));
}
}
message* pEpViewerInterface::convert_mMessage_to_pEpMessage(PEP_msg_direction direction)
{
if(!mMessage)
return NULL;
message *m = new_message(direction);
m->from = new_identity( mMessage->from()->asUnicodeString().toLatin1().data(), "", "", "" );
m->to = identity_list_add(m->to,
new_identity( mMessage->to()->asUnicodeString().toLatin1().data(), "", "", "" )
);
foreach ( KMime::Content *attachment, mMessage->contents() ) {
m->attachments = bloblist_add(
m->attachments,
attachment->decodedContent().data(),
attachment->size(),
attachment->contentType()->mimeType().data(),
MimeTreeParser::NodeHelper::fileName(attachment).toLatin1().data()
);
}
return m;
#if 0
m.dir=0;
m.id=""; // UTF-8 string of message ID
m.shortmsg=""; // UTF-8 string of short message
m.longmsg=""; // UTF-8 string of long message (plain)
@ -35,7 +66,6 @@ message* pEpViewerInterface::convert_mMessage_to_pEpMessage(PEP_msg_direction di
pEp_identity from;
m.from=&from; // whom the message is from
m.from->address=mMessage->from()->asUnicodeString().toLatin1().data();
identity_list to;
m.to=&to; // whom the message is to
@ -69,23 +99,6 @@ message* pEpViewerInterface::convert_mMessage_to_pEpMessage(PEP_msg_direction di
// (read_only to the outside)
*/
/* QByteArray type;
QByteArray pgpText;
foreach ( KMime::Content *attachment, mMessage->contents() ) {
type = attachment->contentType()->mimeType();
if(type==QByteArray("application/octet-stream")) {
//attachment->setContent(QByteArray("pEp"));
//attachment->contentType()->setMimeType(QByteArray("text/plain"));
//mMessage->contents().removeOne(attachment);
pgpText=attachment->decodedContent();
} else if(type==QByteArray("application/pgp-encrypted")) {
//attachment->setContent(QByteArray("pEp"));
//attachment->contentType()->setMimeType(QByteArray("text/plain"));
} else {
qDebug() << type;
}
}*/
#endif
}

@ -25,7 +25,7 @@ ViewerPluginInterface *ViewerPluginpEp::createView(QWidget *parent, KActionColle
QString ViewerPluginpEp::viewerPluginName() const
{
return QStringLiteral("foo/bar");
return QStringLiteral("pEp/Security");
}
#include "viewerpluginpep.moc"

@ -19,9 +19,7 @@
#include <QColor>
#include <QStringLiteral>
#include <QByteArray>
#include <QDBusInterface>
#include <QDBusReply>
#include <QVariantList>
#include <ItemFetchJob>
#include <ItemFetchScope>
@ -36,18 +34,6 @@
#include <pEp/mime.h>
#include <pEp/message.h>
// The pEp D-Bus binding
#include <pEpDBusAdapter/pep-client.h>
DBus::BusDispatcher dispatcher;
pEp::Client *start_pEpClient()
{
DBus::default_dispatcher = &dispatcher;
DBus::Connection conn = DBus::Connection::SessionBus();
return new pEp::Client(conn, "/pep/security", "pep.security");
}
using namespace MessageViewer;
pEpViewerInterface::pEpViewerInterface(KActionCollection *ac, QWidget *parent)
@ -56,7 +42,13 @@ pEpViewerInterface::pEpViewerInterface(KActionCollection *ac, QWidget *parent)
mStatusWidget = new QWidget(parent);
mStatusWidget->setFixedHeight(20);
parent->layout()->addWidget(mStatusWidget);
m_pEpDBusAdapter = ::start_pEpClient();
m_pEpClient = new QDBusInterface(
QStringLiteral("org.freedesktop.Akonadi.Agent.pEpAgent"),
QStringLiteral("/security/pep"),
QStringLiteral("security.pep"),
QDBusConnection::sessionBus()
);
}
pEpViewerInterface::~pEpViewerInterface()
@ -78,9 +70,9 @@ bool pEpViewerInterface::isApEpMessage(KMime::Content *content)
if(content->attachments().size()) {
qDebug() << __FUNCTION__ << "Has attachments";
for(KMime::Content *c : content->attachments()) {
//if(isApEpMessage(c)) return true;
isApEpMessage(c);
}
//if(isApEpMessage(c)) return true;
isApEpMessage(c);
}
} else {
//qDebug() << content->decodedContent();
}
@ -91,43 +83,21 @@ bool pEpViewerInterface::isApEpMessage(KMime::Content *content)
return false;
}
void pEpViewerInterface::decryptMessage()
void pEpViewerInterface::setMessage(const KMime::Message::Ptr &value)
{
message *m;
QList<QVariant> args;
char *ms;
std::vector<std::string> keylist;
int flags, status, rating;
std::string src, dst;
// fill the pEp message struct and turn it into a string
m = convert_mMessage_to_pEpMessage(PEP_dir_incoming);
::mime_encode_message(m, true, &ms, true);
src = std::string(ms);
m_pEpDBusAdapter->decrypt_message(src,keylist,rating,flags,status,dst);
//convert_pEpMessage_to_mMessage(m);
//mMessage->contentType()->setMimeType(QByteArray("text/plain"));
}
void pEpViewerInterface::setMessage(const KMime::Message::Ptr &value)
{
QByteArray type;
QDBusReply<QVariant> reply;
QVariant testload = QVariant(QStringLiteral("test"));
if(value) {
qDebug() << "Set message";
mMessage = value;
type = mMessage->contentType()->mimeType();
if(type==QByteArray("multipart/mixed")) {
qDebug() << "Multipart detected";
} else if(type==QByteArray("multipart/encrypted")) {
qDebug() << "Encrypted message detected";
decryptMessage();
} else {
qDebug() << type;
m = convert_mMessage_to_pEpMessage(PEP_dir_incoming);
::mime_encode_message(m, true, &ms, true);
if(m_pEpClient->isValid()) {
auto ret = m_pEpClient->call(QStringLiteral("decrypt_message"), QLatin1String(ms));
args = ret.arguments();
qDebug() << args;
}
//value->mainBodyPart()->assemble();
//if(isApEpMessage(value->mainBodyPart())) qDebug() << "pEp message detected";
//else qDebug() << "Not a pEp message";
}
}
@ -143,6 +113,7 @@ void pEpViewerInterface::showWidget()
void pEpViewerInterface::setMessageItem(const Akonadi::Item &item)
{
qDebug() << __FUNCTION__;
mMessageItem = item;
if(item.hasPayload()) {
setMessage(item.payload<KMime::Message::Ptr>());
@ -160,7 +131,8 @@ void pEpViewerInterface::updateAction(const Akonadi::Item &item)
qDebug() << __FUNCTION__;
mMessageItem = item;
if(item.hasPayload()) {
setMessage(item.payload<KMime::Message::Ptr>());
qDebug() << __FUNCTION__;
setMessageItem(item);
}
}

@ -9,6 +9,9 @@
#include <MessageViewer/ViewerPluginInterface>
#include <QDBusInterface>
#include <QDBusReply>
#include <pEp/message.h>
class KActionCollection;
@ -39,12 +42,11 @@ public:
private:
// glue between Akonadi and pEp:
message *convert_mMessage_to_pEpMessage(PEP_msg_direction direction);
void convert_pEpMessage_to_mMessage(message m);
void decryptMessage();
void convert_pEpMessage_to_mMessage(message *m);
bool isApEpMessage(KMime::Content *c);
pEp::Client *m_pEpDBusAdapter = nullptr;
QDBusInterface *m_pEpClient = nullptr;
KMime::Message::Ptr mMessage;
Akonadi::Item mMessageItem;
QList<QAction *> mAction;

@ -1 +1 @@
Subproject commit 01707a39c235ea5f74ad2718c65dab6514548842
Subproject commit 576be0e7c253bc15e30af98f16357e79a4066c16
Loading…
Cancel
Save