1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
/*
* SPDX-FileCopyrightText: 2014 Christian Mollekopf <mollekopf@kolabsys.com>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
*/
#pragma once
#include <KIMAP/FetchJob>
#include <KIMAP/SearchJob>
#include <KJob>
#include "messagehelper.h"
/**
* A job that retrieves a set of messages in reverse-ordered batches.
* After each batch fetchNextBatch() needs to be called (for throttling the download speed)
*/
class BatchFetcher : public KJob
{
Q_OBJECT
public:
BatchFetcher(MessageHelper::Ptr messageHelper, const KIMAP::ImapSet &set, const KIMAP::FetchJob::FetchScope &scope, int batchSize, KIMAP::Session *session);
~BatchFetcher() override;
void start() override;
void fetchNextBatch();
void setUidBased(bool);
void setSearchUids(const KIMAP::ImapInterval &interval);
void setGmailExtensionsEnabled(bool enable);
Q_SIGNALS:
void itemsRetrieved(const Akonadi::Item::List &);
private Q_SLOTS:
void onMessagesAvailable(const QMap<qint64, KIMAP::Message> &messages);
void onHeadersFetchDone(KJob *job);
void onUidSearchDone(KJob *job);
private:
// Batch fetching
KIMAP::ImapSet m_currentSet;
const KIMAP::FetchJob::FetchScope m_scope;
KIMAP::Session *const m_session;
const int m_batchSize;
bool m_uidBased = false;
int m_fetchedItemsInCurrentBatch = 0;
const MessageHelper::Ptr m_messageHelper;
bool m_fetchInProgress = false;
bool m_continuationRequested = false;
KIMAP::ImapInterval m_searchUidInterval;
bool m_gmailEnabled = false;
bool m_searchInChunks = false;
};
|