File indexing completed on 2024-05-12 05:17:13
0001 /* 0002 SPDX-FileCopyrightText: 2009 Andras Mantia <amantia@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "getacljob.h" 0008 0009 #include "kimap_debug.h" 0010 #include <KLocalizedString> 0011 0012 #include "acljobbase_p.h" 0013 #include "response_p.h" 0014 #include "rfccodecs.h" 0015 #include "session_p.h" 0016 0017 namespace KIMAP 0018 { 0019 class GetAclJobPrivate : public AclJobBasePrivate 0020 { 0021 public: 0022 GetAclJobPrivate(Session *session, const QString &name) 0023 : AclJobBasePrivate(session, name) 0024 { 0025 } 0026 ~GetAclJobPrivate() 0027 { 0028 } 0029 0030 QMap<QByteArray, Acl::Rights> userRights; 0031 }; 0032 } 0033 0034 using namespace KIMAP; 0035 0036 GetAclJob::GetAclJob(Session *session) 0037 : AclJobBase(*new GetAclJobPrivate(session, i18n("GetAcl"))) 0038 { 0039 } 0040 0041 GetAclJob::~GetAclJob() 0042 { 0043 } 0044 0045 void GetAclJob::doStart() 0046 { 0047 Q_D(GetAclJob); 0048 0049 d->tags << d->sessionInternal()->sendCommand("GETACL", '\"' + KIMAP::encodeImapFolderName(d->mailBox.toUtf8()) + '\"'); 0050 } 0051 0052 void GetAclJob::handleResponse(const Response &response) 0053 { 0054 Q_D(GetAclJob); 0055 // qCDebug(KIMAP_LOG) << response.toString(); 0056 0057 if (handleErrorReplies(response) == NotHandled) { 0058 if (response.content.size() >= 4 && response.content[1].toString() == "ACL") { 0059 int i = 3; 0060 while (i < response.content.size() - 1) { 0061 QByteArray id = response.content[i].toString(); 0062 QByteArray rights = response.content[i + 1].toString(); 0063 d->userRights[id] = Acl::rightsFromString(rights); 0064 i += 2; 0065 } 0066 } 0067 } 0068 } 0069 0070 QList<QByteArray> GetAclJob::identifiers() const 0071 { 0072 Q_D(const GetAclJob); 0073 return d->userRights.keys(); 0074 } 0075 0076 bool GetAclJob::hasRightEnabled(const QByteArray &identifier, Acl::Right right) const 0077 { 0078 Q_D(const GetAclJob); 0079 if (d->userRights.contains(identifier)) { 0080 Acl::Rights rights = d->userRights[identifier]; 0081 return rights & right; 0082 } 0083 0084 return false; 0085 } 0086 0087 Acl::Rights GetAclJob::rights(const QByteArray &identifier) const 0088 { 0089 Q_D(const GetAclJob); 0090 Acl::Rights result; 0091 if (d->userRights.contains(identifier)) { 0092 result = d->userRights[identifier]; 0093 } 0094 return result; 0095 } 0096 0097 QMap<QByteArray, Acl::Rights> GetAclJob::allRights() const 0098 { 0099 Q_D(const GetAclJob); 0100 return d->userRights; 0101 } 0102 0103 #include "moc_getacljob.cpp"