File indexing completed on 2025-01-05 04:47:01

0001 /*
0002     SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "queryhelper.h"
0008 
0009 #include "storage/querybuilder.h"
0010 
0011 #include "private/imapset_p.h"
0012 
0013 using namespace Akonadi;
0014 using namespace Akonadi::Server;
0015 
0016 void QueryHelper::setToQuery(const ImapSet &set, const QString &column, QueryBuilder &qb)
0017 {
0018     auto newSet = set;
0019     newSet.optimize();
0020     Query::Condition cond(Query::Or);
0021     const auto intervals = newSet.intervals();
0022     for (const ImapInterval &i : intervals) {
0023         if (i.hasDefinedBegin() && i.hasDefinedEnd()) {
0024             if (i.size() == 1) {
0025                 cond.addValueCondition(column, Query::Equals, i.begin());
0026             } else {
0027                 if (i.begin() != 1) { // 1 is our standard lower bound, so we don't have to check for it explicitly
0028                     Query::Condition subCond(Query::And);
0029                     subCond.addValueCondition(column, Query::GreaterOrEqual, i.begin());
0030                     subCond.addValueCondition(column, Query::LessOrEqual, i.end());
0031                     cond.addCondition(subCond);
0032                 } else {
0033                     cond.addValueCondition(column, Query::LessOrEqual, i.end());
0034                 }
0035             }
0036         } else if (i.hasDefinedBegin()) {
0037             if (i.begin() != 1) { // 1 is our standard lower bound, so we don't have to check for it explicitly
0038                 cond.addValueCondition(column, Query::GreaterOrEqual, i.begin());
0039             }
0040         } else if (i.hasDefinedEnd()) {
0041             cond.addValueCondition(column, Query::LessOrEqual, i.end());
0042         }
0043     }
0044     if (!cond.isEmpty()) {
0045         qb.addCondition(cond);
0046     }
0047 }