File indexing completed on 2024-05-12 05:17:22

0001 /*
0002     Copyright (c) 2009 Andras Mantia <amantia@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or modify it
0005     under the terms of the GNU Library General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or (at your
0007     option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful, but WITHOUT
0010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0012     License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to the
0016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0017     02110-1301, USA.
0018 */
0019 
0020 #include "getacljob.h"
0021 
0022 #include "kimap_debug.h"
0023 
0024 #include "acljobbase_p.h"
0025 #include "message_p.h"
0026 #include "session_p.h"
0027 #include "rfccodecs.h"
0028 
0029 namespace KIMAP2
0030 {
0031 class GetAclJobPrivate : public AclJobBasePrivate
0032 {
0033 public:
0034     GetAclJobPrivate(Session *session, const QString &name) : AclJobBasePrivate(session, name) {}
0035     ~GetAclJobPrivate() { }
0036 
0037     QMap<QByteArray, Acl::Rights> userRights;
0038 };
0039 }
0040 
0041 using namespace KIMAP2;
0042 
0043 GetAclJob::GetAclJob(Session *session)
0044     : AclJobBase(*new GetAclJobPrivate(session, "GetAcl"))
0045 {
0046 }
0047 
0048 GetAclJob::~GetAclJob()
0049 {
0050 }
0051 
0052 void GetAclJob::doStart()
0053 {
0054     Q_D(GetAclJob);
0055 
0056     d->sendCommand("GETACL", '\"' + KIMAP2::encodeImapFolderName(d->mailBox.toUtf8()) + '\"');
0057 }
0058 
0059 void GetAclJob::handleResponse(const Message &response)
0060 {
0061     Q_D(GetAclJob);
0062 //   qCDebug(KIMAP2_LOG) << response.toString();
0063 
0064     if (handleErrorReplies(response) == NotHandled) {
0065         if (response.content.size() >= 4 &&
0066                 response.content[1].toString() == "ACL") {
0067             int i = 3;
0068             while (i < response.content.size() - 1) {
0069                 QByteArray id = response.content[i].toString();
0070                 QByteArray rights = response.content[i + 1].toString();
0071                 d->userRights[id] = Acl::rightsFromString(rights);
0072                 i += 2;
0073             }
0074         }
0075     }
0076 }
0077 
0078 QList<QByteArray> GetAclJob::identifiers() const
0079 {
0080     Q_D(const GetAclJob);
0081     return d->userRights.keys();
0082 }
0083 
0084 bool GetAclJob::hasRightEnabled(const QByteArray &identifier, Acl::Right right) const
0085 {
0086     Q_D(const GetAclJob);
0087     if (d->userRights.contains(identifier)) {
0088         Acl::Rights rights = d->userRights[identifier];
0089         return rights & right;
0090     }
0091 
0092     return false;
0093 }
0094 
0095 Acl::Rights GetAclJob::rights(const QByteArray &identifier) const
0096 {
0097     Q_D(const GetAclJob);
0098     Acl::Rights result;
0099     if (d->userRights.contains(identifier)) {
0100         result = d->userRights[identifier];
0101     }
0102     return result;
0103 }
0104 
0105 QMap<QByteArray, Acl::Rights> GetAclJob::allRights() const
0106 {
0107     Q_D(const GetAclJob);
0108     return d->userRights;
0109 }