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