summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-25 10:20:51 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-25 10:20:51 +0200
commit76892330fbf737cbdb09dc7bc4099418fc4cd1cc (patch)
tree204b3d3067caa88869e3a6ff0ae811b1ec2416a9
parent39a20d8ce774f94f22009d4e571bfa39ba087f3b (diff)
downloadsink-76892330fbf737cbdb09dc7bc4099418fc4cd1cc.tar.gz
sink-76892330fbf737cbdb09dc7bc4099418fc4cd1cc.zip
Convenience fetch overload
-rw-r--r--examples/imapresource/imapserverproxy.cpp34
-rw-r--r--examples/imapresource/imapserverproxy.h1
2 files changed, 19 insertions, 16 deletions
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp
index dfb134c..58d2772 100644
--- a/examples/imapresource/imapserverproxy.cpp
+++ b/examples/imapresource/imapserverproxy.cpp
@@ -142,6 +142,23 @@ KAsync::Job<void> ImapServerProxy::fetch(const KIMAP::ImapSet &set, KIMAP::Fetch
142 return runJob(fetch); 142 return runJob(fetch);
143} 143}
144 144
145KAsync::Job<void> ImapServerProxy::fetch(const KIMAP::ImapSet &set, KIMAP::FetchJob::FetchScope scope, const std::function<void(const QVector<Message> &)> &callback)
146{
147 return fetch(set, scope,
148 [callback](const QString &mailbox,
149 const QMap<qint64,qint64> &uids,
150 const QMap<qint64,qint64> &sizes,
151 const QMap<qint64,KIMAP::MessageAttribute> &attrs,
152 const QMap<qint64,KIMAP::MessageFlags> &flags,
153 const QMap<qint64,KIMAP::MessagePtr> &messages) {
154 QVector<Message> list;
155 for (const auto &id : uids.keys()) {
156 list << Message{uids.value(id), sizes.value(id), attrs.value(id), flags.value(id), messages.value(id)};
157 }
158 callback(list);
159 });
160}
161
145KAsync::Job<QList<qint64>> ImapServerProxy::fetchHeaders(const QString &mailbox) 162KAsync::Job<QList<qint64>> ImapServerProxy::fetchHeaders(const QString &mailbox)
146{ 163{
147 auto list = QSharedPointer<QList<qint64>>::create(); 164 auto list = QSharedPointer<QList<qint64>>::create();
@@ -230,22 +247,7 @@ KAsync::Future<void> ImapServerProxy::fetchMessages(const Folder &folder, std::f
230 247
231 KIMAP::ImapSet set; 248 KIMAP::ImapSet set;
232 set.add(uidsToFetch.toVector()); 249 set.add(uidsToFetch.toVector());
233 return fetch(set, scope, 250 return fetch(set, scope, callback);
234 [callback](const QString &mailbox,
235 const QMap<qint64,qint64> &uids,
236 const QMap<qint64,qint64> &sizes,
237 const QMap<qint64,KIMAP::MessageAttribute> &attrs,
238 const QMap<qint64,KIMAP::MessageFlags> &flags,
239 const QMap<qint64,KIMAP::MessagePtr> &messages) {
240 Trace() << "Received " << uids.size() << " messages from " << mailbox;
241 Trace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size();
242
243 QVector<Message> list;
244 for (const auto &id : uids.keys()) {
245 list << Message{uids.value(id), sizes.value(id), attrs.value(id), flags.value(id), messages.value(id)};
246 }
247 callback(list);
248 });
249 }); 251 });
250 252
251 }); 253 });
diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h
index 7000c67..a5a1296 100644
--- a/examples/imapresource/imapserverproxy.h
+++ b/examples/imapresource/imapserverproxy.h
@@ -80,6 +80,7 @@ public:
80 const QMap<qint64,KIMAP::MessagePtr> &)> FetchCallback; 80 const QMap<qint64,KIMAP::MessagePtr> &)> FetchCallback;
81 81
82 KAsync::Job<void> fetch(const KIMAP::ImapSet &set, KIMAP::FetchJob::FetchScope scope, FetchCallback callback); 82 KAsync::Job<void> fetch(const KIMAP::ImapSet &set, KIMAP::FetchJob::FetchScope scope, FetchCallback callback);
83 KAsync::Job<void> fetch(const KIMAP::ImapSet &set, KIMAP::FetchJob::FetchScope scope, const std::function<void(const QVector<Message> &)> &callback);
83 KAsync::Job<void> list(KIMAP::ListJob::Option option, const std::function<void(const QList<KIMAP::MailBoxDescriptor> &mailboxes,const QList<QList<QByteArray> > &flags)> &callback); 84 KAsync::Job<void> list(KIMAP::ListJob::Option option, const std::function<void(const QList<KIMAP::MailBoxDescriptor> &mailboxes,const QList<QList<QByteArray> > &flags)> &callback);
84 85
85 //Composed calls that do login etc. 86 //Composed calls that do login etc.