Commit a654faad authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

IMAP: port to new KIMAP API

Connect to the new FetchJob signal. It allows us to use new
connect syntax, and it's faster, because we don't have to do
any QMap lookups.
parent 87605e14
......@@ -71,7 +71,7 @@ set(IDENTITYMANAGEMENT_LIB_VERSION "5.5.40")
set(KMAILTRANSPORT_LIB_VERSION "5.5.40")
set(CALENDARUTILS_LIB_VERSION "5.5.40")
set(KDAV_LIB_VERSION "5.5.40")
set(KIMAP_LIB_VERSION "5.5.40")
set(KIMAP_LIB_VERSION "5.5.61")
set(KMBOX_LIB_VERSION "5.5.40")
set(AKONADICALENDAR_LIB_VERSION "5.5.40")
set(KONTACTINTERFACE_LIB_VERSION "5.5.40")
......
......@@ -169,39 +169,25 @@ void BatchFetcher::fetchNextBatch()
fetch->setUidBased(m_uidBased);
fetch->setScope(m_scope);
fetch->setGmailExtensionsEnabled(m_gmailEnabled);
connect(fetch, SIGNAL(headersReceived(QString,
QMap<qint64, qint64>,
QMap<qint64, qint64>,
QMap<qint64, KIMAP::MessageAttribute>,
QMap<qint64, KIMAP::MessageFlags>,
QMap<qint64, KIMAP::MessagePtr>)),
this, SLOT(onHeadersReceived(QString,
QMap<qint64, qint64>,
QMap<qint64, qint64>,
QMap<qint64, KIMAP::MessageAttribute>,
QMap<qint64, KIMAP::MessageFlags>,
QMap<qint64, KIMAP::MessagePtr>)));
connect(fetch, &KIMAP::FetchJob::messagesAvailable,
this, &BatchFetcher::onMessagesAvailable);
connect(fetch, &KJob::result,
this, &BatchFetcher::onHeadersFetchDone);
m_fetchInProgress = true;
fetch->start();
}
void BatchFetcher::onHeadersReceived(const QString &mailBox,
const QMap<qint64, qint64> &uids,
const QMap<qint64, qint64> &sizes,
const QMap<qint64, KIMAP::MessageAttribute> &attrs,
const QMap<qint64, KIMAP::MessageFlags> &flags,
const QMap<qint64, KIMAP::MessagePtr> &messages)
void BatchFetcher::onMessagesAvailable(const QMap<qint64, KIMAP::Message> &messages)
{
Q_UNUSED(mailBox);
KIMAP::FetchJob *fetch = static_cast<KIMAP::FetchJob *>(sender());
Akonadi::Item::List addedItems;
foreach (qint64 number, uids.keys()) { //krazy:exclude=foreach
for (auto msg = messages.cbegin(), end = messages.cend(); msg != end; ++msg) {
//qDebug( 5327 ) << "Flags: " << i.flags();
bool ok;
const Akonadi::Item item = m_messageHelper->createItemFromMessage(messages[number], uids[number], sizes[number], attrs.values(number), flags[number], fetch->scope(), ok);
const auto item = m_messageHelper->createItemFromMessage(
msg->message, msg->uid, msg->size, msg->attributes,
msg->flags, fetch->scope(), ok);
if (ok) {
m_fetchedItemsInCurrentBatch++;
addedItems << item;
......
......@@ -51,12 +51,7 @@ Q_SIGNALS:
void itemsRetrieved(const Akonadi::Item::List &);
private Q_SLOTS:
void onHeadersReceived(const QString &mailBox,
const QMap<qint64, qint64> &uids,
const QMap<qint64, qint64> &sizes,
const QMap<qint64, KIMAP::MessageAttribute> &attrs,
const QMap<qint64, KIMAP::MessageFlags> &flags,
const QMap<qint64, KIMAP::MessagePtr> &messages);
void onMessagesAvailable(const QMap<qint64, KIMAP::Message> &messages);
void onHeadersFetchDone(KJob *job);
void onUidSearchDone(KJob *job);
......
......@@ -126,6 +126,7 @@ ImapResourceBase::ImapResourceBase(const QString &id)
changeRecorder()->fetchCollection(true);
changeRecorder()->collectionFetchScope().setAncestorRetrieval(CollectionFetchScope::All);
changeRecorder()->collectionFetchScope().setIncludeStatistics(true);
changeRecorder()->collectionFetchScope().fetchAttribute<CollectionAnnotationsAttribute>();
changeRecorder()->itemFetchScope().fetchFullPayload(true);
changeRecorder()->itemFetchScope().setAncestorRetrieval(ItemFetchScope::All);
changeRecorder()->itemFetchScope().setFetchModificationTime(false);
......
......@@ -32,7 +32,7 @@ MessageHelper::~MessageHelper()
Akonadi::Item MessageHelper::createItemFromMessage(const KMime::Message::Ptr &message,
const qint64 uid,
const qint64 size,
const QList<KIMAP::MessageAttribute> &attrs,
const QMap<QByteArray, QVariant> &attrs,
const QList<QByteArray> &flags,
const KIMAP::FetchJob::FetchScope &scope,
bool &ok) const
......
......@@ -33,7 +33,7 @@ public:
virtual Akonadi::Item createItemFromMessage(const KMime::Message::Ptr &message,
const qint64 uid,
const qint64 size,
const QList<KIMAP::MessageAttribute> &attrs,
const QMap<QByteArray, QVariant> &attrs,
const QList<QByteArray> &flags,
const KIMAP::FetchJob::FetchScope &scope,
bool &ok) const;
......
......@@ -82,14 +82,8 @@ void RetrieveItemTask::triggerFetchJob()
scope.parts.clear();// = parts.toList();
scope.mode = KIMAP::FetchJob::FetchScope::Content;
fetch->setScope(scope);
connect(fetch, SIGNAL(messagesReceived(QString,
QMap<qint64, qint64>,
QMap<qint64, KIMAP::MessageAttribute>,
QMap<qint64, KIMAP::MessagePtr>)),
this, SLOT(onMessagesReceived(QString,
QMap<qint64, qint64>,
QMap<qint64, KIMAP::MessageAttribute>,
QMap<qint64, KIMAP::MessagePtr>)));
connect(fetch, &KIMAP::FetchJob::messagesAvailable,
this, &RetrieveItemTask::onMessagesReceived);
//TODO: Handle parts retrieval
//connect( fetch, SIGNAL(partsReceived(QString,QMap<qint64,qint64>,QMap<qint64,KIMAP::MessageParts>)),
// this, SLOT(onPartsReceived(QString,QMap<qint64,qint64>,QMap<qint64,KIMAP::MessageParts>)) );
......@@ -98,16 +92,10 @@ void RetrieveItemTask::triggerFetchJob()
fetch->start();
}
void RetrieveItemTask::onMessagesReceived(const QString &mailBox,
const QMap<qint64, qint64> &uids,
const QMap<qint64, KIMAP::MessageAttribute> &attrs,
const QMap<qint64, KIMAP::MessagePtr> &messages)
void RetrieveItemTask::onMessagesReceived(const QMap<qint64, KIMAP::Message> &messages)
{
Q_UNUSED(mailBox);
KIMAP::FetchJob *fetch = qobject_cast<KIMAP::FetchJob *>(sender());
Q_ASSERT(fetch != nullptr);
Q_ASSERT(uids.size() == 1);
Q_ASSERT(messages.size() == 1);
Akonadi::Item i = item();
......@@ -115,11 +103,13 @@ void RetrieveItemTask::onMessagesReceived(const QString &mailBox,
qCDebug(IMAPRESOURCE_LOG) << "MESSAGE from Imap server" << item().remoteId();
Q_ASSERT(item().isValid());
const qint64 number = uids.cbegin().key();
const auto message = messages.cbegin();
const qint64 number = message->uid;
bool ok;
const Akonadi::Item remoteItem = resourceState()->messageHelper()->createItemFromMessage(messages[number], uids[number], 0, attrs.values(number), QList<QByteArray>(), fetch->scope(), ok);
const Akonadi::Item remoteItem = resourceState()->messageHelper()->createItemFromMessage(
message->message, message->uid, 0, message->attributes, {}, fetch->scope(), ok);
if (!ok) {
qCWarning(IMAPRESOURCE_LOG) << "Failed to retrieve message " << uids[number];
qCWarning(IMAPRESOURCE_LOG) << "Failed to retrieve message " << message->uid;
cancelTask(i18n("No message retrieved, failed to read the message."));
return;
}
......
......@@ -36,10 +36,7 @@ public:
private Q_SLOTS:
void onSelectDone(KJob *job);
void onMessagesReceived(const QString &mailBox,
const QMap<qint64, qint64> &uids,
const QMap<qint64, KIMAP::MessageAttribute> &attrs,
const QMap<qint64, KIMAP::MessagePtr> &messages);
void onMessagesReceived(const QMap<qint64, KIMAP::Message> &messages);
void onContentFetchDone(KJob *job);
protected:
......
......@@ -72,50 +72,30 @@ void KolabRetrieveTagTask::onFinalSelectDone(KJob *job)
scope.parts.clear();
scope.mode = KIMAP::FetchJob::FetchScope::Full;
fetch->setScope(scope);
connect(fetch, SIGNAL(headersReceived(QString,
QMap<qint64, qint64>,
QMap<qint64, qint64>,
QMap<qint64, KIMAP::MessageAttribute>,
QMap<qint64, KIMAP::MessageFlags>,
QMap<qint64, KIMAP::MessagePtr>)),
this, SLOT(onHeadersReceived(QString,
QMap<qint64, qint64>,
QMap<qint64, qint64>,
QMap<qint64, KIMAP::MessageAttribute>,
QMap<qint64, KIMAP::MessageFlags>,
QMap<qint64, KIMAP::MessagePtr>)));
connect(fetch, &KIMAP::FetchJob::messagesAvailable,
this, &KolabRetrieveTagTask::onMessagesAvailable);
connect(fetch, &KJob::result,
this, &KolabRetrieveTagTask::onHeadersFetchDone);
fetch->start();
}
void KolabRetrieveTagTask::onHeadersReceived(const QString &mailBox,
const QMap<qint64, qint64> &uids,
const QMap<qint64, qint64> &sizes,
const QMap<qint64, KIMAP::MessageAttribute> &attrs,
const QMap<qint64, KIMAP::MessageFlags> &flags,
const QMap<qint64, KIMAP::MessagePtr> &messages)
void KolabRetrieveTagTask::onHeadersReceived(const QMap<qint64, KIMAP::Message> &messages)
{
Q_UNUSED(mailBox);
Q_UNUSED(sizes);
Q_UNUSED(attrs);
KIMAP::FetchJob *fetch = static_cast<KIMAP::FetchJob *>(sender());
Q_ASSERT(fetch);
foreach (qint64 number, uids.keys()) { //krazy:exclude=foreach
if (flags[number].contains(ImapFlags::Deleted)) {
for (auto it = messages.cbegin(), end = messages.cend(); it != end; ++it) {
if (it->flags.contains(ImapFlags::Deleted)) {
continue;
}
const KMime::Message::Ptr msg = messages[number];
const KMime::Message::Ptr msg = it->message;
const Kolab::KolabObjectReader reader(msg);
switch (reader.getType()) {
case Kolab::RelationConfigurationObject:
if (mRetrieveType == RetrieveTags && reader.isTag()) {
extractTag(reader, uids[number]);
extractTag(reader, it->uid);
} else if (mRetrieveType == RetrieveRelations && reader.isRelation()) {
extractRelation(reader, uids[number]);
extractRelation(reader, it->uid);
}
break;
......
......@@ -52,12 +52,7 @@ private:
private Q_SLOTS:
void onFinalSelectDone(KJob *job);
void onHeadersReceived(const QString &mailBox,
const QMap<qint64, qint64> &uids,
const QMap<qint64, qint64> &sizes,
const QMap<qint64, KIMAP::MessageAttribute> &attrs,
const QMap<qint64, KIMAP::MessageFlags> &flags,
const QMap<qint64, KIMAP::MessagePtr> &messages);
void onMessagesAvailable(const QMap<qint64, KIMAP::Message> &messages);
void onHeadersFetchDone(KJob *job);
private:
......
......@@ -83,37 +83,21 @@ void UpdateMessageJob::fetchHeaders()
scope.parts.clear();
scope.mode = KIMAP::FetchJob::FetchScope::Headers;
fetchJob->setScope(scope);
connect(fetchJob, SIGNAL(headersReceived(QString,
QMap<qint64, qint64>,
QMap<qint64, qint64>,
QMap<qint64, KIMAP::MessageAttribute>,
QMap<qint64, KIMAP::MessageFlags>,
QMap<qint64, KIMAP::MessagePtr>)),
this, SLOT(onHeadersReceived(QString,
QMap<qint64, qint64>,
QMap<qint64, qint64>,
QMap<qint64, KIMAP::MessageAttribute>,
QMap<qint64, KIMAP::MessageFlags>,
QMap<qint64, KIMAP::MessagePtr>)));
connect(fetchJob, &KIMAP::FetchJob::messagesAvailable,
this, &UpdateMessageJob::onMessagesAvailable);
connect(fetchJob, &KJob::result,
this, &UpdateMessageJob::onHeadersFetchDone);
fetchJob->start();
}
void UpdateMessageJob::onHeadersReceived(const QString &,
const QMap<qint64, qint64> &uids,
const QMap<qint64, qint64> &,
const QMap<qint64, KIMAP::MessageAttribute> &,
const QMap<qint64, KIMAP::MessageFlags> &flags,
const QMap<qint64, KIMAP::MessagePtr> &)
void UpdateMessageJob::onMessagesAvailable(const QMap<qint64, KIMAP::Message> &messages)
{
//Filter deleted messages
foreach (qint64 number, uids.keys()) { //krazy:exclude=foreach
for (auto it = messages.cbegin(), end = messages.cend(); it != end; ++it) {
// const KMime::Message::Ptr msg = messages[number];
if (!flags[number].contains(ImapFlags::Deleted)) {
mFoundUids << uids[number];
if (!it->flags.contains(ImapFlags::Deleted)) {
mFoundUids = it->uid;
}
}
}
......@@ -166,19 +150,8 @@ void UpdateMessageJob::onSearchDone(KJob *job)
scope.parts.clear();
scope.mode = KIMAP::FetchJob::FetchScope::Full;
fetchJob->setScope(scope);
connect(fetchJob, SIGNAL(headersReceived(QString,
QMap<qint64, qint64>,
QMap<qint64, qint64>,
QMap<qint64, KIMAP::MessageAttribute>,
QMap<qint64, KIMAP::MessageFlags>,
QMap<qint64, KIMAP::MessagePtr>)),
this, SLOT(onConflictingMessagesReceived(QString,
QMap<qint64, qint64>,
QMap<qint64, qint64>,
QMap<qint64, KIMAP::MessageAttribute>,
QMap<qint64, KIMAP::MessageFlags>,
QMap<qint64, KIMAP::MessagePtr>)));
connect(fetchJob, &KIMAP::FetchJob::messagesAvailable,
this, &UpdateMessageJob::onConflictingMessagesReceived);
connect(fetchJob, &KJob::result,
this, &UpdateMessageJob::onConflictingMessageFetchDone);
fetchJob->start();
......@@ -188,16 +161,11 @@ void UpdateMessageJob::onSearchDone(KJob *job)
}
}
void UpdateMessageJob::onConflictingMessagesReceived(const QString &,
const QMap<qint64, qint64> &uids,
const QMap<qint64, qint64> &,
const QMap<qint64, KIMAP::MessageAttribute> &,
const QMap<qint64, KIMAP::MessageFlags> &flags,
const QMap<qint64, KIMAP::MessagePtr> &messages)
void UpdateMessageJob::onConflictingMessagesReceived(const QMap<qint64, KIMAP::Message> &messages)
{
foreach (qint64 number, uids.keys()) { //krazy:exclude=foreach
if (!flags[number].contains(ImapFlags::Deleted)) {
mMessagesToMerge << messages[number];
for (auto it = messages.cbegin(), end = messages.cend(); it != end; ++it) {
if (!it->flags.contains(ImapFlags::Deleted)) {
mMessagesToMerge << it->message;
}
}
}
......
......@@ -49,21 +49,11 @@ private:
void appendMessage();
private Q_SLOTS:
void onHeadersReceived(const QString &,
const QMap<qint64, qint64> &uids,
const QMap<qint64, qint64> &,
const QMap<qint64, KIMAP::MessageAttribute> &,
const QMap<qint64, KIMAP::MessageFlags> &,
const QMap<qint64, KIMAP::MessagePtr> &);
void onMessagesAvailable(const QMap<qint64, KIMAP::Message> &messages);
void onHeadersFetchDone(KJob *job);
void onSelectDone(KJob *job);
void onSearchDone(KJob *job);
void onConflictingMessagesReceived(const QString &,
const QMap<qint64, qint64> &uids,
const QMap<qint64, qint64> &,
const QMap<qint64, KIMAP::MessageAttribute> &,
const QMap<qint64, KIMAP::MessageFlags> &,
const QMap<qint64, KIMAP::MessagePtr> &);
void onConflictingMessagesReceived(const QMap<qint64, KIMAP::Message> &message_;
void onConflictingMessageFetchDone(KJob *job);
void onReplaceDone(KJob *job);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment