summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <dvratil@kde.org>2016-10-22 23:28:58 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-10-22 23:28:59 (GMT)
commitc4df9ce8c50f35b9ad9d5d66709c8a6c2d00a3e0 (patch)
tree9985d66946b3a6288800182e861ce9ae2b243c6f
parent78ea1208a3f008aca0cf52bc6fefb722547edae2 (diff)
Port from deprecated KIMAP::SearchJob API to KIMAP::Term API
No more deprecation warnings, neater code. Had to adapt relevant autotests a little because KIMAP::SearchJob uses different IMAP generator for the old API and the new KIMAP::Term-based API.
-rw-r--r--resources/imap/additemtask.cpp16
-rw-r--r--resources/imap/autotests/testadditemtask.cpp4
-rw-r--r--resources/imap/autotests/testchangeitemtask.cpp2
-rw-r--r--resources/imap/autotests/testmoveitemstask.cpp8
-rw-r--r--resources/imap/changeitemtask.cpp16
-rw-r--r--resources/imap/moveitemstask.cpp18
-rw-r--r--resources/imap/replacemessagejob.cpp14
-rw-r--r--resources/kolab/kolabaddtagtask.cpp14
-rw-r--r--resources/kolab/updatemessagejob.cpp3
9 files changed, 41 insertions, 54 deletions
diff --git a/resources/imap/additemtask.cpp b/resources/imap/additemtask.cpp
index cd64593..6c40b1c 100644
--- a/resources/imap/additemtask.cpp
+++ b/resources/imap/additemtask.cpp
@@ -125,16 +125,10 @@ void AddItemTask::triggerSearchJob(KIMAP::Session *session)
KIMAP::SearchJob *search = new KIMAP::SearchJob(session);
search->setUidBased(true);
- search->setSearchLogic(KIMAP::SearchJob::And);
if (!m_messageId.isEmpty()) {
- QByteArray header = "Message-ID ";
- header += m_messageId;
-
- search->addSearchCriteria(KIMAP::SearchJob::Header, header);
+ search->setTerm(KIMAP::Term(QStringLiteral("Message-ID"), QString::fromLatin1(m_messageId)));
} else {
- search->addSearchCriteria(KIMAP::SearchJob::New);
-
Akonadi::Collection c = collection();
UidNextAttribute *uidNext = c.attribute<UidNextAttribute>();
if (!uidNext) {
@@ -142,9 +136,11 @@ void AddItemTask::triggerSearchJob(KIMAP::Session *session)
search->deleteLater();
return;
}
- KIMAP::ImapInterval interval(uidNext->uidNext());
-
- search->addSearchCriteria(KIMAP::SearchJob::Uid, interval.toImapSequence());
+ search->setTerm(KIMAP::Term(KIMAP::Term::And,
+ { KIMAP::Term(KIMAP::Term::New),
+ KIMAP::Term(KIMAP::Term::Uid,
+ KIMAP::ImapSet(uidNext->uidNext(), 0))
+ }));
}
connect(search, &KJob::result,
diff --git a/resources/imap/autotests/testadditemtask.cpp b/resources/imap/autotests/testadditemtask.cpp
index b108793..4066f5e 100644
--- a/resources/imap/autotests/testadditemtask.cpp
+++ b/resources/imap/autotests/testadditemtask.cpp
@@ -83,7 +83,7 @@ private Q_SLOTS:
<< "S: A000003 OK append done"
<< "C: A000004 SELECT \"INBOX/Foo\""
<< "S: A000004 OK select done"
- << "C: A000005 UID SEARCH HEADER Message-ID <42.4242.foo@bar.org>"
+ << "C: A000005 UID SEARCH HEADER Message-ID \"<42.4242.foo@bar.org>\""
<< "S: * SEARCH 66"
<< "S: A000005 OK search done";
@@ -98,7 +98,7 @@ private Q_SLOTS:
<< "S: A000003 OK append done"
<< "C: A000004 SELECT \"INBOX/Foo\""
<< "S: A000004 OK select done"
- << "C: A000005 UID SEARCH HEADER Message-ID <42.4242.foo@bar.org>"
+ << "C: A000005 UID SEARCH HEADER Message-ID \"<42.4242.foo@bar.org>\""
<< "S: * SEARCH 65 66"
<< "S: A000005 OK search done";
callNames.clear();
diff --git a/resources/imap/autotests/testchangeitemtask.cpp b/resources/imap/autotests/testchangeitemtask.cpp
index d219854..90fb7e7 100644
--- a/resources/imap/autotests/testchangeitemtask.cpp
+++ b/resources/imap/autotests/testchangeitemtask.cpp
@@ -99,7 +99,7 @@ private Q_SLOTS:
<< "S: A000003 OK append done"
<< "C: A000004 SELECT \"INBOX/Foo\""
<< "S: A000004 OK select done"
- << "C: A000005 UID SEARCH HEADER Message-ID <42.4242.foo@bar.org>"
+ << "C: A000005 UID SEARCH HEADER Message-ID \"<42.4242.foo@bar.org>\""
<< "S: * SEARCH 65"
<< "S: A000005 OK search done"
<< "C: A000006 UID STORE 5 +FLAGS (\\Deleted)"
diff --git a/resources/imap/autotests/testmoveitemstask.cpp b/resources/imap/autotests/testmoveitemstask.cpp
index 5d414fd..08cd0bd 100644
--- a/resources/imap/autotests/testmoveitemstask.cpp
+++ b/resources/imap/autotests/testmoveitemstask.cpp
@@ -126,7 +126,7 @@ private Q_SLOTS:
<< "S: A000005 OK store done"
<< "C: A000006 SELECT \"INBOX/Bar\""
<< "S: A000006 OK select done"
- << "C: A000007 UID SEARCH (HEADER Message-ID <42.4242.foo@bar.org>)"
+ << "C: A000007 UID SEARCH HEADER Message-ID \"<42.4242.foo@bar.org>\""
<< "S: * SEARCH 65"
<< "S: A000007 OK search done";
@@ -192,7 +192,7 @@ private Q_SLOTS:
<< "S: A000005 OK store done"
<< "C: A000006 SELECT \"INBOX/Bar\""
<< "S: A000006 OK select done"
- << "C: A000007 UID SEARCH (HEADER Message-ID <42.4242.foo@bar.org>)"
+ << "C: A000007 UID SEARCH HEADER Message-ID \"<42.4242.foo@bar.org>\""
<< "S: * SEARCH 61 65"
<< "S: A000007 OK search done";
@@ -323,7 +323,7 @@ private Q_SLOTS:
<< "S: A000004 OK MOVE done"
<< "C: A000005 SELECT \"INBOX/Bar\""
<< "S: A000005 OK select done"
- << "C: A000006 UID SEARCH (HEADER Message-ID <42.4242.foo@bar.org>)"
+ << "C: A000006 UID SEARCH HEADER Message-ID \"<42.4242.foo@bar.org>\""
<< "S: * SEARCH 65"
<< "S: A000006 OK search done";
@@ -385,7 +385,7 @@ private Q_SLOTS:
<< "S: A000004 OK MOVE done"
<< "C: A000005 SELECT \"INBOX/Bar\""
<< "S: A000005 OK select done"
- << "C: A000006 UID SEARCH (HEADER Message-ID <42.4242.foo@bar.org>)"
+ << "C: A000006 UID SEARCH HEADER Message-ID \"<42.4242.foo@bar.org>\""
<< "S: * SEARCH 61 65"
<< "S: A000006 OK search done";
diff --git a/resources/imap/changeitemtask.cpp b/resources/imap/changeitemtask.cpp
index 29f1b55..2887cf1 100644
--- a/resources/imap/changeitemtask.cpp
+++ b/resources/imap/changeitemtask.cpp
@@ -191,16 +191,10 @@ void ChangeItemTask::triggerSearchJob()
KIMAP::SearchJob *search = new KIMAP::SearchJob(m_session);
search->setUidBased(true);
- search->setSearchLogic(KIMAP::SearchJob::And);
if (!m_messageId.isEmpty()) {
- QByteArray header = "Message-ID ";
- header += m_messageId;
-
- search->addSearchCriteria(KIMAP::SearchJob::Header, header);
+ search->setTerm(KIMAP::Term(QStringLiteral("Message-ID"), QString::fromLatin1(m_messageId)));
} else {
- search->addSearchCriteria(KIMAP::SearchJob::New);
-
UidNextAttribute *uidNext = item().parentCollection().attribute<UidNextAttribute>();
if (!uidNext) {
qCWarning(IMAPRESOURCE_LOG) << "Failed to determine new uid.";
@@ -208,9 +202,11 @@ void ChangeItemTask::triggerSearchJob()
search->deleteLater();
return;
}
- KIMAP::ImapInterval interval(uidNext->uidNext());
-
- search->addSearchCriteria(KIMAP::SearchJob::Uid, interval.toImapSequence());
+ search->setTerm(KIMAP::Term(KIMAP::Term::And,
+ { KIMAP::Term(KIMAP::Term::New),
+ KIMAP::Term(KIMAP::Term::Uid,
+ KIMAP::ImapSet(uidNext->uidNext(), 0))
+ }));
}
connect(search, &KIMAP::SearchJob::result, this, &ChangeItemTask::onSearchDone);
diff --git a/resources/imap/moveitemstask.cpp b/resources/imap/moveitemstask.cpp
index 405adf6..00ef8c7 100644
--- a/resources/imap/moveitemstask.cpp
+++ b/resources/imap/moveitemstask.cpp
@@ -237,17 +237,15 @@ void MoveItemsTask::onPreSearchSelectDone(KJob *job)
search->setUidBased(true);
if (!m_messageIds.isEmpty()) {
- search->setSearchLogic(KIMAP::SearchJob::Or);
-
+ QVector<KIMAP::Term> subterms;
+ subterms.reserve(m_messageIds.size());
foreach (const QByteArray &messageId, m_messageIds) {
QByteArray header = "Message-ID ";
header += messageId;
- search->addSearchCriteria(KIMAP::SearchJob::Header, header);
+ subterms << KIMAP::Term(QStringLiteral("Message-ID"), QString::fromLatin1(messageId));
}
+ search->setTerm(KIMAP::Term(KIMAP::Term::Or, subterms));
} else {
- search->setSearchLogic(KIMAP::SearchJob::And);
- search->addSearchCriteria(KIMAP::SearchJob::New);
-
Akonadi::Collection c = targetCollection();
UidNextAttribute *uidNext = c.attribute<UidNextAttribute>();
if (!uidNext) {
@@ -255,9 +253,11 @@ void MoveItemsTask::onPreSearchSelectDone(KJob *job)
search->deleteLater();
return;
}
- KIMAP::ImapInterval interval(uidNext->uidNext());
-
- search->addSearchCriteria(KIMAP::SearchJob::Uid, interval.toImapSequence());
+ search->setTerm(KIMAP::Term(KIMAP::Term::And,
+ { KIMAP::Term(KIMAP::Term::New),
+ KIMAP::Term(KIMAP::Term::Uid,
+ KIMAP::ImapSet(uidNext->uidNext(), 0))
+ }));
}
connect(search, &KIMAP::SearchJob::result, this, &MoveItemsTask::onSearchDone);
diff --git a/resources/imap/replacemessagejob.cpp b/resources/imap/replacemessagejob.cpp
index 1bc28a2..020d8be 100644
--- a/resources/imap/replacemessagejob.cpp
+++ b/resources/imap/replacemessagejob.cpp
@@ -106,16 +106,10 @@ void ReplaceMessageJob::triggerSearchJob()
KIMAP::SearchJob *search = new KIMAP::SearchJob(mSession);
search->setUidBased(true);
- search->setSearchLogic(KIMAP::SearchJob::And);
if (!mMessageId.isEmpty()) {
- QByteArray header = "Message-ID ";
- header += mMessageId;
-
- search->addSearchCriteria(KIMAP::SearchJob::Header, header);
+ search->setTerm(KIMAP::Term(QStringLiteral("Message-ID"), QString::fromLatin1(mMessageId)));
} else {
- search->addSearchCriteria(KIMAP::SearchJob::New);
-
if (mUidNext < 0) {
qCWarning(IMAPRESOURCE_LOG) << "Could not determine the UID for the newly created message on the server";
search->deleteLater();
@@ -123,7 +117,11 @@ void ReplaceMessageJob::triggerSearchJob()
emitResult();
return;
}
- search->addSearchCriteria(KIMAP::SearchJob::Uid, KIMAP::ImapInterval(mUidNext).toImapSequence());
+ search->setTerm(KIMAP::Term(KIMAP::Term::And,
+ { KIMAP::Term(KIMAP::Term::New),
+ KIMAP::Term(KIMAP::Term::Uid,
+ KIMAP::ImapSet(mUidNext, 0))
+ }));
}
connect(search, &KJob::result,
diff --git a/resources/kolab/kolabaddtagtask.cpp b/resources/kolab/kolabaddtagtask.cpp
index 7de7c4f..7f22424 100644
--- a/resources/kolab/kolabaddtagtask.cpp
+++ b/resources/kolab/kolabaddtagtask.cpp
@@ -99,16 +99,10 @@ void KolabAddTagTask::triggerSearchJob(KIMAP::Session *session)
KIMAP::SearchJob *search = new KIMAP::SearchJob(session);
search->setUidBased(true);
- search->setSearchLogic(KIMAP::SearchJob::And);
if (!mMessageId.isEmpty()) {
- QByteArray header = "Message-ID ";
- header += mMessageId;
-
- search->addSearchCriteria(KIMAP::SearchJob::Header, header);
+ search->setTerm(KIMAP::Term(QStringLiteral("Message-ID"), QString::fromLatin1(mMessageId)));
} else {
- search->addSearchCriteria(KIMAP::SearchJob::New);
-
UidNextAttribute *uidNext = relationCollection().attribute<UidNextAttribute>();
if (!uidNext) {
cancelTask(i18n("Could not determine the UID for the newly created message on the server"));
@@ -117,7 +111,11 @@ void KolabAddTagTask::triggerSearchJob(KIMAP::Session *session)
}
KIMAP::ImapInterval interval(uidNext->uidNext());
- search->addSearchCriteria(KIMAP::SearchJob::Uid, interval.toImapSequence());
+ search->setTerm(KIMAP::Term(KIMAP::Term::And,
+ { KIMAP::Term(KIMAP::Term::New),
+ KIMAP::Term(KIMAP::Term::Uid,
+ KIMAP::ImapSet(uidNext->uidNext(), 0))
+ }));
}
connect(search, &KJob::result,
diff --git a/resources/kolab/updatemessagejob.cpp b/resources/kolab/updatemessagejob.cpp
index a2226e7..382d186 100644
--- a/resources/kolab/updatemessagejob.cpp
+++ b/resources/kolab/updatemessagejob.cpp
@@ -135,8 +135,7 @@ void UpdateMessageJob::searchForLatestVersion()
{
KIMAP::SearchJob *search = new KIMAP::SearchJob(mSession);
search->setUidBased(true);
- search->setSearchLogic(KIMAP::SearchJob::And);
- search->addSearchCriteria(KIMAP::SearchJob::Header, "Subject " + mKolabUid);
+ search->setTerm(KIMAP::Term(KIMAP::Term::Subject, QString::fromLatin1(mKolabUid)));
connect(search, &KJob::result,
this, &UpdateMessageJob::onSearchDone);
search->start();