File indexing completed on 2024-06-23 05:07:03
0001 /* 0002 SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "tagdeletehandler.h" 0008 0009 #include "storage/datastore.h" 0010 #include "storage/queryhelper.h" 0011 #include "storage/selectquerybuilder.h" 0012 0013 #include "private/imapset_p.h" 0014 #include "private/scope_p.h" 0015 0016 using namespace Akonadi; 0017 using namespace Akonadi::Server; 0018 0019 TagDeleteHandler::TagDeleteHandler(AkonadiServer &akonadi) 0020 : Handler(akonadi) 0021 { 0022 } 0023 0024 bool TagDeleteHandler::parseStream() 0025 { 0026 const auto &cmd = Protocol::cmdCast<Protocol::DeleteTagCommand>(m_command); 0027 0028 if (!checkScopeConstraints(cmd.tag(), Scope::Uid)) { 0029 return failureResponse(QStringLiteral("Only UID-based TAGREMOVE is supported")); 0030 } 0031 0032 SelectQueryBuilder<Tag> tagQuery; 0033 QueryHelper::setToQuery(cmd.tag().uidSet(), Tag::idFullColumnName(), tagQuery); 0034 if (!tagQuery.exec()) { 0035 return failureResponse(QStringLiteral("Failed to obtain tags")); 0036 } 0037 0038 const Tag::List tags = tagQuery.result(); 0039 0040 if (!storageBackend()->removeTags(tags)) { 0041 return failureResponse(QStringLiteral("Failed to remove tags")); 0042 } 0043 0044 return successResponse<Protocol::DeleteTagResponse>(); 0045 }