File indexing completed on 2024-11-10 04:40:28

0001 /*
0002     SPDX-FileCopyrightText: 2010 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "indexpolicyattribute.h"
0008 
0009 #include "private/imapparser_p.h"
0010 
0011 using namespace Akonadi;
0012 
0013 class Akonadi::IndexPolicyAttributePrivate
0014 {
0015 public:
0016     bool enable = true;
0017 };
0018 
0019 IndexPolicyAttribute::IndexPolicyAttribute()
0020     : d(new IndexPolicyAttributePrivate())
0021 {
0022 }
0023 
0024 IndexPolicyAttribute::~IndexPolicyAttribute() = default;
0025 
0026 bool IndexPolicyAttribute::indexingEnabled() const
0027 {
0028     return d->enable;
0029 }
0030 
0031 void IndexPolicyAttribute::setIndexingEnabled(bool enable)
0032 {
0033     d->enable = enable;
0034 }
0035 
0036 QByteArray IndexPolicyAttribute::type() const
0037 {
0038     static const QByteArray sType("INDEXPOLICY");
0039     return sType;
0040 }
0041 
0042 Attribute *IndexPolicyAttribute::clone() const
0043 {
0044     auto attr = new IndexPolicyAttribute;
0045     attr->setIndexingEnabled(indexingEnabled());
0046     return attr;
0047 }
0048 
0049 QByteArray IndexPolicyAttribute::serialized() const
0050 {
0051     QList<QByteArray> l;
0052     l.reserve(2);
0053     l.append("ENABLE");
0054     l.append(d->enable ? "true" : "false");
0055     return "(" + ImapParser::join(l, " ") + ')'; // krazy:exclude=doublequote_chars
0056 }
0057 
0058 void IndexPolicyAttribute::deserialize(const QByteArray &data)
0059 {
0060     QList<QByteArray> l;
0061     ImapParser::parseParenthesizedList(data, l);
0062     for (int i = 0; i < l.size() - 1; i += 2) {
0063         const QByteArray &key = l.at(i);
0064         if (key == "ENABLE") {
0065             d->enable = l.at(i + 1) == "true";
0066         }
0067     }
0068 }