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

0001 /*
0002     SPDX-FileCopyrightText: 2014 Christian Mollekopf <mollekopf@kolabsys.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "collectionidentificationattribute.h"
0008 
0009 #include "private/imapparser_p.h"
0010 
0011 #include <QByteArray>
0012 #include <QList>
0013 
0014 using namespace Akonadi;
0015 
0016 class Akonadi::CollectionIdentificationAttributePrivate
0017 {
0018 public:
0019     QByteArray mFolderNamespace;
0020     QByteArray mIdentifier;
0021     QByteArray mName;
0022     QByteArray mOrganizationUnit;
0023     QByteArray mMail;
0024 };
0025 
0026 CollectionIdentificationAttribute::CollectionIdentificationAttribute(const QByteArray &identifier,
0027                                                                      const QByteArray &folderNamespace,
0028                                                                      const QByteArray &name,
0029                                                                      const QByteArray &organizationUnit,
0030                                                                      const QByteArray &mail)
0031     : d(new CollectionIdentificationAttributePrivate())
0032 {
0033     d->mIdentifier = identifier;
0034     d->mFolderNamespace = folderNamespace;
0035     d->mName = name;
0036     d->mOrganizationUnit = organizationUnit;
0037     d->mMail = mail;
0038 }
0039 
0040 CollectionIdentificationAttribute::~CollectionIdentificationAttribute() = default;
0041 
0042 void CollectionIdentificationAttribute::setIdentifier(const QByteArray &identifier)
0043 {
0044     d->mIdentifier = identifier;
0045 }
0046 
0047 QByteArray CollectionIdentificationAttribute::identifier() const
0048 {
0049     return d->mIdentifier;
0050 }
0051 
0052 void CollectionIdentificationAttribute::setMail(const QByteArray &mail)
0053 {
0054     d->mMail = mail;
0055 }
0056 
0057 QByteArray CollectionIdentificationAttribute::mail() const
0058 {
0059     return d->mMail;
0060 }
0061 
0062 void CollectionIdentificationAttribute::setOu(const QByteArray &ou)
0063 {
0064     d->mOrganizationUnit = ou;
0065 }
0066 
0067 QByteArray CollectionIdentificationAttribute::ou() const
0068 {
0069     return d->mOrganizationUnit;
0070 }
0071 
0072 void CollectionIdentificationAttribute::setName(const QByteArray &name)
0073 {
0074     d->mName = name;
0075 }
0076 
0077 QByteArray CollectionIdentificationAttribute::name() const
0078 {
0079     return d->mName;
0080 }
0081 
0082 void CollectionIdentificationAttribute::setCollectionNamespace(const QByteArray &ns)
0083 {
0084     d->mFolderNamespace = ns;
0085 }
0086 
0087 QByteArray CollectionIdentificationAttribute::collectionNamespace() const
0088 {
0089     return d->mFolderNamespace;
0090 }
0091 
0092 QByteArray CollectionIdentificationAttribute::type() const
0093 {
0094     return QByteArrayLiteral("collectionidentification");
0095 }
0096 
0097 Akonadi::Attribute *CollectionIdentificationAttribute::clone() const
0098 {
0099     return new CollectionIdentificationAttribute(d->mIdentifier, d->mFolderNamespace, d->mName, d->mOrganizationUnit, d->mMail);
0100 }
0101 
0102 QByteArray CollectionIdentificationAttribute::serialized() const
0103 {
0104     QList<QByteArray> l;
0105     l << Akonadi::ImapParser::quote(d->mIdentifier);
0106     l << Akonadi::ImapParser::quote(d->mFolderNamespace);
0107     l << Akonadi::ImapParser::quote(d->mName);
0108     l << Akonadi::ImapParser::quote(d->mOrganizationUnit);
0109     l << Akonadi::ImapParser::quote(d->mMail);
0110     return '(' + Akonadi::ImapParser::join(l, " ") + ')';
0111 }
0112 
0113 void CollectionIdentificationAttribute::deserialize(const QByteArray &data)
0114 {
0115     QList<QByteArray> l;
0116     Akonadi::ImapParser::parseParenthesizedList(data, l);
0117     const int size = l.size();
0118     Q_ASSERT(size >= 2);
0119     if (size < 2) {
0120         return;
0121     }
0122     d->mIdentifier = l[0];
0123     d->mFolderNamespace = l[1];
0124 
0125     if (size == 5) {
0126         d->mName = l[2];
0127         d->mOrganizationUnit = l[3];
0128         d->mMail = l[4];
0129     }
0130 }